From f90ff90659871ee5df8408476a3e4b832a21b17c Mon Sep 17 00:00:00 2001 From: "Felix H. Dahlke" Date: Fri, 11 Jan 2013 18:24:52 -0500 Subject: [PATCH] * lisp/progmodes/js.el: Fix multiline declarations's indentation. (js--declaration-keyword-re): New var. (js--multi-line-declaration-indentation): New function. (js--proper-indentation): Use it. Fixes: debbugs:8576 --- lisp/ChangeLog | 107 ++++++++++++++++----------------------------------- lisp/progmodes/js.el | 37 +++++++++++++++++- 2 files changed, 70 insertions(+), 74 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a2dfb8023b3..c600e37570f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,102 +1,63 @@ -2013-01-11 Aaron S. Hawley - - * calc/calc.el (calc-highlight-selections-with-faces) - (calc-dispatch): Fix ambiguous doc string cross-reference(s). +2013-01-11 Felix H. Dahlke - * comint.el (comint-history-isearch-message): Fix ambiguous doc - string cross-reference(s). + * progmodes/js.el: Fix multiline declarations's indentation (bug#8576). + (js--declaration-keyword-re): New var. + (js--multi-line-declaration-indentation): New function. + (js--proper-indentation): Use it. - * emacs-lisp/edebug.el (edebug-read, edebug-eval-defun): Fix - ambiguous doc string cross-reference(s). +2013-01-11 Aaron S. Hawley + * calc/calc.el (calc-highlight-selections-with-faces) + (calc-dispatch): + * comint.el (comint-history-isearch-message): + * emacs-lisp/edebug.el (edebug-read, edebug-eval-defun): * ffap.el (ffap-string-at-point-region, ffap-next) (ffap-string-at-point, ffap-string-around) (ffap-copy-string-as-kill, ffap-highlight-overlay) - (ffap-literally): Fix ambiguous doc string cross-reference(s). - + (ffap-literally): * font-lock.el (font-lock-keywords-alist) - (font-lock-removed-keywords-alist): Fix ambiguous doc string - cross-reference(s). - - * help-mode.el (help-xref-symbol-regexp): Add "call" as a hint for - a cross-reference to a function. - - * info.el (Info-find-emacs-command-nodes): Fix ambiguous doc - string cross-reference(s). - - * international/mule.el (add-to-coding-system-list): Fix ambiguous - doc string cross-reference(s). - - * isearch.el (isearch-message-function, isearch-fail-pos): Fix - ambiguous doc string cross-reference(s). - - * misearch.el (multi-isearch-next-buffer-function): Fix ambiguous - doc string cross-reference(s). - - * newcomment.el (comment-box): Fix ambiguous doc string - cross-reference(s). - + (font-lock-removed-keywords-alist): + * help-mode.el (help-xref-symbol-regexp): + * info.el (Info-find-emacs-command-nodes): + * international/mule.el (add-to-coding-system-list): + * isearch.el (isearch-message-function, isearch-fail-pos): + * misearch.el (multi-isearch-next-buffer-function): + * newcomment.el (comment-box): * printing.el (pr-txt-printer-alist, pr-ps-printer-alist) - (pr-setting-database): Fix ambiguous doc string - cross-reference(s). - + (pr-setting-database): * progmodes/cc-fonts.el (c-font-lock-keywords-3) (c++-font-lock-keywords-3, objc-font-lock-keywords-3) (java-font-lock-keywords-3, idl-font-lock-keywords-3) - (pike-font-lock-keywords-3): Fix ambiguous doc string - cross-reference(s). - - * progmodes/compile.el (compile): Fix ambiguous doc string - cross-reference(s). - + (pike-font-lock-keywords-3): + * progmodes/compile.el (compile): * progmodes/etags.el (tags-table-files) - (tags-table-files-function, tags-included-tables-function): Fix - ambiguous doc string cross-reference(s). - + (tags-table-files-function, tags-included-tables-function): * progmodes/gdb-mi.el (gdb, gdb-setup-windows) - (gdb-restore-windows): Fix ambiguous doc string - cross-reference(s). - + (gdb-restore-windows): * ps-print.el (ps-even-or-odd-pages, ps-spool-buffer-with-faces) - (ps-n-up-filling-database): Fix ambiguous doc string - cross-reference(s). - - * server.el (server-buffer, server-log): Fix ambiguous doc string - cross-reference(s). - + (ps-n-up-filling-database): + * server.el (server-buffer, server-log): * simple.el (newline, delete-backward-char, delete-forward-char) (minibuffer-history-isearch-message, kill-line, track-eol) - (temporary-goal-column): Fix ambiguous doc string - cross-reference(s). - + (temporary-goal-column): * textmodes/flyspell.el (flyspell-mark-duplications-flag) - (flyspell-default-deplacement-commands): Fix ambiguous doc string - cross-reference(s). - - * textmodes/ispell.el (ispell-accept-output): Fix ambiguous doc - string cross-reference(s). - - * textmodes/sgml-mode.el (html-tag-help): Fix ambiguous doc string - cross-reference(s). - + (flyspell-default-deplacement-commands): + * textmodes/ispell.el (ispell-accept-output): + * textmodes/sgml-mode.el (html-tag-help): * vc/compare-w.el (compare-ignore-whitespace) - (compare-ignore-case, compare-windows-dehighlight): Fix ambiguous - doc string cross-reference(s). - - * vc/diff.el (diff): Fix ambiguous doc string cross-reference(s). - + (compare-ignore-case, compare-windows-dehighlight): + * vc/diff.el (diff): * whitespace.el (whitespace-point) (whitespace-font-lock-refontify, whitespace-bob-marker) - (whitespace-eob-marker): Fix ambiguous doc string - cross-reference(s). + (whitespace-eob-marker): Fix ambiguous doc string cross-reference(s). 2013-01-11 Michael Albinus * autorevert.el (top): Require 'cl in order to pacify byte compiler. (auto-revert-notify-rm-watch): Ignore errors. (auto-revert-notify-add-watch): Ignore errors. Use '(modify) for - inotify, and '(size last-write-time) for w32notify. Set - buffer-local `auto-revert-use-notify' to nil when adding a file + inotify, and '(size last-write-time) for w32notify. + Set buffer-local `auto-revert-use-notify' to nil when adding a file watch fails - this is a fallback to the file modification check. (auto-revert-notify-event-p, auto-revert-notify-event-descriptor) (auto-revert-notify-event-action) diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 683b3927ae3..96e6039a8c2 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -1680,12 +1680,15 @@ This performs fontification according to `js--class-styles'." "each")) "Regexp matching keywords optionally followed by an opening brace.") +(defconst js--declaration-keyword-re + (regexp-opt '("var" "let" "const") 'words) + "Regular expression matching variable declaration keywords.") + (defconst js--indent-operator-re (concat "[-+*/%<>=&^|?:.]\\([^-+*/]\\|$\\)\\|" (js--regexp-opt-symbol '("in" "instanceof"))) "Regexp matching operators that affect indentation of continued expressions.") - (defun js--looking-at-operator-p () "Return non-nil if point is on a JavaScript operator, other than a comma." (save-match-data @@ -1764,6 +1767,37 @@ nil." (list (cons 'c js-comment-lineup-func)))) (c-get-syntactic-indentation (list (cons symbol anchor))))) +(defun js--multi-line-declaration-indentation () + "Helper function for `js--proper-indentation'. +Return the proper indentation of the current line if it belongs to a declaration +statement spanning multiple lines; otherwise, return nil." + (let (at-opening-bracket) + (save-excursion + (back-to-indentation) + (when (not (looking-at js--declaration-keyword-re)) + (when (looking-at js--indent-operator-re) + (goto-char (match-end 0))) + (while (and (not at-opening-bracket) + (not (bobp)) + (let ((pos (point))) + (save-excursion + (js--backward-syntactic-ws) + (or (eq (char-before) ?,) + (and (not (eq (char-before) ?\;)) + (prog2 + (skip-chars-backward "[[:punct:]]") + (looking-at js--indent-operator-re) + (js--backward-syntactic-ws)) + (not (eq (char-before) ?\;))) + (and (>= pos (point-at-bol)) + (<= pos (point-at-eol))))))) + (condition-case err + (backward-sexp) + (scan-error (setq at-opening-bracket t)))) + (when (looking-at js--declaration-keyword-re) + (goto-char (match-end 0)) + (1+ (current-column))))))) + (defun js--proper-indentation (parse-status) "Return the proper indentation for the current line." (save-excursion @@ -1772,6 +1806,7 @@ nil." (js--get-c-offset 'c (nth 8 parse-status))) ((nth 8 parse-status) 0) ; inside string ((js--ctrl-statement-indentation)) + ((js--multi-line-declaration-indentation)) ((eq (char-after) ?#) 0) ((save-excursion (js--beginning-of-macro)) 4) ((nth 1 parse-status) -- 2.11.4.GIT