annotate lisp/lisp-mode.el @ 629:a6c89d799f00

[xemacs-hg @ 2001-07-15 08:18:59 by adrian] [PATCH] xemacs-21.5: typo fixes of of this this nature for lisp/ <8zhqhahu.fsf@ecf.teradyne.com>
author adrian
date Sun, 15 Jul 2001 08:18:59 +0000
parents 023b83f4e54b
children 943eaba38521
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1996, 1997 Free Software Foundation, Inc.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
4 ;; Copyright (C) 1995 Tinker Systems.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Maintainer: FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Keywords: lisp, languages, dumped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;; 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;;; Synched up with: FSF 19.34 (but starting to diverge).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;; This file is dumped with XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 ;; The base major mode for editing Lisp code (used also for Emacs Lisp).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;; This mode is documented in the Emacs manual
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 (defgroup lisp nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 "Lisp support, including Emacs Lisp."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 :group 'languages
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 :group 'development)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 (defvar lisp-mode-syntax-table nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 (defvar emacs-lisp-mode-syntax-table nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 (defvar lisp-mode-abbrev-table nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
46 (defun construct-lisp-mode-menu (popup-p emacs-lisp-p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
47 (flet ((popup-wrap (form)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
48 (if popup-p `(menu-call-at-event ',form) form)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
49 `(,@(if emacs-lisp-p
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
50 `(["%_Byte-Compile This File" ,(popup-wrap
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
51 'emacs-lisp-byte-compile)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
52 ["B%_yte-Compile/Load This File"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
53 ,(popup-wrap 'emacs-lisp-byte-compile-and-load)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
54 ["Byte-%_Recompile Directory..."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
55 ,(popup-wrap 'byte-recompile-directory)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
56 "---"))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
57 ["%_Evaluate Region or Defun"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
58 ,(popup-wrap '(if (region-exists-p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
59 (call-interactively 'eval-region)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
60 (call-interactively 'eval-defun)))]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
61 ["Evaluate %_Whole Buffer" ,(popup-wrap 'eval-current-buffer)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
62 ["Evaluate Last %_S-expression" ,(popup-wrap 'eval-last-sexp)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
63 "---"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
64 ,@(if popup-p
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
65 '(["%_Find Function"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
66 (find-function (menu-call-at-event '(function-at-point)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
67 :suffix (let ((fun (menu-call-at-event '(function-at-point))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
68 (if fun (symbol-name fun) ""))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
69 :active (and (fboundp 'find-function)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
70 (menu-call-at-event '(function-at-point)))]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
71 ["%_Find Variable"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
72 (find-variable (menu-call-at-event '(variable-at-point)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
73 :suffix (let ((fun (menu-call-at-event '(variable-at-point))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
74 (if fun (symbol-name fun) ""))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
75 :active (and (fboundp 'find-variable)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
76 (menu-call-at-event '(variable-at-point)))]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
77 ["%_Help on Function"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
78 (describe-function (menu-call-at-event '(function-at-point)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
79 :suffix (let ((fun (menu-call-at-event '(function-at-point))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
80 (if fun (symbol-name fun) ""))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
81 :active (and (fboundp 'describe-function)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
82 (menu-call-at-event '(function-at-point)))]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
83 ["%_Help on Variable"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
84 (describe-variable (menu-call-at-event '(variable-at-point)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
85 :suffix (let ((fun (menu-call-at-event '(variable-at-point))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
86 (if fun (symbol-name fun) ""))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
87 :active (and (fboundp 'describe-variable)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
88 (menu-call-at-event '(variable-at-point)))])
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
89 '(["Find %_Function..." find-function
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
90 :active (fboundp 'find-function)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
91 ["Find %_Variable..." find-variable
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
92 :active (fboundp 'find-variable)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
93 ["%_Help on Function..." describe-function
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
94 :active (fboundp 'describe-function)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
95 ["Hel%_p on Variable..." describe-variable
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
96 :active (fboundp 'describe-variable)]))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
97 "---"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
98 ["Instrument This Defun for %_Debugging" ,(popup-wrap 'edebug-defun)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
99 ["%_Trace Function..." trace-function-background]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
100 ["%_Untrace All Functions" untrace-all
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
101 :active (fboundp 'untrace-all)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
102 "---"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
103 ["%_Comment Out Region" comment-region :active (region-exists-p)]
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
104 ["Unc%_omment Region" (comment-region (region-beginning)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
105 (region-end) '(4))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 460
diff changeset
106 :active (region-exists-p)]
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
107 "---"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
108 ["%_Indent Region or Balanced Expression"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
109 ,(popup-wrap '(if (region-exists-p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
110 (call-interactively 'indent-region)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
111 (call-interactively 'indent-sexp)))]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
112 ["I%_ndent Defun"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
113 ,(popup-wrap '(progn
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
114 (beginning-of-defun)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
115 (indent-sexp)))]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
116 "---"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
117 "Look for debug-on-error under Options->Troubleshooting"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
118 )))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
120 (defvar lisp-interaction-mode-popup-menu
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
121 (cons "Lisp-Interaction" (construct-lisp-mode-menu t nil)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
122
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
123 (defvar emacs-lisp-mode-popup-menu
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
124 (cons "Emacs-Lisp" (construct-lisp-mode-menu t t)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 ;Don't have a menubar entry in Lisp Interaction mode. Otherwise, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 ;*scratch* buffer has a Lisp menubar item! Very confusing.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
128 ;Jan Vroonhof really wants this, so it's back. --ben
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
129 (defvar lisp-interaction-mode-menubar-menu
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
130 (cons "%_Lisp" (construct-lisp-mode-menu nil nil)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
132 (defvar emacs-lisp-mode-menubar-menu
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
133 (cons "%_Lisp" (construct-lisp-mode-menu nil t)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 (if (not emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 (let ((i 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 (setq emacs-lisp-mode-syntax-table (make-syntax-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 (while (< i ?0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 (setq i (1+ i)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 (setq i (1+ ?9))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 (while (< i ?A)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 (setq i (1+ i)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 (setq i (1+ ?Z))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 (while (< i ?a)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 (setq i (1+ i)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 (setq i (1+ ?z))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 (while (< i 128)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 (setq i (1+ i)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 (modify-syntax-entry ? " " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 (modify-syntax-entry ?\t " " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 (modify-syntax-entry ?\f " " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 (modify-syntax-entry ?\n "> " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 ;; Give CR the same syntax as newline, for selective-display.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 (modify-syntax-entry ?\^m "> " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 (modify-syntax-entry ?\; "< " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 (modify-syntax-entry ?` "' " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 (modify-syntax-entry ?' "' " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (modify-syntax-entry ?, "' " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 ;; Used to be singlequote; changed for flonums.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 (modify-syntax-entry ?. "_ " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 (modify-syntax-entry ?# "' " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (modify-syntax-entry ?\" "\" " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 (modify-syntax-entry ?\\ "\\ " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 (modify-syntax-entry ?\( "() " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 (modify-syntax-entry ?\) ")( " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 (modify-syntax-entry ?\[ "(] " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 (modify-syntax-entry ?\] ")[ " emacs-lisp-mode-syntax-table)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 (if (not lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 (progn (setq lisp-mode-syntax-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 (copy-syntax-table emacs-lisp-mode-syntax-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 (modify-syntax-entry ?\[ "_ " lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 ;; XEmacs changes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 (modify-syntax-entry ?\] "_ " lisp-mode-syntax-table)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
179 (modify-syntax-entry ?# "' 58" lisp-mode-syntax-table)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
180 (modify-syntax-entry ?| "\" 67" lisp-mode-syntax-table)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 (define-abbrev-table 'lisp-mode-abbrev-table ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 (defvar lisp-imenu-generic-expression
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 '(
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 (nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 "^\\s-*(def\\(un\\|subst\\|macro\\|advice\\)\\s-+\\([-A-Za-z0-9+*|:]+\\)" 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 ("Variables"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 "^\\s-*(def\\(var\\|const\\|custom\\)\\s-+\\([-A-Za-z0-9+*|:]+\\)" 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 ("Types"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 "^\\s-*(def\\(group\\|type\\|struct\\|class\\|ine-condition\\)\\s-+\\([-A-Za-z0-9+*|:]+\\)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 (defun lisp-mode-variables (lisp-syntax)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 (cond (lisp-syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 (set-syntax-table lisp-mode-syntax-table)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 (setq local-abbrev-table lisp-mode-abbrev-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 (make-local-variable 'paragraph-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 (setq paragraph-start (concat page-delimiter "\\|$" ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 (make-local-variable 'paragraph-separate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (setq paragraph-separate paragraph-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (make-local-variable 'paragraph-ignore-fill-prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 (setq paragraph-ignore-fill-prefix t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 (make-local-variable 'fill-paragraph-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (setq fill-paragraph-function 'lisp-fill-paragraph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 ;; Adaptive fill mode gets in the way of auto-fill,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 ;; and should make no difference for explicit fill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 ;; because lisp-fill-paragraph should do the job.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 (make-local-variable 'adaptive-fill-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (setq adaptive-fill-mode nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 (make-local-variable 'indent-line-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 (setq indent-line-function 'lisp-indent-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 (make-local-variable 'indent-region-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 (setq indent-region-function 'lisp-indent-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 (make-local-variable 'parse-sexp-ignore-comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 (setq parse-sexp-ignore-comments t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 (make-local-variable 'outline-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (setq outline-regexp ";;; \\|(....")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (make-local-variable 'comment-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 (setq comment-start ";")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 (set (make-local-variable 'block-comment-start) ";;")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 (make-local-variable 'comment-start-skip)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 ;; Look within the line for a ; following an even number of backslashes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 ;; after either a non-backslash or the line beginning.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (setq comment-start-skip "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+ *")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 (make-local-variable 'comment-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 (setq comment-column 40)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 (make-local-variable 'comment-indent-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 (setq comment-indent-function 'lisp-comment-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (set (make-local-variable 'dabbrev-case-fold-search) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (set (make-local-variable 'dabbrev-case-replace) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (make-local-variable 'imenu-generic-expression)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (setq imenu-generic-expression lisp-imenu-generic-expression))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (defvar shared-lisp-mode-map ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 "Keymap for commands shared by all sorts of Lisp modes.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (if shared-lisp-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (setq shared-lisp-mode-map (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 ;; XEmacs changes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (set-keymap-name shared-lisp-mode-map 'shared-lisp-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (define-key shared-lisp-mode-map "\M-;" 'lisp-indent-for-comment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (define-key shared-lisp-mode-map "\e\C-q" 'indent-sexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 (defvar emacs-lisp-mode-map ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 "Keymap for Emacs Lisp mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 All commands in `shared-lisp-mode-map' are inherited by this map.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 (if emacs-lisp-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 ;; XEmacs: Ignore FSF nconc stuff
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 (setq emacs-lisp-mode-map (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (set-keymap-name emacs-lisp-mode-map 'emacs-lisp-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 (set-keymap-parents emacs-lisp-mode-map (list shared-lisp-mode-map))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (define-key emacs-lisp-mode-map "\e\t" 'lisp-complete-symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 ;; XEmacs: Not sure what the FSF menu bindings are. I hope XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 ;; doesn't need them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (defun emacs-lisp-byte-compile ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 "Byte compile the file containing the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 (if buffer-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 ;; XEmacs change. Force buffer save first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 (save-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 (byte-compile-file buffer-file-name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 (error "The buffer must be saved in a file first.")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (defun emacs-lisp-byte-compile-and-load ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 "Byte-compile the current file (if it has changed), then load compiled code."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (or buffer-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 (error "The buffer must be saved in a file first"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (require 'bytecomp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 ;; Recompile if file or buffer has changed since last compilation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 (if (and (buffer-modified-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (y-or-n-p (format "save buffer %s first? " (buffer-name))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 (save-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (let ((compiled-file-name (byte-compile-dest-file buffer-file-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (if (file-newer-than-file-p compiled-file-name buffer-file-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 (load-file compiled-file-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 (byte-compile-file buffer-file-name t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 (defun emacs-lisp-mode ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 "Major mode for editing Lisp code to run in Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 Commands:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 Delete converts tabs to spaces as it moves back.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 Blank lines separate paragraphs. Semicolons start comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 \\{emacs-lisp-mode-map}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 Entry to this mode calls the value of `emacs-lisp-mode-hook'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 if that value is non-nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 (kill-all-local-variables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 (use-local-map emacs-lisp-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 (set-syntax-table emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 ;; XEmacs changes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 (setq major-mode 'emacs-lisp-mode
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
305 mode-popup-menu emacs-lisp-mode-popup-menu
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 mode-name "Emacs-Lisp")
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
307 (if (and (featurep 'menubar)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
308 current-menubar)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
309 (progn
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 ;; make a local copy of the menubar, so our modes don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 ;; change the global menubar
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
312 (set-buffer-menubar current-menubar)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
313 (add-submenu nil emacs-lisp-mode-menubar-menu)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 (lisp-mode-variables nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 (run-hooks 'emacs-lisp-mode-hook))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316
430
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
317 (put 'emacs-lisp-mode 'font-lock-lisp-like t)
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
318
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 (defvar lisp-mode-map ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 "Keymap for ordinary Lisp mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 All commands in `shared-lisp-mode-map' are inherited by this map.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (if lisp-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 ;; XEmacs changes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (setq lisp-mode-map (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 (set-keymap-name lisp-mode-map 'lisp-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 (set-keymap-parents lisp-mode-map (list shared-lisp-mode-map))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (define-key lisp-mode-map "\e\C-x" 'lisp-send-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 ;; gag, no. use ilisp. -jwz
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 ;; (define-key lisp-mode-map "\C-c\C-z" 'run-lisp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 (defun lisp-mode ()
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 502
diff changeset
335 "Major mode for editing Lisp code for Lisps other than Emacs Lisp.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 Commands:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 Delete converts tabs to spaces as it moves back.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 Blank lines separate paragraphs. Semicolons start comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 \\{lisp-mode-map}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 Note that `run-lisp' may be used either to start an inferior Lisp job
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 or to switch back to an existing one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 Entry to this mode calls the value of `lisp-mode-hook'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 if that value is non-nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 (kill-all-local-variables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (use-local-map lisp-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (setq major-mode 'lisp-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 (setq mode-name "Lisp")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 (lisp-mode-variables t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 (set-syntax-table lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 (run-hooks 'lisp-mode-hook))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 ;; This will do unless shell.el is loaded.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 (defun lisp-send-defun ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 "Send the current defun to the Lisp process made by \\[run-lisp]."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 (error "Process lisp does not exist"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 ;; XEmacs change: emacs-lisp-mode-map is a more appropriate parent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 (defvar lisp-interaction-mode-map ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 "Keymap for Lisp Interaction mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 All commands in `shared-lisp-mode-map' are inherited by this map.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 (if lisp-interaction-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 ;; XEmacs set keymap our way
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 (setq lisp-interaction-mode-map (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 (set-keymap-name lisp-interaction-mode-map 'lisp-interaction-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 (set-keymap-parents lisp-interaction-mode-map (list emacs-lisp-mode-map))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 (define-key lisp-interaction-mode-map "\e\C-x" 'eval-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 (define-key lisp-interaction-mode-map "\e\t" 'lisp-complete-symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 (define-key lisp-interaction-mode-map "\n" 'eval-print-last-sexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 (defun lisp-interaction-mode ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 "Major mode for typing and evaluating Lisp forms.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 Like Lisp mode except that \\[eval-print-last-sexp] evals the Lisp expression
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 before point, and prints its value into the buffer, advancing point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 Commands:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 Delete converts tabs to spaces as it moves back.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 Paragraphs are separated only by blank lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 Semicolons start comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 \\{lisp-interaction-mode-map}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 Entry to this mode calls the value of `lisp-interaction-mode-hook'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 if that value is non-nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 (kill-all-local-variables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 (use-local-map lisp-interaction-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 (setq major-mode 'lisp-interaction-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 (setq mode-name "Lisp Interaction")
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
393 (setq mode-popup-menu lisp-interaction-mode-popup-menu)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
394 (if (and (featurep 'menubar)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
395 current-menubar)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
396 (progn
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
397 ;; make a local copy of the menubar, so our modes don't
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
398 ;; change the global menubar
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
399 (set-buffer-menubar current-menubar)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
400 (add-submenu nil lisp-interaction-mode-menubar-menu)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 (set-syntax-table emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 (lisp-mode-variables nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 (run-hooks 'lisp-interaction-mode-hook))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 (defun eval-print-last-sexp ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 "Evaluate sexp before point; print value into current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (let ((standard-output (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 (terpri)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 (eval-last-sexp t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 (terpri)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 (defcustom eval-interactive-verbose t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 "*Non-nil means that interactive evaluation can print messages.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 The messages are printed when the expression is treated differently
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 using `\\[eval-last-sexp]' and `\\[eval-defun]' than it than it would have been
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 treated noninteractively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 The printed messages are \"defvar treated as defconst\" and \"defcustom
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 evaluation forced\". See `eval-interactive' for more details."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 :group 'lisp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 (defun eval-interactive (expr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 "Like `eval' except that it transforms defvars to defconsts.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 The evaluation of defcustom forms is forced."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 (cond ((and (eq (car-safe expr) 'defvar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 (> (length expr) 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 (eval (cons 'defconst (cdr expr)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 (when eval-interactive-verbose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 (message "defvar treated as defconst")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 (sit-for 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 (message ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 (nth 1 expr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 ((and (eq (car-safe expr) 'defcustom)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 (> (length expr) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 (default-boundp (nth 1 expr)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 ;; Force variable to be bound
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 ;; #### defcustom might specify a different :set method.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 (set-default (nth 1 expr) (eval (nth 2 expr)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 ;; And evaluate the defcustom
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 (eval expr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 (when eval-interactive-verbose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 (message "defcustom evaluation forced")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 (sit-for 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 (message ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 (nth 1 expr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 (eval expr))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 ;; XEmacs change, based on Bob Weiner suggestion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 (defun eval-last-sexp (eval-last-sexp-arg-internal) ;dynamic scoping wonderment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 "Evaluate sexp before point; print value in minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 With argument, print output into current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 (opoint (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 ignore-quotes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 (prin1 (eval-interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 (letf (((syntax-table) emacs-lisp-mode-syntax-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 ;; If this sexp appears to be enclosed in `...' then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 ;; ignore the surrounding quotes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 (setq ignore-quotes (or (eq (char-after) ?\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 (eq (char-before) ?\')))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 (forward-sexp -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 ;; vladimir@cs.ualberta.ca 30-Jul-1997: skip ` in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 ;; `variable' so that the value is returned, not the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 ;; name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 (if (and ignore-quotes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 (eq (char-after) ?\`))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 (forward-char))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 (narrow-to-region (point-min) opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 (let ((expr (read (current-buffer))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 (if (eq (car-safe expr) 'interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 ;; If it's an (interactive ...) form, it's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 ;; more useful to show how an interactive call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 ;; would use it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 `(call-interactively
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 (lambda (&rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 ,expr args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 expr)))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 (defun eval-defun (eval-defun-arg-internal)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 "Evaluate defun that point is in or before.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 Print value in minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 With argument, insert value in current buffer after the defun."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 (let ((standard-output (if eval-defun-arg-internal (current-buffer) t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 (prin1 (eval-interactive (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 (end-of-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 (beginning-of-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 (read (current-buffer)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 (defun lisp-comment-indent ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 (if (looking-at "\\s<\\s<\\s<")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 (current-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 (if (looking-at "\\s<\\s<")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 ;; #### FSF has:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 ;; (let ((tem (or (calculate-lisp-indent) (current-column)))) ...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 (let ((tem (calculate-lisp-indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 (if (listp tem) (car tem) tem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 (max (if (bolp) 0 (1+ (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 comment-column))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 (defun lisp-indent-for-comment ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 "Indent this line's comment appropriately, or insert an empty comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 If adding a new comment on a blank line, use `block-comment-start' instead
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 of `comment-start' to open the comment."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 ;; by Stig@hackvan.com
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 ;; #### - This functionality, the recognition of block-comment-{start,end},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 ;; will perhaps be standardized across modes and move to indent-for-comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 (if (and block-comment-start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 (save-excursion (beginning-of-line) (looking-at "^[ \t]*$")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 (insert block-comment-start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 (indent-for-comment))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 (defvar lisp-indent-offset nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 (defvar lisp-indent-function 'lisp-indent-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 (defun lisp-indent-line (&optional whole-exp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 "Indent current line as Lisp code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 With argument, indent any additional lines of the same expression
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 rigidly along with this one."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 (let ((indent (calculate-lisp-indent)) shift-amt beg end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 (pos (- (point-max) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 (setq beg (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 (if (looking-at "\\s<\\s<\\s<")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 ;; Don't alter indentation of a ;;; comment line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 (goto-char (- (point-max) pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 (if (and (looking-at "\\s<") (not (looking-at "\\s<\\s<")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 ;; Single-semicolon comment lines should be indented
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 ;; as comment lines, not as code.
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
543 (progn (indent-for-comment) (backward-char 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 (if (listp indent) (setq indent (car indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 (setq shift-amt (- indent (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 (if (zerop shift-amt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 (delete-region beg (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 (indent-to indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 ;; If initial point was within line's indentation,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 ;; position after the indentation. Else stay at same point in text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 (if (> (- (point-max) pos) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 (goto-char (- (point-max) pos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 ;; If desired, shift remaining lines of expression the same amount.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 (and whole-exp (not (zerop shift-amt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 (goto-char beg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 (forward-sexp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 (setq end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 (goto-char beg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 (setq beg (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 (> end beg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 (indent-code-rigidly beg end shift-amt)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 (defvar calculate-lisp-indent-last-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 (defun calculate-lisp-indent (&optional parse-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 "Return appropriate indentation for current line as Lisp code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 In usual case returns an integer: the column to indent to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 Can instead return a list, whose car is the column to indent to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 This means that following lines at the same level of indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 should not necessarily be indented the same way.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 The second element of the list is the buffer position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 of the start of the containing expression."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 (let ((indent-point (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 ;; XEmacs change (remove paren-depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 state ;;paren-depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 ;; setting this to a number inhibits calling hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 (desired-indent nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 (retry t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 calculate-lisp-indent-last-sexp containing-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 (if parse-start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 (goto-char parse-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 (beginning-of-defun))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 ;; Find outermost containing sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 (while (< (point) indent-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 (setq state (parse-partial-sexp (point) indent-point 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 ;; Find innermost containing sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 (while (and retry
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 ;; XEmacs change (remove paren-depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 (> ;;(setq paren-depth (elt state 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 (elt state 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 (setq retry nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 (setq calculate-lisp-indent-last-sexp (elt state 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 (setq containing-sexp (elt state 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 ;; Position following last unclosed open.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 (goto-char (1+ containing-sexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 ;; Is there a complete sexp since then?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 (if (and calculate-lisp-indent-last-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 (> calculate-lisp-indent-last-sexp (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 ;; Yes, but is there a containing sexp after that?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 (let ((peek (parse-partial-sexp calculate-lisp-indent-last-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 indent-point 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 (if (setq retry (car (cdr peek))) (setq state peek)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 (if retry
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 ;; Innermost containing sexp found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 (goto-char (1+ containing-sexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 (if (not calculate-lisp-indent-last-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 ;; indent-point immediately follows open paren.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 ;; Don't call hook.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 (setq desired-indent (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 ;; Find the start of first element of containing sexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 (cond ((looking-at "\\s(")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 ;; First element of containing sexp is a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 ;; Indent under that list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 ((> (save-excursion (forward-line 1) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 calculate-lisp-indent-last-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 ;; This is the first line to start within the containing sexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 ;; It's almost certainly a function call.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 (if (= (point) calculate-lisp-indent-last-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 ;; Containing sexp has nothing before this line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 ;; except the first element. Indent under that element.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 ;; Skip the first element, find start of second (the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 ;; argument of the function call) and indent under.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 (progn (forward-sexp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 (parse-partial-sexp (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 calculate-lisp-indent-last-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 0 t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 (backward-prefix-chars))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 ;; Indent beneath first sexp on same line as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 ;; calculate-lisp-indent-last-sexp. Again, it's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 ;; almost certainly a function call.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 (goto-char calculate-lisp-indent-last-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 0 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 (backward-prefix-chars)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 ;; Point is at the point to indent under unless we are inside a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 ;; Call indentation hook except when overridden by lisp-indent-offset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 ;; or if the desired indentation has already been computed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 (let ((normal-indent (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 (cond ((elt state 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 ;; Inside a string, don't change indentation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 (goto-char indent-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 (desired-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 ((and (boundp 'lisp-indent-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 lisp-indent-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 (not retry))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 (or (funcall lisp-indent-function indent-point state)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 normal-indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 ;; XEmacs change:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 ;; lisp-indent-offset shouldn't override lisp-indent-function !
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 ((and (integerp lisp-indent-offset) containing-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 ;; Indent by constant offset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 (goto-char containing-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 (+ normal-indent lisp-indent-offset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 normal-indent))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 (defun lisp-indent-function (indent-point state)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 ;; free reference to `calculate-lisp-indent-last-sexp'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 ;; in #'calculate-lisp-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 (let ((normal-indent (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 (goto-char (1+ (elt state 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 (if (and (elt state 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 (not (looking-at "\\sw\\|\\s_")))
629
a6c89d799f00 [xemacs-hg @ 2001-07-15 08:18:59 by adrian]
adrian
parents: 613
diff changeset
680 ;; car of form doesn't seem to be a symbol
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 (if (not (> (save-excursion (forward-line 1) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 calculate-lisp-indent-last-sexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 (progn (goto-char calculate-lisp-indent-last-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 (parse-partial-sexp (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 calculate-lisp-indent-last-sexp 0 t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 ;; Indent under the list or under the first sexp on the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 ;; line as calculate-lisp-indent-last-sexp. Note that first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 ;; thing on that line has to be complete sexp since we are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 ;; inside the innermost containing sexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 (backward-prefix-chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 (let ((function (buffer-substring (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 (progn (forward-sexp 1) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 method)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
697 (if (condition-case nil
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
698 (save-excursion
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
699 (backward-up-list 1)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
700 (backward-up-list 1)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
701 (backward-up-list 1)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
702 (looking-at "(flet\\s-"))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
703 (error nil))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
704 (setq method 'defun)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
705 (setq method (or (get (intern-soft function) 'lisp-indent-function)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
706 (get (intern-soft function) 'lisp-indent-hook))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 (cond ((or (eq method 'defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 (and (null method)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 (> (length function) 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 (string-match "\\`def" function)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 (lisp-indent-defform state indent-point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 ((integerp method)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 (lisp-indent-specform method state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 indent-point normal-indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 (method
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 (funcall method state indent-point)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 (defvar lisp-body-indent 2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 "Number of columns to indent the second line of a `(def...)' form.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 (defun lisp-indent-specform (count state indent-point normal-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 (let ((containing-form-start (elt state 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 (i count)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 body-indent containing-form-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 ;; Move to the start of containing form, calculate indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 ;; to use for non-distinguished forms (> count), and move past the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 ;; function symbol. lisp-indent-function guarantees that there is at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 ;; least one word or symbol character following open paren of containing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 ;; form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 (goto-char containing-form-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 (setq containing-form-column (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 (setq body-indent (+ lisp-body-indent containing-form-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 (forward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 (forward-sexp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 ;; Now find the start of the last form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 (parse-partial-sexp (point) indent-point 1 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 (while (and (< (point) indent-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 (condition-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 (setq count (1- count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 (forward-sexp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 (parse-partial-sexp (point) indent-point 1 t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 (error nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 ;; Point is sitting on first character of last (or count) sexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 (if (> count 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 ;; A distinguished form. If it is the first or second form use double
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 ;; lisp-body-indent, else normal indent. With lisp-body-indent bound
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 ;; to 2 (the default), this just happens to work the same with if as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 ;; the older code, but it makes unwind-protect, condition-case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 ;; with-output-to-temp-buffer, et. al. much more tasteful. The older,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 ;; less hacked, behavior can be obtained by replacing below with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 ;; (list normal-indent containing-form-start).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 (if (<= (- i count) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 (list (+ containing-form-column (* 2 lisp-body-indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 containing-form-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 (list normal-indent containing-form-start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 ;; A non-distinguished form. Use body-indent if there are no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 ;; distinguished forms and this is the first undistinguished form,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 ;; or if this is the first undistinguished form and the preceding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 ;; distinguished form has indentation at least as great as body-indent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 (if (or (and (= i 0) (= count 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 (and (= count 0) (<= body-indent normal-indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 body-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 normal-indent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 (defun lisp-indent-defform (state indent-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 (goto-char (car (cdr state)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 (if (> (point) (car (cdr (cdr state))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 (goto-char (car (cdr state)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 (+ lisp-body-indent (current-column)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 ;; (put 'progn 'lisp-indent-function 0), say, causes progn to be indented
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 ;; like defun if the first form is placed on the next line, otherwise
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 ;; it is indented like any other form (i.e. forms line up under first).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 (put 'lambda 'lisp-indent-function 'defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 (put 'autoload 'lisp-indent-function 'defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 (put 'progn 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 (put 'prog1 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 (put 'prog2 'lisp-indent-function 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 (put 'save-excursion 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 (put 'save-window-excursion 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 (put 'save-selected-window 'lisp-indent-function 0)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
787 (put 'with-selected-window 'lisp-indent-function 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 (put 'save-selected-frame 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 (put 'with-selected-frame 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 (put 'save-restriction 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 (put 'save-match-data 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 (put 'let 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 (put 'let* 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 (put 'let-specifier 'lisp-indent-function 1)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
795 (put 'flet 'lisp-indent-function 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 (put 'while 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 (put 'if 'lisp-indent-function 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 (put 'catch 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 (put 'condition-case 'lisp-indent-function 2)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
800 (put 'handler-case 'lisp-indent-function 1)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
801 (put 'handler-bind 'lisp-indent-function 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 (put 'call-with-condition-handler 'lisp-indent-function 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 (put 'unwind-protect 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 (put 'save-current-buffer 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 (put 'with-current-buffer 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 (put 'with-string-as-buffer-contents 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 (put 'with-temp-file 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 (put 'with-temp-buffer 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 (put 'with-output-to-string 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 (put 'with-output-to-temp-buffer 'lisp-indent-function 1)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
811 (put 'with-slots 'lisp-indent-function 2)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
812 (put 'with-open-file 'lisp-indent-function 1)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
813 (put 'with-open-stream 'lisp-indent-function 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 (put 'eval-after-load 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 (put 'display-message 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 (put 'display-warning 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 (put 'lmessage 'lisp-indent-function 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 (put 'lwarn 'lisp-indent-function 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 (put 'global-set-key 'lisp-indent-function 1)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
820 (put 'print-unreadable-object 'lisp-indent-function 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 (defun indent-sexp (&optional endpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 "Indent each line of the list starting just after point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 If optional arg ENDPOS is given, indent each line, stopping when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 ENDPOS is encountered."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 (let ((indent-stack (list nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 (next-depth 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 ;; If ENDPOS is non-nil, use nil as STARTING-POINT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 ;; so that calculate-lisp-indent will find the beginning of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 ;; the defun we are in.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 ;; If ENDPOS is nil, it is safe not to scan before point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 ;; since every line we indent is more deeply nested than point is.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 (starting-point (if endpos nil (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 (last-point (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 last-depth bol outer-loop-done inner-loop-done state this-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 (or endpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 ;; Get error now if we don't have a complete sexp after point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 (save-excursion (forward-sexp 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 (setq outer-loop-done nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 (while (if endpos (< (point) endpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 (not outer-loop-done))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 (setq last-depth next-depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 inner-loop-done nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 ;; Parse this line so we can learn the state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 ;; to indent the next line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 ;; This inner loop goes through only once
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 ;; unless a line ends inside a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 (while (and (not inner-loop-done)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 (not (setq outer-loop-done (eobp))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 nil nil state))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 (setq next-depth (car state))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 ;; If the line contains a comment other than the sort
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 ;; that is indented like code,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 ;; indent it now with indent-for-comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 ;; Comments indented like code are right already.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 ;; In any case clear the in-comment flag in the state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 ;; because parse-partial-sexp never sees the newlines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 (if (car (nthcdr 4 state))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 (progn (indent-for-comment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 (setcar (nthcdr 4 state) nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 ;; If this line ends inside a string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 ;; go straight to next line, remaining within the inner loop,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 ;; and turn off the \-flag.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 (if (car (nthcdr 3 state))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 (setcar (nthcdr 5 state) nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 (setq inner-loop-done t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 (and endpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 (<= next-depth 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 (setq indent-stack (append indent-stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 (make-list (- next-depth) nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 last-depth (- last-depth next-depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 next-depth 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 (or outer-loop-done endpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 (setq outer-loop-done (<= next-depth 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 (if outer-loop-done
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 (while (> last-depth next-depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 (setq indent-stack (cdr indent-stack)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 last-depth (1- last-depth)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 (while (< last-depth next-depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 (setq indent-stack (cons nil indent-stack)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 last-depth (1+ last-depth)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 ;; Now go to the next line and indent it according
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 ;; to what we learned from parsing the previous one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 (setq bol (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 ;; But not if the line is blank, or just a comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 ;; (except for double-semi comments; indent them as usual).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 (if (or (eobp) (looking-at "\\s<\\|\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 (if (and (car indent-stack)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 (>= (car indent-stack) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 (setq this-indent (car indent-stack))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 (let ((val (calculate-lisp-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 (if (car indent-stack) (- (car indent-stack))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 starting-point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 (if (integerp val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 (setcar indent-stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 (setq this-indent val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 (setcar indent-stack (- (car (cdr val))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 (setq this-indent (car val)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 (if (/= (current-column) this-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 (progn (delete-region bol (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 (indent-to this-indent)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 (or outer-loop-done
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 (setq outer-loop-done (= (point) last-point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 (setq last-point (point)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 ;; Indent every line whose first char is between START and END inclusive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 (defun lisp-indent-region (start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 (let ((endmark (copy-marker end)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 (and (bolp) (not (eolp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 (lisp-indent-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 (indent-sexp endmark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 (set-marker endmark nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 ;;;; Lisp paragraph filling commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 (defun lisp-fill-paragraph (&optional justify)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 "Like \\[fill-paragraph], but handle Emacs Lisp comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 If any of the current line is a comment, fill the comment or the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 paragraph of it that point is in, preserving the comment's indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 and initial semicolons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 (let (
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 ;; Non-nil if the current line contains a comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 has-comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 ;; Non-nil if the current line contains code and a comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 has-code-and-comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 ;; If has-comment, the appropriate fill-prefix for the comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 comment-fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 ;; Figure out what kind of comment we are looking at.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 ;; A line with nothing but a comment on it?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 ((looking-at "[ \t]*;[; \t]*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 (setq has-comment t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 comment-fill-prefix (buffer-substring (match-beginning 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 (match-end 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 ;; A line with some code, followed by a comment? Remember that the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 ;; semi which starts the comment shouldn't be part of a string or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 ;; character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 ;; XEmacs Try this the FSF and see if it works.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 ; ((progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 ; (while (not (looking-at ";\\|$"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 ; (skip-chars-forward "^;\n\"\\\\?")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 ; (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 ; ((eq (char-after (point)) ?\\) (forward-char 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 ; ((memq (char-after (point)) '(?\" ??)) (forward-sexp 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 ; (looking-at ";+[\t ]*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 ; (setq has-comment t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 ((condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 (narrow-to-region (point-min)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 (save-excursion (end-of-line) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 (while (not (looking-at ";\\|$"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 (skip-chars-forward "^;\n\"\\\\?")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 ((eq (char-after (point)) ?\\) (forward-char 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 ((memq (char-after (point)) '(?\" ??)) (forward-sexp 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 (looking-at ";+[\t ]*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 (error nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 (setq has-comment t has-code-and-comment t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 (setq comment-fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 (concat (make-string (/ (current-column) 8) ?\t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 (make-string (% (current-column) 8) ?\ )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 (buffer-substring (match-beginning 0) (match-end 0)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 (if (not has-comment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 (fill-paragraph justify)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 ;; Narrow to include only the comment, and then fill the region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 (narrow-to-region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 ;; Find the first line we should include in the region to fill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 (while (and (zerop (forward-line -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 (looking-at "^[ \t]*;")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 ;; We may have gone too far. Go forward again.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 (or (looking-at ".*;")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 ;; Find the beginning of the first line past the region to fill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 (while (progn (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 (looking-at "^[ \t]*;")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 ;; Lines with only semicolons on them can be paragraph boundaries.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 (let* ((paragraph-start (concat paragraph-start "\\|[ \t;]*$"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 (paragraph-separate (concat paragraph-start "\\|[ \t;]*$"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 (paragraph-ignore-fill-prefix nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 (fill-prefix comment-fill-prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 (after-line (if has-code-and-comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 (forward-line 1) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 (end (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 (forward-paragraph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 (or (bolp) (newline 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 ;; If this comment starts on a line with code,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 ;; include that like in the filling.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 (beg (progn (backward-paragraph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 (if (eq (point) after-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 (forward-line -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 (fill-region-as-paragraph beg end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 justify nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 (goto-char beg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 (if (looking-at fill-prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 (re-search-forward comment-start-skip)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 (point))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 (defun indent-code-rigidly (start end arg &optional nochange-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 "Indent all lines of code, starting in the region, sideways by ARG columns.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 Does not affect lines starting inside comments or strings, assuming that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 the start of the region is not inside them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 Called from a program, takes args START, END, COLUMNS and NOCHANGE-REGEXP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 The last is a regexp which, if matched at the beginning of a line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 means don't indent that line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 (interactive "r\np")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 (let (state)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 (setq end (point-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 (or (bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 (setq state (parse-partial-sexp (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 (forward-line 1) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 nil nil state)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 (while (< (point) end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 (or (car (nthcdr 3 state))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 (and nochange-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 (looking-at nochange-regexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 ;; If line does not start in string, indent it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 (let ((indent (current-indentation)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 (or (eolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 (indent-to (max 0 (+ indent arg)) 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 (setq state (parse-partial-sexp (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 (forward-line 1) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 nil nil state))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 (provide 'lisp-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 ;;; lisp-mode.el ends here