diff options
| author | Tom Tromey | 2017-08-27 12:54:01 -0600 |
|---|---|---|
| committer | Tom Tromey | 2017-08-27 12:54:19 -0600 |
| commit | 9e79a31c09d673019be2a2c78bf8b7db89351819 (patch) | |
| tree | cd9d5cf9d85b7fa9f30e3b88f3a258e9f874a7c8 | |
| parent | 5440b238b1ec4175dd32bc14b4098f6570b2ca85 (diff) | |
| download | emacs-9e79a31c09d673019be2a2c78bf8b7db89351819.tar.gz emacs-9e79a31c09d673019be2a2c78bf8b7db89351819.zip | |
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.
| -rw-r--r-- | lisp/progmodes/js.el | 5 | ||||
| -rw-r--r-- | test/lisp/progmodes/js-tests.el | 19 |
2 files changed, 24 insertions, 0 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index e6ffe4d75a6..cd315fb33ce 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', | |||
| 2380 | (fill-paragraph-function #'c-fill-paragraph)) | 2380 | (fill-paragraph-function #'c-fill-paragraph)) |
| 2381 | (c-fill-paragraph justify))) | 2381 | (c-fill-paragraph justify))) |
| 2382 | 2382 | ||
| 2383 | (defun js-do-auto-fill () | ||
| 2384 | (let ((js--filling-paragraph t)) | ||
| 2385 | (c-do-auto-fill))) | ||
| 2386 | |||
| 2383 | ;;; Type database and Imenu | 2387 | ;;; Type database and Imenu |
| 2384 | 2388 | ||
| 2385 | ;; We maintain a cache of semantic information, i.e., the classes and | 2389 | ;; 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." | |||
| 3863 | (setq-local comment-start "// ") | 3867 | (setq-local comment-start "// ") |
| 3864 | (setq-local comment-end "") | 3868 | (setq-local comment-end "") |
| 3865 | (setq-local fill-paragraph-function #'js-c-fill-paragraph) | 3869 | (setq-local fill-paragraph-function #'js-c-fill-paragraph) |
| 3870 | (setq-local normal-auto-fill-function #'js-do-auto-fill) | ||
| 3866 | 3871 | ||
| 3867 | ;; Parse cache | 3872 | ;; Parse cache |
| 3868 | (add-hook 'before-change-functions #'js--flush-caches t t) | 3873 | (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 8e1bac10cd1..4e27913930b 100644 --- a/test/lisp/progmodes/js-tests.el +++ b/test/lisp/progmodes/js-tests.el | |||
| @@ -60,6 +60,25 @@ | |||
| 60 | * Load the inspector's shared head.js for use by tests that need to | 60 | * Load the inspector's shared head.js for use by tests that need to |
| 61 | * open the something or other")))) | 61 | * open the something or other")))) |
| 62 | 62 | ||
| 63 | (ert-deftest js-mode-fill-comment-bug () | ||
| 64 | (with-temp-buffer | ||
| 65 | (insert "/** | ||
| 66 | * javadoc stuff here | ||
| 67 | * | ||
| 68 | * what | ||
| 69 | */ | ||
| 70 | function f( ) { | ||
| 71 | // comment-auto-fill-only-comments is a variable defined in ‘newcomment.el’. comment comment") | ||
| 72 | (js-mode) | ||
| 73 | (setq-local comment-auto-fill-only-comments t) | ||
| 74 | (setq-local fill-column 75) | ||
| 75 | (auto-fill-mode 1) | ||
| 76 | (funcall auto-fill-function) | ||
| 77 | (beginning-of-line) | ||
| 78 | ;; Filling should have inserted the correct comment start. | ||
| 79 | (should (equal (buffer-substring (point) (+ 7 (point))) | ||
| 80 | " // ")))) | ||
| 81 | |||
| 63 | (ert-deftest js-mode-regexp-syntax () | 82 | (ert-deftest js-mode-regexp-syntax () |
| 64 | (with-temp-buffer | 83 | (with-temp-buffer |
| 65 | ;; Normally indentation tests are done in manual/indent, but in | 84 | ;; Normally indentation tests are done in manual/indent, but in |