diff options
| author | Daniel Colascione | 2015-03-15 00:17:05 -0700 |
|---|---|---|
| committer | Daniel Colascione | 2015-03-15 00:17:14 -0700 |
| commit | 994168240aa3d81cb42cef2f049fec5739f9d850 (patch) | |
| tree | 2f3792a12323c5f59fcca0b3318a8be3139b7f62 | |
| parent | 2f12fc56bf094dbbeb4fde1980627432a82ae23f (diff) | |
| download | emacs-994168240aa3d81cb42cef2f049fec5739f9d850.tar.gz emacs-994168240aa3d81cb42cef2f049fec5739f9d850.zip | |
Support indenting backquote substitutions in cl-indent
* lisp/emacs-lisp/cl-indent.el
(lisp-indent-backquote-substitution-mode): New user option.
(common-lisp-indent-function-1, common-lisp-loop-part-indentation)
(common-lisp-indent-function): Support normally indenting
backquote substitutions.
(extended-loop-p): Rename to `lisp-extended-loop-p'.
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/emacs-lisp/cl-indent.el | 62 |
2 files changed, 60 insertions, 11 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a9cf1b0f88f..fb2291c534c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2015-03-15 Daniel Colascione <dancol@dancol.org> | ||
| 2 | |||
| 3 | * emacs-lisp/cl-indent.el | ||
| 4 | (lisp-indent-backquote-substitution-mode): New user option. | ||
| 5 | (common-lisp-indent-function-1, common-lisp-loop-part-indentation) | ||
| 6 | (common-lisp-indent-function): Support normally indenting | ||
| 7 | backquote substitutions. | ||
| 8 | (extended-loop-p): Rename to `lisp-extended-loop-p'. | ||
| 9 | |||
| 1 | 2015-03-14 Michael R. Mauger <michael@mauger.com> | 10 | 2015-03-14 Michael R. Mauger <michael@mauger.com> |
| 2 | 11 | ||
| 3 | * progmodes/sql.el: Version 3.5 | 12 | * progmodes/sql.el: Version 3.5 |
diff --git a/lisp/emacs-lisp/cl-indent.el b/lisp/emacs-lisp/cl-indent.el index 1bcfb6df2cf..5e75406cf22 100644 --- a/lisp/emacs-lisp/cl-indent.el +++ b/lisp/emacs-lisp/cl-indent.el | |||
| @@ -138,6 +138,19 @@ If non-nil, alignment is done with the first parameter | |||
| 138 | :type 'boolean | 138 | :type 'boolean |
| 139 | :group 'lisp-indent) | 139 | :group 'lisp-indent) |
| 140 | 140 | ||
| 141 | (defcustom lisp-indent-backquote-substitution-mode t | ||
| 142 | "How to indent substitutions in backquotes. | ||
| 143 | If `t', the default, indent substituted forms normally. | ||
| 144 | If `nil', do not apply special indentation rule to substituted | ||
| 145 | forms. If `corrected', subtract the `,' or `,@' from the form | ||
| 146 | column, indenting as if this character sequence were not present. | ||
| 147 | In any case, do not backtrack beyond a backquote substitution. | ||
| 148 | |||
| 149 | Until Emacs 25.1, the `nil' behavior was hard-wired." | ||
| 150 | :version "25.1" | ||
| 151 | :type '(choice (const corrected) (const nil) (const t)) | ||
| 152 | :group 'lisp-indent) | ||
| 153 | |||
| 141 | 154 | ||
| 142 | (defvar lisp-indent-defun-method '(4 &lambda &body) | 155 | (defvar lisp-indent-defun-method '(4 &lambda &body) |
| 143 | "Defun-like indentation method. | 156 | "Defun-like indentation method. |
| @@ -145,7 +158,7 @@ This applies when the value of the `common-lisp-indent-function' property | |||
| 145 | is set to `defun'.") | 158 | is set to `defun'.") |
| 146 | 159 | ||
| 147 | 160 | ||
| 148 | (defun extended-loop-p (loop-start) | 161 | (defun lisp-extended-loop-p (loop-start) |
| 149 | "True if an extended loop form starts at LOOP-START." | 162 | "True if an extended loop form starts at LOOP-START." |
| 150 | (condition-case () | 163 | (condition-case () |
| 151 | (save-excursion | 164 | (save-excursion |
| @@ -170,11 +183,22 @@ the standard lisp indent package." | |||
| 170 | "Compute the indentation of loop form constituents." | 183 | "Compute the indentation of loop form constituents." |
| 171 | (let* ((loop-indentation (save-excursion | 184 | (let* ((loop-indentation (save-excursion |
| 172 | (goto-char (elt state 1)) | 185 | (goto-char (elt state 1)) |
| 173 | (current-column)))) | 186 | (current-column)))) |
| 187 | (when (and (eq lisp-indent-backquote-substitution-mode 'corrected)) | ||
| 188 | (save-excursion | ||
| 189 | (goto-char (elt state 1)) | ||
| 190 | (incf loop-indentation | ||
| 191 | (cond ((eq (char-before) ?,) -1) | ||
| 192 | ((and (eq (char-before) ?@) | ||
| 193 | (progn (backward-char) | ||
| 194 | (eq (char-before) ?,))) | ||
| 195 | -2) | ||
| 196 | (t 0))))) | ||
| 197 | |||
| 174 | (goto-char indent-point) | 198 | (goto-char indent-point) |
| 175 | (beginning-of-line) | 199 | (beginning-of-line) |
| 176 | (list | 200 | (list |
| 177 | (cond ((not (extended-loop-p (elt state 1))) | 201 | (cond ((not (lisp-extended-loop-p (elt state 1))) |
| 178 | (+ loop-indentation lisp-simple-loop-indentation)) | 202 | (+ loop-indentation lisp-simple-loop-indentation)) |
| 179 | ((looking-at "^\\s-*\\(:?\\sw+\\|;\\)") | 203 | ((looking-at "^\\s-*\\(:?\\sw+\\|;\\)") |
| 180 | (+ loop-indentation lisp-loop-keyword-indentation)) | 204 | (+ loop-indentation lisp-loop-keyword-indentation)) |
| @@ -264,9 +288,15 @@ at `common-lisp-indent-function' and, if set, use its value | |||
| 264 | instead." | 288 | instead." |
| 265 | ;; FIXME: why do we need to special-case loop? | 289 | ;; FIXME: why do we need to special-case loop? |
| 266 | (if (save-excursion (goto-char (elt state 1)) | 290 | (if (save-excursion (goto-char (elt state 1)) |
| 267 | (looking-at (if (derived-mode-p 'emacs-lisp-mode) | 291 | (and (looking-at (if (derived-mode-p 'emacs-lisp-mode) |
| 268 | "(\\(cl-\\)?[Ll][Oo][Oo][Pp]" | 292 | "(\\(cl-\\)?loop" |
| 269 | "([Ll][Oo][Oo][Pp]"))) | 293 | "([Ll][Oo][Oo][Pp]")) |
| 294 | (or lisp-indent-backquote-substitution-mode | ||
| 295 | (not | ||
| 296 | (or (and (eq (char-before) ?@) | ||
| 297 | (progn (backward-char) | ||
| 298 | (eq (char-before) ?,))) | ||
| 299 | (eq (char-before) ?,)))))) | ||
| 270 | (common-lisp-loop-part-indentation indent-point state) | 300 | (common-lisp-loop-part-indentation indent-point state) |
| 271 | (common-lisp-indent-function-1 indent-point state))) | 301 | (common-lisp-indent-function-1 indent-point state))) |
| 272 | 302 | ||
| @@ -373,11 +403,21 @@ instead." | |||
| 373 | (not (eq (char-after (- containing-sexp 2)) ?\#))) | 403 | (not (eq (char-after (- containing-sexp 2)) ?\#))) |
| 374 | ;; No indentation for "'(...)" elements | 404 | ;; No indentation for "'(...)" elements |
| 375 | (setq calculated (1+ sexp-column))) | 405 | (setq calculated (1+ sexp-column))) |
| 376 | ((or (eq (char-after (1- containing-sexp)) ?\,) | 406 | ((when |
| 377 | (and (eq (char-after (1- containing-sexp)) ?\@) | 407 | (or (eq (char-after (1- containing-sexp)) ?\,) |
| 378 | (eq (char-after (- containing-sexp 2)) ?\,))) | 408 | (and (eq (char-after (1- containing-sexp)) ?\@) |
| 379 | ;; ",(...)" or ",@(...)" | 409 | (eq (char-after (- containing-sexp 2)) ?\,))) |
| 380 | (setq calculated normal-indent)) | 410 | ;; ",(...)" or ",@(...)" |
| 411 | (when (eq lisp-indent-backquote-substitution-mode | ||
| 412 | 'corrected) | ||
| 413 | (incf sexp-column -1) | ||
| 414 | (when (eq (char-after (1- containing-sexp)) ?\@) | ||
| 415 | (incf sexp-column -1))) | ||
| 416 | (cond (lisp-indent-backquote-substitution-mode | ||
| 417 | (setf tentative-calculated normal-indent) | ||
| 418 | (setq depth lisp-indent-maximum-backtracking) | ||
| 419 | nil) | ||
| 420 | (t (setq calculated normal-indent))))) | ||
| 381 | ((eq (char-after (1- containing-sexp)) ?\#) | 421 | ((eq (char-after (1- containing-sexp)) ?\#) |
| 382 | ;; "#(...)" | 422 | ;; "#(...)" |
| 383 | (setq calculated (1+ sexp-column))) | 423 | (setq calculated (1+ sexp-column))) |