emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Smie-auto-fill doesn’t respect comment-auto-fill-only-comments


From: Tom Tromey
Subject: Re: Smie-auto-fill doesn’t respect comment-auto-fill-only-comments
Date: Mon, 22 May 2017 00:24:20 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Stefan> Please check also comment-start, since you don't want to check
Stefan> (syntax-ppss) if there's no comment-start defined.  Well, technically,
Stefan> it shouldn't make any difference, but it's the way it's been defined so
Stefan> far, so it makes sense to preserve it.

Stefan> The patch looks good, but please also remove the
Stefan> comment-auto-fill-only-comments handling from newcomment.el

Like the appended?
I wasn't sure if I did the newcomment.el part correctly.

Also, any comment on the prog-mode suggestion?

thanks,
Tom

diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index 4b261c3..44dd7e1 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -1381,10 +1381,9 @@ comment-indent-new-line
   (interactive)
   (comment-normalize-vars t)
   (let (compos comin)
-    ;; If we are not inside a comment and we only auto-fill comments,
-    ;; don't do anything (unless no comment syntax is defined).
+    ;; If we are not inside a comment 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 ea3a495..33a4082 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -7191,6 +7191,13 @@ default-indent-new-line
        ;; If we're not inside a comment, just try to indent.
        (t (indent-according-to-mode))))))
 
+(defun internal-auto-fill ()
+  "The function called by `self-insert-command' to perform auto-filling."
+  (when (or (not comment-start)
+            (not comment-auto-fill-only-comments)
+            (nth 4 (syntax-ppss)))
+    (do-auto-fill)))
+
 (defvar normal-auto-fill-function 'do-auto-fill
   "The function to use for `auto-fill-function' if Auto Fill mode is turned on.
 Some major modes set this.")
diff --git a/src/cmds.c b/src/cmds.c
index 51652d5..6f2db86 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -268,9 +268,10 @@ Whichever character you type to run this command is 
inserted.
 The numeric prefix argument N says how many times to repeat the insertion.
 Before insertion, `expand-abbrev' is executed if the inserted character does
 not have word syntax and the previous character in the buffer does.
-After insertion, the value of `auto-fill-function' is called if the
-`auto-fill-chars' table has a non-nil value for the inserted character.
-At the end, it runs `post-self-insert-hook'.  */)
+After insertion, `internal-auto-fill' is called if
+`auto-fill-function' is non-nil and if the `auto-fill-chars' table has
+a non-nil value for the inserted character.  At the end, it runs
+`post-self-insert-hook'.  */)
   (Lisp_Object n)
 {
   CHECK_NUMBER (n);
@@ -475,7 +476,7 @@ internal_self_insert (int c, EMACS_INT n)
           that.  Must have the newline in place already so filling and
           justification, if any, know where the end is going to be.  */
        SET_PT_BOTH (PT - 1, PT_BYTE - 1);
-      auto_fill_result = call0 (BVAR (current_buffer, auto_fill_function));
+      auto_fill_result = call0 (Qinternal_auto_fill);
       /* Test PT < ZV in case the auto-fill-function is strange.  */
       if (c == '\n' && PT < ZV)
        SET_PT_BOTH (PT + 1, PT_BYTE + 1);
@@ -494,6 +495,8 @@ internal_self_insert (int c, EMACS_INT n)
 void
 syms_of_cmds (void)
 {
+  DEFSYM (Qinternal_auto_fill, "internal-auto-fill");
+
   DEFSYM (Qundo_auto_amalgamate, "undo-auto-amalgamate");
   DEFSYM (Qundo_auto__this_command_amalgamating,
           "undo-auto--this-command-amalgamating");



reply via email to

[Prev in Thread] Current Thread [Next in Thread]