From 9ac7dccc51ee834b06cdabf6a5746eb375f984f0 Mon Sep 17 00:00:00 2001 From: Ingo Lohmar 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-align-list-continuation'. Affects argument lists as well as arrays and object properties. * test/manual/indent/js-indent-align-list-continuation-nil.js: Test the change. --- etc/NEWS | 9 ++++++++- lisp/progmodes/js.el | 8 +++++++- .../js-indent-align-list-continuation-nil.js | 20 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 test/manual/indent/js-indent-align-list-continuation-nil.js diff --git a/etc/NEWS b/etc/NEWS index 2afed2d2534..a766642ef22 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -839,8 +839,15 @@ initialization files. --- ** 'auto-revert-use-notify' is set back to t in 'global-auto-revert-mode'. +** JS mode + +--- +*** JS mode now sets 'comment-multi-line' to t. + --- -** JS mode now sets 'comment-multi-line' to t. +*** New variable 'js-indent-align-list-continuation', when set to nil, +will not align continuations of bracketed lists, but will indent them +by the fixed width 'js-indent-level'. ** CSS mode diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index bae9e52bf0f..e6ffe4d75a6 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -475,6 +475,11 @@ This applies to function movement, marking, and so on." :type 'boolean :group 'js) +(defcustom js-indent-align-list-continuation 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 @@ indentation is aligned to that column." (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-align-list-continuation) + (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-align-list-continuation-nil.js b/test/manual/indent/js-indent-align-list-continuation-nil.js new file mode 100644 index 00000000000..383b2539a26 --- /dev/null +++ b/test/manual/indent/js-indent-align-list-continuation-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-align-list-continuation: nil +// End: -- 2.39.2