[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, 30 Apr 2017 10:52:26 -0600 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) |
>>>>> "Nikolai" == Nikolai Weibull <address@hidden> writes:
Nikolai> Smie-auto-fill doesn’t respect comment-auto-fill-only-comments. I’m
Nikolai> not quite sure whether it actually should, but the issue I’m having is
Nikolai> that auto-fill is being applied in sh-mode, even though I have
Nikolai> comment-auto-fill-only-comments.
I recently noticed this for other programming modes, like js-mode.
I wasn't sure if this is some recent(-ish) change or if I just never
happened to notice it before somehow.
Anyway, I'm trying out the appended, which I'd like to push in.
This won't fix the SMIE issue though. That would require a similar fix
in smie-auto-fill.
Or maybe this should just be done directly in do-auto-fill itself?
Tom
diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el
index 8f66f1c..b5bb637 100644
--- a/lisp/progmodes/prog-mode.el
+++ b/lisp/progmodes/prog-mode.el
@@ -129,6 +129,11 @@ prog-widen
(narrow-to-region (car chunk) (or (cdr chunk) (point-max)))
(widen))))
+(defun prog-mode-do-auto-fill ()
+ "Like `do-auto-fill' but respect `comment-auto-fill-only-comments'."
+ (when (or (not comment-auto-fill-only-comments)
+ (nth 4 (syntax-ppss)))
+ (do-auto-fill)))
(defvar-local prettify-symbols-alist nil
"Alist of symbol prettifications.
@@ -293,6 +298,7 @@ prog-mode
"Major mode for editing programming language source code."
(setq-local require-final-newline mode-require-final-newline)
(setq-local parse-sexp-ignore-comments t)
+ (setq-local normal-auto-fill-function #'prog-mode-do-auto-fill)
;; Any programming language is always written left to right.
(setq bidi-paragraph-direction 'left-to-right))