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: Sun, 21 May 2017 10:43:53 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Stefan> Not sure what you mean: "a function that wraps (the captured value of)
Stefan> normal-auto-fill-function" is exactly what add-function creates.

Yeah, not sure what I was thinking either.

Stefan> But maybe a cleaner patch would change the C code so it doesn't (funcall
Stefan> auto-fill-function) directly but instead it calls a fixed Elisp function
Stefan> which does the comment-auto-fill-only-comments check and then funcalls
Stefan> auto-fill-function.  This would probably make it desirable to
Stefan> move auto-fill-function from buffer.c to simple.el or fill.el.

Here's a patch to do this.

I kept auto-fill-function in the C code because internal_self_insert
checks its value, which seems like it could possibly still be a relevant
optimization.  It's easy enough to remove, though, if you think that's
safe.

Another question is whether prog-mode should set
comment-auto-fill-only-comments.  I tend to think so, but of course
I'm already doing that in my .emacs...

Let me know what you think.  I'd like to push this, or one of these
patches, because this is the main bug I run into in ordinary Emacs use.

Tom

diff --git a/lisp/simple.el b/lisp/simple.el
index ea3a495..971be6b 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -7191,6 +7191,12 @@ 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-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]