comparison lisp/emacs-lisp/cl-indent.el @ 22858:77090a500417

(lisp-indent-defun-method): New variable. (common-lisp-indent-function): Use it. (lisp-indent-259): Uncomment the `&lambda' code. (top-level let): Remove duplicate `catch' and `block'. Use `&lambda' when appropriate. Now the lambda lists are indented appropriately.
author Richard M. Stallman <rms@gnu.org>
date Fri, 31 Jul 1998 03:21:07 +0000
parents 6103b46f200a
children edbc56db94ee
comparison
equal deleted inserted replaced
22857:33b46ddf75b7 22858:77090a500417
78 :type 'integer 78 :type 'integer
79 :group 'lisp-indent) 79 :group 'lisp-indent)
80 80
81 81
82 (defvar lisp-indent-error-function) 82 (defvar lisp-indent-error-function)
83 (defvar lisp-indent-defun-method '(4 &lambda &body))
83 84
84 ;;;###autoload 85 ;;;###autoload
85 (defun common-lisp-indent-function (indent-point state) 86 (defun common-lisp-indent-function (indent-point state)
86 (let ((normal-indent (current-column))) 87 (let ((normal-indent (current-column)))
87 ;; Walk up list levels until we see something 88 ;; Walk up list levels until we see something
112 (if (not (looking-at "\\sw\\|\\s_")) 113 (if (not (looking-at "\\sw\\|\\s_"))
113 ;; This form doesn't seem to start with a symbol 114 ;; This form doesn't seem to start with a symbol
114 (setq function nil method nil) 115 (setq function nil method nil)
115 (setq tem (point)) 116 (setq tem (point))
116 (forward-sexp 1) 117 (forward-sexp 1)
117 (setq function (downcase (buffer-substring tem (point)))) 118 (setq function (downcase (buffer-substring-no-properties
119 tem (point))))
118 (goto-char tem) 120 (goto-char tem)
119 (setq tem (intern-soft function) 121 (setq tem (intern-soft function)
120 method (get tem 'common-lisp-indent-function)) 122 method (get tem 'common-lisp-indent-function))
121 (cond ((and (null method) 123 (cond ((and (null method)
122 (string-match ":[^:]+" function)) 124 (string-match ":[^:]+" function))
144 (setq path (cons n path))) 146 (setq path (cons n path)))
145 147
146 ;; backwards compatibility. 148 ;; backwards compatibility.
147 (cond ((null function)) 149 (cond ((null function))
148 ((null method) 150 ((null method)
149 (if (null (cdr path)) 151 (when (null (cdr path))
150 ;; (package prefix was stripped off above) 152 ;; (package prefix was stripped off above)
151 (setq method (cond ((string-match "\\`def" 153 (setq method (cond ((string-match "\\`def"
152 function) 154 function)
153 '(4 (&whole 4 &rest 1) &body)) 155 lisp-indent-defun-method)
154 ((string-match "\\`\\(with\\|do\\)-" 156 ((string-match "\\`\\(with\\|do\\)-"
155 function) 157 function)
156 '(4 &body)))))) 158 '(&lambda &body))))))
157 ;; backwards compatibility. Bletch. 159 ;; backwards compatibility. Bletch.
158 ((eq method 'defun) 160 ((eq method 'defun)
159 (setq method '(4 (&whole 4 &rest 1) &body)))) 161 (setq method lisp-indent-defun-method)))
160 162
161 (cond ((and (memq (char-after (1- containing-sexp)) '(?\' ?\`)) 163 (cond ((and (memq (char-after (1- containing-sexp)) '(?\' ?\`))
162 (not (eql (char-after (- containing-sexp 2)) ?\#))) 164 (not (eql (char-after (- containing-sexp 2)) ?\#)))
163 ;; No indentation for "'(...)" elements 165 ;; No indentation for "'(...)" elements
164 (setq calculated (1+ sexp-column))) 166 (setq calculated (1+ sexp-column)))
199 (setq calculated (lisp-indent-259 201 (setq calculated (lisp-indent-259
200 method path state indent-point 202 method path state indent-point
201 sexp-column normal-indent)))))) 203 sexp-column normal-indent))))))
202 (goto-char containing-sexp) 204 (goto-char containing-sexp)
203 (setq last-point containing-sexp) 205 (setq last-point containing-sexp)
204 (if (not calculated) 206 (unless calculated
205 (condition-case () 207 (condition-case ()
206 (progn (backward-up-list 1) 208 (progn (backward-up-list 1)
207 (setq depth (1+ depth))) 209 (setq depth (1+ depth)))
208 (error (setq depth lisp-indent-maximum-backtracking)))))) 210 (error (setq depth lisp-indent-maximum-backtracking))))))
209 calculated))) 211 calculated)))
237 ;; n is set to (1- n) and method to (cdr method) 239 ;; n is set to (1- n) and method to (cdr method)
238 ;; each iteration. 240 ;; each iteration.
239 (setq tem (car method)) 241 (setq tem (car method))
240 242
241 (or (eq tem 'nil) ;default indentation 243 (or (eq tem 'nil) ;default indentation
242 ; (eq tem '&lambda) ;abbrev for (&whole 4 (&rest 1)) 244 (eq tem '&lambda) ;lambda list
243 (and (eq tem '&body) (null (cdr method))) 245 (and (eq tem '&body) (null (cdr method)))
244 (and (eq tem '&rest) 246 (and (eq tem '&rest)
245 (consp (cdr method)) (null (cdr (cdr method)))) 247 (consp (cdr method)) (null (cddr method)))
246 (integerp tem) ;explicit indentation specified 248 (integerp tem) ;explicit indentation specified
247 (and (consp tem) ;destructuring 249 (and (consp tem) ;destructuring
248 (eq (car tem) '&whole) 250 (eq (car tem) '&whole)
249 (or (symbolp (car (cdr tem))) 251 (or (symbolp (cadr tem))
250 (integerp (car (cdr tem))))) 252 (integerp (cadr tem))))
251 (and (symbolp tem) ;a function to call to do the work. 253 (and (symbolp tem) ;a function to call to do the work.
252 (null (cdr method))) 254 (null (cdr method)))
253 (lisp-indent-report-bad-format method)) 255 (lisp-indent-report-bad-format method))
254 256
255 (cond ((and tail (not (consp tem))) 257 (cond ((and tail (not (consp tem)))
275 (if (< n 0) 277 (if (< n 0)
276 ;; Too few elements in pattern. 278 ;; Too few elements in pattern.
277 (throw 'exit normal-indent))) 279 (throw 'exit normal-indent)))
278 ((eq tem 'nil) 280 ((eq tem 'nil)
279 (throw 'exit (list normal-indent containing-form-start))) 281 (throw 'exit (list normal-indent containing-form-start)))
280 ; ((eq tem '&lambda) 282 ((eq tem '&lambda)
281 ; ;; abbrev for (&whole 4 &rest 1) 283 (throw 'exit
282 ; (throw 'exit 284 (cond ((null p)
283 ; (cond ((null p) 285 (list (+ sexp-column 4) containing-form-start))
284 ; (list (+ sexp-column 4) containing-form-start)) 286 ((null (cdr p))
285 ; ((null (cdr p)) 287 (+ sexp-column 1))
286 ; (+ sexp-column 1)) 288 (t normal-indent))))
287 ; (t normal-indent))))
288 ((integerp tem) 289 ((integerp tem)
289 (throw 'exit 290 (throw 'exit
290 (if (null p) ;not in subforms 291 (if (null p) ;not in subforms
291 (list (+ sexp-column tem) containing-form-start) 292 (list (+ sexp-column tem) containing-form-start)
292 normal-indent))) 293 normal-indent)))
296 sexp-column normal-indent))) 297 sexp-column normal-indent)))
297 (t 298 (t
298 ;; must be a destructing frob 299 ;; must be a destructing frob
299 (if (not (null p)) 300 (if (not (null p))
300 ;; descend 301 ;; descend
301 (setq method (cdr (cdr tem)) 302 (setq method (cddr tem)
302 n nil) 303 n nil)
303 (setq tem (car (cdr tem))) 304 (setq tem (cadr tem))
304 (throw 'exit 305 (throw 'exit
305 (cond (tail 306 (cond (tail
306 normal-indent) 307 normal-indent)
307 ((eq tem 'nil) 308 ((eq tem 'nil)
308 (list normal-indent 309 (list normal-indent
371 (+ sexp-column lisp-body-indent))) 372 (+ sexp-column lisp-body-indent)))
372 (error (+ sexp-column lisp-body-indent))))) 373 (error (+ sexp-column lisp-body-indent)))))
373 374
374 375
375 (let ((l '((block 1) 376 (let ((l '((block 1)
376 (catch 1)
377 (case (4 &rest (&whole 2 &rest 1))) 377 (case (4 &rest (&whole 2 &rest 1)))
378 (ccase . case) (ecase . case) 378 (ccase . case) (ecase . case)
379 (typecase . case) (etypecase . case) (ctypecase . case) 379 (typecase . case) (etypecase . case) (ctypecase . case)
380 (catch 1) 380 (catch 1)
381 (cond (&rest (&whole 2 &rest 1))) 381 (cond (&rest (&whole 2 &rest 1)))
382 (block 1)
383 (defvar (4 2 2)) 382 (defvar (4 2 2))
384 (defconstant . defvar) 383 (defconstant . defvar)
384 (defcustom (4 2 2 2))
385 (defparameter . defvar) 385 (defparameter . defvar)
386 (define-modify-macro 386 (define-modify-macro
387 (4 &body)) 387 (4 &body))
388 (define-setf-method 388 (defsetf (4 &lambda 4 &body))
389 (4 (&whole 4 &rest 1) &body)) 389 (defun (4 &lambda &body))
390 (defsetf (4 (&whole 4 &rest 1) 4 &body)) 390 (define-setf-method . defun)
391 (defun (4 (&whole 4 &rest 1) &body)) 391 (define-setf-expander . defun)
392 (defmacro . defun) (deftype . defun) 392 (defmacro . defun) (deftype . defun)
393 (defpackage (4 2)) 393 (defpackage (4 2))
394 (defstruct ((&whole 4 &rest (&whole 2 &rest 1)) 394 (defstruct ((&whole 4 &rest (&whole 2 &rest 1))
395 &rest (&whole 2 &rest 1))) 395 &rest (&whole 2 &rest 1)))
396 (destructuring-bind 396 (destructuring-bind
398 (do lisp-indent-do) 398 (do lisp-indent-do)
399 (do* . do) 399 (do* . do)
400 (dolist ((&whole 4 2 1) &body)) 400 (dolist ((&whole 4 2 1) &body))
401 (dotimes . dolist) 401 (dotimes . dolist)
402 (eval-when 1) 402 (eval-when 1)
403 (flet ((&whole 4 &rest (&whole 1 (&whole 4 &rest 1) &body)) 403 (flet ((&whole 4 &rest (&whole 1 &lambda &body)) &body))
404 &body))
405 (labels . flet) 404 (labels . flet)
406 (macrolet . flet) 405 (macrolet . flet)
407 (handler-case (4 &rest (&whole 2 (&whole 4 &rest 1) &body))) 406 (handler-case (4 &rest (&whole 2 &lambda &body)))
408 (restart-case . handler-case) 407 (restart-case . handler-case)
409 ;; `else-body' style 408 ;; `else-body' style
410 (if (nil nil &body)) 409 (if (nil nil &body))
411 ;; single-else style (then and else equally indented) 410 ;; single-else style (then and else equally indented)
412 (if (&rest nil)) 411 (if (&rest nil))
413 ;; (lambda ((&whole 4 &rest 1) &body)) 412 (lambda (&lambda &rest lisp-indent-function-lambda-hack))
414 (lambda ((&whole 4 &rest 1)
415 &rest lisp-indent-function-lambda-hack))
416 (let ((&whole 4 &rest (&whole 1 1 2)) &body)) 413 (let ((&whole 4 &rest (&whole 1 1 2)) &body))
417 (let* . let) 414 (let* . let)
418 (compiler-let . let) ;barf 415 (compiler-let . let) ;barf
419 (handler-bind . let) (restart-bind . let) 416 (handler-bind . let) (restart-bind . let)
420 (locally 1) 417 (locally 1)
426 (multiple-value-prog1 1) 423 (multiple-value-prog1 1)
427 (multiple-value-setq 424 (multiple-value-setq
428 (4 2)) 425 (4 2))
429 (multiple-value-setf . multiple-value-setq) 426 (multiple-value-setf . multiple-value-setq)
430 ;; Combines the worst features of BLOCK, LET and TAGBODY 427 ;; Combines the worst features of BLOCK, LET and TAGBODY
431 (prog ((&whole 4 &rest 1) &rest lisp-indent-tagbody)) 428 (prog (&lambda &rest lisp-indent-tagbody))
432 (prog* . prog) 429 (prog* . prog)
433 (prog1 1) 430 (prog1 1)
434 (prog2 2) 431 (prog2 2)
435 (progn 0) 432 (progn 0)
436 (progv (4 4 &body)) 433 (progv (4 4 &body))
441 (unless 1) 438 (unless 1)
442 (unwind-protect (5 &body)) 439 (unwind-protect (5 &body))
443 (when 1) 440 (when 1)
444 (with-standard-io-syntax (2))))) 441 (with-standard-io-syntax (2)))))
445 (while l 442 (while l
446 (put (car (car l)) 'common-lisp-indent-function 443 (put (caar l) 'common-lisp-indent-function
447 (if (symbolp (cdr (car l))) 444 (if (symbolp (cdar l))
448 (get (cdr (car l)) 'common-lisp-indent-function) 445 (get (cdar l) 'common-lisp-indent-function)
449 (car (cdr (car l))))) 446 (car (cdar l))))
450 (setq l (cdr l)))) 447 (setq l (cdr l))))
451 448
452 449
453 ;(defun foo (x) 450 ;(defun foo (x)
454 ; (tagbody 451 ; (tagbody