From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Smie-auto-fill =?utf-8?Q?doesn=E2=80=99t?= respect comment-auto-fill-only-comments Date: Sun, 30 Apr 2017 13:52:44 -0400 Message-ID: References: <87o9vdj0s5.fsf@tromey.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1493574782 13196 195.159.176.226 (30 Apr 2017 17:53:02 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 30 Apr 2017 17:53:02 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Apr 30 19:52:59 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d4t1j-0003LU-W5 for ged-emacs-devel@m.gmane.org; Sun, 30 Apr 2017 19:52:56 +0200 Original-Received: from localhost ([::1]:45447 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4t1p-0003XN-Ir for ged-emacs-devel@m.gmane.org; Sun, 30 Apr 2017 13:53:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4t1i-0003X6-Tz for emacs-devel@gnu.org; Sun, 30 Apr 2017 13:52:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d4t1f-0005C9-SF for emacs-devel@gnu.org; Sun, 30 Apr 2017 13:52:55 -0400 Original-Received: from [195.159.176.226] (port=36241 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d4t1f-0005Bw-Ld for emacs-devel@gnu.org; Sun, 30 Apr 2017 13:52:51 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1d4t1Y-0003B7-1Z for emacs-devel@gnu.org; Sun, 30 Apr 2017 19:52:44 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 76 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:xY34D9GeDsSdTKRPQ3i1tHgta6o= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:214447 Archived-At: >> This won't fix the SMIE issue though. That would require a similar fix >> in smie-auto-fill. > We should try and find a solution which doesn't require changing every > normal-auto-fill-function. I think the patch below "does the trick" but it's rather ugly. Stefan diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 4b261c34c6..6a2bf35788 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el @@ -1316,13 +1316,6 @@ comment-dwim (insert (comment-padleft comment-end add))) (indent-according-to-mode))))))) -;;;###autoload -(defcustom comment-auto-fill-only-comments nil - "Non-nil means to only auto-fill inside comments. -This has no effect in modes that do not define a comment syntax." - :type 'boolean - :group 'comment) - (defun comment-valid-prefix-p (prefix compos) "Check that the adaptive fill prefix is consistent with the context. PREFIX is the prefix (presumably guessed by `adaptive-fill-mode'). @@ -1384,7 +1377,6 @@ comment-indent-new-line ;; If we are not inside a comment and we only auto-fill comments, ;; don't do anything (unless no comment syntax is defined). (unless (and comment-start - comment-auto-fill-only-comments (not (called-interactively-p 'interactive)) (not (save-excursion (prog1 (setq compos (comment-beginning)) diff --git a/lisp/simple.el b/lisp/simple.el index edc822eb51..72f265d544 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -7175,6 +7175,12 @@ normal-auto-fill-function ;; can be useful to prevent auto-filling. (put 'auto-fill-function 'safe-local-variable 'null) +(defcustom comment-auto-fill-only-comments nil + "Non-nil means to only auto-fill inside comments. +This has no effect in modes that do not define a comment syntax." + :type 'boolean + :group 'comment) + (define-minor-mode auto-fill-mode "Toggle automatic line breaking (Auto Fill mode). With a prefix argument ARG, enable Auto Fill mode if ARG is @@ -7191,8 +7197,19 @@ auto-fill-mode The value of `normal-auto-fill-function' specifies the function to use for `auto-fill-function' when turning Auto Fill mode on." :variable (auto-fill-function - . (lambda (v) (setq auto-fill-function - (if v normal-auto-fill-function))))) + . (lambda (v) + (if (not v) + (setq auto-fill-function nil) + (setq auto-fill-function normal-auto-fill-function) + (add-function :around normal-auto-fill-function + (lambda (orig-fun &rest args) + (if (and comment-start + comment-auto-fill-only-comments + (not (nth 4 (syntax-ppss)))) + ;; Comments exist and we only want to + ;; auto-fill them but we're not in one! + nil + (apply orig-fun args)))))))) ;; This holds a document string used to document auto-fill-mode. (defun auto-fill-function ()