# HG changeset patch # User Ben Wing # Date 1264155500 21600 # Node ID 46f0df723e09261c8087fe2255bc602406b1596c # Parent 4ce4d519bdd82a8ef6c7b949553749b874a44612 (for main branch) Indent all `with-*' expressions correctly -------------------- ChangeLog entries follow: -------------------- lisp/ChangeLog addition: 2010-01-22 Ben Wing * lisp-mode.el: * lisp-mode.el (lisp-indent-function): If the function begins with `with-', assume it is a macro or special form whose last argument is a body. Call `lisp-indent-specform' with a flag indicating that it should indent all arguments as a body instead of with normal (full) indent. * lisp-mode.el (lisp-indent-specform): Add an optional flag argument indicating that all non-distinguished arguments, not just the first, should be indented as a body. This is useful when the number of distinguished (i.e. pre-body) arguments isn't known, and is used for this purpose by `lisp-indent-function'. diff -r 4ce4d519bdd8 -r 46f0df723e09 lisp/ChangeLog --- a/lisp/ChangeLog Thu Jan 21 04:10:57 2010 -0600 +++ b/lisp/ChangeLog Fri Jan 22 04:18:20 2010 -0600 @@ -1,3 +1,18 @@ +2010-01-22 Ben Wing + + * lisp-mode.el: + * lisp-mode.el (lisp-indent-function): + If the function begins with `with-', assume it is a macro or + special form whose last argument is a body. Call + `lisp-indent-specform' with a flag indicating that it should indent + all arguments as a body instead of with normal (full) indent. + * lisp-mode.el (lisp-indent-specform): + Add an optional flag argument indicating that all non-distinguished + arguments, not just the first, should be indented as a body. This + is useful when the number of distinguished (i.e. pre-body) arguments + isn't known, and is used for this purpose by `lisp-indent-function'. + + 2010-01-20 Aidan Kehoe * simple.el (handle-pre-motion-command-current-command-is-motion): diff -r 4ce4d519bdd8 -r 46f0df723e09 lisp/lisp-mode.el --- a/lisp/lisp-mode.el Thu Jan 21 04:10:57 2010 -0600 +++ b/lisp/lisp-mode.el Fri Jan 22 04:18:20 2010 -0600 @@ -2,7 +2,7 @@ ;; Copyright (C) 1985, 1996, 1997 Free Software Foundation, Inc. ;; Copyright (C) 1995 Tinker Systems. -;; Copyright (C) 2002 Ben Wing. +;; Copyright (C) 2002, 2010 Ben Wing. ;; Maintainer: FSF ;; Keywords: lisp, languages, dumped @@ -846,7 +846,11 @@ (lisp-indent-specform method state indent-point normal-indent)) (method - (funcall method state indent-point))))))) + (funcall method state indent-point)) + ((and (> (length function) 5) + (string-match "\\`with-" function)) + (lisp-indent-specform 0 state indent-point normal-indent + t))))))) (defun lisp-indent-quoteform (state indent-point) (goto-char (car (cdr state))) @@ -859,7 +863,24 @@ (defvar lisp-body-indent 2 "Number of columns to indent the second line of a `(def...)' form.") -(defun lisp-indent-specform (count state indent-point normal-indent) +;; COUNT is the number of "distinguished" forms (e.g. arguments before the +;; "body", in a macro taking a body as its last argument). STATE is +;; #### DOCUMENT-ME. INDENT-POINT is #### DOCUMENT-ME. NORMAL-INDENT +;; is the amount of "full" indentation used for arguments that aren't given +;; some special indentation (usually less), and normally it lines up with +;; the first word after the function name. forms are indented as follows: +;; +;; -- The first and second distinguished forms are given 2 times body indent +;; (determined by `lisp-body-indent') +;; -- Other distinguished forms are given normal indent +;; -- The first nondistinguished form (the body, usually) is given body indent +;; -- Normally, any further nondistinguished forms are given normal indent +;; -- However, if INDENT-REMAINING-AS-BODY was specified, any further +;; nondistinguished forms are given body indent. This is useful when the +;; number of distinguished forms isn't known or may vary. + +(defun lisp-indent-specform (count state indent-point normal-indent + &optional indent-remaining-as-body) (let ((containing-form-start (elt state 1)) (i count) body-indent containing-form-column) @@ -900,7 +921,8 @@ ;; or if this is the first undistinguished form and the preceding ;; distinguished form has indentation at least as great as body-indent. (if (or (and (= i 0) (= count 0)) - (and (= count 0) (<= body-indent normal-indent))) + (and (or (= count 0) indent-remaining-as-body) + (<= body-indent normal-indent))) body-indent normal-indent))))