diff options
| author | akater | 2020-05-29 00:26:09 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2020-05-29 00:26:09 -0400 |
| commit | 1b2a881c9b3ef9158cbf28a65b9e94c2dbc6cec2 (patch) | |
| tree | 866d6c596ae734bf9ba3f06fd2e9530aa11de50e | |
| parent | df4991093b94ccc48255a0387a98c536962fd0a7 (diff) | |
| download | emacs-1b2a881c9b3ef9158cbf28a65b9e94c2dbc6cec2.tar.gz emacs-1b2a881c9b3ef9158cbf28a65b9e94c2dbc6cec2.zip | |
* lisp/emacs-lisp/lisp-mode.el: Add new indentation convention
(calculate-lisp-indent): To distinguish code and data when indenting,
introduce the convention that a space between an open paren and
a symbol indicate that this should be indented as a simple data list.
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/emacs-lisp/lisp-mode.el | 8 | ||||
| -rw-r--r-- | test/manual/indent/elisp.el | 5 | ||||
| -rw-r--r-- | test/manual/indent/lisp.lisp | 5 |
4 files changed, 20 insertions, 2 deletions
| @@ -128,6 +128,10 @@ displayed and which are kept hidden. | |||
| 128 | ** Emacs Lisp mode | 128 | ** Emacs Lisp mode |
| 129 | 129 | ||
| 130 | *** The mode-line now indicates whether we're using lexical or dynamic scoping. | 130 | *** The mode-line now indicates whether we're using lexical or dynamic scoping. |
| 131 | *** A space between an open paren and a symbol changes the indentation rule. | ||
| 132 | The presence of a space between an open paren and a symbol now is | ||
| 133 | taken as a statement by the programmer that this should be indented | ||
| 134 | as a data list rather than as a piece of code. | ||
| 131 | 135 | ||
| 132 | ** Dired | 136 | ** Dired |
| 133 | 137 | ||
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 7098a41f274..1311d94cb01 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el | |||
| @@ -956,6 +956,7 @@ is the buffer position of the start of the containing expression." | |||
| 956 | ;; setting this to a number inhibits calling hook | 956 | ;; setting this to a number inhibits calling hook |
| 957 | (desired-indent nil) | 957 | (desired-indent nil) |
| 958 | (retry t) | 958 | (retry t) |
| 959 | whitespace-after-open-paren | ||
| 959 | calculate-lisp-indent-last-sexp containing-sexp) | 960 | calculate-lisp-indent-last-sexp containing-sexp) |
| 960 | (cond ((or (markerp parse-start) (integerp parse-start)) | 961 | (cond ((or (markerp parse-start) (integerp parse-start)) |
| 961 | (goto-char parse-start)) | 962 | (goto-char parse-start)) |
| @@ -985,6 +986,7 @@ is the buffer position of the start of the containing expression." | |||
| 985 | nil | 986 | nil |
| 986 | ;; Innermost containing sexp found | 987 | ;; Innermost containing sexp found |
| 987 | (goto-char (1+ containing-sexp)) | 988 | (goto-char (1+ containing-sexp)) |
| 989 | (setq whitespace-after-open-paren (looking-at (rx whitespace))) | ||
| 988 | (if (not calculate-lisp-indent-last-sexp) | 990 | (if (not calculate-lisp-indent-last-sexp) |
| 989 | ;; indent-point immediately follows open paren. | 991 | ;; indent-point immediately follows open paren. |
| 990 | ;; Don't call hook. | 992 | ;; Don't call hook. |
| @@ -999,9 +1001,11 @@ is the buffer position of the start of the containing expression." | |||
| 999 | calculate-lisp-indent-last-sexp) | 1001 | calculate-lisp-indent-last-sexp) |
| 1000 | ;; This is the first line to start within the containing sexp. | 1002 | ;; This is the first line to start within the containing sexp. |
| 1001 | ;; It's almost certainly a function call. | 1003 | ;; It's almost certainly a function call. |
| 1002 | (if (= (point) calculate-lisp-indent-last-sexp) | 1004 | (if (or (= (point) calculate-lisp-indent-last-sexp) |
| 1005 | whitespace-after-open-paren) | ||
| 1003 | ;; Containing sexp has nothing before this line | 1006 | ;; Containing sexp has nothing before this line |
| 1004 | ;; except the first element. Indent under that element. | 1007 | ;; except the first element, or the first element is |
| 1008 | ;; preceded by whitespace. Indent under that element. | ||
| 1005 | nil | 1009 | nil |
| 1006 | ;; Skip the first element, find start of second (the first | 1010 | ;; Skip the first element, find start of second (the first |
| 1007 | ;; argument of the function call) and indent under. | 1011 | ;; argument of the function call) and indent under. |
diff --git a/test/manual/indent/elisp.el b/test/manual/indent/elisp.el new file mode 100644 index 00000000000..f3874b5c3e0 --- /dev/null +++ b/test/manual/indent/elisp.el | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | (defun x () | ||
| 2 | (print (quote ( thingy great | ||
| 3 | stuff))) | ||
| 4 | (print (quote (thingy great | ||
| 5 | stuff)))) | ||
diff --git a/test/manual/indent/lisp.lisp b/test/manual/indent/lisp.lisp new file mode 100644 index 00000000000..f3874b5c3e0 --- /dev/null +++ b/test/manual/indent/lisp.lisp | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | (defun x () | ||
| 2 | (print (quote ( thingy great | ||
| 3 | stuff))) | ||
| 4 | (print (quote (thingy great | ||
| 5 | stuff)))) | ||