From a463d7b7c1a8e8734ac4bd7be4b32528c2a7614c Mon Sep 17 00:00:00 2001 From: Etienne Date: Mon, 17 Apr 2017 23:35:21 -0400 Subject: [PATCH] Fix js.el filling inline JSDoc tags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lisp/progmodes/js.el (js-inline-jsdoc-tag-p): Add this predicate function to check if the point is inside an inline JSDoc tag. (js-mode): Add `js-inline-jsdoc-tag-p' to `fill-nobreak-predicate' hook. * test/lisp/progmodes/js-tests.el (js-mode-fill-fill-jsdoc-at-start): Add this test to check that a paragraph starts from “@” according to the local `c-paragraph-start' value. * test/lisp/progmodes/js-tests.el (js-mode-fill-inline-jsdoc-tag): Add this test to check filling doesn’t break an inline JSDoc tag. --- lisp/progmodes/js.el | 11 +++++++++++ test/lisp/progmodes/js-tests.el | 31 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index bae9e52..6ea3590 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -2733,6 +2733,13 @@ current buffer. Pushes a mark onto the tag ring just like (push-mark) (goto-char marker))) +(defun js-inline-jsdoc-tag-p () + "Return non-nil if the point is inside an inline JSDoc tag. +This function is useful for adding to the hook `fill-nobreak-predicate', +to prevent the breaking of a line inside an inline JSDoc tag." + ;; First check that we’re inside a comment + (thing-at-point-looking-at "{@\\(?:tutorial\\|link\\(?:code\\|plain\\)?\\).*}")) + ;;; MozRepl integration (define-error 'js-moz-bad-rpc "Mozilla RPC Error") ;; '(timeout error)) @@ -3876,6 +3883,10 @@ If one hasn't been set, or if it's stale, prompt for a new one." c-line-comment-starter "//" c-comment-start-regexp "/[*/]\\|\\s!" comment-start-skip "\\(//+\\|/\\*+\\)\\s *") + + ;; Prevent {@tag foo} from filling + (add-hook 'fill-nobreak-predicate #'js-inline-jsdoc-tag-p nil t) + (setq-local comment-line-break-function #'c-indent-new-comment-line) (setq-local c-block-comment-start-regexp "/\\*") (setq-local comment-multi-line t) diff --git a/test/lisp/progmodes/js-tests.el b/test/lisp/progmodes/js-tests.el index 8e1bac1..973cac7 100644 --- a/test/lisp/progmodes/js-tests.el +++ b/test/lisp/progmodes/js-tests.el @@ -60,6 +60,37 @@ * Load the inspector's shared head.js for use by tests that need to * open the something or other")))) +(ert-deftest js-mode-fill-fill-jsdoc-at-start () + (with-temp-buffer + (insert "/**\n") + (insert " * Load the inspector's shared head.js for use by tests that ") + (insert "need to open the something or other\n") + (insert " * @foo") + (js-mode) + (goto-char (point-min)) + (fill-paragraph) + (should (equal (buffer-substring (point-min) (point-max)) + "/** + * Load the inspector's shared head.js for use by tests that need to + * open the something or other + * @foo")))) + +(ert-deftest js-mode-fill-inline-jsdoc-tag () + (with-temp-buffer + (insert "/**\n") + (insert " * Load the inspector's shared head.js for use by tests that ") + (insert "{@link document.body.style} need to open the something or other\n") + (insert " * @foo") + (js-mode) + (goto-char (point-min)) + (fill-paragraph) + (should (equal (buffer-substring (point-min) (point-max)) + "/** + * Load the inspector's shared head.js for use by tests + * that {@link document.body.style} need to open the something or + * other + * @foo")))) + (ert-deftest js-mode-regexp-syntax () (with-temp-buffer ;; Normally indentation tests are done in manual/indent, but in -- 2.7.4