diff options
author | Victor Ren <[email protected]> | 2016-11-13 03:53:46 +0100 |
---|---|---|
committer | Victor Ren <[email protected]> | 2016-11-19 02:09:05 +0100 |
commit | ba7110c1565a7ca1272a647425aa573596347a47 (patch) | |
tree | 473506184ed78aeccd041d91d088b368b0bcc9aa | |
parent | b4c76edc46f82a4d09d9f569e1d4e6013b265389 (diff) | |
download | otp-ba7110c1565a7ca1272a647425aa573596347a47.tar.gz otp-ba7110c1565a7ca1272a647425aa573596347a47.tar.bz2 otp-ba7110c1565a7ca1272a647425aa573596347a47.zip |
Add an option erlang-icr-indent
The option makes it possible to customize the indention of
if/case/recieve patterns.
Before the change, the indentation of 'if' patterns is 3 steps and
'case' patterns is 4 steps. It cannot be changed alone. Some people
prefer other styles, for example, zero indentation.
case a of
true ->
do_something();
false ->
do_something_else()
end.
This patch just adds an option `erlang-icr-indent'. Its default value is
`nil' which means keeping the legacy behavior. When non-nil, the
pattens of if/case/receive are indented according to
`erlang-icr-indent'. "(setq erlang-icr-indent 0)" will keep
if/case/receive at the same column of the sub-clauses.
Change-Id: I10c32e42dbf69cbe187f55223b9aa7824853e493
-rw-r--r-- | lib/tools/emacs/erlang.el | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/tools/emacs/erlang.el b/lib/tools/emacs/erlang.el index 40f0bb7f80..39c6065ce4 100644 --- a/lib/tools/emacs/erlang.el +++ b/lib/tools/emacs/erlang.el @@ -479,6 +479,11 @@ To activate the workaround, place the following in your `~/.emacs' file: "*Indentation of Erlang calls/clauses within blocks.") (put 'erlang-indent-level 'safe-local-variable 'integerp) +(defvar erlang-icr-indent nil + "*Indentation of Erlang if/case/receive/ patterns. `nil' means + keeping default behavior. When non-nil, indent to th column of + if/case/receive.") + (defvar erlang-indent-guard 2 "*Indentation of Erlang guards.") (put 'erlang-indent-guard 'safe-local-variable 'integerp) @@ -2919,14 +2924,16 @@ Return nil if inside string, t if in a comment." (t (save-excursion (goto-char (nth 1 stack-top)) - (if (looking-at "case[^_a-zA-Z0-9]") - (+ (nth 2 stack-top) erlang-indent-level) - (skip-chars-forward "a-z") - (skip-chars-forward " \t") - (if (memq (following-char) '(?% ?\n)) + (if (and erlang-icr-indent + (looking-at "\\(if\\|case\\|receive\\)[^_a-zA-Z0-9]")) + (+ (nth 2 stack-top) erlang-icr-indent) + (if (looking-at "\\(case\\|receive\\)[^_a-zA-Z0-9]") (+ (nth 2 stack-top) erlang-indent-level) - (current-column)))))) - ) + (skip-chars-forward "a-z") + (skip-chars-forward " \t") + (if (memq (following-char) '(?% ?\n)) + (+ (nth 2 stack-top) erlang-indent-level) + (current-column)))))))) ((and (eq (car stack-top) '||) (looking-at "\\(]\\|>>\\)[^_a-zA-Z0-9]")) (nth 2 (car (cdr stack)))) ;; Real indentation, where operators create extra indentation etc. @@ -2948,7 +2955,9 @@ Return nil if inside string, t if in a comment." ;; If in fun definition use standard indent level not double ;;(if (not (eq (car (car (cdr stack))) 'fun)) ;; Removed it made multi clause fun's look to bad - (setq off (* 2 erlang-indent-level)))) ;; ) + (setq off (+ erlang-indent-level (if (not erlang-icr-indent) + erlang-indent-level + erlang-icr-indent))))) (let ((base (erlang-indent-find-base stack indent-point off skip))) ;; Special cases (goto-char indent-point) |