emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r111490: * lisp/progmodes/js.el: Fix


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111490: * lisp/progmodes/js.el: Fix multiline declarations's indentation.
Date: Fri, 11 Jan 2013 18:24:52 -0500
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111490
fixes bug: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8576
author: Felix H. Dahlke <address@hidden>
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Fri 2013-01-11 18:24:52 -0500
message:
  * 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.
modified:
  lisp/ChangeLog
  lisp/progmodes/js.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-01-11 23:08:55 +0000
+++ b/lisp/ChangeLog    2013-01-11 23:24:52 +0000
@@ -1,102 +1,63 @@
+2013-01-11  Felix H. Dahlke  <address@hidden>
+
+       * 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.
+
 2013-01-11  Aaron S. Hawley  <address@hidden>
 
        * calc/calc.el (calc-highlight-selections-with-faces)
-        (calc-dispatch): Fix ambiguous doc string cross-reference(s).
-
-       * comint.el (comint-history-isearch-message): Fix ambiguous doc
-        string cross-reference(s).
-
-       * emacs-lisp/edebug.el (edebug-read, edebug-eval-defun): Fix
-        ambiguous doc string cross-reference(s).
-
+        (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  <address@hidden>
 
        * 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)

=== modified file 'lisp/progmodes/js.el'
--- a/lisp/progmodes/js.el      2013-01-02 16:13:04 +0000
+++ b/lisp/progmodes/js.el      2013-01-11 23:24:52 +0000
@@ -1680,12 +1680,15 @@
      "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 @@
          (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 @@
            (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)


reply via email to

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