changeset 4942:46f0df723e09

(for main branch) Indent all `with-*' expressions correctly -------------------- ChangeLog entries follow: -------------------- lisp/ChangeLog addition: 2010-01-22 Ben Wing <ben@xemacs.org> * 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'.
author Ben Wing <ben@xemacs.org>
date Fri, 22 Jan 2010 04:18:20 -0600
parents 4ce4d519bdd8
children aacafdd2bc67
files lisp/ChangeLog lisp/lisp-mode.el
diffstat 2 files changed, 41 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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  <ben@xemacs.org>
+
+	* 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  <kehoea@parhasard.net>
 
 	* simple.el (handle-pre-motion-command-current-command-is-motion):
--- 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))))