Mercurial > hg > xemacs-beta
comparison lisp/lisp.el @ 209:41ff10fd062f r20-4b3
Import from CVS: tag r20-4b3
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:04:58 +0200 |
parents | |
children | 8efd647ea9ca |
comparison
equal
deleted
inserted
replaced
208:f427b8ec4379 | 209:41ff10fd062f |
---|---|
1 ;;; lisp.el --- Lisp editing commands for XEmacs | |
2 | |
3 ;; Copyright (C) 1985, 1986, 1994, 1997 Free Software Foundation, Inc. | |
4 | |
5 ;; Maintainer: FSF | |
6 ;; Keywords: lisp, languages, dumped | |
7 | |
8 ;; This file is part of XEmacs. | |
9 | |
10 ;; XEmacs is free software; you can redistribute it and/or modify it | |
11 ;; under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; XEmacs is distributed in the hope that it will be useful, but | |
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 ;; General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
23 ;; 02111-1307, USA. | |
24 | |
25 ;;; Synched up with: Emacs/Mule zeta. | |
26 | |
27 ;;; Commentary: | |
28 | |
29 ;; This file is dumped with XEmacs. | |
30 | |
31 ;; Lisp editing commands to go with Lisp major mode. | |
32 | |
33 ;; 06/11/1997 - Use char-(after|before) instead of | |
34 ;; (following|preceding)-char. -slb | |
35 | |
36 ;;; Code: | |
37 | |
38 ;; Note that this variable is used by non-lisp modes too. | |
39 (defcustom defun-prompt-regexp nil | |
40 "*Non-nil => regexp to ignore, before the character that starts a defun. | |
41 This is only necessary if the opening paren or brace is not in column 0. | |
42 See `beginning-of-defun'." | |
43 :type '(choice (const :tag "none" nil) | |
44 regexp) | |
45 :group 'lisp) | |
46 | |
47 (make-variable-buffer-local 'defun-prompt-regexp) | |
48 | |
49 (defcustom parens-require-spaces t | |
50 "Non-nil => `insert-parentheses' should insert whitespace as needed." | |
51 :type 'boolean | |
52 :group 'editing-basics | |
53 :group 'lisp) | |
54 | |
55 (defun forward-sexp (&optional arg) | |
56 "Move forward across one balanced expression (sexp). | |
57 With argument, do it that many times. Negative arg -N means | |
58 move backward across N balanced expressions." | |
59 ;; XEmacs change (for zmacs regions) | |
60 (interactive "_p") | |
61 (or arg (setq arg 1)) | |
62 ;; XEmacs: evil hack! The other half of the evil hack below. | |
63 (if (and (> arg 0) (looking-at "#s(")) | |
64 (goto-char (+ (point) 2))) | |
65 ;; XEmacs change -- don't bomb out if unbalanced sexp | |
66 (goto-char (or (scan-sexps (point) arg) (buffer-end arg))) | |
67 (if (< arg 0) (backward-prefix-chars)) | |
68 ;; XEmacs: evil hack! Skip back over #s so that structures are read | |
69 ;; properly. the current cheesified syntax tables just aren't up to | |
70 ;; this. | |
71 (if (and (< arg 0) | |
72 (eq (char-after (point)) ?\() | |
73 (>= (- (point) (point-min)) 2) | |
74 (eq (char-after (- (point) 1)) ?s) | |
75 (eq (char-after (- (point) 2)) ?#)) | |
76 (goto-char (- (point) 2)))) | |
77 | |
78 (defun backward-sexp (&optional arg) | |
79 "Move backward across one balanced expression (sexp). | |
80 With argument, do it that many times. Negative arg -N means | |
81 move forward across N balanced expressions." | |
82 ;; XEmacs change (for zmacs regions) | |
83 (interactive "_p") | |
84 (or arg (setq arg 1)) | |
85 (forward-sexp (- arg))) | |
86 | |
87 (defun mark-sexp (arg) | |
88 "Set mark ARG sexps from point. | |
89 The place mark goes is the same place \\[forward-sexp] would | |
90 move to with the same argument. | |
91 Repeat this command to mark more sexps in the same direction." | |
92 (interactive "p") | |
93 ;; XEmacs change | |
94 (mark-something 'mark-sexp 'forward-sexp arg)) | |
95 | |
96 (defun forward-list (&optional arg) | |
97 "Move forward across one balanced group of parentheses. | |
98 With argument, do it that many times. | |
99 Negative arg -N means move backward across N groups of parentheses." | |
100 ;; XEmacs change | |
101 (interactive "_p") | |
102 (or arg (setq arg 1)) | |
103 (goto-char (or (scan-lists (point) arg 0) (buffer-end arg)))) | |
104 | |
105 (defun backward-list (&optional arg) | |
106 "Move backward across one balanced group of parentheses. | |
107 With argument, do it that many times. | |
108 Negative arg -N means move forward across N groups of parentheses." | |
109 ;; XEmacs change (for zmacs regions) | |
110 (interactive "_p") | |
111 (or arg (setq arg 1)) | |
112 (forward-list (- arg))) | |
113 | |
114 (defun down-list (arg) | |
115 "Move forward down one level of parentheses. | |
116 With argument, do this that many times. | |
117 A negative argument means move backward but still go down a level. | |
118 In Lisp programs, an argument is required." | |
119 ;; XEmacs change (for zmacs regions) | |
120 (interactive "_p") | |
121 (let ((inc (if (> arg 0) 1 -1))) | |
122 (while (/= arg 0) | |
123 (goto-char (or (scan-lists (point) inc -1) (buffer-end arg))) | |
124 (setq arg (- arg inc))))) | |
125 | |
126 (defun backward-up-list (arg) | |
127 "Move backward out of one level of parentheses. | |
128 With argument, do this that many times. | |
129 A negative argument means move forward but still to a less deep spot. | |
130 In Lisp programs, an argument is required." | |
131 (interactive "_p") | |
132 (up-list (- arg))) | |
133 | |
134 (defun up-list (arg) | |
135 "Move forward out of one level of parentheses. | |
136 With argument, do this that many times. | |
137 A negative argument means move backward but still to a less deep spot. | |
138 In Lisp programs, an argument is required." | |
139 ;; XEmacs change (for zmacs regions) | |
140 (interactive "_p") | |
141 (let ((inc (if (> arg 0) 1 -1))) | |
142 (while (/= arg 0) | |
143 (goto-char (or (scan-lists (point) inc 1) (buffer-end arg))) | |
144 (setq arg (- arg inc))))) | |
145 | |
146 (defun kill-sexp (arg) | |
147 "Kill the sexp (balanced expression) following the cursor. | |
148 With argument, kill that many sexps after the cursor. | |
149 Negative arg -N means kill N sexps before the cursor." | |
150 (interactive "p") | |
151 (let ((opoint (point))) | |
152 (forward-sexp arg) | |
153 (kill-region opoint (point)))) | |
154 | |
155 (defun backward-kill-sexp (arg) | |
156 "Kill the sexp (balanced expression) preceding the cursor. | |
157 With argument, kill that many sexps before the cursor. | |
158 Negative arg -N means kill N sexps after the cursor." | |
159 (interactive "p") | |
160 (kill-sexp (- arg))) | |
161 | |
162 (defun beginning-of-defun (&optional arg) | |
163 "Move backward to the beginning of a defun. | |
164 With argument, do it that many times. Negative arg -N | |
165 means move forward to Nth following beginning of defun. | |
166 Returns t unless search stops due to beginning or end of buffer. | |
167 | |
168 Normally a defun starts when there is an char with open-parenthesis | |
169 syntax at the beginning of a line. If `defun-prompt-regexp' is | |
170 non-nil, then a string which matches that regexp may precede the | |
171 open-parenthesis, and point ends up at the beginning of the line." | |
172 ;; XEmacs change (for zmacs regions) | |
173 (interactive "_p") | |
174 (and (beginning-of-defun-raw arg) | |
175 (progn (beginning-of-line) t))) | |
176 | |
177 (defun beginning-of-defun-raw (&optional arg) | |
178 "Move point to the character that starts a defun. | |
179 This is identical to beginning-of-defun, except that point does not move | |
180 to the beginning of the line when `defun-prompt-regexp' is non-nil." | |
181 (interactive "p") | |
182 (and arg (< arg 0) (not (eobp)) (forward-char 1)) | |
183 (and (re-search-backward (if defun-prompt-regexp | |
184 (concat "^\\s(\\|" | |
185 "\\(" defun-prompt-regexp "\\)\\s(") | |
186 "^\\s(") | |
187 nil 'move (or arg 1)) | |
188 (progn (goto-char (1- (match-end 0)))) t)) | |
189 | |
190 ;; XEmacs change (optional buffer parameter) | |
191 (defun buffer-end (arg &optional buffer) | |
192 "Return `point-max' of BUFFER if ARG is > 0; return `point-min' otherwise. | |
193 BUFFER defaults to the current buffer if omitted." | |
194 (if (> arg 0) (point-max buffer) (point-min buffer))) | |
195 | |
196 (defun end-of-defun (&optional arg) | |
197 "Move forward to next end of defun. With argument, do it that many times. | |
198 Negative argument -N means move back to Nth preceding end of defun. | |
199 | |
200 An end of a defun occurs right after the close-parenthesis that matches | |
201 the open-parenthesis that starts a defun; see `beginning-of-defun'." | |
202 ;; XEmacs change (for zmacs regions) | |
203 (interactive "_p") | |
204 (if (or (null arg) (= arg 0)) (setq arg 1)) | |
205 (let ((first t)) | |
206 (while (and (> arg 0) (< (point) (point-max))) | |
207 (let ((pos (point))) ; XEmacs -- remove unused npos. | |
208 (while (progn | |
209 (if (and first | |
210 (progn | |
211 (end-of-line 1) | |
212 (beginning-of-defun-raw 1))) | |
213 nil | |
214 (or (bobp) (forward-char -1)) | |
215 (beginning-of-defun-raw -1)) | |
216 (setq first nil) | |
217 (forward-list 1) | |
218 (skip-chars-forward " \t") | |
219 (if (looking-at "\\s<\\|\n") | |
220 (forward-line 1)) | |
221 (<= (point) pos)))) | |
222 (setq arg (1- arg))) | |
223 (while (< arg 0) | |
224 (let ((pos (point))) | |
225 (beginning-of-defun-raw 1) | |
226 (forward-sexp 1) | |
227 (forward-line 1) | |
228 (if (>= (point) pos) | |
229 (if (beginning-of-defun-raw 2) | |
230 (progn | |
231 (forward-list 1) | |
232 (skip-chars-forward " \t") | |
233 (if (looking-at "\\s<\\|\n") | |
234 (forward-line 1))) | |
235 (goto-char (point-min))))) | |
236 (setq arg (1+ arg))))) | |
237 | |
238 (defun mark-defun () | |
239 "Put mark at end of this defun, point at beginning. | |
240 The defun marked is the one that contains point or follows point." | |
241 (interactive) | |
242 (push-mark (point)) | |
243 (end-of-defun) | |
244 (push-mark (point) nil t) | |
245 (beginning-of-defun) | |
246 (re-search-backward "^\n" (- (point) 1) t)) | |
247 | |
248 (defun narrow-to-defun (&optional arg) | |
249 "Make text outside current defun invisible. | |
250 The defun visible is the one that contains point or follows point." | |
251 (interactive) | |
252 (save-excursion | |
253 (widen) | |
254 (end-of-defun) | |
255 (let ((end (point))) | |
256 (beginning-of-defun) | |
257 (narrow-to-region (point) end)))) | |
258 | |
259 (defun insert-parentheses (arg) | |
260 "Enclose following ARG sexps in parentheses. Leave point after open-paren. | |
261 A negative ARG encloses the preceding ARG sexps instead. | |
262 No argument is equivalent to zero: just insert `()' and leave point between. | |
263 If `parens-require-spaces' is non-nil, this command also inserts a space | |
264 before and after, depending on the surrounding characters." | |
265 (interactive "P") | |
266 (if arg (setq arg (prefix-numeric-value arg)) | |
267 (setq arg 0)) | |
268 (cond ((> arg 0) (skip-chars-forward " \t")) | |
269 ((< arg 0) (forward-sexp arg) (setq arg (- arg)))) | |
270 (and parens-require-spaces | |
271 (not (bobp)) | |
272 (memq (char-syntax (char-before (point))) '(?w ?_ ?\) )) | |
273 (insert " ")) | |
274 (insert ?\() | |
275 (save-excursion | |
276 (or (eq arg 0) (forward-sexp arg)) | |
277 (insert ?\)) | |
278 (and parens-require-spaces | |
279 (not (eobp)) | |
280 (memq (char-syntax (char-after (point))) '(?w ?_ ?\( )) | |
281 (insert " ")))) | |
282 | |
283 (defun move-past-close-and-reindent () | |
284 "Move past next `)', delete indentation before it, then indent after it." | |
285 (interactive) | |
286 (up-list 1) | |
287 (forward-char -1) | |
288 (while (save-excursion ; this is my contribution | |
289 (let ((before-paren (point))) | |
290 (back-to-indentation) | |
291 (= (point) before-paren))) | |
292 (delete-indentation)) | |
293 (forward-char 1) | |
294 (newline-and-indent)) | |
295 | |
296 (defun lisp-complete-symbol () | |
297 "Perform completion on Lisp symbol preceding point. | |
298 Compare that symbol against the known Lisp symbols. | |
299 | |
300 The context determines which symbols are considered. | |
301 If the symbol starts just after an open-parenthesis, only symbols | |
302 with function definitions are considered. Otherwise, all symbols with | |
303 function definitions, values or properties are considered." | |
304 (interactive) | |
305 (let* ((end (point)) | |
306 (buffer-syntax (syntax-table)) | |
307 (beg (unwind-protect | |
308 (save-excursion | |
309 ;; XEmacs change | |
310 (if emacs-lisp-mode-syntax-table | |
311 (set-syntax-table emacs-lisp-mode-syntax-table)) | |
312 (backward-sexp 1) | |
313 (while (eq (char-syntax (char-after (point))) ?\') | |
314 (forward-char 1)) | |
315 (point)) | |
316 (set-syntax-table buffer-syntax))) | |
317 (pattern (buffer-substring beg end)) | |
318 (predicate | |
319 (if (eq (char-after (1- beg)) ?\() | |
320 'fboundp | |
321 ;; XEmacs change | |
322 #'(lambda (sym) | |
323 (or (boundp sym) (fboundp sym) | |
324 (symbol-plist sym))))) | |
325 (completion (try-completion pattern obarray predicate))) | |
326 (cond ((eq completion t)) | |
327 ((null completion) | |
328 (message "Can't find completion for \"%s\"" pattern) | |
329 (ding)) | |
330 ((not (string= pattern completion)) | |
331 (delete-region beg end) | |
332 (insert completion)) | |
333 (t | |
334 (message "Making completion list...") | |
335 (let ((list (all-completions pattern obarray predicate)) | |
336 ;FSFmacs crock unnecessary in XEmacs | |
337 ;see minibuf.el | |
338 ;(completion-fixup-function | |
339 ; (function (lambda () (if (save-excursion | |
340 ; (goto-char (max (point-min) | |
341 ; (- (point) 4))) | |
342 ; (looking-at " <f>")) | |
343 ; (forward-char -4)))) | |
344 ) | |
345 (or (eq predicate 'fboundp) | |
346 (let (new) | |
347 (while list | |
348 (setq new (cons (if (fboundp (intern (car list))) | |
349 (list (car list) " <f>") | |
350 (car list)) | |
351 new)) | |
352 (setq list (cdr list))) | |
353 (setq list (nreverse new)))) | |
354 (with-output-to-temp-buffer "*Completions*" | |
355 (display-completion-list list))) | |
356 (message "Making completion list...%s" "done"))))) | |
357 | |
358 ;;; lisp.el ends here |