変更したい動作は、 という関数にハードコードされていますjs--proper-indentation
。あなたの問題に対する洗練されていない修正は、.emacs の関数を置き換えることです:
(require 'cl)
(eval-after-load "js" '(defun js--proper-indentation (parse-status)
"Return the proper indentation for the current line."
(save-excursion
(back-to-indentation)
(cond ((nth 4 parse-status)
(js--get-c-offset 'c (nth 8 parse-status)))
((nth 8 parse-status) 0) ; inside string
((js--ctrl-statement-indentation))
((eq (char-after) ?#) 0)
((save-excursion (js--beginning-of-macro)) 4)
((nth 1 parse-status)
;; A single closing paren/bracket should be indented at the
;; same level as the opening statement. Same goes for
;; "case" and "default".
(let ((same-indent-p (looking-at
"[]})]\\|\\_<case\\_>\\|\\_<default\\_>"))
(continued-expr-p (js--continued-expression-p)))
(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)
(cond (same-indent-p
(current-column))
(continued-expr-p
(+ (current-column) (* 2 js-indent-level)
js-expr-indent-offset))
(t
(+ (current-column) js-indent-level
(case (char-after (nth 1 parse-status))
(?\( js-paren-indent-offset)
(?\[ js-square-indent-offset)
(?\{ js-curly-indent-offset))))))
;; If there is something following the opening
;; paren/bracket, everything else should be indented at
;; the same level.
;; Modified code here:
(unless same-indent-p
(move-beginning-of-line 1)
(forward-char 4))
;; End modified code
(current-column))))
((js--continued-expression-p)
(+ js-indent-level js-expr-indent-offset))
(t 0)))) )
関数の下部に向かって 3 行のコードを変更しました。インデントを 4 文字ではなく 8 文字にしたい場合は、(forward-char 4)
それに応じて行を変更してください。
js--proper-indentation
(およびjsライブラリには)cl.elライブラリが必要ですが、使用するとこれが台無しになることに注意してくださいeval-after-load
。cl
したがって、これを機能させるには、.emacs で明示的に require する必要があります。
この「ソリューション」は、指定した状況でのみ 4 スペースのインデントをハード コードし、ネストされたコードをまったく処理しないことに注意してください。しかし、自分の状況に対処するコードのポイントを知ることで、少なくとも、より洗練されたソリューションのために作業が必要な部分を知ることができます。