Mercurial > hg > xemacs-beta
comparison lisp/lisp-mode.el @ 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 | 8f1ee2d15784 |
children | e4bbe5622a80 |
comparison
equal
deleted
inserted
replaced
4941:4ce4d519bdd8 | 4942:46f0df723e09 |
---|---|
1 ;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands. | 1 ;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands. |
2 | 2 |
3 ;; Copyright (C) 1985, 1996, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985, 1996, 1997 Free Software Foundation, Inc. |
4 ;; Copyright (C) 1995 Tinker Systems. | 4 ;; Copyright (C) 1995 Tinker Systems. |
5 ;; Copyright (C) 2002 Ben Wing. | 5 ;; Copyright (C) 2002, 2010 Ben Wing. |
6 | 6 |
7 ;; Maintainer: FSF | 7 ;; Maintainer: FSF |
8 ;; Keywords: lisp, languages, dumped | 8 ;; Keywords: lisp, languages, dumped |
9 | 9 |
10 ;; This file is part of XEmacs. | 10 ;; This file is part of XEmacs. |
844 (lisp-indent-defform state indent-point)) | 844 (lisp-indent-defform state indent-point)) |
845 ((integerp method) | 845 ((integerp method) |
846 (lisp-indent-specform method state | 846 (lisp-indent-specform method state |
847 indent-point normal-indent)) | 847 indent-point normal-indent)) |
848 (method | 848 (method |
849 (funcall method state indent-point))))))) | 849 (funcall method state indent-point)) |
850 ((and (> (length function) 5) | |
851 (string-match "\\`with-" function)) | |
852 (lisp-indent-specform 0 state indent-point normal-indent | |
853 t))))))) | |
850 | 854 |
851 (defun lisp-indent-quoteform (state indent-point) | 855 (defun lisp-indent-quoteform (state indent-point) |
852 (goto-char (car (cdr state))) | 856 (goto-char (car (cdr state))) |
853 (forward-line 1) | 857 (forward-line 1) |
854 (if (> (point) (car (cdr (cdr state)))) | 858 (if (> (point) (car (cdr (cdr state)))) |
857 (+ 1 (current-column))))) | 861 (+ 1 (current-column))))) |
858 | 862 |
859 (defvar lisp-body-indent 2 | 863 (defvar lisp-body-indent 2 |
860 "Number of columns to indent the second line of a `(def...)' form.") | 864 "Number of columns to indent the second line of a `(def...)' form.") |
861 | 865 |
862 (defun lisp-indent-specform (count state indent-point normal-indent) | 866 ;; COUNT is the number of "distinguished" forms (e.g. arguments before the |
867 ;; "body", in a macro taking a body as its last argument). STATE is | |
868 ;; #### DOCUMENT-ME. INDENT-POINT is #### DOCUMENT-ME. NORMAL-INDENT | |
869 ;; is the amount of "full" indentation used for arguments that aren't given | |
870 ;; some special indentation (usually less), and normally it lines up with | |
871 ;; the first word after the function name. forms are indented as follows: | |
872 ;; | |
873 ;; -- The first and second distinguished forms are given 2 times body indent | |
874 ;; (determined by `lisp-body-indent') | |
875 ;; -- Other distinguished forms are given normal indent | |
876 ;; -- The first nondistinguished form (the body, usually) is given body indent | |
877 ;; -- Normally, any further nondistinguished forms are given normal indent | |
878 ;; -- However, if INDENT-REMAINING-AS-BODY was specified, any further | |
879 ;; nondistinguished forms are given body indent. This is useful when the | |
880 ;; number of distinguished forms isn't known or may vary. | |
881 | |
882 (defun lisp-indent-specform (count state indent-point normal-indent | |
883 &optional indent-remaining-as-body) | |
863 (let ((containing-form-start (elt state 1)) | 884 (let ((containing-form-start (elt state 1)) |
864 (i count) | 885 (i count) |
865 body-indent containing-form-column) | 886 body-indent containing-form-column) |
866 ;; Move to the start of containing form, calculate indentation | 887 ;; Move to the start of containing form, calculate indentation |
867 ;; to use for non-distinguished forms (> count), and move past the | 888 ;; to use for non-distinguished forms (> count), and move past the |
898 ;; A non-distinguished form. Use body-indent if there are no | 919 ;; A non-distinguished form. Use body-indent if there are no |
899 ;; distinguished forms and this is the first undistinguished form, | 920 ;; distinguished forms and this is the first undistinguished form, |
900 ;; or if this is the first undistinguished form and the preceding | 921 ;; or if this is the first undistinguished form and the preceding |
901 ;; distinguished form has indentation at least as great as body-indent. | 922 ;; distinguished form has indentation at least as great as body-indent. |
902 (if (or (and (= i 0) (= count 0)) | 923 (if (or (and (= i 0) (= count 0)) |
903 (and (= count 0) (<= body-indent normal-indent))) | 924 (and (or (= count 0) indent-remaining-as-body) |
925 (<= body-indent normal-indent))) | |
904 body-indent | 926 body-indent |
905 normal-indent)))) | 927 normal-indent)))) |
906 | 928 |
907 (defun lisp-indent-defform (state indent-point) | 929 (defun lisp-indent-defform (state indent-point) |
908 (goto-char (car (cdr state))) | 930 (goto-char (car (cdr state))) |