diff options
author | Henrik Nord <[email protected]> | 2012-06-25 12:21:07 +0200 |
---|---|---|
committer | Henrik Nord <[email protected]> | 2012-06-25 12:21:10 +0200 |
commit | 09110bd2afc87acdd26d57e52e8cdc9514e4fe81 (patch) | |
tree | 81ec907957f32a32a3e4c5c7c6328903afea96d0 /lib/tools/emacs/erlang.el | |
parent | a03f32239b9598328aa1cc09c8926731a02716aa (diff) | |
parent | ad5f78aeaa4b33b6c3e8f50f0af2085d800765f6 (diff) | |
download | otp-09110bd2afc87acdd26d57e52e8cdc9514e4fe81.tar.gz otp-09110bd2afc87acdd26d57e52e8cdc9514e4fe81.tar.bz2 otp-09110bd2afc87acdd26d57e52e8cdc9514e4fe81.zip |
Merge branch 'tab/fix-indentation-records-emacs' into maint
* tab/fix-indentation-records-emacs:
Fix indentation of record fields in Emacs
OTP-10120
Diffstat (limited to 'lib/tools/emacs/erlang.el')
-rw-r--r-- | lib/tools/emacs/erlang.el | 58 |
1 files changed, 46 insertions, 12 deletions
diff --git a/lib/tools/emacs/erlang.el b/lib/tools/emacs/erlang.el index bc7a190fb4..2f6c7f554e 100644 --- a/lib/tools/emacs/erlang.el +++ b/lib/tools/emacs/erlang.el @@ -2986,18 +2986,52 @@ This assumes that the preceding expression is either simple (forward-sexp (- arg)) (let ((col (current-column))) (skip-chars-backward " \t") - ;; Needed to match the colon in "'foo':'bar'". - (if (not (memq (preceding-char) '(?# ?:))) - col - ;; Special hack to handle: (note line break) - ;; [#myrecord{ - ;; foo = foo}] - (or - (ignore-errors - (backward-char 1) - (forward-sexp -1) - (current-column)) - col))))) + ;; Special hack to handle: (note line break) + ;; [#myrecord{ + ;; foo = foo}] + ;; where the call (forward-sexp -1) will fail when point is at the `#'. + (or + (ignore-errors + ;; Needed to match the colon in "'foo':'bar'". + (cond ((eq (preceding-char) ?:) + (backward-char 1) + (forward-sexp -1) + (current-column)) + ((eq (preceding-char) ?#) + ;; We may now be at: + ;; - either a construction of a new record + ;; - or update of a record, in which case we want + ;; the column of the expression to be updated. + ;; + ;; To see which of the two cases we are at, we first + ;; move an expression backwards, check for keywords, + ;; then immediately an expression forwards. Moving + ;; backwards skips past tokens like `,' or `->', but + ;; when moving forwards again, we won't skip past such + ;; tokens. We use this: if, after having moved + ;; forwards, we're back where we started, then it was + ;; a record update. + ;; The check for keywords is to detect cases like: + ;; case Something of #record_construction{...} + (backward-char 1) + (let ((record-start (point)) + (record-start-col (current-column))) + (forward-sexp -1) + (let ((preceding-expr-col (current-column)) + ;; white space definition according to erl_scan + (white-space "\000-\040\200-\240")) + (if (erlang-at-keyword) + ;; The (forward-sexp -1) call moved past a keyword + (1+ record-start-col) + (forward-sexp 1) + (skip-chars-forward white-space record-start) + ;; Are we back where we started? If so, it was an update. + (if (= (point) record-start) + preceding-expr-col + (goto-char record-start) + (1+ (current-column))))))) + (t col))) + col)))) (defun erlang-indent-parenthesis (stack-position) (let ((previous (erlang-indent-find-preceding-expr))) |