diff options
| author | Richard M. Stallman | 2002-05-29 16:40:34 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2002-05-29 16:40:34 +0000 |
| commit | f620e5e2eda449b18961722a1a4b926a17c2663b (patch) | |
| tree | e47346cd99fc247807de5206c51041cb46e779d6 | |
| parent | d09b1c02f517ec6a6129dd16ae95dae213975ca9 (diff) | |
| download | emacs-f620e5e2eda449b18961722a1a4b926a17c2663b.tar.gz emacs-f620e5e2eda449b18961722a1a4b926a17c2663b.zip | |
(common-lisp-indent-function-1):
When recognizing a def... construct, make that indentation
tentative, so that it can be overridden if the list in question
is not actually an expression.
(common-lisp-indent-call-method): New subroutine.
| -rw-r--r-- | lisp/emacs-lisp/cl-indent.el | 79 |
1 files changed, 53 insertions, 26 deletions
diff --git a/lisp/emacs-lisp/cl-indent.el b/lisp/emacs-lisp/cl-indent.el index 18149901a01..2ed810951d9 100644 --- a/lisp/emacs-lisp/cl-indent.el +++ b/lisp/emacs-lisp/cl-indent.el | |||
| @@ -153,7 +153,10 @@ If nil, indent backquoted lists as data, i.e., like quoted lists." | |||
| 153 | (path ()) | 153 | (path ()) |
| 154 | ;; set non-nil when somebody works out the indentation to use | 154 | ;; set non-nil when somebody works out the indentation to use |
| 155 | calculated | 155 | calculated |
| 156 | (last-point indent-point) | 156 | ;; If non-nil, this is an indentation to use |
| 157 | ;; if nothing else specifies it more firmly. | ||
| 158 | tentative-calculated | ||
| 159 | (last-point indent-point) | ||
| 157 | ;; the position of the open-paren of the innermost containing list | 160 | ;; the position of the open-paren of the innermost containing list |
| 158 | (containing-form-start (elt state 1)) | 161 | (containing-form-start (elt state 1)) |
| 159 | ;; the column of the above | 162 | ;; the column of the above |
| @@ -169,7 +172,7 @@ If nil, indent backquoted lists as data, i.e., like quoted lists." | |||
| 169 | (forward-char 1) | 172 | (forward-char 1) |
| 170 | (parse-partial-sexp (point) indent-point 1 t) | 173 | (parse-partial-sexp (point) indent-point 1 t) |
| 171 | ;; Move to the car of the relevant containing form | 174 | ;; Move to the car of the relevant containing form |
| 172 | (let (tem function method) | 175 | (let (tem function method tentative-defun) |
| 173 | (if (not (looking-at "\\sw\\|\\s_")) | 176 | (if (not (looking-at "\\sw\\|\\s_")) |
| 174 | ;; This form doesn't seem to start with a symbol | 177 | ;; This form doesn't seem to start with a symbol |
| 175 | (setq function nil method nil) | 178 | (setq function nil method nil) |
| @@ -209,13 +212,13 @@ If nil, indent backquoted lists as data, i.e., like quoted lists." | |||
| 209 | (cond ((null function)) | 212 | (cond ((null function)) |
| 210 | ((null method) | 213 | ((null method) |
| 211 | (when (null (cdr path)) | 214 | (when (null (cdr path)) |
| 212 | ;; (package prefix was stripped off above) | 215 | ;; (package prefix was stripped off above) |
| 213 | (setq method (cond ((string-match "\\`def" | 216 | (cond ((string-match "\\`def" |
| 214 | function) | 217 | function) |
| 215 | lisp-indent-defun-method) | 218 | (setq tentative-defun t)) |
| 216 | ((string-match "\\`\\(with\\|do\\)-" | 219 | ((string-match "\\`\\(with\\|do\\)-" |
| 217 | function) | 220 | function) |
| 218 | '(&lambda &body)))))) | 221 | (setq method '(&lambda &body)))))) |
| 219 | ;; backwards compatibility. Bletch. | 222 | ;; backwards compatibility. Bletch. |
| 220 | ((eq method 'defun) | 223 | ((eq method 'defun) |
| 221 | (setq method lisp-indent-defun-method))) | 224 | (setq method lisp-indent-defun-method))) |
| @@ -234,7 +237,26 @@ If nil, indent backquoted lists as data, i.e., like quoted lists." | |||
| 234 | ((eq (char-after (1- containing-sexp)) ?\#) | 237 | ((eq (char-after (1- containing-sexp)) ?\#) |
| 235 | ;; "#(...)" | 238 | ;; "#(...)" |
| 236 | (setq calculated (1+ sexp-column))) | 239 | (setq calculated (1+ sexp-column))) |
| 237 | ((null method)) | 240 | ((null method) |
| 241 | ;; If this looks like a call to a `def...' form, | ||
| 242 | ;; think about indenting it as one, but do it | ||
| 243 | ;; tentatively for cases like | ||
| 244 | ;; (flet ((defunp () | ||
| 245 | ;; nil))) | ||
| 246 | ;; Set both normal-indent and tentative-calculated. | ||
| 247 | ;; The latter ensures this value gets used | ||
| 248 | ;; if there are no relevant containing constructs. | ||
| 249 | ;; The former ensures this value gets used | ||
| 250 | ;; if there is a relevant containing construct | ||
| 251 | ;; but we are nested within the structure levels | ||
| 252 | ;; that it specifies indentation for. | ||
| 253 | (if tentative-defun | ||
| 254 | (setq tentative-calculated | ||
| 255 | (common-lisp-indent-call-method | ||
| 256 | function lisp-indent-defun-method | ||
| 257 | path state indent-point | ||
| 258 | sexp-column normal-indent) | ||
| 259 | normal-indent tentative-calculated))) | ||
| 238 | ((integerp method) | 260 | ((integerp method) |
| 239 | ;; convenient top-level hack. | 261 | ;; convenient top-level hack. |
| 240 | ;; (also compatible with lisp-indent-function) | 262 | ;; (also compatible with lisp-indent-function) |
| @@ -253,25 +275,30 @@ If nil, indent backquoted lists as data, i.e., like quoted lists." | |||
| 253 | (t | 275 | (t |
| 254 | ;; other body form | 276 | ;; other body form |
| 255 | normal-indent)))) | 277 | normal-indent)))) |
| 256 | ((symbolp method) | 278 | (t |
| 257 | (let ((lisp-indent-error-function function)) | 279 | (setq calculated |
| 258 | (setq calculated (funcall method | 280 | (common-lisp-indent-call-method |
| 259 | path state indent-point | 281 | function method path state indent-point |
| 260 | sexp-column normal-indent)))) | 282 | sexp-column normal-indent))))) |
| 261 | (t | ||
| 262 | (let ((lisp-indent-error-function function)) | ||
| 263 | (setq calculated (lisp-indent-259 | ||
| 264 | method path state indent-point | ||
| 265 | sexp-column normal-indent)))))) | ||
| 266 | (goto-char containing-sexp) | 283 | (goto-char containing-sexp) |
| 267 | (setq last-point containing-sexp) | 284 | (setq last-point containing-sexp) |
| 268 | (unless calculated | 285 | (unless calculated |
| 269 | (condition-case () | 286 | (condition-case () |
| 270 | (progn (backward-up-list 1) | 287 | (progn (backward-up-list 1) |
| 271 | (setq depth (1+ depth))) | 288 | (setq depth (1+ depth))) |
| 272 | (error (setq depth lisp-indent-maximum-backtracking)))))) | 289 | (error (setq depth lisp-indent-maximum-backtracking)))))) |
| 273 | calculated))) | 290 | (or calculated tentative-calculated)))) |
| 274 | 291 | ||
| 292 | |||
| 293 | (defun common-lisp-indent-call-method (function method path state indent-point | ||
| 294 | sexp-column normal-indent) | ||
| 295 | (let ((lisp-indent-error-function function)) | ||
| 296 | (if (symbolp method) | ||
| 297 | (funcall method | ||
| 298 | path state indent-point | ||
| 299 | sexp-column normal-indent) | ||
| 300 | (lisp-indent-259 method path state indent-point | ||
| 301 | sexp-column normal-indent)))) | ||
| 275 | 302 | ||
| 276 | (defun lisp-indent-report-bad-format (m) | 303 | (defun lisp-indent-report-bad-format (m) |
| 277 | (error "%s has a badly-formed %s property: %s" | 304 | (error "%s has a badly-formed %s property: %s" |