Added library headers.
[emacs.git] / lisp / simple.el
blobb9b0883e372fdf6846d002f4f2fb7cd1b6150760
1 ;;; simple.el --- basic editing commands for Emacs
3 ;; Copyright (C) 1985, 1986, 1987, 1992, 1993 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; any later version.
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 ;;; Code:
23 (defun open-line (arg)
24 "Insert a newline and leave point before it.
25 If there is a fill prefix, insert the fill prefix on the new line
26 if the line would have been empty.
27 With arg N, insert N newlines."
28 (interactive "*p")
29 (let* ((do-fill-prefix (and fill-prefix (bolp)))
30 (flag (and (null do-fill-prefix) (bolp) (not (bobp)))))
31 ;; If this is a simple case, and we are at the beginning of a line,
32 ;; actually insert the newline *before* the preceding newline
33 ;; instead of after. That makes better display behavior.
34 (if flag
35 (progn
36 ;; If undo is enabled, don't let this hack be visible:
37 ;; record the real value of point as the place to move back to
38 ;; if we undo this insert.
39 (if (and buffer-undo-list (not (eq buffer-undo-list t)))
40 (setq buffer-undo-list (cons (point) buffer-undo-list)))
41 (forward-char -1)))
42 (while (> arg 0)
43 (save-excursion
44 (insert ?\n))
45 (if do-fill-prefix (insert fill-prefix))
46 (setq arg (1- arg)))
47 (if flag (forward-char 1))))
49 (defun split-line ()
50 "Split current line, moving portion beyond point vertically down."
51 (interactive "*")
52 (skip-chars-forward " \t")
53 (let ((col (current-column))
54 (pos (point)))
55 (insert ?\n)
56 (indent-to col 0)
57 (goto-char pos)))
59 (defun quoted-insert (arg)
60 "Read next input character and insert it.
61 This is useful for inserting control characters.
62 You may also type up to 3 octal digits, to insert a character with that code.
63 `quoted-insert' inserts the character even in overstrike mode; if you
64 use overstrike as your normal editing mode, you can use this function
65 to insert characters when necessary."
66 (interactive "*p")
67 (let ((char (read-quoted-char)))
68 (insert-char char arg)))
70 (defun delete-indentation (&optional arg)
71 "Join this line to previous and fix up whitespace at join.
72 If there is a fill prefix, delete it from the beginning of this line.
73 With argument, join this line to following line."
74 (interactive "*P")
75 (beginning-of-line)
76 (if arg (forward-line 1))
77 (if (eq (preceding-char) ?\n)
78 (progn
79 (delete-region (point) (1- (point)))
80 ;; If the second line started with the fill prefix,
81 ;; delete the prefix.
82 (if (and fill-prefix
83 (<= (+ (point) (length fill-prefix)) (point-max))
84 (string= fill-prefix
85 (buffer-substring (point)
86 (+ (point) (length fill-prefix)))))
87 (delete-region (point) (+ (point) (length fill-prefix))))
88 (fixup-whitespace))))
90 (defun fixup-whitespace ()
91 "Fixup white space between objects around point.
92 Leave one space or none, according to the context."
93 (interactive "*")
94 (save-excursion
95 (delete-horizontal-space)
96 (if (or (looking-at "^\\|\\s)")
97 (save-excursion (forward-char -1)
98 (looking-at "$\\|\\s(\\|\\s'")))
99 nil
100 (insert ?\ ))))
102 (defun delete-horizontal-space ()
103 "Delete all spaces and tabs around point."
104 (interactive "*")
105 (skip-chars-backward " \t")
106 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
108 (defun just-one-space ()
109 "Delete all spaces and tabs around point, leaving one space."
110 (interactive "*")
111 (skip-chars-backward " \t")
112 (if (= (following-char) ? )
113 (forward-char 1)
114 (insert ? ))
115 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
117 (defun delete-blank-lines ()
118 "On blank line, delete all surrounding blank lines, leaving just one.
119 On isolated blank line, delete that one.
120 On nonblank line, delete all blank lines that follow it."
121 (interactive "*")
122 (let (thisblank singleblank)
123 (save-excursion
124 (beginning-of-line)
125 (setq thisblank (looking-at "[ \t]*$"))
126 ;; Set singleblank if there is just one blank line here.
127 (setq singleblank
128 (and thisblank
129 (not (looking-at "[ \t]*\n[ \t]*$"))
130 (or (bobp)
131 (progn (forward-line -1)
132 (not (looking-at "[ \t]*$")))))))
133 ;; Delete preceding blank lines, and this one too if it's the only one.
134 (if thisblank
135 (progn
136 (beginning-of-line)
137 (if singleblank (forward-line 1))
138 (delete-region (point)
139 (if (re-search-backward "[^ \t\n]" nil t)
140 (progn (forward-line 1) (point))
141 (point-min)))))
142 ;; Delete following blank lines, unless the current line is blank
143 ;; and there are no following blank lines.
144 (if (not (and thisblank singleblank))
145 (save-excursion
146 (end-of-line)
147 (forward-line 1)
148 (delete-region (point)
149 (if (re-search-forward "[^ \t\n]" nil t)
150 (progn (beginning-of-line) (point))
151 (point-max)))))
152 ;; Handle the special case where point is followed by newline and eob.
153 ;; Delete the line, leaving point at eob.
154 (if (looking-at "^[ \t]*\n\\'")
155 (delete-region (point) (point-max)))))
157 (defun back-to-indentation ()
158 "Move point to the first non-whitespace character on this line."
159 (interactive)
160 (beginning-of-line 1)
161 (skip-chars-forward " \t"))
163 (defun newline-and-indent ()
164 "Insert a newline, then indent according to major mode.
165 Indentation is done using the value of `indent-line-function'.
166 In programming language modes, this is the same as TAB.
167 In some text modes, where TAB inserts a tab, this command indents to the
168 column specified by the variable `left-margin'."
169 (interactive "*")
170 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
171 (newline)
172 (indent-according-to-mode))
174 (defun reindent-then-newline-and-indent ()
175 "Reindent current line, insert newline, then indent the new line.
176 Indentation of both lines is done according to the current major mode,
177 which means calling the current value of `indent-line-function'.
178 In programming language modes, this is the same as TAB.
179 In some text modes, where TAB inserts a tab, this indents to the
180 column specified by the variable `left-margin'."
181 (interactive "*")
182 (save-excursion
183 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
184 (indent-according-to-mode))
185 (newline)
186 (indent-according-to-mode))
188 ;; Internal subroutine of delete-char
189 (defun kill-forward-chars (arg)
190 (if (listp arg) (setq arg (car arg)))
191 (if (eq arg '-) (setq arg -1))
192 (kill-region (point) (+ (point) arg)))
194 ;; Internal subroutine of backward-delete-char
195 (defun kill-backward-chars (arg)
196 (if (listp arg) (setq arg (car arg)))
197 (if (eq arg '-) (setq arg -1))
198 (kill-region (point) (- (point) arg)))
200 (defun backward-delete-char-untabify (arg &optional killp)
201 "Delete characters backward, changing tabs into spaces.
202 Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil.
203 Interactively, ARG is the prefix arg (default 1)
204 and KILLP is t if prefix arg is was specified."
205 (interactive "*p\nP")
206 (let ((count arg))
207 (save-excursion
208 (while (and (> count 0) (not (bobp)))
209 (if (= (preceding-char) ?\t)
210 (let ((col (current-column)))
211 (forward-char -1)
212 (setq col (- col (current-column)))
213 (insert-char ?\ col)
214 (delete-char 1)))
215 (forward-char -1)
216 (setq count (1- count)))))
217 (delete-backward-char arg killp)
218 ;; In overwrite mode, back over columns while clearing them out,
219 ;; unless at end of line.
220 (and overwrite-mode (not (eolp))
221 (save-excursion (insert-char ?\ arg))))
223 (defun zap-to-char (arg char)
224 "Kill up to and including ARG'th occurrence of CHAR.
225 Goes backward if ARG is negative; error if CHAR not found."
226 (interactive "p\ncZap to char: ")
227 (kill-region (point) (progn
228 (search-forward (char-to-string char) nil nil arg)
229 ; (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
230 (point))))
232 (defun beginning-of-buffer (&optional arg)
233 "Move point to the beginning of the buffer; leave mark at previous position.
234 With arg N, put point N/10 of the way from the true beginning.
236 Don't use this command in Lisp programs!
237 \(goto-char (point-min)) is faster and avoids clobbering the mark."
238 (interactive "P")
239 (push-mark)
240 (goto-char (if arg
241 (if (> (buffer-size) 10000)
242 ;; Avoid overflow for large buffer sizes!
243 (* (prefix-numeric-value arg)
244 (/ (buffer-size) 10))
245 (/ (+ 10 (* (buffer-size) (prefix-numeric-value arg))) 10))
246 (point-min)))
247 (if arg (forward-line 1)))
249 (defun end-of-buffer (&optional arg)
250 "Move point to the end of the buffer; leave mark at previous position.
251 With arg N, put point N/10 of the way from the true end.
253 Don't use this command in Lisp programs!
254 \(goto-char (point-max)) is faster and avoids clobbering the mark."
255 (interactive "P")
256 (push-mark)
257 (goto-char (if arg
258 (- (1+ (buffer-size))
259 (if (> (buffer-size) 10000)
260 ;; Avoid overflow for large buffer sizes!
261 (* (prefix-numeric-value arg)
262 (/ (buffer-size) 10))
263 (/ (* (buffer-size) (prefix-numeric-value arg)) 10)))
264 (point-max)))
265 ;; If we went to a place in the middle of the buffer,
266 ;; adjust it to the beginning of a line.
267 (if arg (forward-line 1)
268 ;; If the end of the buffer is not already on the screen,
269 ;; then scroll specially to put it near, but not at, the bottom.
270 (if (let ((old-point (point)))
271 (save-excursion
272 (goto-char (window-start))
273 (vertical-motion (window-height))
274 (< (point) old-point)))
275 (recenter -3))))
277 (defun mark-whole-buffer ()
278 "Put point at beginning and mark at end of buffer.
279 You probably should not use this function in Lisp programs;
280 it is usually a mistake for a Lisp function to use any subroutine
281 that uses or sets the mark."
282 (interactive)
283 (push-mark (point))
284 (push-mark (point-max))
285 (goto-char (point-min)))
287 (defun count-lines-region (start end)
288 "Print number of lines and charcters in the region."
289 (interactive "r")
290 (message "Region has %d lines, %d characters"
291 (count-lines start end) (- end start)))
293 (defun what-line ()
294 "Print the current line number (in the buffer) of point."
295 (interactive)
296 (save-restriction
297 (widen)
298 (save-excursion
299 (beginning-of-line)
300 (message "Line %d"
301 (1+ (count-lines 1 (point)))))))
303 (defun count-lines (start end)
304 "Return number of lines between START and END.
305 This is usually the number of newlines between them,
306 but can be one more if START is not equal to END
307 and the greater of them is not at the start of a line."
308 (save-excursion
309 (save-restriction
310 (narrow-to-region start end)
311 (goto-char (point-min))
312 (if (eq selective-display t)
313 (let ((done 0))
314 (while (re-search-forward "[\n\C-m]" nil t 40)
315 (setq done (+ 40 done)))
316 (while (re-search-forward "[\n\C-m]" nil t 1)
317 (setq done (+ 1 done)))
318 done)
319 (- (buffer-size) (forward-line (buffer-size)))))))
321 (defun what-cursor-position ()
322 "Print info on cursor position (on screen and within buffer)."
323 (interactive)
324 (let* ((char (following-char))
325 (beg (point-min))
326 (end (point-max))
327 (pos (point))
328 (total (buffer-size))
329 (percent (if (> total 50000)
330 ;; Avoid overflow from multiplying by 100!
331 (/ (+ (/ total 200) (1- pos)) (max (/ total 100) 1))
332 (/ (+ (/ total 2) (* 100 (1- pos))) (max total 1))))
333 (hscroll (if (= (window-hscroll) 0)
335 (format " Hscroll=%d" (window-hscroll))))
336 (col (current-column)))
337 (if (= pos end)
338 (if (or (/= beg 1) (/= end (1+ total)))
339 (message "point=%d of %d(%d%%) <%d - %d> column %d %s"
340 pos total percent beg end col hscroll)
341 (message "point=%d of %d(%d%%) column %d %s"
342 pos total percent col hscroll))
343 (if (or (/= beg 1) (/= end (1+ total)))
344 (message "Char: %s (0%o) point=%d of %d(%d%%) <%d - %d> column %d %s"
345 (single-key-description char) char pos total percent beg end col hscroll)
346 (message "Char: %s (0%o) point=%d of %d(%d%%) column %d %s"
347 (single-key-description char) char pos total percent col hscroll)))))
349 (defun fundamental-mode ()
350 "Major mode not specialized for anything in particular.
351 Other major modes are defined by comparison with this one."
352 (interactive)
353 (kill-all-local-variables))
355 (defvar read-expression-map (copy-keymap minibuffer-local-map)
356 "Minibuffer keymap used for reading Lisp expressions.")
357 (define-key read-expression-map "\M-\t" 'lisp-complete-symbol)
359 (put 'eval-expression 'disabled t)
361 ;; We define this, rather than making eval interactive,
362 ;; for the sake of completion of names like eval-region, eval-current-buffer.
363 (defun eval-expression (expression)
364 "Evaluate EXPRESSION and print value in minibuffer.
365 Value is also consed on to front of the variable `values'."
366 (interactive (list (read-from-minibuffer "Eval: "
367 nil read-expression-map t)))
368 (setq values (cons (eval expression) values))
369 (prin1 (car values) t))
371 (defun edit-and-eval-command (prompt command)
372 "Prompting with PROMPT, let user edit COMMAND and eval result.
373 COMMAND is a Lisp expression. Let user edit that expression in
374 the minibuffer, then read and evaluate the result."
375 (let ((command (read-from-minibuffer prompt
376 (prin1-to-string command)
377 read-expression-map t)))
378 ;; Add edited command to command history, unless redundant.
379 (or (equal command (car command-history))
380 (setq command-history (cons command command-history)))
381 (eval command)))
383 (defun repeat-complex-command (arg)
384 "Edit and re-evaluate last complex command, or ARGth from last.
385 A complex command is one which used the minibuffer.
386 The command is placed in the minibuffer as a Lisp form for editing.
387 The result is executed, repeating the command as changed.
388 If the command has been changed or is not the most recent previous command
389 it is added to the front of the command history.
390 You can use the minibuffer history commands \\<minibuffer-local-map>\\[next-history-element] and \\[previous-history-element]
391 to get different commands to edit and resubmit."
392 (interactive "p")
393 (let ((elt (nth (1- arg) command-history))
394 (minibuffer-history-position arg)
395 (minibuffer-history-sexp-flag t)
396 newcmd)
397 (if elt
398 (progn
399 (setq newcmd (read-from-minibuffer "Redo: "
400 (prin1-to-string elt)
401 read-expression-map
403 (cons 'command-history
404 arg)))
405 ;; If command was added to command-history as a string,
406 ;; get rid of that. We want only evallable expressions there.
407 (if (stringp (car command-history))
408 (setq command-history (cdr command-history)))
409 ;; If command to be redone does not match front of history,
410 ;; add it to the history.
411 (or (equal newcmd (car command-history))
412 (setq command-history (cons newcmd command-history)))
413 (eval newcmd))
414 (ding))))
416 (defvar minibuffer-history nil
417 "Default minibuffer history list.
418 This is used for all minibuffer input
419 except when an alternate history list is specified.")
420 (defvar minibuffer-history-sexp-flag nil
421 "Nonzero when doing history operations on `command-history'.
422 More generally, indicates that the history list being acted on
423 contains expressions rather than strings.")
424 (setq minibuffer-history-variable 'minibuffer-history)
425 (setq minibuffer-history-position nil)
426 (defvar minibuffer-history-search-history nil)
428 (mapcar
429 (lambda (key-and-command)
430 (mapcar
431 (lambda (keymap-and-completionp)
432 ;; Arg is (KEYMAP-SYMBOL . COMPLETION-MAP-P).
433 ;; If the cdr of KEY-AND-COMMAND (the command) is a cons,
434 ;; its car is used if COMPLETION-MAP-P is nil, its cdr if it is t.
435 (define-key (symbol-value (car keymap-and-completionp))
436 (car key-and-command)
437 (let ((command (cdr key-and-command)))
438 (if (consp command)
439 ;; (and ... nil) => ... turns back on the completion-oriented
440 ;; history commands which rms turned off since they seem to
441 ;; do things he doesn't like.
442 (if (and (cdr keymap-and-completionp) nil) ;XXX turned off
443 (progn (error "EMACS BUG!") (cdr command))
444 (car command))
445 command))))
446 '((minibuffer-local-map . nil)
447 (minibuffer-local-ns-map . nil)
448 (minibuffer-local-completion-map . t)
449 (minibuffer-local-must-match-map . t)
450 (read-expression-map . nil))))
451 '(("\en" . (next-history-element . next-complete-history-element))
452 ([next] . (next-history-element . next-complete-history-element))
453 ("\ep" . (previous-history-element . previous-complete-history-element))
454 ([prior] . (previous-history-element . previous-complete-history-element))
455 ("\er" . previous-matching-history-element)
456 ("\es" . next-matching-history-element)))
458 (defun previous-matching-history-element (regexp n)
459 "Find the previous history element that matches REGEXP.
460 \(Previous history elements refer to earlier actions.)
461 With prefix argument N, search for Nth previous match.
462 If N is negative, find the next or Nth next match."
463 (interactive
464 (let ((enable-recursive-minibuffers t)
465 (minibuffer-history-sexp-flag nil))
466 (list (read-from-minibuffer "Previous element matching (regexp): "
468 minibuffer-local-map
470 'minibuffer-history-search-history)
471 (prefix-numeric-value current-prefix-arg))))
472 (let ((history (symbol-value minibuffer-history-variable))
473 prevpos
474 (pos minibuffer-history-position))
475 (while (/= n 0)
476 (setq prevpos pos)
477 (setq pos (min (max 1 (+ pos (if (< n 0) -1 1))) (length history)))
478 (if (= pos prevpos)
479 (error (if (= pos 1)
480 "No later matching history item"
481 "No earlier matching history item")))
482 (if (string-match regexp
483 (if minibuffer-history-sexp-flag
484 (prin1-to-string (nth (1- pos) history))
485 (nth (1- pos) history)))
486 (setq n (+ n (if (< n 0) 1 -1)))))
487 (setq minibuffer-history-position pos)
488 (erase-buffer)
489 (let ((elt (nth (1- pos) history)))
490 (insert (if minibuffer-history-sexp-flag
491 (prin1-to-string elt)
492 elt)))
493 (goto-char (point-min)))
494 (if (or (eq (car (car command-history)) 'previous-matching-history-element)
495 (eq (car (car command-history)) 'next-matching-history-element))
496 (setq command-history (cdr command-history))))
498 (defun next-matching-history-element (regexp n)
499 "Find the next history element that matches REGEXP.
500 \(The next history element refers to a more recent action.)
501 With prefix argument N, search for Nth next match.
502 If N is negative, find the previous or Nth previous match."
503 (interactive
504 (let ((enable-recursive-minibuffers t)
505 (minibuffer-history-sexp-flag nil))
506 (list (read-from-minibuffer "Next element matching (regexp): "
508 minibuffer-local-map
510 'minibuffer-history-search-history)
511 (prefix-numeric-value current-prefix-arg))))
512 (previous-matching-history-element regexp (- n)))
514 (defun next-history-element (n)
515 "Insert the next element of the minibuffer history into the minibuffer."
516 (interactive "p")
517 (let ((narg (min (max 1 (- minibuffer-history-position n))
518 (length (symbol-value minibuffer-history-variable)))))
519 (if (= minibuffer-history-position narg)
520 (error (if (= minibuffer-history-position 1)
521 "End of history; no next item"
522 "Beginning of history; no preceding item"))
523 (erase-buffer)
524 (setq minibuffer-history-position narg)
525 (let ((elt (nth (1- minibuffer-history-position)
526 (symbol-value minibuffer-history-variable))))
527 (insert
528 (if minibuffer-history-sexp-flag
529 (prin1-to-string elt)
530 elt)))
531 (goto-char (point-min)))))
533 (defun previous-history-element (n)
534 "Inserts the previous element of the minibuffer history into the minibuffer."
535 (interactive "p")
536 (next-history-element (- n)))
538 (defun next-complete-history-element (n)
540 Get previous element of history which is a completion of minibuffer contents."
541 (interactive "p")
542 (let ((point-at-start (point)))
543 (next-matching-history-element
544 (concat "^" (regexp-quote (buffer-substring (point-min) (point)))) n)
545 ;; next-matching-history-element always puts us at (point-min).
546 ;; Move to the position we were at before changing the buffer contents.
547 ;; This is still sensical, because the text before point has not changed.
548 (goto-char point-at-start)))
550 (defun previous-complete-history-element (n)
551 "Get next element of history which is a completion of minibuffer contents."
552 (interactive "p")
553 (next-complete-history-element (- n)))
555 (defun goto-line (arg)
556 "Goto line ARG, counting from line 1 at beginning of buffer."
557 (interactive "NGoto line: ")
558 (save-restriction
559 (widen)
560 (goto-char 1)
561 (if (eq selective-display t)
562 (re-search-forward "[\n\C-m]" nil 'end (1- arg))
563 (forward-line (1- arg)))))
565 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
566 (fset 'advertised-undo 'undo)
568 (defun undo (&optional arg)
569 "Undo some previous changes.
570 Repeat this command to undo more changes.
571 A numeric argument serves as a repeat count."
572 (interactive "*p")
573 (let ((modified (buffer-modified-p)))
574 (or (eq (selected-window) (minibuffer-window))
575 (message "Undo!"))
576 (or (eq last-command 'undo)
577 (progn (undo-start)
578 (undo-more 1)))
579 (setq this-command 'undo)
580 (undo-more (or arg 1))
581 (and modified (not (buffer-modified-p))
582 (delete-auto-save-file-if-necessary))))
584 (defun undo-start ()
585 "Set `pending-undo-list' to the front of the undo list.
586 The next call to `undo-more' will undo the most recently made change."
587 (if (eq buffer-undo-list t)
588 (error "No undo information in this buffer"))
589 (setq pending-undo-list buffer-undo-list))
591 (defun undo-more (count)
592 "Undo back N undo-boundaries beyond what was already undone recently.
593 Call `undo-start' to get ready to undo recent changes,
594 then call `undo-more' one or more times to undo them."
595 (or pending-undo-list
596 (error "No further undo information"))
597 (setq pending-undo-list (primitive-undo count pending-undo-list)))
599 (defvar last-shell-command "")
600 (defvar last-shell-command-on-region "")
602 (defun shell-command (command &optional flag)
603 "Execute string COMMAND in inferior shell; display output, if any.
604 If COMMAND ends in ampersand, execute it asynchronously.
606 Optional second arg non-nil (prefix arg, if interactive)
607 means insert output in current buffer after point (leave mark after it).
608 This cannot be done asynchronously."
609 (interactive (list (read-string "Shell command: " last-shell-command)
610 current-prefix-arg))
611 (if flag
612 (progn (barf-if-buffer-read-only)
613 (push-mark)
614 ;; We do not use -f for csh; we will not support broken use of
615 ;; .cshrcs. Even the BSD csh manual says to use
616 ;; "if ($?prompt) exit" before things which are not useful
617 ;; non-interactively. Besides, if someone wants their other
618 ;; aliases for shell commands then they can still have them.
619 (call-process shell-file-name nil t nil
620 "-c" command)
621 (exchange-point-and-mark))
622 ;; Preserve the match data in case called from a program.
623 (let ((data (match-data)))
624 (unwind-protect
625 (if (string-match "[ \t]*&[ \t]*$" command)
626 ;; Command ending with ampersand means asynchronous.
627 (let ((buffer (get-buffer-create "*shell-command*"))
628 (directory default-directory)
629 proc)
630 ;; Remove the ampersand.
631 (setq command (substring command 0 (match-beginning 0)))
632 ;; If will kill a process, query first.
633 (setq proc (get-buffer-process buffer))
634 (if proc
635 (if (yes-or-no-p "A command is running. Kill it? ")
636 (kill-process proc)
637 (error "Shell command in progress")))
638 (save-excursion
639 (set-buffer buffer)
640 (erase-buffer)
641 (display-buffer buffer)
642 (setq default-directory directory)
643 (setq proc (start-process "Shell" buffer
644 shell-file-name "-c" command))
645 (setq mode-line-process '(": %s"))
646 (set-process-sentinel proc 'shell-command-sentinel)
647 (set-process-filter proc 'shell-command-filter)
649 (shell-command-on-region (point) (point) command nil))
650 (store-match-data data)))))
652 ;; We have a sentinel to prevent insertion of a termination message
653 ;; in the buffer itself.
654 (defun shell-command-sentinel (process signal)
655 (if (memq (process-status process) '(exit signal))
656 (progn
657 (message "%s: %s."
658 (car (cdr (cdr (process-command process))))
659 (substring signal 0 -1))
660 (save-excursion
661 (set-buffer (process-buffer process))
662 (setq mode-line-process nil))
663 (delete-process process))))
665 (defun shell-command-filter (proc string)
666 ;; Do save-excursion by hand so that we can leave point numerically unchanged
667 ;; despite an insertion immediately after it.
668 (let* ((obuf (current-buffer))
669 (buffer (process-buffer proc))
670 opoint
671 (window (get-buffer-window buffer))
672 (pos (window-start window)))
673 (unwind-protect
674 (progn
675 (set-buffer buffer)
676 (setq opoint (point))
677 (goto-char (point-max))
678 (insert-before-markers string))
679 ;; insert-before-markers moved this marker: set it back.
680 (set-window-start window pos)
681 ;; Finish our save-excursion.
682 (goto-char opoint)
683 (set-buffer obuf))))
685 (defun shell-command-on-region (start end command &optional flag interactive)
686 "Execute string COMMAND in inferior shell with region as input.
687 Normally display output (if any) in temp buffer `*Shell Command Output*';
688 Prefix arg means replace the region with it.
689 Noninteractive args are START, END, COMMAND, FLAG.
690 Noninteractively FLAG means insert output in place of text from START to END,
691 and put point at the end, but don't alter the mark.
693 If the output is one line, it is displayed in the echo area,
694 but it is nonetheless available in buffer `*Shell Command Output*'
695 even though that buffer is not automatically displayed. If there is no output
696 or output is inserted in the current buffer then `*Shell Command Output*' is
697 deleted."
698 (interactive (list (region-beginning) (region-end)
699 (read-string "Shell command on region: "
700 last-shell-command-on-region)
701 current-prefix-arg
702 (prefix-numeric-value current-prefix-arg)))
703 (if flag
704 ;; Replace specified region with output from command.
705 (let ((swap (and interactive (< (point) (mark)))))
706 ;; Don't muck with mark
707 ;; unless called interactively.
708 (and interactive (push-mark))
709 (call-process-region start end shell-file-name t t nil
710 "-c" command)
711 (if (get-buffer "*Shell Command Output*")
712 (kill-buffer "*Shell Command Output*"))
713 (and interactive swap (exchange-point-and-mark)))
714 ;; No prefix argument: put the output in a temp buffer,
715 ;; replacing its entire contents.
716 (let ((buffer (get-buffer-create "*Shell Command Output*")))
717 (if (eq buffer (current-buffer))
718 ;; If the input is the same buffer as the output,
719 ;; delete everything but the specified region,
720 ;; then replace that region with the output.
721 (progn (delete-region end (point-max))
722 (delete-region (point-min) start)
723 (call-process-region (point-min) (point-max)
724 shell-file-name t t nil
725 "-c" command))
726 ;; Clear the output buffer, then run the command with output there.
727 (save-excursion
728 (set-buffer buffer)
729 (erase-buffer))
730 (call-process-region start end shell-file-name
731 nil buffer nil
732 "-c" command))
733 ;; Report the amount of output.
734 (let ((lines (save-excursion
735 (set-buffer buffer)
736 (if (= (buffer-size) 0)
738 (count-lines (point-min) (point-max))))))
739 (cond ((= lines 0)
740 (message "(Shell command completed with no output)")
741 (kill-buffer "*Shell Command Output*"))
742 ((= lines 1)
743 (message "%s"
744 (save-excursion
745 (set-buffer buffer)
746 (goto-char (point-min))
747 (buffer-substring (point)
748 (progn (end-of-line) (point))))))
750 (set-window-start (display-buffer buffer) 1)))))))
752 (defun universal-argument ()
753 "Begin a numeric argument for the following command.
754 Digits or minus sign following \\[universal-argument] make up the numeric argument.
755 \\[universal-argument] following the digits or minus sign ends the argument.
756 \\[universal-argument] without digits or minus sign provides 4 as argument.
757 Repeating \\[universal-argument] without digits or minus sign
758 multiplies the argument by 4 each time."
759 (interactive nil)
760 (let ((factor 4)
761 key)
762 ;; (describe-arg (list factor) 1)
763 (setq key (read-key-sequence nil t))
764 (while (equal (key-binding key) 'universal-argument)
765 (setq factor (* 4 factor))
766 ;; (describe-arg (list factor) 1)
767 (setq key (read-key-sequence nil t)))
768 (prefix-arg-internal key factor nil)))
770 (defun prefix-arg-internal (key factor value)
771 (let ((sign 1))
772 (if (and (numberp value) (< value 0))
773 (setq sign -1 value (- value)))
774 (if (eq value '-)
775 (setq sign -1 value nil))
776 ;; (describe-arg value sign)
777 (while (equal key "-")
778 (setq sign (- sign) factor nil)
779 ;; (describe-arg value sign)
780 (setq key (read-key-sequence nil t)))
781 (while (and (stringp key)
782 (= (length key) 1)
783 (not (string< key "0"))
784 (not (string< "9" key)))
785 (setq value (+ (* (if (numberp value) value 0) 10)
786 (- (aref key 0) ?0))
787 factor nil)
788 ;; (describe-arg value sign)
789 (setq key (read-key-sequence nil t)))
790 (setq prefix-arg
791 (cond (factor (list factor))
792 ((numberp value) (* value sign))
793 ((= sign -1) '-)))
794 ;; Calling universal-argument after digits
795 ;; terminates the argument but is ignored.
796 (if (eq (key-binding key) 'universal-argument)
797 (progn
798 (describe-arg value sign)
799 (setq key (read-key-sequence nil t))))
800 (setq unread-command-events (listify-key-sequence key))))
802 (defun describe-arg (value sign)
803 (cond ((numberp value)
804 (message "Arg: %d" (* value sign)))
805 ((consp value)
806 (message "Arg: [%d]" (car value)))
807 ((< sign 0)
808 (message "Arg: -"))))
810 (defun digit-argument (arg)
811 "Part of the numeric argument for the next command.
812 \\[universal-argument] following digits or minus sign ends the argument."
813 (interactive "P")
814 (prefix-arg-internal (char-to-string (logand last-command-char ?\177))
815 nil arg))
817 (defun negative-argument (arg)
818 "Begin a negative numeric argument for the next command.
819 \\[universal-argument] following digits or minus sign ends the argument."
820 (interactive "P")
821 (prefix-arg-internal "-" nil arg))
823 (defun forward-to-indentation (arg)
824 "Move forward ARG lines and position at first nonblank character."
825 (interactive "p")
826 (forward-line arg)
827 (skip-chars-forward " \t"))
829 (defun backward-to-indentation (arg)
830 "Move backward ARG lines and position at first nonblank character."
831 (interactive "p")
832 (forward-line (- arg))
833 (skip-chars-forward " \t"))
835 (defun kill-line (&optional arg)
836 "Kill the rest of the current line; if no nonblanks there, kill thru newline.
837 With prefix argument, kill that many lines from point.
838 Negative arguments kill lines backward.
840 When calling from a program, nil means \"no arg\",
841 a number counts as a prefix arg."
842 (interactive "P")
843 (kill-region (point)
844 ;; Don't shift point before doing the delete; that way,
845 ;; undo will record the right position of point.
846 (save-excursion
847 (if arg
848 (forward-line (prefix-numeric-value arg))
849 (if (eobp)
850 (signal 'end-of-buffer nil))
851 (if (looking-at "[ \t]*$")
852 (forward-line 1)
853 (end-of-line)))
854 (point))))
856 ;;;; Window system cut and paste hooks.
858 (defvar interprogram-cut-function nil
859 "Function to call to make a killed region available to other programs.
861 Most window systems provide some sort of facility for cutting and
862 pasting text between the windows of different programs. On startup,
863 this variable is set to a function which emacs will call whenever text
864 is put in the kill ring to make the new kill available to other
865 programs.
867 The function takes one argument, TEXT, which is a string containing
868 the text which should be made available.")
870 (defvar interprogram-paste-function nil
871 "Function to call to get text cut from other programs.
873 Most window systems provide some sort of facility for cutting and
874 pasting text between the windows of different programs. On startup,
875 this variable is set to a function which emacs will call to obtain
876 text that other programs have provided for pasting.
878 The function should be called with no arguments. If the function
879 returns nil, then no other program has provided such text, and the top
880 of the Emacs kill ring should be used. If the function returns a
881 string, that string should be put in the kill ring as the latest kill.
883 Note that the function should return a string only if a program other
884 than Emacs has provided a string for pasting; if Emacs provided the
885 most recent string, the function should return nil. If it is
886 difficult to tell whether Emacs or some other program provided the
887 current string, it is probably good enough to return nil if the string
888 is equal (according to `string=') to the last text Emacs provided.")
892 ;;;; The kill ring data structure.
894 (defvar kill-ring nil
895 "List of killed text sequences.
896 Since the kill ring is supposed to interact nicely with cut-and-paste
897 facilities offered by window systems, use of this variable should
898 interact nicely with `interprogram-cut-function' and
899 `interprogram-paste-function'. The functions `kill-new',
900 `kill-append', and `current-kill' are supposed to implement this
901 interaction; you may want to use them instead of manipulating the kill
902 ring directly.")
904 (defconst kill-ring-max 30
905 "*Maximum length of kill ring before oldest elements are thrown away.")
907 (defvar kill-ring-yank-pointer nil
908 "The tail of the kill ring whose car is the last thing yanked.")
910 (defun kill-new (string)
911 "Make STRING the latest kill in the kill ring.
912 Set the kill-ring-yank pointer to point to it.
913 If `interprogram-cut-function' is non-nil, apply it to STRING."
914 (setq kill-ring (cons string kill-ring))
915 (if (> (length kill-ring) kill-ring-max)
916 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
917 (setq kill-ring-yank-pointer kill-ring)
918 (if interprogram-cut-function
919 (funcall interprogram-cut-function string)))
921 (defun kill-append (string before-p)
922 "Append STRING to the end of the latest kill in the kill ring.
923 If BEFORE-P is non-nil, prepend STRING to the kill.
924 If `interprogram-cut-function' is set, pass the resulting kill to
925 it."
926 (setcar kill-ring
927 (if before-p
928 (concat string (car kill-ring))
929 (concat (car kill-ring) string)))
930 (if interprogram-cut-function
931 (funcall interprogram-cut-function (car kill-ring))))
933 (defun current-kill (n &optional do-not-move)
934 "Rotate the yanking point by N places, and then return that kill.
935 If N is zero, `interprogram-paste-function' is set, and calling it
936 returns a string, then that string is added to the front of the
937 kill ring and returned as the latest kill.
938 If optional arg DO-NOT-MOVE is non-nil, then don't actually move the
939 yanking point; just return the Nth kill forward."
940 (let ((interprogram-paste (and (= n 0)
941 interprogram-paste-function
942 (funcall interprogram-paste-function))))
943 (if interprogram-paste
944 (progn
945 ;; Disable the interprogram cut function when we add the new
946 ;; text to the kill ring, so Emacs doesn't try to own the
947 ;; selection, with identical text.
948 (let ((interprogram-cut-function nil))
949 (kill-new interprogram-paste))
950 interprogram-paste)
951 (or kill-ring (error "Kill ring is empty"))
952 (let* ((length (length kill-ring))
953 (ARGth-kill-element
954 (nthcdr (% (+ n (- length (length kill-ring-yank-pointer)))
955 length)
956 kill-ring)))
957 (or do-not-move
958 (setq kill-ring-yank-pointer ARGth-kill-element))
959 (car ARGth-kill-element)))))
963 ;;;; Commands for manipulating the kill ring.
965 (defun kill-region (beg end)
966 "Kill between point and mark.
967 The text is deleted but saved in the kill ring.
968 The command \\[yank] can retrieve it from there.
969 \(If you want to kill and then yank immediately, use \\[copy-region-as-kill].)
970 If the buffer is read-only, Emacs will beep and refrain from deleting
971 the text, but put the text in the kill ring anyway. This means that
972 you can use the killing commands to copy text from a read-only buffer.
974 This is the primitive for programs to kill text (as opposed to deleting it).
975 Supply two arguments, character numbers indicating the stretch of text
976 to be killed.
977 Any command that calls this function is a \"kill command\".
978 If the previous command was also a kill command,
979 the text killed this time appends to the text killed last time
980 to make one entry in the kill ring."
981 (interactive "r")
982 (cond
984 ;; If the buffer is read-only, we should beep, in case the person
985 ;; just isn't aware of this. However, there's no harm in putting
986 ;; the region's text in the kill ring, anyway.
987 (buffer-read-only
988 (copy-region-as-kill beg end)
989 ;; This should always barf, and give us the correct error.
990 (barf-if-buffer-read-only))
992 ;; In certain cases, we can arrange for the undo list and the kill
993 ;; ring to share the same string object. This code does that.
994 ((not (or (eq buffer-undo-list t)
995 (eq last-command 'kill-region)
996 (eq beg end)))
997 ;; Don't let the undo list be truncated before we can even access it.
998 (let ((undo-strong-limit (+ (- (max beg end) (min beg end)) 100)))
999 (delete-region beg end)
1000 ;; Take the same string recorded for undo
1001 ;; and put it in the kill-ring.
1002 (kill-new (car (car buffer-undo-list)))
1003 (setq this-command 'kill-region)))
1006 (copy-region-as-kill beg end)
1007 (delete-region beg end))))
1009 (defun copy-region-as-kill (beg end)
1010 "Save the region as if killed, but don't kill it.
1011 If `interprogram-cut-function' is non-nil, also save the text for a window
1012 system cut and paste."
1013 (interactive "r")
1014 (if (eq last-command 'kill-region)
1015 (kill-append (buffer-substring beg end) (< end beg))
1016 (kill-new (buffer-substring beg end)))
1017 (setq this-command 'kill-region)
1018 nil)
1020 (defun kill-ring-save (beg end)
1021 "Save the region as if killed, but don't kill it.
1022 This command is similar to copy-region-as-kill, except that it gives
1023 visual feedback indicating the extent of the region being copied.
1024 If `interprogram-cut-function' is non-nil, also save the text for a window
1025 system cut and paste."
1026 (interactive "r")
1027 (copy-region-as-kill beg end)
1028 (if (interactive-p)
1029 (save-excursion
1030 (let ((other-end (if (= (point) beg) end beg)))
1031 (if (pos-visible-in-window-p other-end (selected-window))
1032 (progn
1033 (goto-char other-end)
1034 (sit-for 1))
1035 (let* ((killed-text (current-kill 0))
1036 (message-len (min (length killed-text) 40)))
1037 (if (= (point) beg)
1038 ;; Don't say "killed"; that is misleading.
1039 (message "Saved text until \"%s\""
1040 (substring killed-text (- message-len)))
1041 (message "Saved text from \"%s\""
1042 (substring killed-text 0 message-len)))))))))
1044 (defun append-next-kill ()
1045 "Cause following command, if it kills, to append to previous kill."
1046 (interactive)
1047 (if (interactive-p)
1048 (progn
1049 (setq this-command 'kill-region)
1050 (message "If the next command is a kill, it will append"))
1051 (setq last-command 'kill-region)))
1053 (defun yank-pop (arg)
1054 "Replace just-yanked stretch of killed text with a different stretch.
1055 This command is allowed only immediately after a `yank' or a `yank-pop'.
1056 At such a time, the region contains a stretch of reinserted
1057 previously-killed text. `yank-pop' deletes that text and inserts in its
1058 place a different stretch of killed text.
1060 With no argument, the previous kill is inserted.
1061 With argument N, insert the Nth previous kill.
1062 If N is negative, this is a more recent kill.
1064 The sequence of kills wraps around, so that after the oldest one
1065 comes the newest one."
1066 (interactive "*p")
1067 (if (not (eq last-command 'yank))
1068 (error "Previous command was not a yank"))
1069 (setq this-command 'yank)
1070 (let ((before (< (point) (mark))))
1071 (delete-region (point) (mark))
1072 (set-mark (point))
1073 (insert (current-kill arg))
1074 (if before (exchange-point-and-mark)))
1075 nil)
1077 (defun yank (&optional arg)
1078 "Reinsert the last stretch of killed text.
1079 More precisely, reinsert the stretch of killed text most recently
1080 killed OR yanked. Put point at end, and set mark at beginning.
1081 With just C-u as argument, same but put point at beginning (and mark at end).
1082 With argument N, reinsert the Nth most recently killed stretch of killed
1083 text.
1084 See also the command \\[yank-pop]."
1085 (interactive "*P")
1086 (push-mark (point))
1087 (insert (current-kill (cond
1088 ((listp arg) 0)
1089 ((eq arg '-) -1)
1090 (t (1- arg)))))
1091 (if (consp arg)
1092 (exchange-point-and-mark))
1093 nil)
1095 (defun rotate-yank-pointer (arg)
1096 "Rotate the yanking point in the kill ring.
1097 With argument, rotate that many kills forward (or backward, if negative)."
1098 (interactive "p")
1099 (current-kill arg))
1102 (defun insert-buffer (buffer)
1103 "Insert after point the contents of BUFFER.
1104 Puts mark after the inserted text.
1105 BUFFER may be a buffer or a buffer name."
1106 (interactive (list (progn (barf-if-buffer-read-only)
1107 (read-buffer "Insert buffer: " (other-buffer) t))))
1108 (or (bufferp buffer)
1109 (setq buffer (get-buffer buffer)))
1110 (let (start end newmark)
1111 (save-excursion
1112 (save-excursion
1113 (set-buffer buffer)
1114 (setq start (point-min) end (point-max)))
1115 (insert-buffer-substring buffer start end)
1116 (setq newmark (point)))
1117 (push-mark newmark))
1118 nil)
1120 (defun append-to-buffer (buffer start end)
1121 "Append to specified buffer the text of the region.
1122 It is inserted into that buffer before its point.
1124 When calling from a program, give three arguments:
1125 BUFFER (or buffer name), START and END.
1126 START and END specify the portion of the current buffer to be copied."
1127 (interactive
1128 (list (read-buffer "Append to buffer: " (other-buffer nil t) t)))
1129 (let ((oldbuf (current-buffer)))
1130 (save-excursion
1131 (set-buffer (get-buffer-create buffer))
1132 (insert-buffer-substring oldbuf start end))))
1134 (defun prepend-to-buffer (buffer start end)
1135 "Prepend to specified buffer the text of the region.
1136 It is inserted into that buffer after its point.
1138 When calling from a program, give three arguments:
1139 BUFFER (or buffer name), START and END.
1140 START and END specify the portion of the current buffer to be copied."
1141 (interactive "BPrepend to buffer: \nr")
1142 (let ((oldbuf (current-buffer)))
1143 (save-excursion
1144 (set-buffer (get-buffer-create buffer))
1145 (save-excursion
1146 (insert-buffer-substring oldbuf start end)))))
1148 (defun copy-to-buffer (buffer start end)
1149 "Copy to specified buffer the text of the region.
1150 It is inserted into that buffer, replacing existing text there.
1152 When calling from a program, give three arguments:
1153 BUFFER (or buffer name), START and END.
1154 START and END specify the portion of the current buffer to be copied."
1155 (interactive "BCopy to buffer: \nr")
1156 (let ((oldbuf (current-buffer)))
1157 (save-excursion
1158 (set-buffer (get-buffer-create buffer))
1159 (erase-buffer)
1160 (save-excursion
1161 (insert-buffer-substring oldbuf start end)))))
1163 (defun mark (&optional force)
1164 "Return this buffer's mark value as integer, or nil if no active mark now.
1165 If optional argument FORCE is non-nil, access the mark value
1166 even if the mark is not currently active.
1168 If you are using this in an editing command, you are most likely making
1169 a mistake; see the documentation of `set-mark'."
1170 (if (or force mark-active)
1171 (marker-position (mark-marker))
1172 (error "The mark is not currently active")))
1174 (defun set-mark (pos)
1175 "Set this buffer's mark to POS. Don't use this function!
1176 That is to say, don't use this function unless you want
1177 the user to see that the mark has moved, and you want the previous
1178 mark position to be lost.
1180 Normally, when a new mark is set, the old one should go on the stack.
1181 This is why most applications should use push-mark, not set-mark.
1183 Novice Emacs Lisp programmers often try to use the mark for the wrong
1184 purposes. The mark saves a location for the user's convenience.
1185 Most editing commands should not alter the mark.
1186 To remember a location for internal use in the Lisp program,
1187 store it in a Lisp variable. Example:
1189 (let ((beg (point))) (forward-line 1) (delete-region beg (point)))."
1191 (setq mark-active t)
1192 (run-hooks 'activate-mark-hook)
1193 (set-marker (mark-marker) pos (current-buffer)))
1195 (defvar mark-ring nil
1196 "The list of saved former marks of the current buffer,
1197 most recent first.")
1198 (make-variable-buffer-local 'mark-ring)
1200 (defconst mark-ring-max 16
1201 "*Maximum size of mark ring. Start discarding off end if gets this big.")
1203 (defun set-mark-command (arg)
1204 "Set mark at where point is, or jump to mark.
1205 With no prefix argument, set mark, and push old mark position on mark ring.
1206 With argument, jump to mark, and pop a new position for mark off the ring.
1208 Novice Emacs Lisp programmers often try to use the mark for the wrong
1209 purposes. See the documentation of `set-mark' for more information."
1210 (interactive "P")
1211 (if (null arg)
1212 (push-mark)
1213 (if (null (mark t))
1214 (error "No mark set in this buffer")
1215 (goto-char (mark))
1216 (pop-mark))))
1218 (defun push-mark (&optional location nomsg)
1219 "Set mark at LOCATION (point, by default) and push old mark on mark ring.
1220 Displays \"Mark set\" unless the optional second arg NOMSG is non-nil.
1222 Novice Emacs Lisp programmers often try to use the mark for the wrong
1223 purposes. See the documentation of `set-mark' for more information."
1224 (if (null (mark t))
1226 (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring))
1227 (if (> (length mark-ring) mark-ring-max)
1228 (progn
1229 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil)
1230 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil))))
1231 (set-mark (or location (point)))
1232 (or nomsg executing-macro (> (minibuffer-depth) 0)
1233 (message "Mark set"))
1234 nil)
1236 (defun pop-mark ()
1237 "Pop off mark ring into the buffer's actual mark.
1238 Does not set point. Does nothing if mark ring is empty."
1239 (if mark-ring
1240 (progn
1241 (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker)))))
1242 (set-mark (+ 0 (car mark-ring)))
1243 (move-marker (car mark-ring) nil)
1244 (if (null (mark)) (ding))
1245 (setq mark-ring (cdr mark-ring)))))
1247 (fset 'exchange-dot-and-mark 'exchange-point-and-mark)
1248 (defun exchange-point-and-mark ()
1249 "Put the mark where point is now, and point where the mark is now.
1250 This command works even when the mark is not active,
1251 and it reactivates the mark."
1252 (interactive nil)
1253 (let ((omark (mark t)))
1254 (if (null omark)
1255 (error "No mark set in this buffer"))
1256 (set-mark (point))
1257 (goto-char omark)
1258 nil))
1260 (defun next-line (arg)
1261 "Move cursor vertically down ARG lines.
1262 If there is no character in the target line exactly under the current column,
1263 the cursor is positioned after the character in that line which spans this
1264 column, or at the end of the line if it is not long enough.
1265 If there is no line in the buffer after this one,
1266 a newline character is inserted to create a line
1267 and the cursor moves to that line.
1269 The command \\[set-goal-column] can be used to create
1270 a semipermanent goal column to which this command always moves.
1271 Then it does not try to move vertically. This goal column is stored
1272 in `goal-column', which is nil when there is none.
1274 If you are thinking of using this in a Lisp program, consider
1275 using `forward-line' instead. It is usually easier to use
1276 and more reliable (no dependence on goal column, etc.)."
1277 (interactive "p")
1278 (if (= arg 1)
1279 (let ((opoint (point)))
1280 (forward-line 1)
1281 (if (or (= opoint (point))
1282 (not (eq (preceding-char) ?\n)))
1283 (insert ?\n)
1284 (goto-char opoint)
1285 (line-move arg)))
1286 (line-move arg))
1287 nil)
1289 (defun previous-line (arg)
1290 "Move cursor vertically up ARG lines.
1291 If there is no character in the target line exactly over the current column,
1292 the cursor is positioned after the character in that line which spans this
1293 column, or at the end of the line if it is not long enough.
1295 The command \\[set-goal-column] can be used to create
1296 a semipermanent goal column to which this command always moves.
1297 Then it does not try to move vertically.
1299 If you are thinking of using this in a Lisp program, consider using
1300 `forward-line' with a negative argument instead. It is usually easier
1301 to use and more reliable (no dependence on goal column, etc.)."
1302 (interactive "p")
1303 (line-move (- arg))
1304 nil)
1306 (defconst track-eol nil
1307 "*Non-nil means vertical motion starting at end of line keeps to ends of lines.
1308 This means moving to the end of each line moved onto.
1309 The beginning of a blank line does not count as the end of a line.")
1311 (defvar goal-column nil
1312 "*Semipermanent goal column for vertical motion, as set by \\[set-goal-column], or nil.")
1313 (make-variable-buffer-local 'goal-column)
1315 (defvar temporary-goal-column 0
1316 "Current goal column for vertical motion.
1317 It is the column where point was
1318 at the start of current run of vertical motion commands.
1319 When the `track-eol' feature is doing its job, the value is 9999.")
1321 (defun line-move (arg)
1322 (if (not (or (eq last-command 'next-line)
1323 (eq last-command 'previous-line)))
1324 (setq temporary-goal-column
1325 (if (and track-eol (eolp)
1326 ;; Don't count beg of empty line as end of line
1327 ;; unless we just did explicit end-of-line.
1328 (or (not (bolp)) (eq last-command 'end-of-line)))
1329 9999
1330 (current-column))))
1331 (if (not (integerp selective-display))
1332 (forward-line arg)
1333 ;; Move by arg lines, but ignore invisible ones.
1334 (while (> arg 0)
1335 (vertical-motion 1)
1336 (forward-char -1)
1337 (forward-line 1)
1338 (setq arg (1- arg)))
1339 (while (< arg 0)
1340 (vertical-motion -1)
1341 (beginning-of-line)
1342 (setq arg (1+ arg))))
1343 (move-to-column (or goal-column temporary-goal-column))
1344 nil)
1346 ;;; Many people have said they rarely use this feature, and often type
1347 ;;; it by accident. Maybe it shouldn't even be on a key.
1348 (put 'set-goal-column 'disabled t)
1350 (defun set-goal-column (arg)
1351 "Set the current horizontal position as a goal for \\[next-line] and \\[previous-line].
1352 Those commands will move to this position in the line moved to
1353 rather than trying to keep the same horizontal position.
1354 With a non-nil argument, clears out the goal column
1355 so that \\[next-line] and \\[previous-line] resume vertical motion.
1356 The goal column is stored in the variable `goal-column'."
1357 (interactive "P")
1358 (if arg
1359 (progn
1360 (setq goal-column nil)
1361 (message "No goal column"))
1362 (setq goal-column (current-column))
1363 (message (substitute-command-keys
1364 "Goal column %d (use \\[set-goal-column] with an arg to unset it)")
1365 goal-column))
1366 nil)
1368 (defun transpose-chars (arg)
1369 "Interchange characters around point, moving forward one character.
1370 With prefix arg ARG, effect is to take character before point
1371 and drag it forward past ARG other characters (backward if ARG negative).
1372 If no argument and at end of line, the previous two chars are exchanged."
1373 (interactive "*P")
1374 (and (null arg) (eolp) (forward-char -1))
1375 (transpose-subr 'forward-char (prefix-numeric-value arg)))
1377 (defun transpose-words (arg)
1378 "Interchange words around point, leaving point at end of them.
1379 With prefix arg ARG, effect is to take word before or around point
1380 and drag it forward past ARG other words (backward if ARG negative).
1381 If ARG is zero, the words around or after point and around or after mark
1382 are interchanged."
1383 (interactive "*p")
1384 (transpose-subr 'forward-word arg))
1386 (defun transpose-sexps (arg)
1387 "Like \\[transpose-words] but applies to sexps.
1388 Does not work on a sexp that point is in the middle of
1389 if it is a list or string."
1390 (interactive "*p")
1391 (transpose-subr 'forward-sexp arg))
1393 (defun transpose-lines (arg)
1394 "Exchange current line and previous line, leaving point after both.
1395 With argument ARG, takes previous line and moves it past ARG lines.
1396 With argument 0, interchanges line point is in with line mark is in."
1397 (interactive "*p")
1398 (transpose-subr (function
1399 (lambda (arg)
1400 (if (= arg 1)
1401 (progn
1402 ;; Move forward over a line,
1403 ;; but create a newline if none exists yet.
1404 (end-of-line)
1405 (if (eobp)
1406 (newline)
1407 (forward-char 1)))
1408 (forward-line arg))))
1409 arg))
1411 (defun transpose-subr (mover arg)
1412 (let (start1 end1 start2 end2)
1413 (if (= arg 0)
1414 (progn
1415 (save-excursion
1416 (funcall mover 1)
1417 (setq end2 (point))
1418 (funcall mover -1)
1419 (setq start2 (point))
1420 (goto-char (mark))
1421 (funcall mover 1)
1422 (setq end1 (point))
1423 (funcall mover -1)
1424 (setq start1 (point))
1425 (transpose-subr-1))
1426 (exchange-point-and-mark)))
1427 (while (> arg 0)
1428 (funcall mover -1)
1429 (setq start1 (point))
1430 (funcall mover 1)
1431 (setq end1 (point))
1432 (funcall mover 1)
1433 (setq end2 (point))
1434 (funcall mover -1)
1435 (setq start2 (point))
1436 (transpose-subr-1)
1437 (goto-char end2)
1438 (setq arg (1- arg)))
1439 (while (< arg 0)
1440 (funcall mover -1)
1441 (setq start2 (point))
1442 (funcall mover -1)
1443 (setq start1 (point))
1444 (funcall mover 1)
1445 (setq end1 (point))
1446 (funcall mover 1)
1447 (setq end2 (point))
1448 (transpose-subr-1)
1449 (setq arg (1+ arg)))))
1451 (defun transpose-subr-1 ()
1452 (if (> (min end1 end2) (max start1 start2))
1453 (error "Don't have two things to transpose"))
1454 (let ((word1 (buffer-substring start1 end1))
1455 (word2 (buffer-substring start2 end2)))
1456 (delete-region start2 end2)
1457 (goto-char start2)
1458 (insert word1)
1459 (goto-char (if (< start1 start2) start1
1460 (+ start1 (- (length word1) (length word2)))))
1461 (delete-char (length word1))
1462 (insert word2)))
1464 (defconst comment-column 32
1465 "*Column to indent right-margin comments to.
1466 Setting this variable automatically makes it local to the current buffer.
1467 Each mode establishes a different default value for this variable; you
1468 can the value for a particular mode using that mode's hook.")
1469 (make-variable-buffer-local 'comment-column)
1471 (defconst comment-start nil
1472 "*String to insert to start a new comment, or nil if no comment syntax defined.")
1474 (defconst comment-start-skip nil
1475 "*Regexp to match the start of a comment plus everything up to its body.
1476 If there are any \\(...\\) pairs, the comment delimiter text is held to begin
1477 at the place matched by the close of the first pair.")
1479 (defconst comment-end ""
1480 "*String to insert to end a new comment.
1481 Should be an empty string if comments are terminated by end-of-line.")
1483 (defconst comment-indent-hook
1484 '(lambda () comment-column)
1485 "Function to compute desired indentation for a comment.
1486 This function is called with no args with point at the beginning of
1487 the comment's starting delimiter.")
1489 (defun indent-for-comment ()
1490 "Indent this line's comment to comment column, or insert an empty comment."
1491 (interactive "*")
1492 (beginning-of-line 1)
1493 (if (null comment-start)
1494 (error "No comment syntax defined")
1495 (let* ((eolpos (save-excursion (end-of-line) (point)))
1496 cpos indent begpos)
1497 (if (re-search-forward comment-start-skip eolpos 'move)
1498 (progn (setq cpos (point-marker))
1499 ;; Find the start of the comment delimiter.
1500 ;; If there were paren-pairs in comment-start-skip,
1501 ;; position at the end of the first pair.
1502 (if (match-end 1)
1503 (goto-char (match-end 1))
1504 ;; If comment-start-skip matched a string with internal
1505 ;; whitespace (not final whitespace) then the delimiter
1506 ;; start at the end of that whitespace.
1507 ;; Otherwise, it starts at the beginning of what was matched.
1508 (skip-chars-backward " \t" (match-beginning 0))
1509 (skip-chars-backward "^ \t" (match-beginning 0)))))
1510 (setq begpos (point))
1511 ;; Compute desired indent.
1512 (if (= (current-column)
1513 (setq indent (funcall comment-indent-hook)))
1514 (goto-char begpos)
1515 ;; If that's different from current, change it.
1516 (skip-chars-backward " \t")
1517 (delete-region (point) begpos)
1518 (indent-to indent))
1519 ;; An existing comment?
1520 (if cpos
1521 (progn (goto-char cpos)
1522 (set-marker cpos nil))
1523 ;; No, insert one.
1524 (insert comment-start)
1525 (save-excursion
1526 (insert comment-end))))))
1528 (defun set-comment-column (arg)
1529 "Set the comment column based on point.
1530 With no arg, set the comment column to the current column.
1531 With just minus as arg, kill any comment on this line.
1532 With any other arg, set comment column to indentation of the previous comment
1533 and then align or create a comment on this line at that column."
1534 (interactive "P")
1535 (if (eq arg '-)
1536 (kill-comment nil)
1537 (if arg
1538 (progn
1539 (save-excursion
1540 (beginning-of-line)
1541 (re-search-backward comment-start-skip)
1542 (beginning-of-line)
1543 (re-search-forward comment-start-skip)
1544 (goto-char (match-beginning 0))
1545 (setq comment-column (current-column))
1546 (message "Comment column set to %d" comment-column))
1547 (indent-for-comment))
1548 (setq comment-column (current-column))
1549 (message "Comment column set to %d" comment-column))))
1551 (defun kill-comment (arg)
1552 "Kill the comment on this line, if any.
1553 With argument, kill comments on that many lines starting with this one."
1554 ;; this function loses in a lot of situations. it incorrectly recognises
1555 ;; comment delimiters sometimes (ergo, inside a string), doesn't work
1556 ;; with multi-line comments, can kill extra whitespace if comment wasn't
1557 ;; through end-of-line, et cetera.
1558 (interactive "P")
1559 (or comment-start-skip (error "No comment syntax defined"))
1560 (let ((count (prefix-numeric-value arg)) endc)
1561 (while (> count 0)
1562 (save-excursion
1563 (end-of-line)
1564 (setq endc (point))
1565 (beginning-of-line)
1566 (and (string< "" comment-end)
1567 (setq endc
1568 (progn
1569 (re-search-forward (regexp-quote comment-end) endc 'move)
1570 (skip-chars-forward " \t")
1571 (point))))
1572 (beginning-of-line)
1573 (if (re-search-forward comment-start-skip endc t)
1574 (progn
1575 (goto-char (match-beginning 0))
1576 (skip-chars-backward " \t")
1577 (kill-region (point) endc)
1578 ;; to catch comments a line beginnings
1579 (indent-according-to-mode))))
1580 (if arg (forward-line 1))
1581 (setq count (1- count)))))
1583 (defun comment-region (beg end &optional arg)
1584 "Comment the region; third arg numeric means use ARG comment characters.
1585 If ARG is negative, delete that many comment characters instead.
1586 Comments are terminated on each line, even for syntax in which newline does
1587 not end the comment. Blank lines do not get comments."
1588 ;; if someone wants it to only put a comment-start at the beginning and
1589 ;; comment-end at the end then typing it, C-x C-x, closing it, C-x C-x
1590 ;; is easy enough. No option is made here for other than commenting
1591 ;; every line.
1592 (interactive "r\np")
1593 (or comment-start (error "No comment syntax is defined"))
1594 (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
1595 (save-excursion
1596 (save-restriction
1597 (let ((cs comment-start) (ce comment-end))
1598 (cond ((not arg) (setq arg 1))
1599 ((> arg 1)
1600 (while (> (setq arg (1- arg)) 0)
1601 (setq cs (concat cs comment-start)
1602 ce (concat ce comment-end)))))
1603 (narrow-to-region beg end)
1604 (goto-char beg)
1605 (while (not (eobp))
1606 (if (< arg 0)
1607 (let ((count arg))
1608 (while (and (> 1 (setq count (1+ count)))
1609 (looking-at (regexp-quote cs)))
1610 (delete-char (length cs)))
1611 (if (string= "" ce) ()
1612 (setq count arg)
1613 (while (> 1 (setq count (1+ count)))
1614 (end-of-line)
1615 ;; this is questionable if comment-end ends in whitespace
1616 ;; that is pretty brain-damaged though
1617 (skip-chars-backward " \t")
1618 (backward-char (length ce))
1619 (if (looking-at (regexp-quote ce))
1620 (delete-char (length ce)))))
1621 (forward-line 1))
1622 (if (looking-at "[ \t]*$") ()
1623 (insert cs)
1624 (if (string= "" ce) ()
1625 (end-of-line)
1626 (insert ce)))
1627 (search-forward "\n" nil 'move)))))))
1629 (defun backward-word (arg)
1630 "Move backward until encountering the end of a word.
1631 With argument, do this that many times.
1632 In programs, it is faster to call `forward-word' with negative arg."
1633 (interactive "p")
1634 (forward-word (- arg)))
1636 (defun mark-word (arg)
1637 "Set mark arg words away from point."
1638 (interactive "p")
1639 (push-mark
1640 (save-excursion
1641 (forward-word arg)
1642 (point))))
1644 (defun kill-word (arg)
1645 "Kill characters forward until encountering the end of a word.
1646 With argument, do this that many times."
1647 (interactive "p")
1648 (kill-region (point) (save-excursion (forward-word arg) (point))))
1650 (defun backward-kill-word (arg)
1651 "Kill characters backward until encountering the end of a word.
1652 With argument, do this that many times."
1653 (interactive "p")
1654 (kill-word (- arg)))
1656 (defconst fill-prefix nil
1657 "*String for filling to insert at front of new line, or nil for none.
1658 Setting this variable automatically makes it local to the current buffer.")
1659 (make-variable-buffer-local 'fill-prefix)
1661 (defconst auto-fill-inhibit-regexp nil
1662 "*Regexp to match lines which should not be auto-filled.")
1664 (defun do-auto-fill ()
1665 (let (give-up)
1666 (or (and auto-fill-inhibit-regexp
1667 (save-excursion (beginning-of-line)
1668 (looking-at auto-fill-inhibit-regexp)))
1669 (while (and (not give-up) (> (current-column) fill-column))
1670 (let ((fill-point
1671 (let ((opoint (point)))
1672 (save-excursion
1673 (move-to-column (1+ fill-column))
1674 (skip-chars-backward "^ \t\n")
1675 (if (bolp)
1676 (re-search-forward "[ \t]" opoint t))
1677 (skip-chars-backward " \t")
1678 (point)))))
1679 ;; If there is a space on the line before fill-point,
1680 ;; and nonspaces precede it, break the line there.
1681 (if (save-excursion
1682 (goto-char fill-point)
1683 (not (bolp)))
1684 ;; If point is at the fill-point, do not `save-excursion'.
1685 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
1686 ;; point will end up before it rather than after it.
1687 (if (save-excursion
1688 (skip-chars-backward " \t")
1689 (= (point) fill-point))
1690 (indent-new-comment-line)
1691 (save-excursion
1692 (goto-char fill-point)
1693 (indent-new-comment-line)))
1694 ;; No place to break => stop trying.
1695 (setq give-up t)))))))
1697 (defconst comment-multi-line nil
1698 "*Non-nil means \\[indent-new-comment-line] should continue same comment
1699 on new line, with no new terminator or starter.
1700 This is obsolete because you might as well use \\[newline-and-indent].")
1702 (defun indent-new-comment-line ()
1703 "Break line at point and indent, continuing comment if presently within one.
1704 The body of the continued comment is indented under the previous comment line.
1706 This command is intended for styles where you write a comment per line,
1707 starting a new comment (and terminating it if necessary) on each line.
1708 If you want to continue one comment across several lines, use \\[newline-and-indent]."
1709 (interactive "*")
1710 (let (comcol comstart)
1711 (skip-chars-backward " \t")
1712 (delete-region (point)
1713 (progn (skip-chars-forward " \t")
1714 (point)))
1715 (insert ?\n)
1716 (if (not comment-multi-line)
1717 (save-excursion
1718 (if (and comment-start-skip
1719 (let ((opoint (point)))
1720 (forward-line -1)
1721 (re-search-forward comment-start-skip opoint t)))
1722 ;; The old line is a comment.
1723 ;; Set WIN to the pos of the comment-start.
1724 ;; But if the comment is empty, look at preceding lines
1725 ;; to find one that has a nonempty comment.
1726 (let ((win (match-beginning 0)))
1727 (while (and (eolp) (not (bobp))
1728 (let (opoint)
1729 (beginning-of-line)
1730 (setq opoint (point))
1731 (forward-line -1)
1732 (re-search-forward comment-start-skip opoint t)))
1733 (setq win (match-beginning 0)))
1734 ;; Indent this line like what we found.
1735 (goto-char win)
1736 (setq comcol (current-column))
1737 (setq comstart (buffer-substring (point) (match-end 0)))))))
1738 (if comcol
1739 (let ((comment-column comcol)
1740 (comment-start comstart)
1741 (comment-end comment-end))
1742 (and comment-end (not (equal comment-end ""))
1743 ; (if (not comment-multi-line)
1744 (progn
1745 (forward-char -1)
1746 (insert comment-end)
1747 (forward-char 1))
1748 ; (setq comment-column (+ comment-column (length comment-start))
1749 ; comment-start "")
1752 (if (not (eolp))
1753 (setq comment-end ""))
1754 (insert ?\n)
1755 (forward-char -1)
1756 (indent-for-comment)
1757 (save-excursion
1758 ;; Make sure we delete the newline inserted above.
1759 (end-of-line)
1760 (delete-char 1)))
1761 (if fill-prefix
1762 (insert fill-prefix)
1763 (indent-according-to-mode)))))
1765 (defun auto-fill-mode (&optional arg)
1766 "Toggle auto-fill mode.
1767 With arg, turn auto-fill mode on if and only if arg is positive.
1768 In auto-fill mode, inserting a space at a column beyond fill-column
1769 automatically breaks the line at a previous space."
1770 (interactive "P")
1771 (prog1 (setq auto-fill-function
1772 (if (if (null arg)
1773 (not auto-fill-function)
1774 (> (prefix-numeric-value arg) 0))
1775 'do-auto-fill
1776 nil))
1777 ;; update mode-line
1778 (set-buffer-modified-p (buffer-modified-p))))
1780 (defun turn-on-auto-fill ()
1781 "Unconditionally turn on Auto Fill mode."
1782 (auto-fill-mode 1))
1784 (defun set-fill-column (arg)
1785 "Set `fill-column' to current column, or to argument if given.
1786 The variable `fill-column' has a separate value for each buffer."
1787 (interactive "P")
1788 (setq fill-column (if (integerp arg) arg (current-column)))
1789 (message "fill-column set to %d" fill-column))
1791 (defun set-selective-display (arg)
1792 "Set `selective-display' to ARG; clear it if no arg.
1793 When the value of `selective-display' is a number > 0,
1794 lines whose indentation is >= that value are not displayed.
1795 The variable `selective-display' has a separate value for each buffer."
1796 (interactive "P")
1797 (if (eq selective-display t)
1798 (error "selective-display already in use for marked lines"))
1799 (let ((current-vpos
1800 (save-restriction
1801 (narrow-to-region (point-min) (point))
1802 (goto-char (window-start))
1803 (vertical-motion (window-height)))))
1804 (setq selective-display
1805 (and arg (prefix-numeric-value arg)))
1806 (recenter current-vpos))
1807 (set-window-start (selected-window) (window-start (selected-window)))
1808 (princ "selective-display set to " t)
1809 (prin1 selective-display t)
1810 (princ "." t))
1812 (defun overwrite-mode (arg)
1813 "Toggle overwrite mode.
1814 With arg, turn overwrite mode on iff arg is positive.
1815 In overwrite mode, printing characters typed in replace existing text
1816 on a one-for-one basis, rather than pushing it to the right."
1817 (interactive "P")
1818 (setq overwrite-mode
1819 (if (null arg) (not overwrite-mode)
1820 (> (prefix-numeric-value arg) 0)))
1821 (set-buffer-modified-p (buffer-modified-p))) ;No-op, but updates mode line.
1823 (defvar blink-matching-paren t
1824 "*Non-nil means show matching open-paren when close-paren is inserted.")
1826 (defconst blink-matching-paren-distance 4000
1827 "*If non-nil, is maximum distance to search for matching open-paren
1828 when close-paren is inserted.")
1830 (defun blink-matching-open ()
1831 "Move cursor momentarily to the beginning of the sexp before point."
1832 (interactive)
1833 (and (> (point) (1+ (point-min)))
1834 (/= (char-syntax (char-after (- (point) 2))) ?\\ )
1835 blink-matching-paren
1836 (let* ((oldpos (point))
1837 (blinkpos)
1838 (mismatch))
1839 (save-excursion
1840 (save-restriction
1841 (if blink-matching-paren-distance
1842 (narrow-to-region (max (point-min)
1843 (- (point) blink-matching-paren-distance))
1844 oldpos))
1845 (condition-case ()
1846 (setq blinkpos (scan-sexps oldpos -1))
1847 (error nil)))
1848 (and blinkpos (/= (char-syntax (char-after blinkpos))
1849 ?\$)
1850 (setq mismatch
1851 (/= (char-after (1- oldpos))
1852 (logand (lsh (aref (syntax-table)
1853 (char-after blinkpos))
1855 255))))
1856 (if mismatch (setq blinkpos nil))
1857 (if blinkpos
1858 (progn
1859 (goto-char blinkpos)
1860 (if (pos-visible-in-window-p)
1861 (sit-for 1)
1862 (goto-char blinkpos)
1863 (message
1864 "Matches %s"
1865 (if (save-excursion
1866 (skip-chars-backward " \t")
1867 (not (bolp)))
1868 (buffer-substring (progn (beginning-of-line) (point))
1869 (1+ blinkpos))
1870 (buffer-substring blinkpos
1871 (progn
1872 (forward-char 1)
1873 (skip-chars-forward "\n \t")
1874 (end-of-line)
1875 (point)))))))
1876 (cond (mismatch
1877 (message "Mismatched parentheses"))
1878 ((not blink-matching-paren-distance)
1879 (message "Unmatched parenthesis"))))))))
1881 ;Turned off because it makes dbx bomb out.
1882 (setq blink-paren-function 'blink-matching-open)
1884 ; this is just something for the luser to see in a keymap -- this is not
1885 ; how quitting works normally!
1886 (defun keyboard-quit ()
1887 "Signal a quit condition.
1888 During execution of Lisp code, this character causes a quit directly.
1889 At top-level, as an editor command, this simply beeps."
1890 (interactive)
1891 (signal 'quit nil))
1893 (define-key global-map "\C-g" 'keyboard-quit)
1895 (defun set-variable (var val)
1896 "Set VARIABLE to VALUE. VALUE is a Lisp object.
1897 When using this interactively, supply a Lisp expression for VALUE.
1898 If you want VALUE to be a string, you must surround it with doublequotes.
1900 If VARIABLE has a `variable-interactive' property, that is used as if
1901 it were the arg to `interactive' (which see) to interactively read the value."
1902 (interactive
1903 (let* ((var (read-variable "Set variable: "))
1904 (minibuffer-help-form
1905 '(funcall myhelp))
1906 (myhelp
1907 (function
1908 (lambda ()
1909 (with-output-to-temp-buffer "*Help*"
1910 (prin1 var)
1911 (princ "\nDocumentation:\n")
1912 (princ (substring (documentation-property var 'variable-documentation)
1914 (if (boundp var)
1915 (let ((print-length 20))
1916 (princ "\n\nCurrent value: ")
1917 (prin1 (symbol-value var))))
1918 nil)))))
1919 (list var
1920 (let ((prop (get var 'variable-interactive)))
1921 (if prop
1922 ;; Use VAR's `variable-interactive' property
1923 ;; as an interactive spec for prompting.
1924 (call-interactively (list 'lambda '(arg)
1925 (list 'interactive prop)
1926 'arg))
1927 (eval-minibuffer (format "Set %s to value: " var)))))))
1928 (set var val))
1930 ;;; simple.el ends here