Mercurial > hg > xemacs-beta
comparison lisp/lisp.el @ 4726:4bbda1c11a7b
Improve argument names and update docstrings.
author | Stephen J. Turnbull <stephen@xemacs.org> |
---|---|
date | Sun, 01 Nov 2009 16:19:02 +0900 |
parents | 7eef89a3d41f |
children | 308d34e9f07d |
comparison
equal
deleted
inserted
replaced
4725:5690bb2e7a44 | 4726:4bbda1c11a7b |
---|---|
50 "Non-nil => `insert-parentheses' should insert whitespace as needed." | 50 "Non-nil => `insert-parentheses' should insert whitespace as needed." |
51 :type 'boolean | 51 :type 'boolean |
52 :group 'editing-basics | 52 :group 'editing-basics |
53 :group 'lisp) | 53 :group 'lisp) |
54 | 54 |
55 (defun forward-sexp (&optional arg) | 55 (defun forward-sexp (&optional count) |
56 "Move forward across one balanced expression (sexp). | 56 "Move forward across one balanced expression (sexp). |
57 With argument, do it that many times. Negative arg -N means | 57 With non-nil COUNT, do it that many times. Negative COUNT means |
58 move backward across N balanced expressions." | 58 move backward across -COUNT balanced expressions." |
59 ;; XEmacs change (for zmacs regions) | 59 ;; XEmacs change (for zmacs regions) |
60 (interactive "_p") | 60 (interactive "_p") |
61 (or arg (setq arg 1)) | 61 (or count (setq count 1)) |
62 ;; XEmacs: evil hack! The other half of the evil hack below. | 62 ;; XEmacs: evil hack! The other half of the evil hack below. |
63 (if (and (> arg 0) (looking-at "#s(\\|#r[uU]\\{0,1\\}\"")) | 63 (if (and (> count 0) (looking-at "#s(\\|#r[uU]\\{0,1\\}\"")) |
64 (goto-char (1+ (- (point) (- (match-end 0) (match-beginning 0)))))) | 64 (goto-char (1+ (- (point) (- (match-end 0) (match-beginning 0)))))) |
65 (goto-char (or (scan-sexps (point) arg) (buffer-end arg))) | 65 (goto-char (or (scan-sexps (point) count) (buffer-end count))) |
66 (when (< arg 0) | 66 (when (< count 0) |
67 (backward-prefix-chars) | 67 (backward-prefix-chars) |
68 ;; XEmacs: evil hack! Skip back over #[sr] so that structures and raw | 68 ;; XEmacs: evil hack! Skip back over #[sr] so that structures and raw |
69 ;; strings are read properly. the current cheesified syntax tables just | 69 ;; strings are read properly. the current cheesified syntax tables just |
70 ;; aren't up to this. | 70 ;; aren't up to this. |
71 (let* ((diff (- (point) (point-min))) | 71 (let* ((diff (- (point) (point-min))) |
73 (1+ (point)))) | 73 (1+ (point)))) |
74 (matched (string-match "#s(\\|#r[uU]\\{0,1\\}\"" subject))) | 74 (matched (string-match "#s(\\|#r[uU]\\{0,1\\}\"" subject))) |
75 (if matched | 75 (if matched |
76 (goto-char (1+ (- (point) (- (length subject) matched)))))))) | 76 (goto-char (1+ (- (point) (- (length subject) matched)))))))) |
77 | 77 |
78 (defun backward-sexp (&optional arg) | 78 (defun backward-sexp (&optional count) |
79 "Move backward across one balanced expression (sexp). | 79 "Move backward across one balanced expression (sexp). |
80 With argument, do it that many times. Negative arg -N means | 80 With non-nil COUNT, do it that many times. Negative COUNT means |
81 move forward across N balanced expressions." | 81 move forward across -COUNT balanced expressions." |
82 ;; XEmacs change (for zmacs regions) | 82 ;; XEmacs change (for zmacs regions) |
83 (interactive "_p") | 83 (interactive "_p") |
84 (forward-sexp (- (or arg 1)))) | 84 (forward-sexp (- (or count 1)))) |
85 | 85 |
86 (defun mark-sexp (&optional arg) | 86 (defun mark-sexp (&optional count) |
87 "Set mark ARG sexps from point. | 87 "Set mark COUNT sexps from point. |
88 The place mark goes is the same place \\[forward-sexp] would | 88 The place mark goes is the same place \\[forward-sexp] would |
89 move to with the same argument. | 89 move to with the same argument. |
90 Repeat this command to mark more sexps in the same direction." | 90 Repeat this command to mark more sexps in the same direction." |
91 (interactive "p") | 91 (interactive "p") |
92 (mark-something 'mark-sexp 'forward-sexp (or arg 1))) | 92 (mark-something 'mark-sexp 'forward-sexp (or count 1))) |
93 | 93 |
94 (defun forward-list (&optional arg) | 94 (defun forward-list (&optional count) |
95 "Move forward across one balanced group of parentheses. | 95 "Move forward across one balanced group of parentheses. |
96 With argument, do it that many times. | 96 With non-nil COUNT, do it that many times. |
97 Negative arg -N means move backward across N groups of parentheses." | 97 Negative COUNT means move backward across -COUNT groups of parentheses." |
98 ;; XEmacs change | 98 ;; XEmacs change |
99 (interactive "_p") | 99 (interactive "_p") |
100 (goto-char (or (scan-lists (point) (or arg 1) 0) (buffer-end (or arg 1))))) | 100 (goto-char (or (scan-lists (point) (or count 1) 0) |
101 | 101 (buffer-end (or count 1))))) |
102 (defun backward-list (&optional arg) | 102 |
103 (defun backward-list (&optional count) | |
103 "Move backward across one balanced group of parentheses. | 104 "Move backward across one balanced group of parentheses. |
104 With argument, do it that many times. | 105 With non-nil COUNT, do it that many times. |
105 Negative arg -N means move forward across N groups of parentheses." | 106 Negative COUNT means move forward across -COUNT groups of parentheses." |
106 ;; XEmacs change (for zmacs regions) | 107 ;; XEmacs change (for zmacs regions) |
107 (interactive "_p") | 108 (interactive "_p") |
108 (forward-list (- (or arg 1)))) | 109 (forward-list (- (or count 1)))) |
109 | 110 |
110 (defun down-list (&optional arg) | 111 (defun down-list (&optional count) |
111 "Move forward down one level of parentheses. | 112 "Move forward down one level of parentheses. |
112 With argument, do this that many times. | 113 With non-nil COUNT, do this that many times. |
113 A negative argument means move backward but still go down a level." | 114 A negative COUNT means move backward but still go down a level." |
114 ;; XEmacs change (for zmacs regions) | 115 ;; XEmacs change (for zmacs regions) |
115 (interactive "_p") | 116 (interactive "_p") |
116 (or arg (setq arg 1)) | 117 (or count (setq count 1)) |
117 (let ((inc (if (> arg 0) 1 -1))) | 118 (let ((inc (if (> count 0) 1 -1))) |
118 (while (/= arg 0) | 119 (while (/= count 0) |
119 (goto-char (or (scan-lists (point) inc -1) (buffer-end arg))) | 120 (goto-char (or (scan-lists (point) inc -1) (buffer-end count))) |
120 (setq arg (- arg inc))))) | 121 (setq count (- count inc))))) |
121 | 122 |
122 (defun backward-up-list (&optional arg) | 123 (defun backward-up-list (&optional count) |
123 "Move backward out of one level of parentheses. | 124 "Move backward out of one level of parentheses. |
124 With argument, do this that many times. | 125 With COUNT, do this that many times. |
125 A negative argument means move forward but still to a less deep spot." | 126 A negative COUNT means move forward but still to a less deep spot." |
126 (interactive "_p") | 127 (interactive "_p") |
127 (up-list (- (or arg 1)))) | 128 (up-list (- (or count 1)))) |
128 | 129 |
129 (defun up-list (&optional arg) | 130 (defun up-list (&optional count) |
130 "Move forward out of one level of parentheses. | 131 "Move forward out of one level of parentheses. |
131 With argument, do this that many times. | 132 With non-nil COUNT, do this that many times. |
132 A negative argument means move backward but still to a less deep spot. | 133 A negative COUNT means move backward but still to a less deep spot. |
133 In Lisp programs, an argument is required." | 134 In Lisp programs, an argument is required." |
134 ;; XEmacs change (for zmacs regions) | 135 ;; XEmacs change (for zmacs regions) |
135 (interactive "_p") | 136 (interactive "_p") |
136 (or arg (setq arg 1)) | 137 (or count (setq count 1)) |
137 (let ((inc (if (> arg 0) 1 -1))) | 138 (let ((inc (if (> count 0) 1 -1))) |
138 (while (/= arg 0) | 139 (while (/= count 0) |
139 (goto-char (or (scan-lists (point) inc 1) (buffer-end arg))) | 140 (goto-char (or (scan-lists (point) inc 1) (buffer-end count))) |
140 (setq arg (- arg inc))))) | 141 (setq count (- count inc))))) |
141 | 142 |
142 (defun kill-sexp (&optional arg) | 143 (defun kill-sexp (&optional count) |
143 "Kill the sexp (balanced expression) following the cursor. | 144 "Kill the sexp (balanced expression) following the cursor. |
144 With argument, kill that many sexps after the cursor. | 145 With non-nil COUNT, kill that many sexps after the cursor. |
145 Negative arg -N means kill N sexps before the cursor." | 146 Negative COUNT means kill -COUNT sexps before the cursor." |
146 (interactive "p") | 147 (interactive "p") |
147 (let ((opoint (point))) | 148 (let ((opoint (point))) |
148 (forward-sexp (or arg 1)) | 149 (forward-sexp (or count 1)) |
149 (kill-region opoint (point)))) | 150 (kill-region opoint (point)))) |
150 | 151 |
151 (defun backward-kill-sexp (&optional arg) | 152 (defun backward-kill-sexp (&optional count) |
152 "Kill the sexp (balanced expression) preceding the cursor. | 153 "Kill the sexp (balanced expression) preceding the cursor. |
153 With argument, kill that many sexps before the cursor. | 154 With non-nil COUNT, kill that many sexps before the cursor. |
154 Negative arg -N means kill N sexps after the cursor." | 155 Negative COUNT means kill -COUNT sexps after the cursor." |
155 (interactive "p") | 156 (interactive "p") |
156 (kill-sexp (- (or arg 1)))) | 157 (kill-sexp (- (or count 1)))) |
157 | 158 |
158 | 159 |
159 ;; derived stuff from GNU Emacs | 160 ;; derived stuff from GNU Emacs |
160 (defvar beginning-of-defun-function nil | 161 (defvar beginning-of-defun-function nil |
161 "If non-nil, this function will be called by `beginning-of-defun-raw'. | 162 "If non-nil, this function will be called by `beginning-of-defun-raw'. |
173 of the current defun instead of using the standard one implemented by | 174 of the current defun instead of using the standard one implemented by |
174 `end-of-defun'. | 175 `end-of-defun'. |
175 ") | 176 ") |
176 (make-variable-buffer-local 'end-of-defun-function) | 177 (make-variable-buffer-local 'end-of-defun-function) |
177 | 178 |
178 (defun beginning-of-defun (&optional arg) | 179 (defun beginning-of-defun (&optional count) |
179 "Move backward to the beginning of the current defun. | 180 "Move backward to the beginning of the current defun. |
180 With argument, do it that many times. Negative arg -N | 181 With COUNT, do it that many times. Negative COUNT |
181 means move forward to Nth following beginning of defun. | 182 means move forward to -COUNTth following beginning of defun. |
182 Returns t unless search stops due to beginning or end of buffer. | 183 Returns t unless search stops due to beginning or end of buffer. |
183 | 184 |
184 In the default implementation provided by `beginning-of-defun-raw', | 185 In the default implementation provided by `beginning-of-defun-raw', |
185 a defun starts at a char with open-parenthesis syntax at the beginning | 186 a defun starts at a char with open-parenthesis syntax at the beginning |
186 of a line. If `defun-prompt-regexp' is non-nil, then a string which | 187 of a line. If `defun-prompt-regexp' is non-nil, then a string which |
190 | 191 |
191 If the beginning of defun function returns t, point moves to the | 192 If the beginning of defun function returns t, point moves to the |
192 beginning of the line containing the beginning of defun." | 193 beginning of the line containing the beginning of defun." |
193 ;; XEmacs change (for zmacs regions) | 194 ;; XEmacs change (for zmacs regions) |
194 (interactive "_p") | 195 (interactive "_p") |
195 (and (beginning-of-defun-raw arg) | 196 (and (beginning-of-defun-raw count) |
196 (progn (beginning-of-line) t))) | 197 (progn (beginning-of-line) t))) |
197 | 198 |
198 (defun beginning-of-defun-raw (&optional arg) | 199 (defun beginning-of-defun-raw (&optional count) |
199 "Move point to the character that starts a defun. | 200 "Move point to the character that starts a defun. |
200 This is identical to beginning-of-defun, except that point does not move | 201 This is identical to beginning-of-defun, except that point does not move |
201 to the beginning of the line when `defun-prompt-regexp' is non-nil." | 202 to the beginning of the line when `defun-prompt-regexp' is non-nil." |
202 (interactive "p") | 203 (interactive "p") |
203 (unless arg (setq arg 1)) | 204 (unless count (setq count 1)) |
204 (if beginning-of-defun-function | 205 (if beginning-of-defun-function |
205 (funcall beginning-of-defun-function arg) | 206 (funcall beginning-of-defun-function count) |
206 (and (< arg 0) (not (eobp)) (forward-char 1)) | 207 (and (< count 0) (not (eobp)) (forward-char 1)) |
207 (and | 208 (and |
208 (re-search-backward (if defun-prompt-regexp | 209 (re-search-backward (if defun-prompt-regexp |
209 (concat "^\\s(\\|" | 210 (concat "^\\s(\\|" |
210 "\\(" defun-prompt-regexp "\\)\\s(") | 211 "\\(" defun-prompt-regexp "\\)\\s(") |
211 "^\\s(") | 212 "^\\s(") |
212 nil 'move arg) | 213 nil 'move count) |
213 (progn (goto-char (1- (match-end 0)))) t))) | 214 (progn (goto-char (1- (match-end 0)))) t))) |
214 | 215 |
215 ;; XEmacs change (optional buffer parameter) | 216 ;; XEmacs change (optional buffer parameter) |
216 (defun buffer-end (arg &optional buffer) | 217 (defun buffer-end (direction &optional buffer) |
217 "Return `point-max' of BUFFER if ARG is > 0; return `point-min' otherwise. | 218 "Return `point-max' of BUFFER if DIRECTION > 0, else return `point-min'. |
218 BUFFER defaults to the current buffer if omitted." | 219 BUFFER defaults to the current buffer if omitted." |
219 (if (> arg 0) (point-max buffer) (point-min buffer))) | 220 (if (> direction 0) (point-max buffer) (point-min buffer))) |
220 | 221 |
221 (defun end-of-defun (&optional arg) | 222 (defun end-of-defun (&optional count) |
222 "Move forward to next end of defun. With argument, do it that many times. | 223 "Move forward to next end of defun. |
223 Negative argument -N means move back to Nth preceding end of defun. | 224 Non-nil COUNT means do it that many times (default is 1). |
225 Negative COUNT means move back to -COUNTth preceding end of defun. | |
224 | 226 |
225 In the default implementation, the end of a defun is the end of the | 227 In the default implementation, the end of a defun is the end of the |
226 s-expression started at the character identified by `beginning-of-defun'. | 228 s-expression started at the character identified by `beginning-of-defun'. |
227 | 229 |
228 If `end-of-defun-function' is non-nil, none of the default processing is | 230 If `end-of-defun-function' is non-nil, none of the default processing is |
229 done. For a repetition count greater than 1, `end-of-defun-function' is | 231 done. For a repetition count greater than 1, `end-of-defun-function' is |
230 called that many times. If the repetition count is less than 1, nothing | 232 called that many times. If the repetition count is less than 1, nothing |
231 is done. \(This is a bug.)" | 233 is done. \(This is a bug.)" |
232 ;; XEmacs change (for zmacs regions) | 234 ;; XEmacs change (for zmacs regions) |
233 (interactive "_p") | 235 (interactive "_p") |
234 (if (or (null arg) (= arg 0)) (setq arg 1)) | 236 (if (or (null count) (= count 0)) (setq count 1)) |
235 (if end-of-defun-function | 237 (if end-of-defun-function |
236 (if (> arg 0) | 238 (if (> count 0) |
237 (dotimes (i arg) | 239 (dotimes (i count) |
238 (funcall end-of-defun-function))) | 240 (funcall end-of-defun-function))) |
239 (let ((first t)) | 241 (let ((first t)) |
240 (while (and (> arg 0) (< (point) (point-max))) | 242 (while (and (> count 0) (< (point) (point-max))) |
241 (let ((pos (point))) ; XEmacs -- remove unused npos. | 243 (let ((pos (point))) ; XEmacs -- remove unused npos. |
242 (while (progn | 244 (while (progn |
243 (if (and first | 245 (if (and first |
244 (progn | 246 (progn |
245 (end-of-line 1) | 247 (end-of-line 1) |
251 (forward-list 1) | 253 (forward-list 1) |
252 (skip-chars-forward " \t") | 254 (skip-chars-forward " \t") |
253 (if (looking-at "\\s<\\|\n") | 255 (if (looking-at "\\s<\\|\n") |
254 (forward-line 1)) | 256 (forward-line 1)) |
255 (<= (point) pos)))) | 257 (<= (point) pos)))) |
256 (setq arg (1- arg))) | 258 (setq count (1- count))) |
257 (while (< arg 0) | 259 (while (< count 0) |
258 (let ((pos (point))) | 260 (let ((pos (point))) |
259 (beginning-of-defun-raw 1) | 261 (beginning-of-defun-raw 1) |
260 (forward-sexp 1) | 262 (forward-sexp 1) |
261 (forward-line 1) | 263 (forward-line 1) |
262 (if (>= (point) pos) | 264 (if (>= (point) pos) |
265 (forward-list 1) | 267 (forward-list 1) |
266 (skip-chars-forward " \t") | 268 (skip-chars-forward " \t") |
267 (if (looking-at "\\s<\\|\n") | 269 (if (looking-at "\\s<\\|\n") |
268 (forward-line 1))) | 270 (forward-line 1))) |
269 (goto-char (point-min))))) | 271 (goto-char (point-min))))) |
270 (setq arg (1+ arg)))))) | 272 (setq count (1+ count)))))) |
271 | 273 |
272 (defun mark-defun () | 274 (defun mark-defun () |
273 "Put mark at end of this defun, point at beginning. | 275 "Put mark at end of this defun, point at beginning. |
274 The defun marked is the one that contains point or follows point." | 276 The defun marked is the one that contains point or follows point." |
275 (interactive) | 277 (interactive) |
279 (beginning-of-defun) | 281 (beginning-of-defun) |
280 (re-search-backward "^\n" (- (point) 1) t)) | 282 (re-search-backward "^\n" (- (point) 1) t)) |
281 | 283 |
282 (defun narrow-to-defun (&optional arg) | 284 (defun narrow-to-defun (&optional arg) |
283 "Make text outside current defun invisible. | 285 "Make text outside current defun invisible. |
284 The defun visible is the one that contains point or follows point." | 286 The defun visible is the one that contains point or follows point. |
287 Optional ARG is currently ignored." | |
285 (interactive) | 288 (interactive) |
286 (save-excursion | 289 (save-excursion |
287 (widen) | 290 (widen) |
288 (end-of-defun) | 291 (end-of-defun) |
289 (let ((end (point))) | 292 (let ((end (point))) |
290 (beginning-of-defun) | 293 (beginning-of-defun) |
291 (narrow-to-region (point) end)))) | 294 (narrow-to-region (point) end)))) |
292 | 295 |
293 (defun insert-parentheses (arg) | 296 (defun insert-parentheses (count) |
294 "Enclose following ARG sexps in parentheses. Leave point after open-paren. | 297 "Enclose following COUNT sexps in parentheses. Leave point after open-paren. |
295 A negative ARG encloses the preceding ARG sexps instead. | 298 A negative COUNT encloses the preceding -COUNT sexps instead. |
296 No argument is equivalent to zero: just insert `()' and leave point between. | 299 COUNT defaults to zero: just insert `()' and leave point between. |
297 If `parens-require-spaces' is non-nil, this command also inserts a space | 300 If `parens-require-spaces' is non-nil, this command also inserts a space |
298 before and after, depending on the surrounding characters." | 301 before and after, depending on the surrounding characters." |
299 (interactive "P") | 302 (interactive "P") |
300 (if arg (setq arg (prefix-numeric-value arg)) | 303 (if count (setq count (prefix-numeric-value count)) |
301 (setq arg 0)) | 304 (setq count 0)) |
302 (cond ((> arg 0) (skip-chars-forward " \t")) | 305 (cond ((> count 0) (skip-chars-forward " \t")) |
303 ((< arg 0) (forward-sexp arg) (setq arg (- arg)))) | 306 ((< count 0) (forward-sexp count) (setq count (- count)))) |
304 (and parens-require-spaces | 307 (and parens-require-spaces |
305 (not (bobp)) | 308 (not (bobp)) |
306 (memq (char-syntax (char-before (point))) '(?w ?_ ?\) )) | 309 (memq (char-syntax (char-before (point))) '(?w ?_ ?\) )) |
307 (insert " ")) | 310 (insert " ")) |
308 (insert ?\() | 311 (insert ?\() |
309 (save-excursion | 312 (save-excursion |
310 (or (eq arg 0) (forward-sexp arg)) | 313 (or (eq count 0) (forward-sexp count)) |
311 (insert ?\)) | 314 (insert ?\)) |
312 (and parens-require-spaces | 315 (and parens-require-spaces |
313 (not (eobp)) | 316 (not (eobp)) |
314 (memq (char-syntax (char-after (point))) '(?w ?_ ?\( )) | 317 (memq (char-syntax (char-after (point))) '(?w ?_ ?\( )) |
315 (insert " ")))) | 318 (insert " ")))) |