emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 9e79a31: Fix auto-fill bug in js-mode


From: Tom Tromey
Subject: [Emacs-diffs] master 9e79a31: Fix auto-fill bug in js-mode
Date: Sun, 27 Aug 2017 14:55:09 -0400 (EDT)

branch: master
commit 9e79a31c09d673019be2a2c78bf8b7db89351819
Author: Tom Tromey <address@hidden>
Commit: Tom Tromey <address@hidden>

    Fix auto-fill bug in js-mode
    
    * lisp/progmodes/js.el (js-do-auto-fill): New function.
    (js-mode): Set normal-auto-fill-function.
    * test/lisp/progmodes/js-tests.el (js-mode-fill-comment-bug): New
    test.
---
 lisp/progmodes/js.el            |  5 +++++
 test/lisp/progmodes/js-tests.el | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index e6ffe4d..cd315fb 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -2380,6 +2380,10 @@ i.e., customize JSX element indentation with 
`sgml-basic-offset',
         (fill-paragraph-function #'c-fill-paragraph))
     (c-fill-paragraph justify)))
 
+(defun js-do-auto-fill ()
+  (let ((js--filling-paragraph t))
+    (c-do-auto-fill)))
+
 ;;; Type database and Imenu
 
 ;; We maintain a cache of semantic information, i.e., the classes and
@@ -3863,6 +3867,7 @@ If one hasn't been set, or if it's stale, prompt for a 
new one."
   (setq-local comment-start "// ")
   (setq-local comment-end "")
   (setq-local fill-paragraph-function #'js-c-fill-paragraph)
+  (setq-local normal-auto-fill-function #'js-do-auto-fill)
 
   ;; Parse cache
   (add-hook 'before-change-functions #'js--flush-caches t t)
diff --git a/test/lisp/progmodes/js-tests.el b/test/lisp/progmodes/js-tests.el
index 8e1bac1..4e27913 100644
--- a/test/lisp/progmodes/js-tests.el
+++ b/test/lisp/progmodes/js-tests.el
@@ -60,6 +60,25 @@
  * Load the inspector's shared head.js for use by tests that need to
  * open the something or other"))))
 
+(ert-deftest js-mode-fill-comment-bug ()
+  (with-temp-buffer
+    (insert "/**
+ * javadoc stuff here
+ *
+ * what
+ */
+function f( ) {
+    // comment-auto-fill-only-comments is a variable defined in 
‘newcomment.el’. comment comment")
+    (js-mode)
+    (setq-local comment-auto-fill-only-comments t)
+    (setq-local fill-column 75)
+    (auto-fill-mode 1)
+    (funcall auto-fill-function)
+    (beginning-of-line)
+    ;; Filling should have inserted the correct comment start.
+    (should (equal (buffer-substring (point) (+ 7 (point)))
+                   "    // "))))
+
 (ert-deftest js-mode-regexp-syntax ()
   (with-temp-buffer
     ;; Normally indentation tests are done in manual/indent, but in



reply via email to

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