From: Jackson Hamilton <jackson@jacksonrayhamilton.com>
To: emacs-devel <emacs-devel@gnu.org>
Subject: Requesting patch review
Date: Sat, 7 Mar 2015 18:09:01 -0800 [thread overview]
Message-ID: <CAGiE8AzsfKi6YH2FP247H1cZOpS2nyPVDTmB0tYu6U3AM5XLUQ@mail.gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 123 bytes --]
Hi guys,
New patch for js-mode. Adds a new indentation option. I would appreciate
review before merging.
Thanks,
Jackson
[-- Attachment #1.2: Type: text/html, Size: 202 bytes --]
[-- Attachment #2: 0001-New-indentation-option-for-js-mode.patch --]
[-- Type: text/x-patch, Size: 4144 bytes --]
From 4915e411a22eeefc9561639f5cde2bbdf1731c00 Mon Sep 17 00:00:00 2001
From: Jackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Date: Sat, 7 Mar 2015 18:01:05 -0800
Subject: [PATCH] New indentation option for js-mode
* lisp/progmodes/js.el (js--proper-indentation): Add and use custom
option `js-dynamic-multi-line-declaration-indentation'.
---
lisp/ChangeLog | 5 +++++
lisp/progmodes/js.el | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0b277c7..2609693 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-07 Jackson Ray Hamilton <jackson@jacksonrayhamilton.com>
+
+ * lisp/progmodes/js.el (js--proper-indentation): Add and use new
+ custom option `js-dynamic-multi-line-declaration-indentation'.
+
2015-03-07 Stefan Monnier <monnier@iro.umontreal.ca>
* battery.el (battery-echo-area-format): Simplify default.
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index d7712e4..2f00da0 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -509,6 +509,37 @@ getting timeout messages."
:type 'integer
:group 'js)
+(defcustom js-dynamic-multi-line-declaration-indentation nil
+ "Non-nil to indent the first function, array or object literal
+in a multi-line variable declaration specially.
+
+Normally, the first item is unindented, and subsequent items have
+their identifiers lined up against the first:
+
+ var o = {
+ foo: 3
+ };
+
+ var o = {
+ foo: 3
+ },
+ bar = 2;
+
+With this option enabled, the first declaration will be indented
+if there are more declarations, such that the first function,
+array or object lines up nicely with the remaining declarations:
+
+ var o = {
+ foo: 3
+ };
+
+ var o = {
+ foo: 3
+ },
+ bar = 2;"
+ :type 'boolean
+ :group 'js)
+
;;; KeyMap
(defvar js-mode-map
@@ -1884,13 +1915,34 @@ In particular, return the buffer position of the first `for' kwd."
;; "case" and "default".
(let ((same-indent-p (looking-at "[]})]"))
(switch-keyword-p (looking-at "default\\_>\\|case\\_>[^:]"))
- (continued-expr-p (js--continued-expression-p)))
+ (continued-expr-p (js--continued-expression-p))
+ declaration-keyword-end)
(goto-char (nth 1 parse-status)) ; go to the opening char
(if (looking-at "[({[]\\s-*\\(/[/*]\\|$\\)")
(progn ; nothing following the opening paren/bracket
(skip-syntax-backward " ")
(when (eq (char-before) ?\)) (backward-list))
(back-to-indentation)
+ (when (and js-dynamic-multi-line-declaration-indentation
+ ;; Check the condition and
+ ;; simultaneously preserve the match
+ ;; data.
+ (when (looking-at js--declaration-keyword-re)
+ (setq declaration-keyword-end (match-end 0)))
+ ;; Determine if the declaration
+ ;; statement has multiple declarations
+ ;; (implied if at least one is separated
+ ;; by a ",").
+ (save-excursion
+ (goto-char (nth 1 parse-status))
+ (when (condition-case nil
+ (progn
+ (forward-sexp)
+ t)
+ (error nil))
+ (while (forward-comment 1))
+ (looking-at ","))))
+ (goto-char (1+ declaration-keyword-end)))
(let* ((in-switch-p (unless same-indent-p
(looking-at "\\_<switch\\_>")))
(same-indent-p (or same-indent-p
--
1.9.1
next reply other threads:[~2015-03-08 2:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-08 2:09 Jackson Hamilton [this message]
2015-03-08 8:16 ` Requesting patch review Thien-Thi Nguyen
2015-03-08 17:55 ` Dmitry Gutov
2015-03-08 22:01 ` Jackson Hamilton
2015-03-09 23:36 ` Dmitry Gutov
2015-03-10 1:34 ` Jackson Hamilton
2015-03-10 3:22 ` Stefan Monnier
2015-03-10 16:04 ` Dmitry Gutov
2015-03-10 23:39 ` Paul Eggert
2015-03-10 0:40 ` Running test/indent examples, Was: " Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAGiE8AzsfKi6YH2FP247H1cZOpS2nyPVDTmB0tYu6U3AM5XLUQ@mail.gmail.com \
--to=jackson@jacksonrayhamilton.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).