bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#27503: 26.0.50; Not lining up Javascript arguments


From: Ingo Lohmar
Subject: bug#27503: 26.0.50; Not lining up Javascript arguments
Date: Sat, 01 Jul 2017 13:23:20 +0200

On Thu, Jun 29 2017 03:52 (+0300), Dmitry Gutov wrote:

> On 6/28/17 5:56 PM, Ingo Lohmar wrote:
>> Rigidly was just meant as the opposite of the default "aligned" 
>> indentation, I am not attached to the variable name *at all*. Maybe 
>> ...-indent-aligned and change the default to t?
>
> Sounds good to me. Maybe also add an example file in test/manual/indent?

Hi Dmitry,

I hope I understood the manual/indent idea correctly.  Below is the
updated patch including a test file.

I changed the variable name to `js-indent-cont-nonempty-aligned' now
(with "flipped" boolean meaning, as discussed before).  This is more
succinct and starts with `js-indent-...' to convey the feature area to
which this setting belongs.

What's the procedure for patches arising from a bug report --- should I
add a NEWS entry (for 26.1, marked +++) and just commit this to master
myself?



>From f0ec15d5fa82b0ca9b4c6aa7032262252ab63e40 Mon Sep 17 00:00:00 2001
From: Ingo Lohmar <address@hidden>
Date: Sat, 1 Jul 2017 13:09:20 +0200
Subject: [PATCH] Offer non-aligned indentation in lists in js-mode (Bug#27503)

* lisp/progmodes/js.el (js--proper-indentation):
New customization option 'js-indent-cont-nonempty-aligned'.  Affects
argument lists as well as arrays and object properties.
* test/manual/indent/js-indent-cont-nonempty-aligned-nil.js: Test the change.
---
 lisp/progmodes/js.el                                 |  8 +++++++-
 .../indent/js-indent-cont-nonempty-aligned-nil.js    | 20 ++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 test/manual/indent/js-indent-cont-nonempty-aligned-nil.js

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index bae9e52bf0..d284ddae4d 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -475,6 +475,11 @@ js-flat-functions
   :type 'boolean
   :group 'js)
 
+(defcustom js-indent-cont-nonempty-aligned t
+  "Align continuation of non-empty ([{ lines in `js-mode'."
+  :type 'boolean
+  :group 'js)
+
 (defcustom js-comment-lineup-func #'c-lineup-C-comments
   "Lineup function for `cc-mode-style', for C comments in `js-mode'."
   :type 'function
@@ -2092,7 +2097,8 @@ js--proper-indentation
                  (switch-keyword-p (looking-at "default\\_>\\|case\\_>[^:]"))
                  (continued-expr-p (js--continued-expression-p)))
              (goto-char (nth 1 parse-status)) ; go to the opening char
-             (if (looking-at "[({[]\\s-*\\(/[/*]\\|$\\)")
+             (if (or (not js-indent-cont-nonempty-aligned)
+                     (looking-at "[({[]\\s-*\\(/[/*]\\|$\\)"))
                  (progn ; nothing following the opening paren/bracket
                    (skip-syntax-backward " ")
                    (when (eq (char-before) ?\)) (backward-list))
diff --git a/test/manual/indent/js-indent-cont-nonempty-aligned-nil.js 
b/test/manual/indent/js-indent-cont-nonempty-aligned-nil.js
new file mode 100644
index 0000000000..428e922fbb
--- /dev/null
+++ b/test/manual/indent/js-indent-cont-nonempty-aligned-nil.js
@@ -0,0 +1,20 @@
+const funcAssignment = function (arg1,
+    arg2,
+    arg3) {
+    return { test: this,
+        which: "would",
+        align: "as well with the default setting"
+    };
+}
+
+function funcDeclaration(arg1,
+    arg2
+) {
+    return [arg1,
+        arg2];
+}
+
+// Local Variables:
+// indent-tabs-mode: nil
+// js-indent-cont-nonempty-aligned: nil
+// End:
-- 
2.11.0






reply via email to

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