Mercurial > emacs
comparison lisp/emacs-lisp/lisp.el @ 84:225a5c57fe64
Initial revision
author | root <root> |
---|---|
date | Mon, 27 Aug 1990 04:15:41 +0000 |
parents | |
children | 7cfabf2a8964 |
comparison
equal
deleted
inserted
replaced
83:aafe1b6c4ab7 | 84:225a5c57fe64 |
---|---|
1 ;; Lisp editing commands for Emacs | |
2 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc. | |
3 | |
4 ;; This file is part of GNU Emacs. | |
5 | |
6 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
7 ;; it under the terms of the GNU General Public License as published by | |
8 ;; the Free Software Foundation; either version 1, or (at your option) | |
9 ;; any later version. | |
10 | |
11 ;; GNU Emacs is distributed in the hope that it will be useful, | |
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 ;; GNU General Public License for more details. | |
15 | |
16 ;; You should have received a copy of the GNU General Public License | |
17 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 | |
20 | |
21 (defvar defun-prompt-regexp nil | |
22 "Non-nil => regexp to ignore, before the `(' that starts a defun.") | |
23 | |
24 (defun forward-sexp (&optional arg) | |
25 "Move forward across one balanced expression (sexp). | |
26 With argument, do it that many times. | |
27 Negative arg -N means move backward across N balanced expressions." | |
28 (interactive "p") | |
29 (or arg (setq arg 1)) | |
30 (goto-char (or (scan-sexps (point) arg) (buffer-end arg))) | |
31 (if (< arg 0) (backward-prefix-chars))) | |
32 | |
33 (defun backward-sexp (&optional arg) | |
34 "Move backward across one balanced expression (sexp). | |
35 With argument, do it that many times. | |
36 Negative arg -N means move forward across N balanced expressions." | |
37 (interactive "p") | |
38 (or arg (setq arg 1)) | |
39 (forward-sexp (- arg))) | |
40 | |
41 (defun mark-sexp (arg) | |
42 "Set mark ARG sexps from point. | |
43 The place mark goes is the same place \\[forward-sexp] would move to | |
44 with the same argument." | |
45 (interactive "p") | |
46 (push-mark | |
47 (save-excursion | |
48 (forward-sexp arg) | |
49 (point)))) | |
50 | |
51 (defun forward-list (&optional arg) | |
52 "Move forward across one balanced group of parentheses. | |
53 With argument, do it that many times. | |
54 Negative arg -N means move backward across N groups of parentheses." | |
55 (interactive "p") | |
56 (or arg (setq arg 1)) | |
57 (goto-char (or (scan-lists (point) arg 0) (buffer-end arg)))) | |
58 | |
59 (defun backward-list (&optional arg) | |
60 "Move backward across one balanced group of parentheses. | |
61 With argument, do it that many times. | |
62 Negative arg -N means move forward across N groups of parentheses." | |
63 (interactive "p") | |
64 (or arg (setq arg 1)) | |
65 (forward-list (- arg))) | |
66 | |
67 (defun down-list (arg) | |
68 "Move forward down one level of parentheses. | |
69 With argument, do this that many times. | |
70 A negative argument means move backward but still go down a level. | |
71 In Lisp programs, an argument is required." | |
72 (interactive "p") | |
73 (let ((inc (if (> arg 0) 1 -1))) | |
74 (while (/= arg 0) | |
75 (goto-char (or (scan-lists (point) inc -1) (buffer-end arg))) | |
76 (setq arg (- arg inc))))) | |
77 | |
78 (defun backward-up-list (arg) | |
79 "Move backward out of one level of parentheses. | |
80 With argument, do this that many times. | |
81 A negative argument means move forward but still to a less deep spot. | |
82 In Lisp programs, an argument is required." | |
83 (interactive "p") | |
84 (up-list (- arg))) | |
85 | |
86 (defun up-list (arg) | |
87 "Move forward out of one level of parentheses. | |
88 With argument, do this that many times. | |
89 A negative argument means move backward but still to a less deep spot. | |
90 In Lisp programs, an argument is required." | |
91 (interactive "p") | |
92 (let ((inc (if (> arg 0) 1 -1))) | |
93 (while (/= arg 0) | |
94 (goto-char (or (scan-lists (point) inc 1) (buffer-end arg))) | |
95 (setq arg (- arg inc))))) | |
96 | |
97 (defun kill-sexp (arg) | |
98 "Kill the sexp (balanced expression) following the cursor. | |
99 With argument, kill that many sexps after the cursor. | |
100 Negative arg -N means kill N sexps before the cursor." | |
101 (interactive "p") | |
102 (let ((opoint (point))) | |
103 (forward-sexp arg) | |
104 (kill-region opoint (point)))) | |
105 | |
106 (defun backward-kill-sexp (arg) | |
107 "Kill the sexp (balanced expression) preceding the cursor. | |
108 With argument, kill that many sexps before the cursor. | |
109 Negative arg -N means kill N sexps after the cursor." | |
110 (interactive "p") | |
111 (kill-sexp (- arg))) | |
112 | |
113 (defun beginning-of-defun (&optional arg) | |
114 "Move backward to the beginning of a defun. | |
115 With argument, do it that many times. Negative arg -N | |
116 means move forward to Nth following beginning of defun. | |
117 Returns t unless search stops due to beginning or end of buffer. | |
118 | |
119 Normally a defun starts when there is an char with open-parenthesis | |
120 syntax at the beginning of a line. If `defun-prompt-regexp' is | |
121 non-nil, then a string which matches that regexp may precede the | |
122 open-parenthesis." | |
123 (interactive "p") | |
124 (and arg (< arg 0) (forward-char 1)) | |
125 (and (re-search-backward (if defun-prompt-regexp | |
126 (concat "^\\s(\\|" | |
127 "\\(" defun-prompt-regexp "\\)\\s(") | |
128 "^\\s(") | |
129 nil 'move (or arg 1)) | |
130 (progn (beginning-of-line) t))) | |
131 | |
132 (defun buffer-end (arg) | |
133 (if (> arg 0) (point-max) (point-min))) | |
134 | |
135 (defun end-of-defun (&optional arg) | |
136 "Move forward to next end of defun. With argument, do it that many times. | |
137 Negative argument -N means move back to Nth preceding end of defun. | |
138 | |
139 An end of a defun occurs right after the close-parenthesis that matches | |
140 the open-parenthesis that starts a defun; see `beginning-of-defun'." | |
141 (interactive "p") | |
142 (if (or (null arg) (= arg 0)) (setq arg 1)) | |
143 (let ((first t)) | |
144 (while (and (> arg 0) (< (point) (point-max))) | |
145 (let ((pos (point)) npos) | |
146 (while (progn | |
147 (if (and first | |
148 (progn | |
149 (forward-char 1) | |
150 (beginning-of-defun 1))) | |
151 nil | |
152 (or (bobp) (forward-char -1)) | |
153 (beginning-of-defun -1)) | |
154 (setq first nil) | |
155 (forward-list 1) | |
156 (skip-chars-forward " \t") | |
157 (if (looking-at "\\s<\\|\n") | |
158 (forward-line 1)) | |
159 (<= (point) pos)))) | |
160 (setq arg (1- arg))) | |
161 (while (< arg 0) | |
162 (let ((pos (point))) | |
163 (beginning-of-defun 1) | |
164 (forward-sexp 1) | |
165 (forward-line 1) | |
166 (if (>= (point) pos) | |
167 (if (beginning-of-defun 2) | |
168 (progn | |
169 (forward-list 1) | |
170 (skip-chars-forward " \t") | |
171 (if (looking-at "[;\n]") | |
172 (forward-line 1))) | |
173 (goto-char (point-min))))) | |
174 (setq arg (1+ arg))))) | |
175 | |
176 (defun mark-defun () | |
177 "Put mark at end of this defun, point at beginning. | |
178 The defun marked is the one that contains point or follows point." | |
179 (interactive) | |
180 (push-mark (point)) | |
181 (end-of-defun) | |
182 (push-mark (point)) | |
183 (beginning-of-defun) | |
184 (re-search-backward "^\n" (- (point) 1) t)) | |
185 | |
186 (defun insert-parentheses (arg) | |
187 "Put parentheses around next ARG sexps. Leave point after open-paren. | |
188 No argument is equivalent to zero: just insert () and leave point between." | |
189 (interactive "P") | |
190 (if arg (skip-chars-forward " \t")) | |
191 (and (memq (char-syntax (preceding-char)) '(?w ?_ ?\) )) | |
192 (insert " ")) | |
193 ; (or (memq (char-syntax (preceding-char)) '(?\ ?> ?\( )) | |
194 ; (insert " "))) | |
195 (insert ?\() | |
196 (save-excursion | |
197 (if arg | |
198 (forward-sexp (prefix-numeric-value arg))) | |
199 (insert ?\)) | |
200 ; (or (memq (char-syntax (following-char)) '(?\ ?> ?\( )) | |
201 ; (insert " ")) | |
202 (and (memq (char-syntax (following-char)) '(?w ?_ ?\( )) | |
203 (insert " ")) | |
204 )) | |
205 | |
206 (defun move-past-close-and-reindent () | |
207 "Move past next `)', delete indentation before it, then indent after it." | |
208 (interactive) | |
209 (up-list 1) | |
210 (forward-char -1) | |
211 (while (save-excursion ; this is my contribution | |
212 (let ((before-paren (point))) | |
213 (back-to-indentation) | |
214 (= (point) before-paren))) | |
215 (delete-indentation)) | |
216 (forward-char 1) | |
217 (newline-and-indent)) | |
218 | |
219 (defun lisp-complete-symbol () | |
220 "Perform completion on Lisp symbol preceding point. | |
221 That symbol is compared against the symbols that exist | |
222 and any additional characters determined by what is there | |
223 are inserted. | |
224 If the symbol starts just after an open-parenthesis, | |
225 only symbols with function definitions are considered. | |
226 Otherwise, all symbols with function definitions, values | |
227 or properties are considered." | |
228 (interactive) | |
229 (let* ((end (point)) | |
230 (buffer-syntax (syntax-table)) | |
231 (beg (save-excursion | |
232 (set-syntax-table lisp-mode-syntax-table) | |
233 (backward-sexp 1) | |
234 (while (= (char-syntax (following-char)) ?\') | |
235 (forward-char 1)) | |
236 (point) | |
237 (set-syntax-table buffer-syntax))) | |
238 (pattern (buffer-substring beg end)) | |
239 (predicate | |
240 (if (eq (char-after (1- beg)) ?\() | |
241 'fboundp | |
242 (function (lambda (sym) | |
243 (or (boundp sym) (fboundp sym) | |
244 (symbol-plist sym)))))) | |
245 (completion (try-completion pattern obarray predicate))) | |
246 (cond ((eq completion t)) | |
247 ((null completion) | |
248 (message "Can't find completion for \"%s\"" pattern) | |
249 (ding)) | |
250 ((not (string= pattern completion)) | |
251 (delete-region beg end) | |
252 (insert completion)) | |
253 (t | |
254 (message "Making completion list...") | |
255 (let ((list (all-completions pattern obarray predicate))) | |
256 (or (eq predicate 'fboundp) | |
257 (let (new) | |
258 (while list | |
259 (setq new (cons (if (fboundp (intern (car list))) | |
260 (list (car list) " <f>") | |
261 (car list)) | |
262 new)) | |
263 (setq list (cdr list))) | |
264 (setq list (nreverse new)))) | |
265 (with-output-to-temp-buffer " *Completions*" | |
266 (display-completion-list list))) | |
267 (message "Making completion list...%s" "done"))))) |