all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Smie-auto-fill doesn’t respect comment-auto-fill-only-comments
Date: Sun, 21 May 2017 10:43:53 -0600	[thread overview]
Message-ID: <87r2zidut2.fsf@bapiya> (raw)
In-Reply-To: <jwv7f1zkrep.fsf-monnier+gmane.emacs.devel@gnu.org> (Stefan Monnier's message of "Tue, 02 May 2017 15:18:43 -0400")

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");



  parent reply	other threads:[~2017-05-21 16:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-06 12:04 Smie-auto-fill doesn’t respect comment-auto-fill-only-comments Nikolai Weibull
2017-04-23 19:31 ` Nikolai Weibull
2017-04-25  0:18   ` Ian Dunn
2017-04-30 16:52 ` Tom Tromey
2017-04-30 17:08   ` Stefan Monnier
2017-04-30 17:52     ` Stefan Monnier
2017-05-02 18:57       ` Tom Tromey
2017-05-02 19:18         ` Stefan Monnier
2017-05-03  1:14           ` Ian Dunn
2017-05-21 16:43           ` Tom Tromey [this message]
2017-05-21 21:03             ` Stefan Monnier
2017-05-22  6:24               ` Tom Tromey
2017-05-22 19:12                 ` Stefan Monnier
2017-05-29 21:20                   ` Tom Tromey
2017-05-30  3:25                     ` Stefan Monnier
2017-08-05 20:39                       ` Tom Tromey
2017-08-05 20:50                         ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r2zidut2.fsf@bapiya \
    --to=tom@tromey.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.