annotate lisp/lisp-mode.el @ 392:1f50e6fe4f3f r21-2-11

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