("Romanian"): Remove unibyte-syntax property.
[emacs.git] / lisp / simple.el
blob36d1ce52c5edf212bc92fdff099665910a6d0e11
1 ;;; simple.el --- basic editing commands for Emacs
3 ;; Copyright (C) 1985, 86, 87, 93, 94, 95, 96, 97, 98, 99, 2000, 2001
4 ;; Free Software Foundation, Inc.
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
23 ;;; Commentary:
25 ;; A grab-bag of basic Emacs commands not specifically related to some
26 ;; major mode or to file-handling.
28 ;;; Code:
30 (eval-when-compile
31 (autoload 'widget-convert "wid-edit")
32 (autoload 'shell-mode "shell"))
35 (defgroup killing nil
36 "Killing and yanking commands"
37 :group 'editing)
39 (defgroup paren-matching nil
40 "Highlight (un)matching of parens and expressions."
41 :group 'matching)
44 (defun fundamental-mode ()
45 "Major mode not specialized for anything in particular.
46 Other major modes are defined by comparison with this one."
47 (interactive)
48 (kill-all-local-variables))
50 ;; Making and deleting lines.
52 (defun newline (&optional arg)
53 "Insert a newline, and move to left margin of the new line if it's blank.
54 If `use-hard-newlines' is non-nil, the newline is marked with the
55 text-property `hard'.
56 With ARG, insert that many newlines.
57 Call `auto-fill-function' if the current column number is greater
58 than the value of `fill-column' and ARG is `nil'."
59 (interactive "*P")
60 (barf-if-buffer-read-only)
61 ;; Inserting a newline at the end of a line produces better redisplay in
62 ;; try_window_id than inserting at the beginning of a line, and the textual
63 ;; result is the same. So, if we're at beginning of line, pretend to be at
64 ;; the end of the previous line.
65 (let ((flag (and (not (bobp))
66 (bolp)
67 ;; Make sure no functions want to be told about
68 ;; the range of the changes.
69 (not after-change-functions)
70 (not before-change-functions)
71 ;; Make sure there are no markers here.
72 (not (buffer-has-markers-at (1- (point))))
73 (not (buffer-has-markers-at (point)))
74 ;; Make sure no text properties want to know
75 ;; where the change was.
76 (not (get-char-property (1- (point)) 'modification-hooks))
77 (not (get-char-property (1- (point)) 'insert-behind-hooks))
78 (or (eobp)
79 (not (get-char-property (point) 'insert-in-front-hooks)))
80 ;; Make sure the newline before point isn't intangible.
81 (not (get-char-property (1- (point)) 'intangible))
82 ;; Make sure the newline before point isn't read-only.
83 (not (get-char-property (1- (point)) 'read-only))
84 ;; Make sure the newline before point isn't invisible.
85 (not (get-char-property (1- (point)) 'invisible))
86 ;; Make sure the newline before point has the same
87 ;; properties as the char before it (if any).
88 (< (or (previous-property-change (point)) -2)
89 (- (point) 2))))
90 (was-page-start (and (bolp)
91 (looking-at page-delimiter)))
92 (beforepos (point)))
93 (if flag (backward-char 1))
94 ;; Call self-insert so that auto-fill, abbrev expansion etc. happens.
95 ;; Set last-command-char to tell self-insert what to insert.
96 (let ((last-command-char ?\n)
97 ;; Don't auto-fill if we have a numeric argument.
98 ;; Also not if flag is true (it would fill wrong line);
99 ;; there is no need to since we're at BOL.
100 (auto-fill-function (if (or arg flag) nil auto-fill-function)))
101 (unwind-protect
102 (self-insert-command (prefix-numeric-value arg))
103 ;; If we get an error in self-insert-command, put point at right place.
104 (if flag (forward-char 1))))
105 ;; Even if we did *not* get an error, keep that forward-char;
106 ;; all further processing should apply to the newline that the user
107 ;; thinks he inserted.
109 ;; Mark the newline(s) `hard'.
110 (if use-hard-newlines
111 (set-hard-newline-properties
112 (- (point) (if arg (prefix-numeric-value arg) 1)) (point)))
113 ;; If the newline leaves the previous line blank,
114 ;; and we have a left margin, delete that from the blank line.
115 (or flag
116 (save-excursion
117 (goto-char beforepos)
118 (beginning-of-line)
119 (and (looking-at "[ \t]$")
120 (> (current-left-margin) 0)
121 (delete-region (point) (progn (end-of-line) (point))))))
122 ;; Indent the line after the newline, except in one case:
123 ;; when we added the newline at the beginning of a line
124 ;; which starts a page.
125 (or was-page-start
126 (move-to-left-margin nil t)))
127 nil)
129 (defun set-hard-newline-properties (from to)
130 (let ((sticky (get-text-property from 'rear-nonsticky)))
131 (put-text-property from to 'hard 't)
132 ;; If rear-nonsticky is not "t", add 'hard to rear-nonsticky list
133 (if (and (listp sticky) (not (memq 'hard sticky)))
134 (put-text-property from (point) 'rear-nonsticky
135 (cons 'hard sticky)))))
137 (defun open-line (arg)
138 "Insert a newline and leave point before it.
139 If there is a fill prefix and/or a left-margin, insert them on the new line
140 if the line would have been blank.
141 With arg N, insert N newlines."
142 (interactive "*p")
143 (let* ((do-fill-prefix (and fill-prefix (bolp)))
144 (do-left-margin (and (bolp) (> (current-left-margin) 0)))
145 (loc (point))
146 ;; Don't expand an abbrev before point.
147 (abbrev-mode nil))
148 (newline arg)
149 (goto-char loc)
150 (while (> arg 0)
151 (cond ((bolp)
152 (if do-left-margin (indent-to (current-left-margin)))
153 (if do-fill-prefix (insert-and-inherit fill-prefix))))
154 (forward-line 1)
155 (setq arg (1- arg)))
156 (goto-char loc)
157 (end-of-line)))
159 (defun split-line ()
160 "Split current line, moving portion beyond point vertically down."
161 (interactive "*")
162 (skip-chars-forward " \t")
163 (let ((col (current-column))
164 (pos (point)))
165 (newline 1)
166 (indent-to col 0)
167 (goto-char pos)))
169 (defun delete-indentation (&optional arg)
170 "Join this line to previous and fix up whitespace at join.
171 If there is a fill prefix, delete it from the beginning of this line.
172 With argument, join this line to following line."
173 (interactive "*P")
174 (beginning-of-line)
175 (if arg (forward-line 1))
176 (if (eq (preceding-char) ?\n)
177 (progn
178 (delete-region (point) (1- (point)))
179 ;; If the second line started with the fill prefix,
180 ;; delete the prefix.
181 (if (and fill-prefix
182 (<= (+ (point) (length fill-prefix)) (point-max))
183 (string= fill-prefix
184 (buffer-substring (point)
185 (+ (point) (length fill-prefix)))))
186 (delete-region (point) (+ (point) (length fill-prefix))))
187 (fixup-whitespace))))
189 (defalias 'join-line #'delete-indentation) ; easier to find
191 (defun delete-blank-lines ()
192 "On blank line, delete all surrounding blank lines, leaving just one.
193 On isolated blank line, delete that one.
194 On nonblank line, delete any immediately following blank lines."
195 (interactive "*")
196 (let (thisblank singleblank)
197 (save-excursion
198 (beginning-of-line)
199 (setq thisblank (looking-at "[ \t]*$"))
200 ;; Set singleblank if there is just one blank line here.
201 (setq singleblank
202 (and thisblank
203 (not (looking-at "[ \t]*\n[ \t]*$"))
204 (or (bobp)
205 (progn (forward-line -1)
206 (not (looking-at "[ \t]*$")))))))
207 ;; Delete preceding blank lines, and this one too if it's the only one.
208 (if thisblank
209 (progn
210 (beginning-of-line)
211 (if singleblank (forward-line 1))
212 (delete-region (point)
213 (if (re-search-backward "[^ \t\n]" nil t)
214 (progn (forward-line 1) (point))
215 (point-min)))))
216 ;; Delete following blank lines, unless the current line is blank
217 ;; and there are no following blank lines.
218 (if (not (and thisblank singleblank))
219 (save-excursion
220 (end-of-line)
221 (forward-line 1)
222 (delete-region (point)
223 (if (re-search-forward "[^ \t\n]" nil t)
224 (progn (beginning-of-line) (point))
225 (point-max)))))
226 ;; Handle the special case where point is followed by newline and eob.
227 ;; Delete the line, leaving point at eob.
228 (if (looking-at "^[ \t]*\n\\'")
229 (delete-region (point) (point-max)))))
231 (defun delete-trailing-whitespace ()
232 "Delete all the trailing whitespace across the current buffer.
233 All whitespace after the last non-whitespace character in a line is deleted.
234 This respects narrowing, created by \\[narrow-to-region] and friends.
235 A formfeed is not considered whitespace by this function."
236 (interactive "*")
237 (save-match-data
238 (save-excursion
239 (goto-char (point-min))
240 (while (re-search-forward "\\s-$" nil t)
241 (skip-syntax-backward "-" (save-excursion (forward-line 0) (point)))
242 ;; Don't delete formfeeds, even if they are considered whitespace.
243 (save-match-data
244 (if (looking-at ".*\f")
245 (goto-char (match-end 0))))
246 (delete-region (point) (match-end 0))))))
248 (defun newline-and-indent ()
249 "Insert a newline, then indent according to major mode.
250 Indentation is done using the value of `indent-line-function'.
251 In programming language modes, this is the same as TAB.
252 In some text modes, where TAB inserts a tab, this command indents to the
253 column specified by the function `current-left-margin'."
254 (interactive "*")
255 (delete-horizontal-space t)
256 (newline)
257 (indent-according-to-mode))
259 (defun reindent-then-newline-and-indent ()
260 "Reindent current line, insert newline, then indent the new line.
261 Indentation of both lines is done according to the current major mode,
262 which means calling the current value of `indent-line-function'.
263 In programming language modes, this is the same as TAB.
264 In some text modes, where TAB inserts a tab, this indents to the
265 column specified by the function `current-left-margin'."
266 (interactive "*")
267 (delete-horizontal-space t)
268 (let ((pos (point)))
269 ;; Be careful to insert the newline before indenting the line.
270 ;; Otherwise, the indentation might be wrong.
271 (newline)
272 (save-excursion
273 (goto-char pos)
274 (indent-according-to-mode))
275 (indent-according-to-mode)))
277 (defun quoted-insert (arg)
278 "Read next input character and insert it.
279 This is useful for inserting control characters.
281 If the first character you type after this command is an octal digit,
282 you should type a sequence of octal digits which specify a character code.
283 Any nondigit terminates the sequence. If the terminator is a RET,
284 it is discarded; any other terminator is used itself as input.
285 The variable `read-quoted-char-radix' specifies the radix for this feature;
286 set it to 10 or 16 to use decimal or hex instead of octal.
288 In overwrite mode, this function inserts the character anyway, and
289 does not handle octal digits specially. This means that if you use
290 overwrite as your normal editing mode, you can use this function to
291 insert characters when necessary.
293 In binary overwrite mode, this function does overwrite, and octal
294 digits are interpreted as a character code. This is intended to be
295 useful for editing binary files."
296 (interactive "*p")
297 (let ((char (if (or (not overwrite-mode)
298 (eq overwrite-mode 'overwrite-mode-binary))
299 (read-quoted-char)
300 (read-char))))
301 ;; Assume character codes 0240 - 0377 stand for characters in some
302 ;; single-byte character set, and convert them to Emacs
303 ;; characters.
304 (if (and enable-multibyte-characters
305 (>= char ?\240)
306 (<= char ?\377))
307 (setq char (unibyte-char-to-multibyte char)))
308 (if (> arg 0)
309 (if (eq overwrite-mode 'overwrite-mode-binary)
310 (delete-char arg)))
311 (while (> arg 0)
312 (insert-and-inherit char)
313 (setq arg (1- arg)))))
315 (defun forward-to-indentation (arg)
316 "Move forward ARG lines and position at first nonblank character."
317 (interactive "p")
318 (forward-line arg)
319 (skip-chars-forward " \t"))
321 (defun backward-to-indentation (arg)
322 "Move backward ARG lines and position at first nonblank character."
323 (interactive "p")
324 (forward-line (- arg))
325 (skip-chars-forward " \t"))
327 (defun back-to-indentation ()
328 "Move point to the first non-whitespace character on this line."
329 (interactive)
330 (beginning-of-line 1)
331 (skip-chars-forward " \t"))
333 (defun fixup-whitespace ()
334 "Fixup white space between objects around point.
335 Leave one space or none, according to the context."
336 (interactive "*")
337 (save-excursion
338 (delete-horizontal-space)
339 (if (or (looking-at "^\\|\\s)")
340 (save-excursion (forward-char -1)
341 (looking-at "$\\|\\s(\\|\\s'")))
343 (insert ?\ ))))
345 (defun delete-horizontal-space (&optional backward-only)
346 "Delete all spaces and tabs around point.
347 If BACKWARD-ONLY is non-nil, only delete spaces before point."
348 (interactive "*")
349 (let ((orig-pos (point)))
350 (delete-region
351 (if backward-only
352 orig-pos
353 (progn
354 (skip-chars-forward " \t")
355 (constrain-to-field nil orig-pos t)))
356 (progn
357 (skip-chars-backward " \t")
358 (constrain-to-field nil orig-pos)))))
360 (defun just-one-space ()
361 "Delete all spaces and tabs around point, leaving one space."
362 (interactive "*")
363 (let ((orig-pos (point)))
364 (skip-chars-backward " \t")
365 (constrain-to-field nil orig-pos)
366 (if (= (following-char) ? )
367 (forward-char 1)
368 (insert ? ))
369 (delete-region
370 (point)
371 (progn
372 (skip-chars-forward " \t")
373 (constrain-to-field nil orig-pos t)))))
375 (defun beginning-of-buffer (&optional arg)
376 "Move point to the beginning of the buffer; leave mark at previous position.
377 With arg N, put point N/10 of the way from the beginning.
379 If the buffer is narrowed, this command uses the beginning and size
380 of the accessible part of the buffer.
382 Don't use this command in Lisp programs!
383 \(goto-char (point-min)) is faster and avoids clobbering the mark."
384 (interactive "P")
385 (push-mark)
386 (let ((size (- (point-max) (point-min))))
387 (goto-char (if arg
388 (+ (point-min)
389 (if (> size 10000)
390 ;; Avoid overflow for large buffer sizes!
391 (* (prefix-numeric-value arg)
392 (/ size 10))
393 (/ (+ 10 (* size (prefix-numeric-value arg))) 10)))
394 (point-min))))
395 (if arg (forward-line 1)))
397 (defun end-of-buffer (&optional arg)
398 "Move point to the end of the buffer; leave mark at previous position.
399 With arg N, put point N/10 of the way from the end.
401 If the buffer is narrowed, this command uses the beginning and size
402 of the accessible part of the buffer.
404 Don't use this command in Lisp programs!
405 \(goto-char (point-max)) is faster and avoids clobbering the mark."
406 (interactive "P")
407 (push-mark)
408 (let ((size (- (point-max) (point-min))))
409 (goto-char (if arg
410 (- (point-max)
411 (if (> size 10000)
412 ;; Avoid overflow for large buffer sizes!
413 (* (prefix-numeric-value arg)
414 (/ size 10))
415 (/ (* size (prefix-numeric-value arg)) 10)))
416 (point-max))))
417 ;; If we went to a place in the middle of the buffer,
418 ;; adjust it to the beginning of a line.
419 (cond (arg (forward-line 1))
420 ((> (point) (window-end nil t))
421 ;; If the end of the buffer is not already on the screen,
422 ;; then scroll specially to put it near, but not at, the bottom.
423 (overlay-recenter (point))
424 (recenter -3))))
426 (defun mark-whole-buffer ()
427 "Put point at beginning and mark at end of buffer.
428 You probably should not use this function in Lisp programs;
429 it is usually a mistake for a Lisp function to use any subroutine
430 that uses or sets the mark."
431 (interactive)
432 (push-mark (point))
433 (push-mark (point-max) nil t)
434 (goto-char (point-min)))
437 ;; Counting lines, one way or another.
439 (defun goto-line (arg)
440 "Goto line ARG, counting from line 1 at beginning of buffer."
441 (interactive "NGoto line: ")
442 (setq arg (prefix-numeric-value arg))
443 (save-restriction
444 (widen)
445 (goto-char 1)
446 (if (eq selective-display t)
447 (re-search-forward "[\n\C-m]" nil 'end (1- arg))
448 (forward-line (1- arg)))))
450 (defun count-lines-region (start end)
451 "Print number of lines and characters in the region."
452 (interactive "r")
453 (message "Region has %d lines, %d characters"
454 (count-lines start end) (- end start)))
456 (defun what-line ()
457 "Print the current buffer line number and narrowed line number of point."
458 (interactive)
459 (let ((opoint (point)) start)
460 (save-excursion
461 (save-restriction
462 (goto-char (point-min))
463 (widen)
464 (forward-line 0)
465 (setq start (point))
466 (goto-char opoint)
467 (forward-line 0)
468 (if (/= start 1)
469 (message "line %d (narrowed line %d)"
470 (1+ (count-lines 1 (point)))
471 (1+ (count-lines start (point))))
472 (message "Line %d" (1+ (count-lines 1 (point)))))))))
474 (defun count-lines (start end)
475 "Return number of lines between START and END.
476 This is usually the number of newlines between them,
477 but can be one more if START is not equal to END
478 and the greater of them is not at the start of a line."
479 (save-excursion
480 (save-restriction
481 (narrow-to-region start end)
482 (goto-char (point-min))
483 (if (eq selective-display t)
484 (save-match-data
485 (let ((done 0))
486 (while (re-search-forward "[\n\C-m]" nil t 40)
487 (setq done (+ 40 done)))
488 (while (re-search-forward "[\n\C-m]" nil t 1)
489 (setq done (+ 1 done)))
490 (goto-char (point-max))
491 (if (and (/= start end)
492 (not (bolp)))
493 (1+ done)
494 done)))
495 (- (buffer-size) (forward-line (buffer-size)))))))
497 (defun what-cursor-position (&optional detail)
498 "Print info on cursor position (on screen and within buffer).
499 Also describe the character after point, and give its character code
500 in octal, decimal and hex.
502 For a non-ASCII multibyte character, also give its encoding in the
503 buffer's selected coding system if the coding system encodes the
504 character safely. If the character is encoded into one byte, that
505 code is shown in hex. If the character is encoded into more than one
506 byte, just \"...\" is shown.
508 In addition, with prefix argument, show details about that character
509 in *Help* buffer. See also the command `describe-char-after'."
510 (interactive "P")
511 (let* ((char (following-char))
512 (beg (point-min))
513 (end (point-max))
514 (pos (point))
515 (total (buffer-size))
516 (percent (if (> total 50000)
517 ;; Avoid overflow from multiplying by 100!
518 (/ (+ (/ total 200) (1- pos)) (max (/ total 100) 1))
519 (/ (+ (/ total 2) (* 100 (1- pos))) (max total 1))))
520 (hscroll (if (= (window-hscroll) 0)
522 (format " Hscroll=%d" (window-hscroll))))
523 (col (current-column)))
524 (if (= pos end)
525 (if (or (/= beg 1) (/= end (1+ total)))
526 (message "point=%d of %d (%d%%) <%d - %d> column %d %s"
527 pos total percent beg end col hscroll)
528 (message "point=%d of %d (%d%%) column %d %s"
529 pos total percent col hscroll))
530 (let ((coding buffer-file-coding-system)
531 encoded encoding-msg)
532 (if (or (not coding)
533 (eq (coding-system-type coding) t))
534 (setq coding default-buffer-file-coding-system))
535 ;; Fixme: can we actually have invalid chars now?
536 (if (not (char-valid-p char))
537 (setq encoding-msg
538 (format "(0%o, %d, 0x%x, invalid)" char char char))
539 (setq encoded (and (>= char 128) (encode-coding-char char coding)))
540 (setq encoding-msg
541 (if encoded
542 (format "(0%o, %d, 0x%x, file %s)"
543 char char char
544 (if (> (length encoded) 1)
545 "..."
546 (encoded-string-description encoded coding)))
547 (format "(0%o, %d, 0x%x)" char char char))))
548 (if detail
549 ;; We show the detailed information about CHAR.
550 (describe-char-after (point)))
551 (if (or (/= beg 1) (/= end (1+ total)))
552 (message "Char: %s %s point=%d of %d (%d%%) <%d - %d> column %d %s"
553 (if (< char 256)
554 (single-key-description char)
555 (buffer-substring-no-properties (point) (1+ (point))))
556 encoding-msg pos total percent beg end col hscroll)
557 (message "Char: %s %s point=%d of %d (%d%%) column %d %s"
558 (if (< char 256)
559 (single-key-description char)
560 (buffer-substring-no-properties (point) (1+ (point))))
561 encoding-msg pos total percent col hscroll))))))
563 (defvar read-expression-map
564 (let ((m (make-sparse-keymap)))
565 (define-key m "\M-\t" 'lisp-complete-symbol)
566 (set-keymap-parent m minibuffer-local-map)
568 "Minibuffer keymap used for reading Lisp expressions.")
570 (defvar read-expression-history nil)
572 (defcustom eval-expression-print-level 4
573 "*Value to use for `print-level' when printing value in `eval-expression'.
574 A value of nil means no limit."
575 :group 'lisp
576 :type '(choice (const :tag "No Limit" nil) integer)
577 :version "21.1")
579 (defcustom eval-expression-print-length 12
580 "*Value to use for `print-length' when printing value in `eval-expression'.
581 A value of nil means no limit."
582 :group 'lisp
583 :type '(choice (const :tag "No Limit" nil) integer)
584 :version "21.1")
586 (defcustom eval-expression-debug-on-error t
587 "*Non-nil means set `debug-on-error' when evaluating in `eval-expression'.
588 If nil, don't change the value of `debug-on-error'."
589 :group 'lisp
590 :type 'boolean
591 :version "21.1")
593 ;; We define this, rather than making `eval' interactive,
594 ;; for the sake of completion of names like eval-region, eval-current-buffer.
595 (defun eval-expression (eval-expression-arg
596 &optional eval-expression-insert-value)
597 "Evaluate EVAL-EXPRESSION-ARG and print value in the echo area.
598 Value is also consed on to front of the variable `values'.
599 Optional argument EVAL-EXPRESSION-INSERT-VALUE, if non-nil, means
600 insert the result into the current buffer instead of printing it in
601 the echo area."
602 (interactive
603 (list (read-from-minibuffer "Eval: "
604 nil read-expression-map t
605 'read-expression-history)
606 current-prefix-arg))
608 (if (null eval-expression-debug-on-error)
609 (setq values (cons (eval eval-expression-arg) values))
610 (let ((old-value (make-symbol "t")) new-value)
611 ;; Bind debug-on-error to something unique so that we can
612 ;; detect when evaled code changes it.
613 (let ((debug-on-error old-value))
614 (setq values (cons (eval eval-expression-arg) values))
615 (setq new-value debug-on-error))
616 ;; If evaled code has changed the value of debug-on-error,
617 ;; propagate that change to the global binding.
618 (unless (eq old-value new-value)
619 (setq debug-on-error new-value))))
621 (let ((print-length eval-expression-print-length)
622 (print-level eval-expression-print-level))
623 (prin1 (car values)
624 (if eval-expression-insert-value (current-buffer) t))))
626 (defun edit-and-eval-command (prompt command)
627 "Prompting with PROMPT, let user edit COMMAND and eval result.
628 COMMAND is a Lisp expression. Let user edit that expression in
629 the minibuffer, then read and evaluate the result."
630 (let ((command (read-from-minibuffer prompt
631 (prin1-to-string command)
632 read-expression-map t
633 '(command-history . 1))))
634 ;; If command was added to command-history as a string,
635 ;; get rid of that. We want only evaluable expressions there.
636 (if (stringp (car command-history))
637 (setq command-history (cdr command-history)))
639 ;; If command to be redone does not match front of history,
640 ;; add it to the history.
641 (or (equal command (car command-history))
642 (setq command-history (cons command command-history)))
643 (eval command)))
645 (defun repeat-complex-command (arg)
646 "Edit and re-evaluate last complex command, or ARGth from last.
647 A complex command is one which used the minibuffer.
648 The command is placed in the minibuffer as a Lisp form for editing.
649 The result is executed, repeating the command as changed.
650 If the command has been changed or is not the most recent previous command
651 it is added to the front of the command history.
652 You can use the minibuffer history commands \\<minibuffer-local-map>\\[next-history-element] and \\[previous-history-element]
653 to get different commands to edit and resubmit."
654 (interactive "p")
655 (let ((elt (nth (1- arg) command-history))
656 newcmd)
657 (if elt
658 (progn
659 (setq newcmd
660 (let ((print-level nil)
661 (minibuffer-history-position arg)
662 (minibuffer-history-sexp-flag (1+ (minibuffer-depth))))
663 (read-from-minibuffer
664 "Redo: " (prin1-to-string elt) read-expression-map t
665 (cons 'command-history arg))))
667 ;; If command was added to command-history as a string,
668 ;; get rid of that. We want only evaluable expressions there.
669 (if (stringp (car command-history))
670 (setq command-history (cdr command-history)))
672 ;; If command to be redone does not match front of history,
673 ;; add it to the history.
674 (or (equal newcmd (car command-history))
675 (setq command-history (cons newcmd command-history)))
676 (eval newcmd))
677 (ding))))
679 (defvar minibuffer-history nil
680 "Default minibuffer history list.
681 This is used for all minibuffer input
682 except when an alternate history list is specified.")
683 (defvar minibuffer-history-sexp-flag nil
684 "Non-nil when doing history operations on the variable `command-history'.
685 More generally, indicates that the history list being acted on
686 contains expressions rather than strings.
687 It is only valid if its value equals the current minibuffer depth,
688 to handle recursive uses of the minibuffer.")
689 (setq minibuffer-history-variable 'minibuffer-history)
690 (setq minibuffer-history-position nil)
691 (defvar minibuffer-history-search-history nil)
693 (defvar minibuffer-text-before-history nil
694 "Text that was in this minibuffer before any history commands.
695 This is nil if there have not yet been any history commands
696 in this use of the minibuffer.")
698 (add-hook 'minibuffer-setup-hook 'minibuffer-history-initialize)
700 (defun minibuffer-history-initialize ()
701 (setq minibuffer-text-before-history nil))
703 (defun minibuffer-avoid-prompt (new old)
704 "A point-motion hook for the minibuffer, that moves point out of the prompt."
705 (constrain-to-field nil (point-max)))
707 (defcustom minibuffer-history-case-insensitive-variables nil
708 "*Minibuffer history variables for which matching should ignore case.
709 If a history variable is a member of this list, then the
710 \\[previous-matching-history-element] and \\[next-matching-history-element]\
711 commands ignore case when searching it, regardless of `case-fold-search'."
712 :type '(repeat variable)
713 :group 'minibuffer)
715 (defun previous-matching-history-element (regexp n)
716 "Find the previous history element that matches REGEXP.
717 \(Previous history elements refer to earlier actions.)
718 With prefix argument N, search for Nth previous match.
719 If N is negative, find the next or Nth next match.
720 Normally, history elements are matched case-insensitively if
721 `case-fold-search' is non-nil, but an uppercase letter in REGEXP
722 makes the search case-sensitive.
723 See also `minibuffer-history-case-insensitive-variables'."
724 (interactive
725 (let* ((enable-recursive-minibuffers t)
726 (regexp (read-from-minibuffer "Previous element matching (regexp): "
728 minibuffer-local-map
730 'minibuffer-history-search-history)))
731 ;; Use the last regexp specified, by default, if input is empty.
732 (list (if (string= regexp "")
733 (if minibuffer-history-search-history
734 (car minibuffer-history-search-history)
735 (error "No previous history search regexp"))
736 regexp)
737 (prefix-numeric-value current-prefix-arg))))
738 (unless (zerop n)
739 (if (and (zerop minibuffer-history-position)
740 (null minibuffer-text-before-history))
741 (setq minibuffer-text-before-history
742 (minibuffer-contents-no-properties)))
743 (let ((history (symbol-value minibuffer-history-variable))
744 (case-fold-search
745 (if (isearch-no-upper-case-p regexp t) ; assume isearch.el is dumped
746 ;; On some systems, ignore case for file names.
747 (if (memq minibuffer-history-variable
748 minibuffer-history-case-insensitive-variables)
750 ;; Respect the user's setting for case-fold-search:
751 case-fold-search)
752 nil))
753 prevpos
754 match-string
755 match-offset
756 (pos minibuffer-history-position))
757 (while (/= n 0)
758 (setq prevpos pos)
759 (setq pos (min (max 1 (+ pos (if (< n 0) -1 1))) (length history)))
760 (when (= pos prevpos)
761 (error (if (= pos 1)
762 "No later matching history item"
763 "No earlier matching history item")))
764 (setq match-string
765 (if (eq minibuffer-history-sexp-flag (minibuffer-depth))
766 (let ((print-level nil))
767 (prin1-to-string (nth (1- pos) history)))
768 (nth (1- pos) history)))
769 (setq match-offset
770 (if (< n 0)
771 (and (string-match regexp match-string)
772 (match-end 0))
773 (and (string-match (concat ".*\\(" regexp "\\)") match-string)
774 (match-beginning 1))))
775 (when match-offset
776 (setq n (+ n (if (< n 0) 1 -1)))))
777 (setq minibuffer-history-position pos)
778 (goto-char (point-max))
779 (delete-minibuffer-contents)
780 (insert match-string)
781 (goto-char (+ (minibuffer-prompt-end) match-offset))))
782 (if (memq (car (car command-history)) '(previous-matching-history-element
783 next-matching-history-element))
784 (setq command-history (cdr command-history))))
786 (defun next-matching-history-element (regexp n)
787 "Find the next history element that matches REGEXP.
788 \(The next history element refers to a more recent action.)
789 With prefix argument N, search for Nth next match.
790 If N is negative, find the previous or Nth previous match.
791 Normally, history elements are matched case-insensitively if
792 `case-fold-search' is non-nil, but an uppercase letter in REGEXP
793 makes the search case-sensitive."
794 (interactive
795 (let* ((enable-recursive-minibuffers t)
796 (regexp (read-from-minibuffer "Next element matching (regexp): "
798 minibuffer-local-map
800 'minibuffer-history-search-history)))
801 ;; Use the last regexp specified, by default, if input is empty.
802 (list (if (string= regexp "")
803 (setcar minibuffer-history-search-history
804 (nth 1 minibuffer-history-search-history))
805 regexp)
806 (prefix-numeric-value current-prefix-arg))))
807 (previous-matching-history-element regexp (- n)))
809 (defvar minibuffer-temporary-goal-position nil)
811 (defun next-history-element (n)
812 "Insert the next element of the minibuffer history into the minibuffer."
813 (interactive "p")
814 (or (zerop n)
815 (let ((narg (- minibuffer-history-position n))
816 (minimum (if minibuffer-default -1 0))
817 elt minibuffer-returned-to-present)
818 (if (and (zerop minibuffer-history-position)
819 (null minibuffer-text-before-history))
820 (setq minibuffer-text-before-history
821 (minibuffer-contents-no-properties)))
822 (if (< narg minimum)
823 (if minibuffer-default
824 (error "End of history; no next item")
825 (error "End of history; no default available")))
826 (if (> narg (length (symbol-value minibuffer-history-variable)))
827 (error "Beginning of history; no preceding item"))
828 (unless (memq last-command '(next-history-element
829 previous-history-element))
830 (let ((prompt-end (minibuffer-prompt-end)))
831 (set (make-local-variable 'minibuffer-temporary-goal-position)
832 (cond ((<= (point) prompt-end) prompt-end)
833 ((eobp) nil)
834 (t (point))))))
835 (goto-char (point-max))
836 (delete-minibuffer-contents)
837 (setq minibuffer-history-position narg)
838 (cond ((= narg -1)
839 (setq elt minibuffer-default))
840 ((= narg 0)
841 (setq elt (or minibuffer-text-before-history ""))
842 (setq minibuffer-returned-to-present t)
843 (setq minibuffer-text-before-history nil))
844 (t (setq elt (nth (1- minibuffer-history-position)
845 (symbol-value minibuffer-history-variable)))))
846 (insert
847 (if (and (eq minibuffer-history-sexp-flag (minibuffer-depth))
848 (not minibuffer-returned-to-present))
849 (let ((print-level nil))
850 (prin1-to-string elt))
851 elt))
852 (goto-char (or minibuffer-temporary-goal-position (point-max))))))
854 (defun previous-history-element (n)
855 "Inserts the previous element of the minibuffer history into the minibuffer."
856 (interactive "p")
857 (next-history-element (- n)))
859 (defun next-complete-history-element (n)
860 "Get next history element which completes the minibuffer before the point.
861 The contents of the minibuffer after the point are deleted, and replaced
862 by the new completion."
863 (interactive "p")
864 (let ((point-at-start (point)))
865 (next-matching-history-element
866 (concat
867 "^" (regexp-quote (buffer-substring (minibuffer-prompt-end) (point))))
869 ;; next-matching-history-element always puts us at (point-min).
870 ;; Move to the position we were at before changing the buffer contents.
871 ;; This is still sensical, because the text before point has not changed.
872 (goto-char point-at-start)))
874 (defun previous-complete-history-element (n)
876 Get previous history element which completes the minibuffer before the point.
877 The contents of the minibuffer after the point are deleted, and replaced
878 by the new completion."
879 (interactive "p")
880 (next-complete-history-element (- n)))
882 ;; For compatibility with the old subr of the same name.
883 (defun minibuffer-prompt-width ()
884 "Return the display width of the minibuffer prompt.
885 Return 0 if current buffer is not a mini-buffer."
886 ;; Return the width of everything before the field at the end of
887 ;; the buffer; this should be 0 for normal buffers.
888 (1- (minibuffer-prompt-end)))
890 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
891 (defalias 'advertised-undo 'undo)
893 (defun undo (&optional arg)
894 "Undo some previous changes.
895 Repeat this command to undo more changes.
896 A numeric argument serves as a repeat count.
898 In Transient Mark mode when the mark is active, only undo changes within
899 the current region. Similarly, when not in Transient Mark mode, just C-u
900 as an argument limits undo to changes within the current region."
901 (interactive "*P")
902 ;; Make last-command indicate for the next command that this was an undo.
903 ;; That way, another undo will undo more.
904 ;; If we get to the end of the undo history and get an error,
905 ;; another undo command will find the undo history empty
906 ;; and will get another error. To begin undoing the undos,
907 ;; you must type some other command.
908 (setq this-command 'undo)
909 (let ((modified (buffer-modified-p))
910 (recent-save (recent-auto-save-p)))
911 (or (eq (selected-window) (minibuffer-window))
912 (message "Undo!"))
913 (unless (eq last-command 'undo)
914 (if (if transient-mark-mode mark-active (and arg (not (numberp arg))))
915 (undo-start (region-beginning) (region-end))
916 (undo-start))
917 ;; get rid of initial undo boundary
918 (undo-more 1))
919 (undo-more
920 (if (or transient-mark-mode (numberp arg))
921 (prefix-numeric-value arg)
923 ;; Don't specify a position in the undo record for the undo command.
924 ;; Instead, undoing this should move point to where the change is.
925 (let ((tail buffer-undo-list)
926 (prev nil))
927 (while (car tail)
928 (when (integerp (car tail))
929 (let ((pos (car tail)))
930 (if (null prev)
931 (setq buffer-undo-list (cdr tail))
932 (setcdr prev (cdr tail)))
933 (setq tail (cdr tail))
934 (while (car tail)
935 (if (eq pos (car tail))
936 (if prev
937 (setcdr prev (cdr tail))
938 (setq buffer-undo-list (cdr tail)))
939 (setq prev tail))
940 (setq tail (cdr tail)))
941 (setq tail nil)))
942 (setq prev tail tail (cdr tail))))
944 (and modified (not (buffer-modified-p))
945 (delete-auto-save-file-if-necessary recent-save))))
947 (defvar pending-undo-list nil
948 "Within a run of consecutive undo commands, list remaining to be undone.")
950 (defvar undo-in-progress nil
951 "Non-nil while performing an undo.
952 Some change-hooks test this variable to do something different.")
954 (defun undo-more (count)
955 "Undo back N undo-boundaries beyond what was already undone recently.
956 Call `undo-start' to get ready to undo recent changes,
957 then call `undo-more' one or more times to undo them."
958 (or pending-undo-list
959 (error "No further undo information"))
960 (let ((undo-in-progress t))
961 (setq pending-undo-list (primitive-undo count pending-undo-list))))
963 ;; Deep copy of a list
964 (defun undo-copy-list (list)
965 "Make a copy of undo list LIST."
966 (mapcar 'undo-copy-list-1 list))
968 (defun undo-copy-list-1 (elt)
969 (if (consp elt)
970 (cons (car elt) (undo-copy-list-1 (cdr elt)))
971 elt))
973 (defun undo-start (&optional beg end)
974 "Set `pending-undo-list' to the front of the undo list.
975 The next call to `undo-more' will undo the most recently made change.
976 If BEG and END are specified, then only undo elements
977 that apply to text between BEG and END are used; other undo elements
978 are ignored. If BEG and END are nil, all undo elements are used."
979 (if (eq buffer-undo-list t)
980 (error "No undo information in this buffer"))
981 (setq pending-undo-list
982 (if (and beg end (not (= beg end)))
983 (undo-make-selective-list (min beg end) (max beg end))
984 buffer-undo-list)))
986 (defvar undo-adjusted-markers)
988 (defun undo-make-selective-list (start end)
989 "Return a list of undo elements for the region START to END.
990 The elements come from `buffer-undo-list', but we keep only
991 the elements inside this region, and discard those outside this region.
992 If we find an element that crosses an edge of this region,
993 we stop and ignore all further elements."
994 (let ((undo-list-copy (undo-copy-list buffer-undo-list))
995 (undo-list (list nil))
996 undo-adjusted-markers
997 some-rejected
998 undo-elt undo-elt temp-undo-list delta)
999 (while undo-list-copy
1000 (setq undo-elt (car undo-list-copy))
1001 (let ((keep-this
1002 (cond ((and (consp undo-elt) (eq (car undo-elt) t))
1003 ;; This is a "was unmodified" element.
1004 ;; Keep it if we have kept everything thus far.
1005 (not some-rejected))
1007 (undo-elt-in-region undo-elt start end)))))
1008 (if keep-this
1009 (progn
1010 (setq end (+ end (cdr (undo-delta undo-elt))))
1011 ;; Don't put two nils together in the list
1012 (if (not (and (eq (car undo-list) nil)
1013 (eq undo-elt nil)))
1014 (setq undo-list (cons undo-elt undo-list))))
1015 (if (undo-elt-crosses-region undo-elt start end)
1016 (setq undo-list-copy nil)
1017 (setq some-rejected t)
1018 (setq temp-undo-list (cdr undo-list-copy))
1019 (setq delta (undo-delta undo-elt))
1021 (when (/= (cdr delta) 0)
1022 (let ((position (car delta))
1023 (offset (cdr delta)))
1025 ;; Loop down the earlier events adjusting their buffer
1026 ;; positions to reflect the fact that a change to the buffer
1027 ;; isn't being undone. We only need to process those element
1028 ;; types which undo-elt-in-region will return as being in
1029 ;; the region since only those types can ever get into the
1030 ;; output
1032 (while temp-undo-list
1033 (setq undo-elt (car temp-undo-list))
1034 (cond ((integerp undo-elt)
1035 (if (>= undo-elt position)
1036 (setcar temp-undo-list (- undo-elt offset))))
1037 ((atom undo-elt) nil)
1038 ((stringp (car undo-elt))
1039 ;; (TEXT . POSITION)
1040 (let ((text-pos (abs (cdr undo-elt)))
1041 (point-at-end (< (cdr undo-elt) 0 )))
1042 (if (>= text-pos position)
1043 (setcdr undo-elt (* (if point-at-end -1 1)
1044 (- text-pos offset))))))
1045 ((integerp (car undo-elt))
1046 ;; (BEGIN . END)
1047 (when (>= (car undo-elt) position)
1048 (setcar undo-elt (- (car undo-elt) offset))
1049 (setcdr undo-elt (- (cdr undo-elt) offset))))
1050 ((null (car undo-elt))
1051 ;; (nil PROPERTY VALUE BEG . END)
1052 (let ((tail (nthcdr 3 undo-elt)))
1053 (when (>= (car tail) position)
1054 (setcar tail (- (car tail) offset))
1055 (setcdr tail (- (cdr tail) offset))))))
1056 (setq temp-undo-list (cdr temp-undo-list))))))))
1057 (setq undo-list-copy (cdr undo-list-copy)))
1058 (nreverse undo-list)))
1060 (defun undo-elt-in-region (undo-elt start end)
1061 "Determine whether UNDO-ELT falls inside the region START ... END.
1062 If it crosses the edge, we return nil."
1063 (cond ((integerp undo-elt)
1064 (and (>= undo-elt start)
1065 (< undo-elt end)))
1066 ((eq undo-elt nil)
1068 ((atom undo-elt)
1069 nil)
1070 ((stringp (car undo-elt))
1071 ;; (TEXT . POSITION)
1072 (and (>= (abs (cdr undo-elt)) start)
1073 (< (abs (cdr undo-elt)) end)))
1074 ((and (consp undo-elt) (markerp (car undo-elt)))
1075 ;; This is a marker-adjustment element (MARKER . ADJUSTMENT).
1076 ;; See if MARKER is inside the region.
1077 (let ((alist-elt (assq (car undo-elt) undo-adjusted-markers)))
1078 (unless alist-elt
1079 (setq alist-elt (cons (car undo-elt)
1080 (marker-position (car undo-elt))))
1081 (setq undo-adjusted-markers
1082 (cons alist-elt undo-adjusted-markers)))
1083 (and (cdr alist-elt)
1084 (>= (cdr alist-elt) start)
1085 (< (cdr alist-elt) end))))
1086 ((null (car undo-elt))
1087 ;; (nil PROPERTY VALUE BEG . END)
1088 (let ((tail (nthcdr 3 undo-elt)))
1089 (and (>= (car tail) start)
1090 (< (cdr tail) end))))
1091 ((integerp (car undo-elt))
1092 ;; (BEGIN . END)
1093 (and (>= (car undo-elt) start)
1094 (< (cdr undo-elt) end)))))
1096 (defun undo-elt-crosses-region (undo-elt start end)
1097 "Test whether UNDO-ELT crosses one edge of that region START ... END.
1098 This assumes we have already decided that UNDO-ELT
1099 is not *inside* the region START...END."
1100 (cond ((atom undo-elt) nil)
1101 ((null (car undo-elt))
1102 ;; (nil PROPERTY VALUE BEG . END)
1103 (let ((tail (nthcdr 3 undo-elt)))
1104 (not (or (< (car tail) end)
1105 (> (cdr tail) start)))))
1106 ((integerp (car undo-elt))
1107 ;; (BEGIN . END)
1108 (not (or (< (car undo-elt) end)
1109 (> (cdr undo-elt) start))))))
1111 ;; Return the first affected buffer position and the delta for an undo element
1112 ;; delta is defined as the change in subsequent buffer positions if we *did*
1113 ;; the undo.
1114 (defun undo-delta (undo-elt)
1115 (if (consp undo-elt)
1116 (cond ((stringp (car undo-elt))
1117 ;; (TEXT . POSITION)
1118 (cons (abs (cdr undo-elt)) (length (car undo-elt))))
1119 ((integerp (car undo-elt))
1120 ;; (BEGIN . END)
1121 (cons (car undo-elt) (- (car undo-elt) (cdr undo-elt))))
1123 '(0 . 0)))
1124 '(0 . 0)))
1126 (defvar shell-command-history nil
1127 "History list for some commands that read shell commands.")
1129 (defvar shell-command-switch "-c"
1130 "Switch used to have the shell execute its command line argument.")
1132 (defvar shell-command-default-error-buffer nil
1133 "*Buffer name for `shell-command' and `shell-command-on-region' error output.
1134 This buffer is used when `shell-command' or 'shell-command-on-region'
1135 is run interactively. A value of nil means that output to stderr and
1136 stdout will be intermixed in the output stream.")
1138 (defun shell-command (command &optional output-buffer error-buffer)
1139 "Execute string COMMAND in inferior shell; display output, if any.
1140 With prefix argument, insert the COMMAND's output at point.
1142 If COMMAND ends in ampersand, execute it asynchronously.
1143 The output appears in the buffer `*Async Shell Command*'.
1144 That buffer is in shell mode.
1146 Otherwise, COMMAND is executed synchronously. The output appears in
1147 the buffer `*Shell Command Output*'. If the output is short enough to
1148 display in the echo area (which is determined by the variables
1149 `resize-mini-windows' and `max-mini-window-height'), it is shown
1150 there, but it is nonetheless available in buffer `*Shell Command
1151 Output*' even though that buffer is not automatically displayed.
1153 To specify a coding system for converting non-ASCII characters
1154 in the shell command output, use \\[universal-coding-system-argument]
1155 before this command.
1157 Noninteractive callers can specify coding systems by binding
1158 `coding-system-for-read' and `coding-system-for-write'.
1160 The optional second argument OUTPUT-BUFFER, if non-nil,
1161 says to put the output in some other buffer.
1162 If OUTPUT-BUFFER is a buffer or buffer name, put the output there.
1163 If OUTPUT-BUFFER is not a buffer and not nil,
1164 insert output in current buffer. (This cannot be done asynchronously.)
1165 In either case, the output is inserted after point (leaving mark after it).
1167 If the command terminates without error, but generates output,
1168 and you did not specify \"insert it in the current buffer\",
1169 the output can be displayed in the echo area or in its buffer.
1170 If the output is short enough to display in the echo area
1171 \(determined by the variable `max-mini-window-height' if
1172 `resize-mini-windows' is non-nil), it is shown there. Otherwise,
1173 the buffer containing the output is displayed.
1175 If there is output and an error, and you did not specify \"insert it
1176 in the current buffer\", a message about the error goes at the end
1177 of the output.
1179 If there is no output, or if output is inserted in the current buffer,
1180 then `*Shell Command Output*' is deleted.
1182 If the optional third argument ERROR-BUFFER is non-nil, it is a buffer
1183 or buffer name to which to direct the command's standard error output.
1184 If it is nil, error output is mingled with regular output.
1185 In an interactive call, the variable `shell-command-default-error-buffer'
1186 specifies the value of ERROR-BUFFER."
1188 (interactive (list (read-from-minibuffer "Shell command: "
1189 nil nil nil 'shell-command-history)
1190 current-prefix-arg
1191 shell-command-default-error-buffer))
1192 ;; Look for a handler in case default-directory is a remote file name.
1193 (let ((handler
1194 (find-file-name-handler (directory-file-name default-directory)
1195 'shell-command)))
1196 (if handler
1197 (funcall handler 'shell-command command output-buffer error-buffer)
1198 (if (and output-buffer
1199 (not (or (bufferp output-buffer) (stringp output-buffer))))
1200 ;; Output goes in current buffer.
1201 (let ((error-file
1202 (if error-buffer
1203 (make-temp-file
1204 (expand-file-name "scor"
1205 (or small-temporary-file-directory
1206 temporary-file-directory)))
1207 nil)))
1208 (barf-if-buffer-read-only)
1209 (push-mark nil t)
1210 ;; We do not use -f for csh; we will not support broken use of
1211 ;; .cshrcs. Even the BSD csh manual says to use
1212 ;; "if ($?prompt) exit" before things which are not useful
1213 ;; non-interactively. Besides, if someone wants their other
1214 ;; aliases for shell commands then they can still have them.
1215 (call-process shell-file-name nil
1216 (if error-file
1217 (list t error-file)
1219 nil shell-command-switch command)
1220 (when (and error-file (file-exists-p error-file))
1221 (if (< 0 (nth 7 (file-attributes error-file)))
1222 (with-current-buffer (get-buffer-create error-buffer)
1223 (let ((pos-from-end (- (point-max) (point))))
1224 (or (bobp)
1225 (insert "\f\n"))
1226 ;; Do no formatting while reading error file,
1227 ;; because that can run a shell command, and we
1228 ;; don't want that to cause an infinite recursion.
1229 (format-insert-file error-file nil)
1230 ;; Put point after the inserted errors.
1231 (goto-char (- (point-max) pos-from-end)))
1232 (display-buffer (current-buffer))))
1233 (delete-file error-file))
1234 ;; This is like exchange-point-and-mark, but doesn't
1235 ;; activate the mark. It is cleaner to avoid activation,
1236 ;; even though the command loop would deactivate the mark
1237 ;; because we inserted text.
1238 (goto-char (prog1 (mark t)
1239 (set-marker (mark-marker) (point)
1240 (current-buffer)))))
1241 ;; Output goes in a separate buffer.
1242 ;; Preserve the match data in case called from a program.
1243 (save-match-data
1244 (if (string-match "[ \t]*&[ \t]*$" command)
1245 ;; Command ending with ampersand means asynchronous.
1246 (let ((buffer (get-buffer-create
1247 (or output-buffer "*Async Shell Command*")))
1248 (directory default-directory)
1249 proc)
1250 ;; Remove the ampersand.
1251 (setq command (substring command 0 (match-beginning 0)))
1252 ;; If will kill a process, query first.
1253 (setq proc (get-buffer-process buffer))
1254 (if proc
1255 (if (yes-or-no-p "A command is running. Kill it? ")
1256 (kill-process proc)
1257 (error "Shell command in progress")))
1258 (save-excursion
1259 (set-buffer buffer)
1260 (setq buffer-read-only nil)
1261 (erase-buffer)
1262 (display-buffer buffer)
1263 (setq default-directory directory)
1264 (setq proc (start-process "Shell" buffer shell-file-name
1265 shell-command-switch command))
1266 (setq mode-line-process '(":%s"))
1267 (require 'shell) (shell-mode)
1268 (set-process-sentinel proc 'shell-command-sentinel)
1270 (shell-command-on-region (point) (point) command
1271 output-buffer nil error-buffer)))))))
1273 (defun display-message-or-buffer (message
1274 &optional buffer-name not-this-window frame)
1275 "Display MESSAGE in the echo area if possible, otherwise in a pop-up buffer.
1276 MESSAGE may be either a string or a buffer.
1278 A buffer is displayed using `display-buffer' if MESSAGE is too long for
1279 the maximum height of the echo area, as defined by `max-mini-window-height'
1280 if `resize-mini-windows' is non-nil.
1282 Returns either the string shown in the echo area, or when a pop-up
1283 buffer is used, the window used to display it.
1285 If MESSAGE is a string, then the optional argument BUFFER-NAME is the
1286 name of the buffer used to display it in the case where a pop-up buffer
1287 is used, defaulting to `*Message*'. In the case where MESSAGE is a
1288 string and it is displayed in the echo area, it is not specified whether
1289 the contents are inserted into the buffer anyway.
1291 Optional arguments NOT-THIS-WINDOW and FRAME are as for `display-buffer',
1292 and only used if a buffer is displayed."
1293 (cond ((and (stringp message) (not (string-match "\n" message)))
1294 ;; Trivial case where we can use the echo area
1295 (message "%s" message))
1296 ((and (stringp message)
1297 (= (string-match "\n" message) (1- (length message))))
1298 ;; Trivial case where we can just remove single trailing newline
1299 (message "%s" (substring message 0 (1- (length message)))))
1301 ;; General case
1302 (with-current-buffer
1303 (if (bufferp message)
1304 message
1305 (get-buffer-create (or buffer-name "*Message*")))
1307 (unless (bufferp message)
1308 (erase-buffer)
1309 (insert message))
1311 (let ((lines
1312 (if (= (buffer-size) 0)
1314 (count-lines (point-min) (point-max)))))
1315 (cond ((or (<= lines 1)
1316 (<= lines
1317 (if resize-mini-windows
1318 (cond ((floatp max-mini-window-height)
1319 (* (frame-height)
1320 max-mini-window-height))
1321 ((integerp max-mini-window-height)
1322 max-mini-window-height)
1325 1)))
1326 ;; Echo area
1327 (goto-char (point-max))
1328 (when (bolp)
1329 (backward-char 1))
1330 (message "%s" (buffer-substring (point-min) (point))))
1332 ;; Buffer
1333 (goto-char (point-min))
1334 (display-buffer (current-buffer)
1335 not-this-window frame))))))))
1338 ;; We have a sentinel to prevent insertion of a termination message
1339 ;; in the buffer itself.
1340 (defun shell-command-sentinel (process signal)
1341 (if (memq (process-status process) '(exit signal))
1342 (message "%s: %s."
1343 (car (cdr (cdr (process-command process))))
1344 (substring signal 0 -1))))
1346 (defun shell-command-on-region (start end command
1347 &optional output-buffer replace
1348 error-buffer)
1349 "Execute string COMMAND in inferior shell with region as input.
1350 Normally display output (if any) in temp buffer `*Shell Command Output*';
1351 Prefix arg means replace the region with it. Return the exit code of
1352 COMMAND.
1354 To specify a coding system for converting non-ASCII characters
1355 in the input and output to the shell command, use \\[universal-coding-system-argument]
1356 before this command. By default, the input (from the current buffer)
1357 is encoded in the same coding system that will be used to save the file,
1358 `buffer-file-coding-system'. If the output is going to replace the region,
1359 then it is decoded from that same coding system.
1361 The noninteractive arguments are START, END, COMMAND, OUTPUT-BUFFER,
1362 REPLACE, ERROR-BUFFER. Noninteractive callers can specify coding
1363 systems by binding `coding-system-for-read' and
1364 `coding-system-for-write'.
1366 If the command generates output, the output may be displayed
1367 in the echo area or in a buffer.
1368 If the output is short enough to display in the echo area
1369 \(determined by the variable `max-mini-window-height' if
1370 `resize-mini-windows' is non-nil), it is shown there. Otherwise
1371 it is displayed in the buffer `*Shell Command Output*'. The output
1372 is available in that buffer in both cases.
1374 If there is output and an error, a message about the error
1375 appears at the end of the output.
1377 If there is no output, or if output is inserted in the current buffer,
1378 then `*Shell Command Output*' is deleted.
1380 If the optional fourth argument OUTPUT-BUFFER is non-nil,
1381 that says to put the output in some other buffer.
1382 If OUTPUT-BUFFER is a buffer or buffer name, put the output there.
1383 If OUTPUT-BUFFER is not a buffer and not nil,
1384 insert output in the current buffer.
1385 In either case, the output is inserted after point (leaving mark after it).
1387 If REPLACE, the optional fifth argument, is non-nil, that means insert
1388 the output in place of text from START to END, putting point and mark
1389 around it.
1391 If optional sixth argument ERROR-BUFFER is non-nil, it is a buffer
1392 or buffer name to which to direct the command's standard error output.
1393 If it is nil, error output is mingled with regular output.
1394 In an interactive call, the variable `shell-command-default-error-buffer'
1395 specifies the value of ERROR-BUFFER."
1396 (interactive (let (string)
1397 (unless (mark)
1398 (error "The mark is not set now, so there is no region"))
1399 ;; Do this before calling region-beginning
1400 ;; and region-end, in case subprocess output
1401 ;; relocates them while we are in the minibuffer.
1402 (setq string (read-from-minibuffer "Shell command on region: "
1403 nil nil nil
1404 'shell-command-history))
1405 ;; call-interactively recognizes region-beginning and
1406 ;; region-end specially, leaving them in the history.
1407 (list (region-beginning) (region-end)
1408 string
1409 current-prefix-arg
1410 current-prefix-arg
1411 shell-command-default-error-buffer)))
1412 (let ((error-file
1413 (if error-buffer
1414 (make-temp-file
1415 (expand-file-name "scor"
1416 (or small-temporary-file-directory
1417 temporary-file-directory)))
1418 nil))
1419 exit-status)
1420 (if (or replace
1421 (and output-buffer
1422 (not (or (bufferp output-buffer) (stringp output-buffer)))))
1423 ;; Replace specified region with output from command.
1424 (let ((swap (and replace (< start end))))
1425 ;; Don't muck with mark unless REPLACE says we should.
1426 (goto-char start)
1427 (and replace (push-mark))
1428 (setq exit-status
1429 (call-process-region start end shell-file-name t
1430 (if error-file
1431 (list t error-file)
1433 nil shell-command-switch command))
1434 ;; It is rude to delete a buffer which the command is not using.
1435 ;; (let ((shell-buffer (get-buffer "*Shell Command Output*")))
1436 ;; (and shell-buffer (not (eq shell-buffer (current-buffer)))
1437 ;; (kill-buffer shell-buffer)))
1438 ;; Don't muck with mark unless REPLACE says we should.
1439 (and replace swap (exchange-point-and-mark)))
1440 ;; No prefix argument: put the output in a temp buffer,
1441 ;; replacing its entire contents.
1442 (let ((buffer (get-buffer-create
1443 (or output-buffer "*Shell Command Output*")))
1444 (success nil))
1445 (unwind-protect
1446 (if (eq buffer (current-buffer))
1447 ;; If the input is the same buffer as the output,
1448 ;; delete everything but the specified region,
1449 ;; then replace that region with the output.
1450 (progn (setq buffer-read-only nil)
1451 (delete-region (max start end) (point-max))
1452 (delete-region (point-min) (min start end))
1453 (setq exit-status
1454 (call-process-region (point-min) (point-max)
1455 shell-file-name t
1456 (if error-file
1457 (list t error-file)
1459 nil shell-command-switch
1460 command)))
1461 ;; Clear the output buffer, then run the command with
1462 ;; output there.
1463 (let ((directory default-directory))
1464 (save-excursion
1465 (set-buffer buffer)
1466 (setq buffer-read-only nil)
1467 (if (not output-buffer)
1468 (setq default-directory directory))
1469 (erase-buffer)))
1470 (setq exit-status
1471 (call-process-region start end shell-file-name nil
1472 (if error-file
1473 (list buffer error-file)
1474 buffer)
1475 nil shell-command-switch command)))
1476 (setq success (and exit-status (equal 0 exit-status)))
1477 ;; Report the output.
1478 (if (with-current-buffer buffer (> (point-max) (point-min)))
1479 ;; There's some output, display it
1480 (progn
1481 (if (not success)
1482 (with-current-buffer buffer
1483 (save-excursion
1484 (goto-char (point-max))
1485 (insert (format "...Shell command failed with code %d"
1486 exit-status)))))
1487 (display-message-or-buffer buffer))
1488 ;; No output; error?
1489 (let ((output
1490 (if (and error-file
1491 (< 0 (nth 7 (file-attributes error-file))))
1492 "some error output"
1493 "no output")))
1494 (if (equal 0 exit-status)
1495 (message "(Shell command succeeded with %s)"
1496 output)
1497 (message "(Shell command failed with code %d and %s)"
1498 exit-status output)))
1499 ;; Don't kill: there might be useful info in the undo-log.
1500 ;; (kill-buffer buffer)
1501 ))))
1503 (when (and error-file (file-exists-p error-file))
1504 (if (< 0 (nth 7 (file-attributes error-file)))
1505 (with-current-buffer (get-buffer-create error-buffer)
1506 (let ((pos-from-end (- (point-max) (point))))
1507 (or (bobp)
1508 (insert "\f\n"))
1509 ;; Do no formatting while reading error file,
1510 ;; because that can run a shell command, and we
1511 ;; don't want that to cause an infinite recursion.
1512 (format-insert-file error-file nil)
1513 ;; Put point after the inserted errors.
1514 (goto-char (- (point-max) pos-from-end)))
1515 (display-buffer (current-buffer))))
1516 (delete-file error-file))
1517 exit-status))
1519 (defun shell-command-to-string (command)
1520 "Execute shell command COMMAND and return its output as a string."
1521 (with-output-to-string
1522 (with-current-buffer
1523 standard-output
1524 (call-process shell-file-name nil t nil shell-command-switch command))))
1526 (defvar universal-argument-map
1527 (let ((map (make-sparse-keymap)))
1528 (define-key map [t] 'universal-argument-other-key)
1529 (define-key map (vector meta-prefix-char t) 'universal-argument-other-key)
1530 (define-key map [switch-frame] nil)
1531 (define-key map [?\C-u] 'universal-argument-more)
1532 (define-key map [?-] 'universal-argument-minus)
1533 (define-key map [?0] 'digit-argument)
1534 (define-key map [?1] 'digit-argument)
1535 (define-key map [?2] 'digit-argument)
1536 (define-key map [?3] 'digit-argument)
1537 (define-key map [?4] 'digit-argument)
1538 (define-key map [?5] 'digit-argument)
1539 (define-key map [?6] 'digit-argument)
1540 (define-key map [?7] 'digit-argument)
1541 (define-key map [?8] 'digit-argument)
1542 (define-key map [?9] 'digit-argument)
1543 (define-key map [kp-0] 'digit-argument)
1544 (define-key map [kp-1] 'digit-argument)
1545 (define-key map [kp-2] 'digit-argument)
1546 (define-key map [kp-3] 'digit-argument)
1547 (define-key map [kp-4] 'digit-argument)
1548 (define-key map [kp-5] 'digit-argument)
1549 (define-key map [kp-6] 'digit-argument)
1550 (define-key map [kp-7] 'digit-argument)
1551 (define-key map [kp-8] 'digit-argument)
1552 (define-key map [kp-9] 'digit-argument)
1553 (define-key map [kp-subtract] 'universal-argument-minus)
1554 map)
1555 "Keymap used while processing \\[universal-argument].")
1557 (defvar universal-argument-num-events nil
1558 "Number of argument-specifying events read by `universal-argument'.
1559 `universal-argument-other-key' uses this to discard those events
1560 from (this-command-keys), and reread only the final command.")
1562 (defun universal-argument ()
1563 "Begin a numeric argument for the following command.
1564 Digits or minus sign following \\[universal-argument] make up the numeric argument.
1565 \\[universal-argument] following the digits or minus sign ends the argument.
1566 \\[universal-argument] without digits or minus sign provides 4 as argument.
1567 Repeating \\[universal-argument] without digits or minus sign
1568 multiplies the argument by 4 each time.
1569 For some commands, just \\[universal-argument] by itself serves as a flag
1570 which is different in effect from any particular numeric argument.
1571 These commands include \\[set-mark-command] and \\[start-kbd-macro]."
1572 (interactive)
1573 (setq prefix-arg (list 4))
1574 (setq universal-argument-num-events (length (this-command-keys)))
1575 (setq overriding-terminal-local-map universal-argument-map))
1577 ;; A subsequent C-u means to multiply the factor by 4 if we've typed
1578 ;; nothing but C-u's; otherwise it means to terminate the prefix arg.
1579 (defun universal-argument-more (arg)
1580 (interactive "P")
1581 (if (consp arg)
1582 (setq prefix-arg (list (* 4 (car arg))))
1583 (if (eq arg '-)
1584 (setq prefix-arg (list -4))
1585 (setq prefix-arg arg)
1586 (setq overriding-terminal-local-map nil)))
1587 (setq universal-argument-num-events (length (this-command-keys))))
1589 (defun negative-argument (arg)
1590 "Begin a negative numeric argument for the next command.
1591 \\[universal-argument] following digits or minus sign ends the argument."
1592 (interactive "P")
1593 (cond ((integerp arg)
1594 (setq prefix-arg (- arg)))
1595 ((eq arg '-)
1596 (setq prefix-arg nil))
1598 (setq prefix-arg '-)))
1599 (setq universal-argument-num-events (length (this-command-keys)))
1600 (setq overriding-terminal-local-map universal-argument-map))
1602 (defun digit-argument (arg)
1603 "Part of the numeric argument for the next command.
1604 \\[universal-argument] following digits or minus sign ends the argument."
1605 (interactive "P")
1606 (let* ((char (if (integerp last-command-char)
1607 last-command-char
1608 (get last-command-char 'ascii-character)))
1609 (digit (- (logand char ?\177) ?0)))
1610 (cond ((integerp arg)
1611 (setq prefix-arg (+ (* arg 10)
1612 (if (< arg 0) (- digit) digit))))
1613 ((eq arg '-)
1614 ;; Treat -0 as just -, so that -01 will work.
1615 (setq prefix-arg (if (zerop digit) '- (- digit))))
1617 (setq prefix-arg digit))))
1618 (setq universal-argument-num-events (length (this-command-keys)))
1619 (setq overriding-terminal-local-map universal-argument-map))
1621 ;; For backward compatibility, minus with no modifiers is an ordinary
1622 ;; command if digits have already been entered.
1623 (defun universal-argument-minus (arg)
1624 (interactive "P")
1625 (if (integerp arg)
1626 (universal-argument-other-key arg)
1627 (negative-argument arg)))
1629 ;; Anything else terminates the argument and is left in the queue to be
1630 ;; executed as a command.
1631 (defun universal-argument-other-key (arg)
1632 (interactive "P")
1633 (setq prefix-arg arg)
1634 (let* ((key (this-command-keys))
1635 (keylist (listify-key-sequence key)))
1636 (setq unread-command-events
1637 (append (nthcdr universal-argument-num-events keylist)
1638 unread-command-events)))
1639 (reset-this-command-lengths)
1640 (setq overriding-terminal-local-map nil))
1642 ;;;; Window system cut and paste hooks.
1644 (defvar interprogram-cut-function nil
1645 "Function to call to make a killed region available to other programs.
1647 Most window systems provide some sort of facility for cutting and
1648 pasting text between the windows of different programs.
1649 This variable holds a function that Emacs calls whenever text
1650 is put in the kill ring, to make the new kill available to other
1651 programs.
1653 The function takes one or two arguments.
1654 The first argument, TEXT, is a string containing
1655 the text which should be made available.
1656 The second, PUSH, if non-nil means this is a \"new\" kill;
1657 nil means appending to an \"old\" kill.")
1659 (defvar interprogram-paste-function nil
1660 "Function to call to get text cut from other programs.
1662 Most window systems provide some sort of facility for cutting and
1663 pasting text between the windows of different programs.
1664 This variable holds a function that Emacs calls to obtain
1665 text that other programs have provided for pasting.
1667 The function should be called with no arguments. If the function
1668 returns nil, then no other program has provided such text, and the top
1669 of the Emacs kill ring should be used. If the function returns a
1670 string, that string should be put in the kill ring as the latest kill.
1672 Note that the function should return a string only if a program other
1673 than Emacs has provided a string for pasting; if Emacs provided the
1674 most recent string, the function should return nil. If it is
1675 difficult to tell whether Emacs or some other program provided the
1676 current string, it is probably good enough to return nil if the string
1677 is equal (according to `string=') to the last text Emacs provided.")
1681 ;;;; The kill ring data structure.
1683 (defvar kill-ring nil
1684 "List of killed text sequences.
1685 Since the kill ring is supposed to interact nicely with cut-and-paste
1686 facilities offered by window systems, use of this variable should
1687 interact nicely with `interprogram-cut-function' and
1688 `interprogram-paste-function'. The functions `kill-new',
1689 `kill-append', and `current-kill' are supposed to implement this
1690 interaction; you may want to use them instead of manipulating the kill
1691 ring directly.")
1693 (defcustom kill-ring-max 60
1694 "*Maximum length of kill ring before oldest elements are thrown away."
1695 :type 'integer
1696 :group 'killing)
1698 (defvar kill-ring-yank-pointer nil
1699 "The tail of the kill ring whose car is the last thing yanked.")
1701 (defun kill-new (string &optional replace)
1702 "Make STRING the latest kill in the kill ring.
1703 Set the kill-ring-yank pointer to point to it.
1704 If `interprogram-cut-function' is non-nil, apply it to STRING.
1705 Optional second argument REPLACE non-nil means that STRING will replace
1706 the front of the kill ring, rather than being added to the list."
1707 (and (fboundp 'menu-bar-update-yank-menu)
1708 (menu-bar-update-yank-menu string (and replace (car kill-ring))))
1709 (if (and replace kill-ring)
1710 (setcar kill-ring string)
1711 (setq kill-ring (cons string kill-ring))
1712 (if (> (length kill-ring) kill-ring-max)
1713 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)))
1714 (setq kill-ring-yank-pointer kill-ring)
1715 (if interprogram-cut-function
1716 (funcall interprogram-cut-function string (not replace))))
1718 (defun kill-append (string before-p)
1719 "Append STRING to the end of the latest kill in the kill ring.
1720 If BEFORE-P is non-nil, prepend STRING to the kill.
1721 If `interprogram-cut-function' is set, pass the resulting kill to
1722 it."
1723 (kill-new (if before-p
1724 (concat string (car kill-ring))
1725 (concat (car kill-ring) string))
1728 (defun current-kill (n &optional do-not-move)
1729 "Rotate the yanking point by N places, and then return that kill.
1730 If N is zero, `interprogram-paste-function' is set, and calling it
1731 returns a string, then that string is added to the front of the
1732 kill ring and returned as the latest kill.
1733 If optional arg DO-NOT-MOVE is non-nil, then don't actually move the
1734 yanking point; just return the Nth kill forward."
1735 (let ((interprogram-paste (and (= n 0)
1736 interprogram-paste-function
1737 (funcall interprogram-paste-function))))
1738 (if interprogram-paste
1739 (progn
1740 ;; Disable the interprogram cut function when we add the new
1741 ;; text to the kill ring, so Emacs doesn't try to own the
1742 ;; selection, with identical text.
1743 (let ((interprogram-cut-function nil))
1744 (kill-new interprogram-paste))
1745 interprogram-paste)
1746 (or kill-ring (error "Kill ring is empty"))
1747 (let ((ARGth-kill-element
1748 (nthcdr (mod (- n (length kill-ring-yank-pointer))
1749 (length kill-ring))
1750 kill-ring)))
1751 (or do-not-move
1752 (setq kill-ring-yank-pointer ARGth-kill-element))
1753 (car ARGth-kill-element)))))
1757 ;;;; Commands for manipulating the kill ring.
1759 (defcustom kill-read-only-ok nil
1760 "*Non-nil means don't signal an error for killing read-only text."
1761 :type 'boolean
1762 :group 'killing)
1764 (put 'text-read-only 'error-conditions
1765 '(text-read-only buffer-read-only error))
1766 (put 'text-read-only 'error-message "Text is read-only")
1768 (defun kill-region (beg end)
1769 "Kill between point and mark.
1770 The text is deleted but saved in the kill ring.
1771 The command \\[yank] can retrieve it from there.
1772 \(If you want to kill and then yank immediately, use \\[kill-ring-save].)
1774 If you want to append the killed region to the last killed text,
1775 use \\[append-next-kill] before \\[kill-region].
1777 If the buffer is read-only, Emacs will beep and refrain from deleting
1778 the text, but put the text in the kill ring anyway. This means that
1779 you can use the killing commands to copy text from a read-only buffer.
1781 This is the primitive for programs to kill text (as opposed to deleting it).
1782 Supply two arguments, character numbers indicating the stretch of text
1783 to be killed.
1784 Any command that calls this function is a \"kill command\".
1785 If the previous command was also a kill command,
1786 the text killed this time appends to the text killed last time
1787 to make one entry in the kill ring."
1788 (interactive "r")
1789 (condition-case nil
1790 (let ((string (delete-and-extract-region beg end)))
1791 (when string ;STRING is nil if BEG = END
1792 ;; Add that string to the kill ring, one way or another.
1793 (if (eq last-command 'kill-region)
1794 (kill-append string (< end beg))
1795 (kill-new string)))
1796 (setq this-command 'kill-region))
1797 ((buffer-read-only text-read-only)
1798 ;; The code above failed because the buffer, or some of the characters
1799 ;; in the region, are read-only.
1800 ;; We should beep, in case the user just isn't aware of this.
1801 ;; However, there's no harm in putting
1802 ;; the region's text in the kill ring, anyway.
1803 (copy-region-as-kill beg end)
1804 ;; Set this-command now, so it will be set even if we get an error.
1805 (setq this-command 'kill-region)
1806 ;; This should barf, if appropriate, and give us the correct error.
1807 (if kill-read-only-ok
1808 (message "Read only text copied to kill ring")
1809 ;; Signal an error if the buffer is read-only.
1810 (barf-if-buffer-read-only)
1811 ;; If the buffer isn't read-only, the text is.
1812 (signal 'text-read-only (list (current-buffer)))))))
1814 ;; copy-region-as-kill no longer sets this-command, because it's confusing
1815 ;; to get two copies of the text when the user accidentally types M-w and
1816 ;; then corrects it with the intended C-w.
1817 (defun copy-region-as-kill (beg end)
1818 "Save the region as if killed, but don't kill it.
1819 In Transient Mark mode, deactivate the mark.
1820 If `interprogram-cut-function' is non-nil, also save the text for a window
1821 system cut and paste."
1822 (interactive "r")
1823 (if (eq last-command 'kill-region)
1824 (kill-append (buffer-substring beg end) (< end beg))
1825 (kill-new (buffer-substring beg end)))
1826 (if transient-mark-mode
1827 (setq deactivate-mark t))
1828 nil)
1830 (defun kill-ring-save (beg end)
1831 "Save the region as if killed, but don't kill it.
1832 In Transient Mark mode, deactivate the mark.
1833 If `interprogram-cut-function' is non-nil, also save the text for a window
1834 system cut and paste.
1836 If you want to append the killed line to the last killed text,
1837 use \\[append-next-kill] before \\[kill-ring-save].
1839 This command is similar to `copy-region-as-kill', except that it gives
1840 visual feedback indicating the extent of the region being copied."
1841 (interactive "r")
1842 (copy-region-as-kill beg end)
1843 (if (interactive-p)
1844 (let ((other-end (if (= (point) beg) end beg))
1845 (opoint (point))
1846 ;; Inhibit quitting so we can make a quit here
1847 ;; look like a C-g typed as a command.
1848 (inhibit-quit t))
1849 (if (pos-visible-in-window-p other-end (selected-window))
1850 (unless transient-mark-mode
1851 ;; Swap point and mark.
1852 (set-marker (mark-marker) (point) (current-buffer))
1853 (goto-char other-end)
1854 (sit-for 1)
1855 ;; Swap back.
1856 (set-marker (mark-marker) other-end (current-buffer))
1857 (goto-char opoint)
1858 ;; If user quit, deactivate the mark
1859 ;; as C-g would as a command.
1860 (and quit-flag mark-active
1861 (deactivate-mark)))
1862 (let* ((killed-text (current-kill 0))
1863 (message-len (min (length killed-text) 40)))
1864 (if (= (point) beg)
1865 ;; Don't say "killed"; that is misleading.
1866 (message "Saved text until \"%s\""
1867 (substring killed-text (- message-len)))
1868 (message "Saved text from \"%s\""
1869 (substring killed-text 0 message-len))))))))
1871 (defun append-next-kill (&optional interactive)
1872 "Cause following command, if it kills, to append to previous kill.
1873 The argument is used for internal purposes; do not supply one."
1874 (interactive "p")
1875 ;; We don't use (interactive-p), since that breaks kbd macros.
1876 (if interactive
1877 (progn
1878 (setq this-command 'kill-region)
1879 (message "If the next command is a kill, it will append"))
1880 (setq last-command 'kill-region)))
1882 ;; Yanking.
1884 (defun yank-pop (arg)
1885 "Replace just-yanked stretch of killed text with a different stretch.
1886 This command is allowed only immediately after a `yank' or a `yank-pop'.
1887 At such a time, the region contains a stretch of reinserted
1888 previously-killed text. `yank-pop' deletes that text and inserts in its
1889 place a different stretch of killed text.
1891 With no argument, the previous kill is inserted.
1892 With argument N, insert the Nth previous kill.
1893 If N is negative, this is a more recent kill.
1895 The sequence of kills wraps around, so that after the oldest one
1896 comes the newest one."
1897 (interactive "*p")
1898 (if (not (eq last-command 'yank))
1899 (error "Previous command was not a yank"))
1900 (setq this-command 'yank)
1901 (let ((inhibit-read-only t)
1902 (before (< (point) (mark t))))
1903 (delete-region (point) (mark t))
1904 (set-marker (mark-marker) (point) (current-buffer))
1905 (let ((opoint (point)))
1906 (insert (current-kill arg))
1907 (let ((inhibit-read-only t))
1908 (remove-text-properties opoint (point) '(read-only nil))))
1909 (if before
1910 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1911 ;; It is cleaner to avoid activation, even though the command
1912 ;; loop would deactivate the mark because we inserted text.
1913 (goto-char (prog1 (mark t)
1914 (set-marker (mark-marker) (point) (current-buffer))))))
1915 nil)
1917 (defun yank (&optional arg)
1918 "Reinsert the last stretch of killed text.
1919 More precisely, reinsert the stretch of killed text most recently
1920 killed OR yanked. Put point at end, and set mark at beginning.
1921 With just C-u as argument, same but put point at beginning (and mark at end).
1922 With argument N, reinsert the Nth most recently killed stretch of killed
1923 text.
1924 See also the command \\[yank-pop]."
1925 (interactive "*P")
1926 ;; If we don't get all the way thru, make last-command indicate that
1927 ;; for the following command.
1928 (setq this-command t)
1929 (push-mark (point))
1930 (let ((opoint (point)))
1931 (insert (current-kill (cond
1932 ((listp arg) 0)
1933 ((eq arg '-) -1)
1934 (t (1- arg)))))
1935 (let ((inhibit-read-only t))
1936 ;; Clear `field' property for the sake of copying from the
1937 ;; minibuffer prompt or a *shell* prompt.
1938 (remove-text-properties opoint (point) '(read-only nil field nil))))
1939 (if (consp arg)
1940 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1941 ;; It is cleaner to avoid activation, even though the command
1942 ;; loop would deactivate the mark because we inserted text.
1943 (goto-char (prog1 (mark t)
1944 (set-marker (mark-marker) (point) (current-buffer)))))
1945 ;; If we do get all the way thru, make this-command indicate that.
1946 (setq this-command 'yank)
1947 nil)
1949 (defun rotate-yank-pointer (arg)
1950 "Rotate the yanking point in the kill ring.
1951 With argument, rotate that many kills forward (or backward, if negative)."
1952 (interactive "p")
1953 (current-kill arg))
1955 ;; Some kill commands.
1957 ;; Internal subroutine of delete-char
1958 (defun kill-forward-chars (arg)
1959 (if (listp arg) (setq arg (car arg)))
1960 (if (eq arg '-) (setq arg -1))
1961 (kill-region (point) (forward-point arg)))
1963 ;; Internal subroutine of backward-delete-char
1964 (defun kill-backward-chars (arg)
1965 (if (listp arg) (setq arg (car arg)))
1966 (if (eq arg '-) (setq arg -1))
1967 (kill-region (point) (forward-point (- arg))))
1969 (defcustom backward-delete-char-untabify-method 'untabify
1970 "*The method for untabifying when deleting backward.
1971 Can be `untabify' -- turn a tab to many spaces, then delete one space;
1972 `hungry' -- delete all whitespace, both tabs and spaces;
1973 `all' -- delete all whitespace, including tabs, spaces and newlines;
1974 nil -- just delete one character."
1975 :type '(choice (const untabify) (const hungry) (const all) (const nil))
1976 :version "20.3"
1977 :group 'killing)
1979 (defun backward-delete-char-untabify (arg &optional killp)
1980 "Delete characters backward, changing tabs into spaces.
1981 The exact behavior depends on `backward-delete-char-untabify-method'.
1982 Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil.
1983 Interactively, ARG is the prefix arg (default 1)
1984 and KILLP is t if a prefix arg was specified."
1985 (interactive "*p\nP")
1986 (when (eq backward-delete-char-untabify-method 'untabify)
1987 (let ((count arg))
1988 (save-excursion
1989 (while (and (> count 0) (not (bobp)))
1990 (if (= (preceding-char) ?\t)
1991 (let ((col (current-column)))
1992 (forward-char -1)
1993 (setq col (- col (current-column)))
1994 (insert-char ?\ col)
1995 (delete-char 1)))
1996 (forward-char -1)
1997 (setq count (1- count))))))
1998 (delete-backward-char
1999 (let ((skip (cond ((eq backward-delete-char-untabify-method 'hungry) " \t")
2000 ((eq backward-delete-char-untabify-method 'all)
2001 " \t\n\r"))))
2002 (if skip
2003 (let ((wh (- (point) (save-excursion (skip-chars-backward skip)
2004 (point)))))
2005 (+ arg (if (zerop wh) 0 (1- wh))))
2006 arg))
2007 killp))
2009 (defun zap-to-char (arg char)
2010 "Kill up to and including ARG'th occurrence of CHAR.
2011 Case is ignored if `case-fold-search' is non-nil in the current buffer.
2012 Goes backward if ARG is negative; error if CHAR not found."
2013 (interactive "p\ncZap to char: ")
2014 (kill-region (point) (progn
2015 (search-forward (char-to-string char) nil nil arg)
2016 ; (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
2017 (point))))
2019 ;; kill-line and its subroutines.
2021 (defcustom kill-whole-line nil
2022 "*If non-nil, `kill-line' with no arg at beg of line kills the whole line."
2023 :type 'boolean
2024 :group 'killing)
2026 (defun kill-line (&optional arg)
2027 "Kill the rest of the current line; if no nonblanks there, kill thru newline.
2028 With prefix argument, kill that many lines from point.
2029 Negative arguments kill lines backward.
2030 With zero argument, kills the text before point on the current line.
2032 When calling from a program, nil means \"no arg\",
2033 a number counts as a prefix arg.
2035 To kill a whole line, when point is not at the beginning, type \
2036 \\[beginning-of-line] \\[kill-line] \\[kill-line].
2038 If `kill-whole-line' is non-nil, then this command kills the whole line
2039 including its terminating newline, when used at the beginning of a line
2040 with no argument. As a consequence, you can always kill a whole line
2041 by typing \\[beginning-of-line] \\[kill-line].
2043 If you want to append the killed line to the last killed text,
2044 use \\[append-next-kill] before \\[kill-line].
2046 If the buffer is read-only, Emacs will beep and refrain from deleting
2047 the line, but put the line in the kill ring anyway. This means that
2048 you can use this command to copy text from a read-only buffer."
2049 (interactive "P")
2050 (kill-region (point)
2051 ;; It is better to move point to the other end of the kill
2052 ;; before killing. That way, in a read-only buffer, point
2053 ;; moves across the text that is copied to the kill ring.
2054 ;; The choice has no effect on undo now that undo records
2055 ;; the value of point from before the command was run.
2056 (progn
2057 (if arg
2058 (forward-visible-line (prefix-numeric-value arg))
2059 (if (eobp)
2060 (signal 'end-of-buffer nil))
2061 (if (or (looking-at "[ \t]*$") (and kill-whole-line (bolp)))
2062 (forward-visible-line 1)
2063 (end-of-visible-line)))
2064 (point))))
2066 (defun forward-visible-line (arg)
2067 "Move forward by ARG lines, ignoring currently invisible newlines only.
2068 If ARG is negative, move backward -ARG lines.
2069 If ARG is zero, move to the beginning of the current line."
2070 (condition-case nil
2071 (if (> arg 0)
2072 (while (> arg 0)
2073 (or (zerop (forward-line 1))
2074 (signal 'end-of-buffer nil))
2075 ;; If the following character is currently invisible,
2076 ;; skip all characters with that same `invisible' property value,
2077 ;; then find the next newline.
2078 (while (and (not (eobp))
2079 (let ((prop
2080 (get-char-property (point) 'invisible)))
2081 (if (eq buffer-invisibility-spec t)
2082 prop
2083 (or (memq prop buffer-invisibility-spec)
2084 (assq prop buffer-invisibility-spec)))))
2085 (goto-char
2086 (if (get-text-property (point) 'invisible)
2087 (or (next-single-property-change (point) 'invisible)
2088 (point-max))
2089 (next-overlay-change (point))))
2090 (or (zerop (forward-line 1))
2091 (signal 'end-of-buffer nil)))
2092 (setq arg (1- arg)))
2093 (let ((first t))
2094 (while (or first (< arg 0))
2095 (if (zerop arg)
2096 (beginning-of-line)
2097 (or (zerop (forward-line -1))
2098 (signal 'beginning-of-buffer nil)))
2099 (while (and (not (bobp))
2100 (let ((prop
2101 (get-char-property (1- (point)) 'invisible)))
2102 (if (eq buffer-invisibility-spec t)
2103 prop
2104 (or (memq prop buffer-invisibility-spec)
2105 (assq prop buffer-invisibility-spec)))))
2106 (goto-char
2107 (if (get-text-property (1- (point)) 'invisible)
2108 (or (previous-single-property-change (point) 'invisible)
2109 (point-min))
2110 (previous-overlay-change (point))))
2111 (or (zerop (forward-line -1))
2112 (signal 'beginning-of-buffer nil)))
2113 (setq first nil)
2114 (setq arg (1+ arg)))))
2115 ((beginning-of-buffer end-of-buffer)
2116 nil)))
2118 (defun end-of-visible-line ()
2119 "Move to end of current visible line."
2120 (end-of-line)
2121 ;; If the following character is currently invisible,
2122 ;; skip all characters with that same `invisible' property value,
2123 ;; then find the next newline.
2124 (while (and (not (eobp))
2125 (let ((prop
2126 (get-char-property (point) 'invisible)))
2127 (if (eq buffer-invisibility-spec t)
2128 prop
2129 (or (memq prop buffer-invisibility-spec)
2130 (assq prop buffer-invisibility-spec)))))
2131 (if (get-text-property (point) 'invisible)
2132 (goto-char (next-single-property-change (point) 'invisible))
2133 (goto-char (next-overlay-change (point))))
2134 (end-of-line)))
2136 (defun insert-buffer (buffer)
2137 "Insert after point the contents of BUFFER.
2138 Puts mark after the inserted text.
2139 BUFFER may be a buffer or a buffer name.
2141 This function is meant for the user to run interactively.
2142 Don't call it from programs!"
2143 (interactive
2144 (list
2145 (progn
2146 (barf-if-buffer-read-only)
2147 (read-buffer "Insert buffer: "
2148 (if (eq (selected-window) (next-window (selected-window)))
2149 (other-buffer (current-buffer))
2150 (window-buffer (next-window (selected-window))))
2151 t))))
2152 (or (bufferp buffer)
2153 (setq buffer (get-buffer buffer)))
2154 (let (start end newmark)
2155 (save-excursion
2156 (save-excursion
2157 (set-buffer buffer)
2158 (setq start (point-min) end (point-max)))
2159 (insert-buffer-substring buffer start end)
2160 (setq newmark (point)))
2161 (push-mark newmark))
2162 nil)
2164 (defun append-to-buffer (buffer start end)
2165 "Append to specified buffer the text of the region.
2166 It is inserted into that buffer before its point.
2168 When calling from a program, give three arguments:
2169 BUFFER (or buffer name), START and END.
2170 START and END specify the portion of the current buffer to be copied."
2171 (interactive
2172 (list (read-buffer "Append to buffer: " (other-buffer (current-buffer) t))
2173 (region-beginning) (region-end)))
2174 (let ((oldbuf (current-buffer)))
2175 (save-excursion
2176 (let* ((append-to (get-buffer-create buffer))
2177 (windows (get-buffer-window-list append-to t t))
2178 point)
2179 (set-buffer append-to)
2180 (setq point (point))
2181 (barf-if-buffer-read-only)
2182 (insert-buffer-substring oldbuf start end)
2183 (dolist (window windows)
2184 (when (= (window-point window) point)
2185 (set-window-point window (point))))))))
2187 (defun prepend-to-buffer (buffer start end)
2188 "Prepend to specified buffer the text of the region.
2189 It is inserted into that buffer after its point.
2191 When calling from a program, give three arguments:
2192 BUFFER (or buffer name), START and END.
2193 START and END specify the portion of the current buffer to be copied."
2194 (interactive "BPrepend to buffer: \nr")
2195 (let ((oldbuf (current-buffer)))
2196 (save-excursion
2197 (set-buffer (get-buffer-create buffer))
2198 (barf-if-buffer-read-only)
2199 (save-excursion
2200 (insert-buffer-substring oldbuf start end)))))
2202 (defun copy-to-buffer (buffer start end)
2203 "Copy to specified buffer the text of the region.
2204 It is inserted into that buffer, replacing existing text there.
2206 When calling from a program, give three arguments:
2207 BUFFER (or buffer name), START and END.
2208 START and END specify the portion of the current buffer to be copied."
2209 (interactive "BCopy to buffer: \nr")
2210 (let ((oldbuf (current-buffer)))
2211 (save-excursion
2212 (set-buffer (get-buffer-create buffer))
2213 (barf-if-buffer-read-only)
2214 (erase-buffer)
2215 (save-excursion
2216 (insert-buffer-substring oldbuf start end)))))
2218 (put 'mark-inactive 'error-conditions '(mark-inactive error))
2219 (put 'mark-inactive 'error-message "The mark is not active now")
2221 (defun mark (&optional force)
2222 "Return this buffer's mark value as integer; error if mark inactive.
2223 If optional argument FORCE is non-nil, access the mark value
2224 even if the mark is not currently active, and return nil
2225 if there is no mark at all.
2227 If you are using this in an editing command, you are most likely making
2228 a mistake; see the documentation of `set-mark'."
2229 (if (or force (not transient-mark-mode) mark-active mark-even-if-inactive)
2230 (marker-position (mark-marker))
2231 (signal 'mark-inactive nil)))
2233 ;; Many places set mark-active directly, and several of them failed to also
2234 ;; run deactivate-mark-hook. This shorthand should simplify.
2235 (defsubst deactivate-mark ()
2236 "Deactivate the mark by setting `mark-active' to nil.
2237 \(That makes a difference only in Transient Mark mode.)
2238 Also runs the hook `deactivate-mark-hook'."
2239 (if transient-mark-mode
2240 (progn
2241 (setq mark-active nil)
2242 (run-hooks 'deactivate-mark-hook))))
2244 (defun set-mark (pos)
2245 "Set this buffer's mark to POS. Don't use this function!
2246 That is to say, don't use this function unless you want
2247 the user to see that the mark has moved, and you want the previous
2248 mark position to be lost.
2250 Normally, when a new mark is set, the old one should go on the stack.
2251 This is why most applications should use push-mark, not set-mark.
2253 Novice Emacs Lisp programmers often try to use the mark for the wrong
2254 purposes. The mark saves a location for the user's convenience.
2255 Most editing commands should not alter the mark.
2256 To remember a location for internal use in the Lisp program,
2257 store it in a Lisp variable. Example:
2259 (let ((beg (point))) (forward-line 1) (delete-region beg (point)))."
2261 (if pos
2262 (progn
2263 (setq mark-active t)
2264 (run-hooks 'activate-mark-hook)
2265 (set-marker (mark-marker) pos (current-buffer)))
2266 ;; Normally we never clear mark-active except in Transient Mark mode.
2267 ;; But when we actually clear out the mark value too,
2268 ;; we must clear mark-active in any mode.
2269 (setq mark-active nil)
2270 (run-hooks 'deactivate-mark-hook)
2271 (set-marker (mark-marker) nil)))
2273 (defvar mark-ring nil
2274 "The list of former marks of the current buffer, most recent first.")
2275 (make-variable-buffer-local 'mark-ring)
2276 (put 'mark-ring 'permanent-local t)
2278 (defcustom mark-ring-max 16
2279 "*Maximum size of mark ring. Start discarding off end if gets this big."
2280 :type 'integer
2281 :group 'editing-basics)
2283 (defvar global-mark-ring nil
2284 "The list of saved global marks, most recent first.")
2286 (defcustom global-mark-ring-max 16
2287 "*Maximum size of global mark ring. \
2288 Start discarding off end if gets this big."
2289 :type 'integer
2290 :group 'editing-basics)
2292 (defun set-mark-command (arg)
2293 "Set mark at where point is, or jump to mark.
2294 With no prefix argument, set mark, push old mark position on local mark
2295 ring, and push mark on global mark ring.
2296 With argument, jump to mark, and pop a new position for mark off the ring
2297 \(does not affect global mark ring\).
2299 Novice Emacs Lisp programmers often try to use the mark for the wrong
2300 purposes. See the documentation of `set-mark' for more information."
2301 (interactive "P")
2302 (if (null arg)
2303 (progn
2304 (push-mark nil nil t))
2305 (if (null (mark t))
2306 (error "No mark set in this buffer")
2307 (goto-char (mark t))
2308 (pop-mark))))
2310 (defun push-mark (&optional location nomsg activate)
2311 "Set mark at LOCATION (point, by default) and push old mark on mark ring.
2312 If the last global mark pushed was not in the current buffer,
2313 also push LOCATION on the global mark ring.
2314 Display `Mark set' unless the optional second arg NOMSG is non-nil.
2315 In Transient Mark mode, activate mark if optional third arg ACTIVATE non-nil.
2317 Novice Emacs Lisp programmers often try to use the mark for the wrong
2318 purposes. See the documentation of `set-mark' for more information.
2320 In Transient Mark mode, this does not activate the mark."
2321 (if (null (mark t))
2323 (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring))
2324 (if (> (length mark-ring) mark-ring-max)
2325 (progn
2326 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil)
2327 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil))))
2328 (set-marker (mark-marker) (or location (point)) (current-buffer))
2329 ;; Now push the mark on the global mark ring.
2330 (if (and global-mark-ring
2331 (eq (marker-buffer (car global-mark-ring)) (current-buffer)))
2332 ;; The last global mark pushed was in this same buffer.
2333 ;; Don't push another one.
2335 (setq global-mark-ring (cons (copy-marker (mark-marker)) global-mark-ring))
2336 (if (> (length global-mark-ring) global-mark-ring-max)
2337 (progn
2338 (move-marker (car (nthcdr global-mark-ring-max global-mark-ring))
2339 nil)
2340 (setcdr (nthcdr (1- global-mark-ring-max) global-mark-ring) nil))))
2341 (or nomsg executing-kbd-macro (> (minibuffer-depth) 0)
2342 (message "Mark set"))
2343 (if (or activate (not transient-mark-mode))
2344 (set-mark (mark t)))
2345 nil)
2347 (defun pop-mark ()
2348 "Pop off mark ring into the buffer's actual mark.
2349 Does not set point. Does nothing if mark ring is empty."
2350 (if mark-ring
2351 (progn
2352 (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker)))))
2353 (set-marker (mark-marker) (+ 0 (car mark-ring)) (current-buffer))
2354 (deactivate-mark)
2355 (move-marker (car mark-ring) nil)
2356 (if (null (mark t)) (ding))
2357 (setq mark-ring (cdr mark-ring)))))
2359 (defalias 'exchange-dot-and-mark 'exchange-point-and-mark)
2360 (defun exchange-point-and-mark ()
2361 "Put the mark where point is now, and point where the mark is now.
2362 This command works even when the mark is not active,
2363 and it reactivates the mark."
2364 (interactive nil)
2365 (let ((omark (mark t)))
2366 (if (null omark)
2367 (error "No mark set in this buffer"))
2368 (set-mark (point))
2369 (goto-char omark)
2370 nil))
2372 (defun transient-mark-mode (arg)
2373 "Toggle Transient Mark mode.
2374 With arg, turn Transient Mark mode on if arg is positive, off otherwise.
2376 In Transient Mark mode, when the mark is active, the region is highlighted.
2377 Changing the buffer \"deactivates\" the mark.
2378 So do certain other operations that set the mark
2379 but whose main purpose is something else--for example,
2380 incremental search, \\[beginning-of-buffer], and \\[end-of-buffer].
2382 You can also deactivate the mark by typing \\[keyboard-quit] or
2383 \\[keyboard-escape-quit].
2385 Many commands change their behavior when Transient Mark mode is in effect
2386 and the mark is active, by acting on the region instead of their usual
2387 default part of the buffer's text. Examples of such commands include
2388 \\[comment-dwim], \\[flush-lines], \\[ispell], \\[keep-lines],
2389 \\[query-replace], \\[query-replace-regexp], and \\[undo]. Invoke
2390 \\[apropos-documentation] and type \"transient\" or \"mark.*active\" at
2391 the prompt, to see the documentation of commands which are sensitive to
2392 the Transient Mark mode."
2393 (interactive "P")
2394 (setq transient-mark-mode
2395 (if (null arg)
2396 (not transient-mark-mode)
2397 (> (prefix-numeric-value arg) 0)))
2398 (if (interactive-p)
2399 (if transient-mark-mode
2400 (message "Transient Mark mode enabled")
2401 (message "Transient Mark mode disabled"))))
2403 (defun pop-global-mark ()
2404 "Pop off global mark ring and jump to the top location."
2405 (interactive)
2406 ;; Pop entries which refer to non-existent buffers.
2407 (while (and global-mark-ring (not (marker-buffer (car global-mark-ring))))
2408 (setq global-mark-ring (cdr global-mark-ring)))
2409 (or global-mark-ring
2410 (error "No global mark set"))
2411 (let* ((marker (car global-mark-ring))
2412 (buffer (marker-buffer marker))
2413 (position (marker-position marker)))
2414 (setq global-mark-ring (nconc (cdr global-mark-ring)
2415 (list (car global-mark-ring))))
2416 (set-buffer buffer)
2417 (or (and (>= position (point-min))
2418 (<= position (point-max)))
2419 (widen))
2420 (goto-char position)
2421 (switch-to-buffer buffer)))
2423 (defcustom next-line-add-newlines nil
2424 "*If non-nil, `next-line' inserts newline to avoid `end of buffer' error."
2425 :type 'boolean
2426 :version "21.1"
2427 :group 'editing-basics)
2429 (defun next-line (&optional arg)
2430 "Move cursor vertically down ARG lines.
2431 If there is no character in the target line exactly under the current column,
2432 the cursor is positioned after the character in that line which spans this
2433 column, or at the end of the line if it is not long enough.
2434 If there is no line in the buffer after this one, behavior depends on the
2435 value of `next-line-add-newlines'. If non-nil, it inserts a newline character
2436 to create a line, and moves the cursor to that line. Otherwise it moves the
2437 cursor to the end of the buffer.
2439 The command \\[set-goal-column] can be used to create
2440 a semipermanent goal column for this command.
2441 Then instead of trying to move exactly vertically (or as close as possible),
2442 this command moves to the specified goal column (or as close as possible).
2443 The goal column is stored in the variable `goal-column', which is nil
2444 when there is no goal column.
2446 If you are thinking of using this in a Lisp program, consider
2447 using `forward-line' instead. It is usually easier to use
2448 and more reliable (no dependence on goal column, etc.)."
2449 (interactive "p")
2450 (unless arg (setq arg 1))
2451 (if (and next-line-add-newlines (= arg 1))
2452 (if (save-excursion (end-of-line) (eobp))
2453 ;; When adding a newline, don't expand an abbrev.
2454 (let ((abbrev-mode nil))
2455 (end-of-line)
2456 (insert "\n"))
2457 (line-move arg))
2458 (if (interactive-p)
2459 (condition-case nil
2460 (line-move arg)
2461 ((beginning-of-buffer end-of-buffer) (ding)))
2462 (line-move arg)))
2463 nil)
2465 (defun previous-line (&optional arg)
2466 "Move cursor vertically up ARG lines.
2467 If there is no character in the target line exactly over the current column,
2468 the cursor is positioned after the character in that line which spans this
2469 column, or at the end of the line if it is not long enough.
2471 The command \\[set-goal-column] can be used to create
2472 a semipermanent goal column for this command.
2473 Then instead of trying to move exactly vertically (or as close as possible),
2474 this command moves to the specified goal column (or as close as possible).
2475 The goal column is stored in the variable `goal-column', which is nil
2476 when there is no goal column.
2478 If you are thinking of using this in a Lisp program, consider using
2479 `forward-line' with a negative argument instead. It is usually easier
2480 to use and more reliable (no dependence on goal column, etc.)."
2481 (interactive "p")
2482 (unless arg (setq arg 1))
2483 (if (interactive-p)
2484 (condition-case nil
2485 (line-move (- arg))
2486 ((beginning-of-buffer end-of-buffer) (ding)))
2487 (line-move (- arg)))
2488 nil)
2490 (defcustom track-eol nil
2491 "*Non-nil means vertical motion starting at end of line keeps to ends of lines.
2492 This means moving to the end of each line moved onto.
2493 The beginning of a blank line does not count as the end of a line."
2494 :type 'boolean
2495 :group 'editing-basics)
2497 (defcustom goal-column nil
2498 "*Semipermanent goal column for vertical motion, as set by \\[set-goal-column], or nil."
2499 :type '(choice integer
2500 (const :tag "None" nil))
2501 :group 'editing-basics)
2502 (make-variable-buffer-local 'goal-column)
2504 (defvar temporary-goal-column 0
2505 "Current goal column for vertical motion.
2506 It is the column where point was
2507 at the start of current run of vertical motion commands.
2508 When the `track-eol' feature is doing its job, the value is 9999.")
2510 (defcustom line-move-ignore-invisible nil
2511 "*Non-nil means \\[next-line] and \\[previous-line] ignore invisible lines.
2512 Outline mode sets this."
2513 :type 'boolean
2514 :group 'editing-basics)
2516 (defun line-move-invisible (pos)
2517 "Return non-nil if the character after POS is currently invisible."
2518 (let ((prop
2519 (get-char-property pos 'invisible)))
2520 (if (eq buffer-invisibility-spec t)
2521 prop
2522 (or (memq prop buffer-invisibility-spec)
2523 (assq prop buffer-invisibility-spec)))))
2525 ;; This is the guts of next-line and previous-line.
2526 ;; Arg says how many lines to move.
2527 (defun line-move (arg)
2528 ;; Don't run any point-motion hooks, and disregard intangibility,
2529 ;; for intermediate positions.
2530 (let ((inhibit-point-motion-hooks t)
2531 (opoint (point))
2532 new line-end line-beg)
2533 (unwind-protect
2534 (progn
2535 (if (not (or (eq last-command 'next-line)
2536 (eq last-command 'previous-line)))
2537 (setq temporary-goal-column
2538 (if (and track-eol (eolp)
2539 ;; Don't count beg of empty line as end of line
2540 ;; unless we just did explicit end-of-line.
2541 (or (not (bolp)) (eq last-command 'end-of-line)))
2542 9999
2543 (current-column))))
2544 (if (and (not (integerp selective-display))
2545 (not line-move-ignore-invisible))
2546 ;; Use just newline characters.
2547 ;; Set ARG to 0 if we move as many lines as requested.
2548 (or (if (> arg 0)
2549 (progn (if (> arg 1) (forward-line (1- arg)))
2550 ;; This way of moving forward ARG lines
2551 ;; verifies that we have a newline after the last one.
2552 ;; It doesn't get confused by intangible text.
2553 (end-of-line)
2554 (if (zerop (forward-line 1))
2555 (setq arg 0)))
2556 (and (zerop (forward-line arg))
2557 (bolp)
2558 (setq arg 0)))
2559 (signal (if (< arg 0)
2560 'beginning-of-buffer
2561 'end-of-buffer)
2562 nil))
2563 ;; Move by arg lines, but ignore invisible ones.
2564 (while (> arg 0)
2565 ;; If the following character is currently invisible,
2566 ;; skip all characters with that same `invisible' property value.
2567 (while (and (not (eobp)) (line-move-invisible (point)))
2568 (goto-char (next-char-property-change (point))))
2569 ;; Now move a line.
2570 (end-of-line)
2571 (and (zerop (vertical-motion 1))
2572 (signal 'end-of-buffer nil))
2573 (setq arg (1- arg)))
2574 (while (< arg 0)
2575 (beginning-of-line)
2576 (and (zerop (vertical-motion -1))
2577 (signal 'beginning-of-buffer nil))
2578 (setq arg (1+ arg))
2579 (while (and (not (bobp)) (line-move-invisible (1- (point))))
2580 (goto-char (previous-char-property-change (point)))))))
2582 (cond ((> arg 0)
2583 ;; If we did not move down as far as desired,
2584 ;; at least go to end of line.
2585 (end-of-line))
2586 ((< arg 0)
2587 ;; If we did not move down as far as desired,
2588 ;; at least go to end of line.
2589 (beginning-of-line))
2591 (line-move-finish (or goal-column temporary-goal-column) opoint)))))
2592 nil)
2594 (defun line-move-finish (column opoint)
2595 (let ((repeat t))
2596 (while repeat
2597 ;; Set REPEAT to t to repeat the whole thing.
2598 (setq repeat nil)
2600 ;; Move to the desired column.
2601 (line-move-to-column column)
2603 (let ((new (point))
2604 (line-beg (save-excursion (beginning-of-line) (point)))
2605 (line-end (save-excursion (end-of-line) (point))))
2607 ;; Process intangibility within a line.
2608 ;; Move to the chosen destination position from above,
2609 ;; with intangibility processing enabled.
2611 (goto-char (point-min))
2612 (let ((inhibit-point-motion-hooks nil))
2613 (goto-char new)
2615 ;; If intangibility moves us to a different (later) place
2616 ;; in the same line, use that as the destination.
2617 (if (<= (point) line-end)
2618 (setq new (point))))
2620 ;; Now move to the updated destination, processing fields
2621 ;; as well as intangibility.
2622 (goto-char opoint)
2623 (let ((inhibit-point-motion-hooks nil))
2624 (goto-char
2625 (constrain-to-field new opoint nil t
2626 'inhibit-line-move-field-capture)))
2628 ;; If intangibility processing moved us to a different line,
2629 ;; retry everything within that new line.
2630 (when (or (< (point) line-beg) (> (point) line-end))
2631 ;; Repeat the intangibility and field processing.
2632 (setq repeat t))))))
2634 (defun line-move-to-column (col)
2635 "Try to find column COL, considering invisibility.
2636 This function works only in certain cases,
2637 because what we really need is for `move-to-column'
2638 and `current-column' to be able to ignore invisible text."
2639 (move-to-column col)
2641 (when (and line-move-ignore-invisible
2642 (not (bolp)) (line-move-invisible (1- (point))))
2643 (let ((normal-location (point))
2644 (normal-column (current-column)))
2645 ;; If the following character is currently invisible,
2646 ;; skip all characters with that same `invisible' property value.
2647 (while (and (not (eobp))
2648 (line-move-invisible (point)))
2649 (goto-char (next-char-property-change (point))))
2650 ;; Have we advanced to a larger column position?
2651 (if (> (current-column) normal-column)
2652 ;; We have made some progress towards the desired column.
2653 ;; See if we can make any further progress.
2654 (line-move-to-column (+ (current-column) (- col normal-column)))
2655 ;; Otherwise, go to the place we originally found
2656 ;; and move back over invisible text.
2657 ;; that will get us to the same place on the screen
2658 ;; but with a more reasonable buffer position.
2659 (goto-char normal-location)
2660 (let ((line-beg (save-excursion (beginning-of-line) (point))))
2661 (while (and (not (bolp)) (line-move-invisible (1- (point))))
2662 (goto-char (previous-char-property-change (point) line-beg))))))))
2664 ;;; Many people have said they rarely use this feature, and often type
2665 ;;; it by accident. Maybe it shouldn't even be on a key.
2666 (put 'set-goal-column 'disabled t)
2668 (defun set-goal-column (arg)
2669 "Set the current horizontal position as a goal for \\[next-line] and \\[previous-line].
2670 Those commands will move to this position in the line moved to
2671 rather than trying to keep the same horizontal position.
2672 With a non-nil argument, clears out the goal column
2673 so that \\[next-line] and \\[previous-line] resume vertical motion.
2674 The goal column is stored in the variable `goal-column'."
2675 (interactive "P")
2676 (if arg
2677 (progn
2678 (setq goal-column nil)
2679 (message "No goal column"))
2680 (setq goal-column (current-column))
2681 (message (substitute-command-keys
2682 "Goal column %d (use \\[set-goal-column] with an arg to unset it)")
2683 goal-column))
2684 nil)
2687 (defun scroll-other-window-down (lines)
2688 "Scroll the \"other window\" down.
2689 For more details, see the documentation for `scroll-other-window'."
2690 (interactive "P")
2691 (scroll-other-window
2692 ;; Just invert the argument's meaning.
2693 ;; We can do that without knowing which window it will be.
2694 (if (eq lines '-) nil
2695 (if (null lines) '-
2696 (- (prefix-numeric-value lines))))))
2697 (define-key esc-map [?\C-\S-v] 'scroll-other-window-down)
2699 (defun beginning-of-buffer-other-window (arg)
2700 "Move point to the beginning of the buffer in the other window.
2701 Leave mark at previous position.
2702 With arg N, put point N/10 of the way from the true beginning."
2703 (interactive "P")
2704 (let ((orig-window (selected-window))
2705 (window (other-window-for-scrolling)))
2706 ;; We use unwind-protect rather than save-window-excursion
2707 ;; because the latter would preserve the things we want to change.
2708 (unwind-protect
2709 (progn
2710 (select-window window)
2711 ;; Set point and mark in that window's buffer.
2712 (beginning-of-buffer arg)
2713 ;; Set point accordingly.
2714 (recenter '(t)))
2715 (select-window orig-window))))
2717 (defun end-of-buffer-other-window (arg)
2718 "Move point to the end of the buffer in the other window.
2719 Leave mark at previous position.
2720 With arg N, put point N/10 of the way from the true end."
2721 (interactive "P")
2722 ;; See beginning-of-buffer-other-window for comments.
2723 (let ((orig-window (selected-window))
2724 (window (other-window-for-scrolling)))
2725 (unwind-protect
2726 (progn
2727 (select-window window)
2728 (end-of-buffer arg)
2729 (recenter '(t)))
2730 (select-window orig-window))))
2732 (defun transpose-chars (arg)
2733 "Interchange characters around point, moving forward one character.
2734 With prefix arg ARG, effect is to take character before point
2735 and drag it forward past ARG other characters (backward if ARG negative).
2736 If no argument and at end of line, the previous two chars are exchanged."
2737 (interactive "*P")
2738 (and (null arg) (eolp) (forward-char -1))
2739 (transpose-subr 'forward-char (prefix-numeric-value arg)))
2741 (defun transpose-words (arg)
2742 "Interchange words around point, leaving point at end of them.
2743 With prefix arg ARG, effect is to take word before or around point
2744 and drag it forward past ARG other words (backward if ARG negative).
2745 If ARG is zero, the words around or after point and around or after mark
2746 are interchanged."
2747 (interactive "*p")
2748 (transpose-subr 'forward-word arg))
2750 (defun transpose-sexps (arg)
2751 "Like \\[transpose-words] but applies to sexps.
2752 Does not work on a sexp that point is in the middle of
2753 if it is a list or string."
2754 (interactive "*p")
2755 (transpose-subr 'forward-sexp arg))
2757 (defun transpose-lines (arg)
2758 "Exchange current line and previous line, leaving point after both.
2759 With argument ARG, takes previous line and moves it past ARG lines.
2760 With argument 0, interchanges line point is in with line mark is in."
2761 (interactive "*p")
2762 (transpose-subr (function
2763 (lambda (arg)
2764 (if (> arg 0)
2765 (progn
2766 ;; Move forward over ARG lines,
2767 ;; but create newlines if necessary.
2768 (setq arg (forward-line arg))
2769 (if (/= (preceding-char) ?\n)
2770 (setq arg (1+ arg)))
2771 (if (> arg 0)
2772 (newline arg)))
2773 (forward-line arg))))
2774 arg))
2776 (defun transpose-subr (mover arg &optional special)
2777 (let ((aux (if special mover
2778 (lambda (x)
2779 (cons (progn (funcall mover x) (point))
2780 (progn (funcall mover (- x)) (point))))))
2781 pos1 pos2)
2782 (cond
2783 ((= arg 0)
2784 (save-excursion
2785 (setq pos1 (funcall aux 1))
2786 (goto-char (mark))
2787 (setq pos2 (funcall aux 1))
2788 (transpose-subr-1 pos1 pos2))
2789 (exchange-point-and-mark))
2790 ((> arg 0)
2791 (setq pos1 (funcall aux -1))
2792 (setq pos2 (funcall aux arg))
2793 (transpose-subr-1 pos1 pos2)
2794 (goto-char (car pos2)))
2796 (setq pos1 (funcall aux -1))
2797 (goto-char (car pos1))
2798 (setq pos2 (funcall aux arg))
2799 (transpose-subr-1 pos1 pos2)))))
2801 (defun transpose-subr-1 (pos1 pos2)
2802 (when (> (car pos1) (cdr pos1)) (setq pos1 (cons (cdr pos1) (car pos1))))
2803 (when (> (car pos2) (cdr pos2)) (setq pos2 (cons (cdr pos2) (car pos2))))
2804 (when (> (car pos1) (car pos2))
2805 (let ((swap pos1))
2806 (setq pos1 pos2 pos2 swap)))
2807 (if (> (cdr pos1) (car pos2)) (error "Don't have two things to transpose"))
2808 (atomic-change-group
2809 (let (word2)
2810 (setq word2 (delete-and-extract-region (car pos2) (cdr pos2)))
2811 (goto-char (car pos2))
2812 (insert (delete-and-extract-region (car pos1) (cdr pos1)))
2813 (goto-char (car pos1))
2814 (insert word2))))
2816 (defun backward-word (arg)
2817 "Move backward until encountering the beginning of a word.
2818 With argument, do this that many times."
2819 (interactive "p")
2820 (forward-word (- arg)))
2822 (defun mark-word (arg)
2823 "Set mark arg words away from point.
2824 If this command is repeated, it marks the next ARG words after the ones
2825 already marked."
2826 (interactive "p")
2827 (cond ((and (eq last-command this-command) (mark t))
2828 (set-mark
2829 (save-excursion
2830 (goto-char (mark))
2831 (forward-word arg)
2832 (point))))
2834 (push-mark
2835 (save-excursion
2836 (forward-word arg)
2837 (point))
2838 nil t))))
2840 (defun kill-word (arg)
2841 "Kill characters forward until encountering the end of a word.
2842 With argument, do this that many times."
2843 (interactive "p")
2844 (kill-region (point) (progn (forward-word arg) (point))))
2846 (defun backward-kill-word (arg)
2847 "Kill characters backward until encountering the end of a word.
2848 With argument, do this that many times."
2849 (interactive "p")
2850 (kill-word (- arg)))
2852 (defun current-word (&optional strict)
2853 "Return the word point is on (or a nearby word) as a string.
2854 If optional arg STRICT is non-nil, return nil unless point is within
2855 or adjacent to a word."
2856 (save-excursion
2857 (let ((oldpoint (point)) (start (point)) (end (point)))
2858 (skip-syntax-backward "w_") (setq start (point))
2859 (goto-char oldpoint)
2860 (skip-syntax-forward "w_") (setq end (point))
2861 (if (and (eq start oldpoint) (eq end oldpoint))
2862 ;; Point is neither within nor adjacent to a word.
2863 (and (not strict)
2864 (progn
2865 ;; Look for preceding word in same line.
2866 (skip-syntax-backward "^w_"
2867 (save-excursion (beginning-of-line)
2868 (point)))
2869 (if (bolp)
2870 ;; No preceding word in same line.
2871 ;; Look for following word in same line.
2872 (progn
2873 (skip-syntax-forward "^w_"
2874 (save-excursion (end-of-line)
2875 (point)))
2876 (setq start (point))
2877 (skip-syntax-forward "w_")
2878 (setq end (point)))
2879 (setq end (point))
2880 (skip-syntax-backward "w_")
2881 (setq start (point)))
2882 (buffer-substring-no-properties start end)))
2883 (buffer-substring-no-properties start end)))))
2885 (defcustom fill-prefix nil
2886 "*String for filling to insert at front of new line, or nil for none."
2887 :type '(choice (const :tag "None" nil)
2888 string)
2889 :group 'fill)
2890 (make-variable-buffer-local 'fill-prefix)
2892 (defcustom auto-fill-inhibit-regexp nil
2893 "*Regexp to match lines which should not be auto-filled."
2894 :type '(choice (const :tag "None" nil)
2895 regexp)
2896 :group 'fill)
2898 (defvar comment-line-break-function 'comment-indent-new-line
2899 "*Mode-specific function which line breaks and continues a comment.
2901 This function is only called during auto-filling of a comment section.
2902 The function should take a single optional argument, which is a flag
2903 indicating whether it should use soft newlines.
2905 Setting this variable automatically makes it local to the current buffer.")
2907 ;; This function is used as the auto-fill-function of a buffer
2908 ;; when Auto-Fill mode is enabled.
2909 ;; It returns t if it really did any work.
2910 ;; (Actually some major modes use a different auto-fill function,
2911 ;; but this one is the default one.)
2912 (defun do-auto-fill ()
2913 (let (fc justify bol give-up
2914 (fill-prefix fill-prefix))
2915 (if (or (not (setq justify (current-justification)))
2916 (null (setq fc (current-fill-column)))
2917 (and (eq justify 'left)
2918 (<= (current-column) fc))
2919 (save-excursion (beginning-of-line)
2920 (setq bol (point))
2921 (and auto-fill-inhibit-regexp
2922 (looking-at auto-fill-inhibit-regexp))))
2923 nil ;; Auto-filling not required
2924 (if (memq justify '(full center right))
2925 (save-excursion (unjustify-current-line)))
2927 ;; Choose a fill-prefix automatically.
2928 (when (and adaptive-fill-mode
2929 (or (null fill-prefix) (string= fill-prefix "")))
2930 (let ((prefix
2931 (fill-context-prefix
2932 (save-excursion (backward-paragraph 1) (point))
2933 (save-excursion (forward-paragraph 1) (point)))))
2934 (and prefix (not (equal prefix ""))
2935 ;; Use auto-indentation rather than a guessed empty prefix.
2936 (not (and fill-indent-according-to-mode
2937 (string-match "[ \t]*" prefix)))
2938 (setq fill-prefix prefix))))
2940 (while (and (not give-up) (> (current-column) fc))
2941 ;; Determine where to split the line.
2942 (let* (after-prefix
2943 (fill-point
2944 (let ((opoint (point))
2945 bounce
2946 (first t))
2947 (save-excursion
2948 (beginning-of-line)
2949 (setq after-prefix (point))
2950 (and fill-prefix
2951 (looking-at (regexp-quote fill-prefix))
2952 (setq after-prefix (match-end 0)))
2953 (move-to-column (1+ fc))
2954 ;; Move back to the point where we can break the line.
2955 ;; We break the line between word or
2956 ;; after/before the character which has character
2957 ;; category `|'. We search space, \c| followed by
2958 ;; a character, or \c| following a character. If
2959 ;; not found, place the point at beginning of line.
2960 (while (or first
2961 (and (not (bobp))
2962 (not bounce)
2963 (fill-nobreak-p)))
2964 (setq first nil)
2965 (re-search-backward "[ \t]\\|\\c|.\\|.\\c|\\|^")
2966 ;; If we find nowhere on the line to break it,
2967 ;; break after one word. Set bounce to t
2968 ;; so we will not keep going in this while loop.
2969 (if (<= (point) after-prefix)
2970 (progn
2971 (goto-char after-prefix)
2972 (re-search-forward "[ \t]" opoint t)
2973 (setq bounce t))
2974 (if (looking-at "[ \t]")
2975 ;; Break the line at word boundary.
2976 (skip-chars-backward " \t")
2977 ;; Break the line after/before \c|.
2978 (forward-char 1))))
2979 (if enable-multibyte-characters
2980 ;; If we are going to break the line after or
2981 ;; before a non-ascii character, we may have
2982 ;; to run a special function for the charset
2983 ;; of the character to find the correct break
2984 ;; point.
2985 (if (not (and (eq (charset-after (1- (point))) 'ascii)
2986 (eq (charset-after (point)) 'ascii)))
2987 (fill-find-break-point after-prefix)))
2989 ;; Let fill-point be set to the place where we end up.
2990 ;; But move back before any whitespace here.
2991 (skip-chars-backward " \t")
2992 (point)))))
2994 ;; See whether the place we found is any good.
2995 (if (save-excursion
2996 (goto-char fill-point)
2997 (and (not (bolp))
2998 ;; There is no use breaking at end of line.
2999 (not (save-excursion (skip-chars-forward " ") (eolp)))
3000 ;; It is futile to split at the end of the prefix
3001 ;; since we would just insert the prefix again.
3002 (not (and after-prefix (<= (point) after-prefix)))
3003 ;; Don't split right after a comment starter
3004 ;; since we would just make another comment starter.
3005 (not (and comment-start-skip
3006 (let ((limit (point)))
3007 (beginning-of-line)
3008 (and (re-search-forward comment-start-skip
3009 limit t)
3010 (eq (point) limit)))))))
3011 ;; Ok, we have a useful place to break the line. Do it.
3012 (let ((prev-column (current-column)))
3013 ;; If point is at the fill-point, do not `save-excursion'.
3014 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
3015 ;; point will end up before it rather than after it.
3016 (if (save-excursion
3017 (skip-chars-backward " \t")
3018 (= (point) fill-point))
3019 (funcall comment-line-break-function t)
3020 (save-excursion
3021 (goto-char fill-point)
3022 (funcall comment-line-break-function t)))
3023 ;; Now do justification, if required
3024 (if (not (eq justify 'left))
3025 (save-excursion
3026 (end-of-line 0)
3027 (justify-current-line justify nil t)))
3028 ;; If making the new line didn't reduce the hpos of
3029 ;; the end of the line, then give up now;
3030 ;; trying again will not help.
3031 (if (>= (current-column) prev-column)
3032 (setq give-up t)))
3033 ;; No good place to break => stop trying.
3034 (setq give-up t))))
3035 ;; Justify last line.
3036 (justify-current-line justify t t)
3037 t)))
3039 (defvar normal-auto-fill-function 'do-auto-fill
3040 "The function to use for `auto-fill-function' if Auto Fill mode is turned on.
3041 Some major modes set this.")
3043 (defun auto-fill-mode (&optional arg)
3044 "Toggle Auto Fill mode.
3045 With arg, turn Auto Fill mode on if and only if arg is positive.
3046 In Auto Fill mode, inserting a space at a column beyond `current-fill-column'
3047 automatically breaks the line at a previous space.
3049 The value of `normal-auto-fill-function' specifies the function to use
3050 for `auto-fill-function' when turning Auto Fill mode on."
3051 (interactive "P")
3052 (prog1 (setq auto-fill-function
3053 (if (if (null arg)
3054 (not auto-fill-function)
3055 (> (prefix-numeric-value arg) 0))
3056 normal-auto-fill-function
3057 nil))
3058 (force-mode-line-update)))
3060 ;; This holds a document string used to document auto-fill-mode.
3061 (defun auto-fill-function ()
3062 "Automatically break line at a previous space, in insertion of text."
3063 nil)
3065 (defun turn-on-auto-fill ()
3066 "Unconditionally turn on Auto Fill mode."
3067 (auto-fill-mode 1))
3069 (defun turn-off-auto-fill ()
3070 "Unconditionally turn off Auto Fill mode."
3071 (auto-fill-mode -1))
3073 (custom-add-option 'text-mode-hook 'turn-on-auto-fill)
3075 (defun set-fill-column (arg)
3076 "Set `fill-column' to specified argument.
3077 Use \\[universal-argument] followed by a number to specify a column.
3078 Just \\[universal-argument] as argument means to use the current column."
3079 (interactive "P")
3080 (if (consp arg)
3081 (setq arg (current-column)))
3082 (if (not (integerp arg))
3083 ;; Disallow missing argument; it's probably a typo for C-x C-f.
3084 (error "set-fill-column requires an explicit argument")
3085 (message "Fill column set to %d (was %d)" arg fill-column)
3086 (setq fill-column arg)))
3088 (defun set-selective-display (arg)
3089 "Set `selective-display' to ARG; clear it if no arg.
3090 When the value of `selective-display' is a number > 0,
3091 lines whose indentation is >= that value are not displayed.
3092 The variable `selective-display' has a separate value for each buffer."
3093 (interactive "P")
3094 (if (eq selective-display t)
3095 (error "selective-display already in use for marked lines"))
3096 (let ((current-vpos
3097 (save-restriction
3098 (narrow-to-region (point-min) (point))
3099 (goto-char (window-start))
3100 (vertical-motion (window-height)))))
3101 (setq selective-display
3102 (and arg (prefix-numeric-value arg)))
3103 (recenter current-vpos))
3104 (set-window-start (selected-window) (window-start (selected-window)))
3105 (princ "selective-display set to " t)
3106 (prin1 selective-display t)
3107 (princ "." t))
3109 (defvar overwrite-mode-textual " Ovwrt"
3110 "The string displayed in the mode line when in overwrite mode.")
3111 (defvar overwrite-mode-binary " Bin Ovwrt"
3112 "The string displayed in the mode line when in binary overwrite mode.")
3114 (defun overwrite-mode (arg)
3115 "Toggle overwrite mode.
3116 With arg, turn overwrite mode on iff arg is positive.
3117 In overwrite mode, printing characters typed in replace existing text
3118 on a one-for-one basis, rather than pushing it to the right. At the
3119 end of a line, such characters extend the line. Before a tab,
3120 such characters insert until the tab is filled in.
3121 \\[quoted-insert] still inserts characters in overwrite mode; this
3122 is supposed to make it easier to insert characters when necessary."
3123 (interactive "P")
3124 (setq overwrite-mode
3125 (if (if (null arg) (not overwrite-mode)
3126 (> (prefix-numeric-value arg) 0))
3127 'overwrite-mode-textual))
3128 (force-mode-line-update))
3130 (defun binary-overwrite-mode (arg)
3131 "Toggle binary overwrite mode.
3132 With arg, turn binary overwrite mode on iff arg is positive.
3133 In binary overwrite mode, printing characters typed in replace
3134 existing text. Newlines are not treated specially, so typing at the
3135 end of a line joins the line to the next, with the typed character
3136 between them. Typing before a tab character simply replaces the tab
3137 with the character typed.
3138 \\[quoted-insert] replaces the text at the cursor, just as ordinary
3139 typing characters do.
3141 Note that binary overwrite mode is not its own minor mode; it is a
3142 specialization of overwrite-mode, entered by setting the
3143 `overwrite-mode' variable to `overwrite-mode-binary'."
3144 (interactive "P")
3145 (setq overwrite-mode
3146 (if (if (null arg)
3147 (not (eq overwrite-mode 'overwrite-mode-binary))
3148 (> (prefix-numeric-value arg) 0))
3149 'overwrite-mode-binary))
3150 (force-mode-line-update))
3152 (defcustom line-number-mode t
3153 "*Non-nil means display line number in mode line."
3154 :type 'boolean
3155 :group 'editing-basics)
3157 (defun line-number-mode (arg)
3158 "Toggle Line Number mode.
3159 With arg, turn Line Number mode on iff arg is positive.
3160 When Line Number mode is enabled, the line number appears
3161 in the mode line.
3163 Line numbers do not appear for very large buffers and buffers
3164 with very long lines; see variables `line-number-display-limit'
3165 and `line-number-display-limit-width'."
3166 (interactive "P")
3167 (setq line-number-mode
3168 (if (null arg) (not line-number-mode)
3169 (> (prefix-numeric-value arg) 0)))
3170 (force-mode-line-update))
3172 (defcustom column-number-mode nil
3173 "*Non-nil means display column number in mode line."
3174 :type 'boolean
3175 :group 'editing-basics)
3177 (defun column-number-mode (arg)
3178 "Toggle Column Number mode.
3179 With arg, turn Column Number mode on iff arg is positive.
3180 When Column Number mode is enabled, the column number appears
3181 in the mode line."
3182 (interactive "P")
3183 (setq column-number-mode
3184 (if (null arg) (not column-number-mode)
3185 (> (prefix-numeric-value arg) 0)))
3186 (force-mode-line-update))
3188 (defgroup paren-blinking nil
3189 "Blinking matching of parens and expressions."
3190 :prefix "blink-matching-"
3191 :group 'paren-matching)
3193 (defcustom blink-matching-paren t
3194 "*Non-nil means show matching open-paren when close-paren is inserted."
3195 :type 'boolean
3196 :group 'paren-blinking)
3198 (defcustom blink-matching-paren-on-screen t
3199 "*Non-nil means show matching open-paren when it is on screen.
3200 If nil, means don't show it (but the open-paren can still be shown
3201 when it is off screen)."
3202 :type 'boolean
3203 :group 'paren-blinking)
3205 (defcustom blink-matching-paren-distance (* 25 1024)
3206 "*If non-nil, is maximum distance to search for matching open-paren."
3207 :type 'integer
3208 :group 'paren-blinking)
3210 (defcustom blink-matching-delay 1
3211 "*Time in seconds to delay after showing a matching paren."
3212 :type 'number
3213 :group 'paren-blinking)
3215 (defcustom blink-matching-paren-dont-ignore-comments nil
3216 "*Non-nil means `blink-matching-paren' will not ignore comments."
3217 :type 'boolean
3218 :group 'paren-blinking)
3220 (defun blink-matching-open ()
3221 "Move cursor momentarily to the beginning of the sexp before point."
3222 (interactive)
3223 (and (> (point) (1+ (point-min)))
3224 blink-matching-paren
3225 ;; Verify an even number of quoting characters precede the close.
3226 (= 1 (logand 1 (- (point)
3227 (save-excursion
3228 (forward-char -1)
3229 (skip-syntax-backward "/\\")
3230 (point)))))
3231 (let* ((oldpos (point))
3232 (blinkpos)
3233 (mismatch))
3234 (save-excursion
3235 (save-restriction
3236 (if blink-matching-paren-distance
3237 (narrow-to-region (max (point-min)
3238 (- (point) blink-matching-paren-distance))
3239 oldpos))
3240 (condition-case ()
3241 (let ((parse-sexp-ignore-comments
3242 (and parse-sexp-ignore-comments
3243 (not blink-matching-paren-dont-ignore-comments))))
3244 (setq blinkpos (scan-sexps oldpos -1)))
3245 (error nil)))
3246 (and blinkpos
3247 (/= (char-syntax (char-after blinkpos))
3248 ?\$)
3249 (setq mismatch
3250 (or (null (matching-paren (char-after blinkpos)))
3251 (/= (char-after (1- oldpos))
3252 (matching-paren (char-after blinkpos))))))
3253 (if mismatch (setq blinkpos nil))
3254 (if blinkpos
3255 ;; Don't log messages about paren matching.
3256 (let (message-log-max)
3257 (goto-char blinkpos)
3258 (if (pos-visible-in-window-p)
3259 (and blink-matching-paren-on-screen
3260 (sit-for blink-matching-delay))
3261 (goto-char blinkpos)
3262 (message
3263 "Matches %s"
3264 ;; Show what precedes the open in its line, if anything.
3265 (if (save-excursion
3266 (skip-chars-backward " \t")
3267 (not (bolp)))
3268 (buffer-substring (progn (beginning-of-line) (point))
3269 (1+ blinkpos))
3270 ;; Show what follows the open in its line, if anything.
3271 (if (save-excursion
3272 (forward-char 1)
3273 (skip-chars-forward " \t")
3274 (not (eolp)))
3275 (buffer-substring blinkpos
3276 (progn (end-of-line) (point)))
3277 ;; Otherwise show the previous nonblank line,
3278 ;; if there is one.
3279 (if (save-excursion
3280 (skip-chars-backward "\n \t")
3281 (not (bobp)))
3282 (concat
3283 (buffer-substring (progn
3284 (skip-chars-backward "\n \t")
3285 (beginning-of-line)
3286 (point))
3287 (progn (end-of-line)
3288 (skip-chars-backward " \t")
3289 (point)))
3290 ;; Replace the newline and other whitespace with `...'.
3291 "..."
3292 (buffer-substring blinkpos (1+ blinkpos)))
3293 ;; There is nothing to show except the char itself.
3294 (buffer-substring blinkpos (1+ blinkpos))))))))
3295 (cond (mismatch
3296 (message "Mismatched parentheses"))
3297 ((not blink-matching-paren-distance)
3298 (message "Unmatched parenthesis"))))))))
3300 ;Turned off because it makes dbx bomb out.
3301 (setq blink-paren-function 'blink-matching-open)
3303 ;; This executes C-g typed while Emacs is waiting for a command.
3304 ;; Quitting out of a program does not go through here;
3305 ;; that happens in the QUIT macro at the C code level.
3306 (defun keyboard-quit ()
3307 "Signal a `quit' condition.
3308 During execution of Lisp code, this character causes a quit directly.
3309 At top-level, as an editor command, this simply beeps."
3310 (interactive)
3311 (deactivate-mark)
3312 (signal 'quit nil))
3314 (define-key global-map "\C-g" 'keyboard-quit)
3316 (defvar buffer-quit-function nil
3317 "Function to call to \"quit\" the current buffer, or nil if none.
3318 \\[keyboard-escape-quit] calls this function when its more local actions
3319 \(such as cancelling a prefix argument, minibuffer or region) do not apply.")
3321 (defun keyboard-escape-quit ()
3322 "Exit the current \"mode\" (in a generalized sense of the word).
3323 This command can exit an interactive command such as `query-replace',
3324 can clear out a prefix argument or a region,
3325 can get out of the minibuffer or other recursive edit,
3326 cancel the use of the current buffer (for special-purpose buffers),
3327 or go back to just one window (by deleting all but the selected window)."
3328 (interactive)
3329 (cond ((eq last-command 'mode-exited) nil)
3330 ((> (minibuffer-depth) 0)
3331 (abort-recursive-edit))
3332 (current-prefix-arg
3333 nil)
3334 ((and transient-mark-mode
3335 mark-active)
3336 (deactivate-mark))
3337 ((> (recursion-depth) 0)
3338 (exit-recursive-edit))
3339 (buffer-quit-function
3340 (funcall buffer-quit-function))
3341 ((not (one-window-p t))
3342 (delete-other-windows))
3343 ((string-match "^ \\*" (buffer-name (current-buffer)))
3344 (bury-buffer))))
3346 (define-key global-map "\e\e\e" 'keyboard-escape-quit)
3348 (defcustom read-mail-command 'rmail
3349 "*Your preference for a mail reading package.
3350 This is used by some keybindings which support reading mail.
3351 See also `mail-user-agent' concerning sending mail."
3352 :type '(choice (function-item rmail)
3353 (function-item gnus)
3354 (function-item mh-rmail)
3355 (function :tag "Other"))
3356 :version "21.1"
3357 :group 'mail)
3359 (defcustom mail-user-agent 'sendmail-user-agent
3360 "*Your preference for a mail composition package.
3361 Various Emacs Lisp packages (e.g. Reporter) require you to compose an
3362 outgoing email message. This variable lets you specify which
3363 mail-sending package you prefer.
3365 Valid values include:
3367 `sendmail-user-agent' -- use the default Emacs Mail package.
3368 See Info node `(emacs)Sending Mail'.
3369 `mh-e-user-agent' -- use the Emacs interface to the MH mail system.
3370 See Info node `(mh-e)'.
3371 `message-user-agent' -- use the Gnus Message package.
3372 See Info node `(message)'.
3373 `gnus-user-agent' -- like `message-user-agent', but with Gnus
3374 paraphernalia, particularly the Gcc: header for
3375 archiving.
3377 Additional valid symbols may be available; check with the author of
3378 your package for details. The function should return non-nil if it
3379 succeeds.
3381 See also `read-mail-command' concerning reading mail."
3382 :type '(radio (function-item :tag "Default Emacs mail"
3383 :format "%t\n"
3384 sendmail-user-agent)
3385 (function-item :tag "Emacs interface to MH"
3386 :format "%t\n"
3387 mh-e-user-agent)
3388 (function-item :tag "Gnus Message package"
3389 :format "%t\n"
3390 message-user-agent)
3391 (function-item :tag "Gnus Message with full Gnus features"
3392 :format "%t\n"
3393 gnus-user-agent)
3394 (function :tag "Other"))
3395 :group 'mail)
3397 (defun define-mail-user-agent (symbol composefunc sendfunc
3398 &optional abortfunc hookvar)
3399 "Define a symbol to identify a mail-sending package for `mail-user-agent'.
3401 SYMBOL can be any Lisp symbol. Its function definition and/or
3402 value as a variable do not matter for this usage; we use only certain
3403 properties on its property list, to encode the rest of the arguments.
3405 COMPOSEFUNC is program callable function that composes an outgoing
3406 mail message buffer. This function should set up the basics of the
3407 buffer without requiring user interaction. It should populate the
3408 standard mail headers, leaving the `to:' and `subject:' headers blank
3409 by default.
3411 COMPOSEFUNC should accept several optional arguments--the same
3412 arguments that `compose-mail' takes. See that function's documentation.
3414 SENDFUNC is the command a user would run to send the message.
3416 Optional ABORTFUNC is the command a user would run to abort the
3417 message. For mail packages that don't have a separate abort function,
3418 this can be `kill-buffer' (the equivalent of omitting this argument).
3420 Optional HOOKVAR is a hook variable that gets run before the message
3421 is actually sent. Callers that use the `mail-user-agent' may
3422 install a hook function temporarily on this hook variable.
3423 If HOOKVAR is nil, `mail-send-hook' is used.
3425 The properties used on SYMBOL are `composefunc', `sendfunc',
3426 `abortfunc', and `hookvar'."
3427 (put symbol 'composefunc composefunc)
3428 (put symbol 'sendfunc sendfunc)
3429 (put symbol 'abortfunc (or abortfunc 'kill-buffer))
3430 (put symbol 'hookvar (or hookvar 'mail-send-hook)))
3432 (define-mail-user-agent 'sendmail-user-agent
3433 'sendmail-user-agent-compose
3434 'mail-send-and-exit)
3436 (defun rfc822-goto-eoh ()
3437 ;; Go to header delimiter line in a mail message, following RFC822 rules
3438 (goto-char (point-min))
3439 (when (re-search-forward
3440 "^\\([:\n]\\|[^: \t\n]+[ \t\n]\\)" nil 'move)
3441 (goto-char (match-beginning 0))))
3443 (defun sendmail-user-agent-compose (&optional to subject other-headers continue
3444 switch-function yank-action
3445 send-actions)
3446 (if switch-function
3447 (let ((special-display-buffer-names nil)
3448 (special-display-regexps nil)
3449 (same-window-buffer-names nil)
3450 (same-window-regexps nil))
3451 (funcall switch-function "*mail*")))
3452 (let ((cc (cdr (assoc-ignore-case "cc" other-headers)))
3453 (in-reply-to (cdr (assoc-ignore-case "in-reply-to" other-headers)))
3454 (body (cdr (assoc-ignore-case "body" other-headers))))
3455 (or (mail continue to subject in-reply-to cc yank-action send-actions)
3456 continue
3457 (error "Message aborted"))
3458 (save-excursion
3459 (rfc822-goto-eoh)
3460 (while other-headers
3461 (unless (member-ignore-case (car (car other-headers))
3462 '("in-reply-to" "cc" "body"))
3463 (insert (car (car other-headers)) ": "
3464 (cdr (car other-headers)) "\n"))
3465 (setq other-headers (cdr other-headers)))
3466 (when body
3467 (forward-line 1)
3468 (insert body))
3469 t)))
3471 (define-mail-user-agent 'mh-e-user-agent
3472 'mh-smail-batch 'mh-send-letter 'mh-fully-kill-draft
3473 'mh-before-send-letter-hook)
3475 (defun compose-mail (&optional to subject other-headers continue
3476 switch-function yank-action send-actions)
3477 "Start composing a mail message to send.
3478 This uses the user's chosen mail composition package
3479 as selected with the variable `mail-user-agent'.
3480 The optional arguments TO and SUBJECT specify recipients
3481 and the initial Subject field, respectively.
3483 OTHER-HEADERS is an alist specifying additional
3484 header fields. Elements look like (HEADER . VALUE) where both
3485 HEADER and VALUE are strings.
3487 CONTINUE, if non-nil, says to continue editing a message already
3488 being composed.
3490 SWITCH-FUNCTION, if non-nil, is a function to use to
3491 switch to and display the buffer used for mail composition.
3493 YANK-ACTION, if non-nil, is an action to perform, if and when necessary,
3494 to insert the raw text of the message being replied to.
3495 It has the form (FUNCTION . ARGS). The user agent will apply
3496 FUNCTION to ARGS, to insert the raw text of the original message.
3497 \(The user agent will also run `mail-citation-hook', *after* the
3498 original text has been inserted in this way.)
3500 SEND-ACTIONS is a list of actions to call when the message is sent.
3501 Each action has the form (FUNCTION . ARGS)."
3502 (interactive
3503 (list nil nil nil current-prefix-arg))
3504 (let ((function (get mail-user-agent 'composefunc)))
3505 (funcall function to subject other-headers continue
3506 switch-function yank-action send-actions)))
3508 (defun compose-mail-other-window (&optional to subject other-headers continue
3509 yank-action send-actions)
3510 "Like \\[compose-mail], but edit the outgoing message in another window."
3511 (interactive
3512 (list nil nil nil current-prefix-arg))
3513 (compose-mail to subject other-headers continue
3514 'switch-to-buffer-other-window yank-action send-actions))
3517 (defun compose-mail-other-frame (&optional to subject other-headers continue
3518 yank-action send-actions)
3519 "Like \\[compose-mail], but edit the outgoing message in another frame."
3520 (interactive
3521 (list nil nil nil current-prefix-arg))
3522 (compose-mail to subject other-headers continue
3523 'switch-to-buffer-other-frame yank-action send-actions))
3525 (defvar set-variable-value-history nil
3526 "History of values entered with `set-variable'.")
3528 (defun set-variable (var val)
3529 "Set VARIABLE to VALUE. VALUE is a Lisp object.
3530 When using this interactively, enter a Lisp object for VALUE.
3531 If you want VALUE to be a string, you must surround it with doublequotes.
3532 VALUE is used literally, not evaluated.
3534 If VARIABLE has a `variable-interactive' property, that is used as if
3535 it were the arg to `interactive' (which see) to interactively read VALUE.
3537 If VARIABLE has been defined with `defcustom', then the type information
3538 in the definition is used to check that VALUE is valid."
3539 (interactive
3540 (let* ((default-var (variable-at-point))
3541 (var (if (symbolp default-var)
3542 (read-variable (format "Set variable (default %s): " default-var)
3543 default-var)
3544 (read-variable "Set variable: ")))
3545 (minibuffer-help-form '(describe-variable var))
3546 (prop (get var 'variable-interactive))
3547 (prompt (format "Set %s to value: " var))
3548 (val (if prop
3549 ;; Use VAR's `variable-interactive' property
3550 ;; as an interactive spec for prompting.
3551 (call-interactively `(lambda (arg)
3552 (interactive ,prop)
3553 arg))
3554 (read
3555 (read-string prompt nil
3556 'set-variable-value-history)))))
3557 (list var val)))
3559 (let ((type (get var 'custom-type)))
3560 (when type
3561 ;; Match with custom type.
3562 (require 'cus-edit)
3563 (setq type (widget-convert type))
3564 (unless (widget-apply type :match val)
3565 (error "Value `%S' does not match type %S of %S"
3566 val (car type) var))))
3567 (set var val)
3569 ;; Force a thorough redisplay for the case that the variable
3570 ;; has an effect on the display, like `tab-width' has.
3571 (force-mode-line-update))
3573 ;; Define the major mode for lists of completions.
3575 (defvar completion-list-mode-map nil
3576 "Local map for completion list buffers.")
3577 (or completion-list-mode-map
3578 (let ((map (make-sparse-keymap)))
3579 (define-key map [mouse-2] 'mouse-choose-completion)
3580 (define-key map [down-mouse-2] nil)
3581 (define-key map "\C-m" 'choose-completion)
3582 (define-key map "\e\e\e" 'delete-completion-window)
3583 (define-key map [left] 'previous-completion)
3584 (define-key map [right] 'next-completion)
3585 (setq completion-list-mode-map map)))
3587 ;; Completion mode is suitable only for specially formatted data.
3588 (put 'completion-list-mode 'mode-class 'special)
3590 (defvar completion-reference-buffer nil
3591 "Record the buffer that was current when the completion list was requested.
3592 This is a local variable in the completion list buffer.
3593 Initial value is nil to avoid some compiler warnings.")
3595 (defvar completion-no-auto-exit nil
3596 "Non-nil means `choose-completion-string' should never exit the minibuffer.
3597 This also applies to other functions such as `choose-completion'
3598 and `mouse-choose-completion'.")
3600 (defvar completion-base-size nil
3601 "Number of chars at beginning of minibuffer not involved in completion.
3602 This is a local variable in the completion list buffer
3603 but it talks about the buffer in `completion-reference-buffer'.
3604 If this is nil, it means to compare text to determine which part
3605 of the tail end of the buffer's text is involved in completion.")
3607 (defun delete-completion-window ()
3608 "Delete the completion list window.
3609 Go to the window from which completion was requested."
3610 (interactive)
3611 (let ((buf completion-reference-buffer))
3612 (if (one-window-p t)
3613 (if (window-dedicated-p (selected-window))
3614 (delete-frame (selected-frame)))
3615 (delete-window (selected-window))
3616 (if (get-buffer-window buf)
3617 (select-window (get-buffer-window buf))))))
3619 (defun previous-completion (n)
3620 "Move to the previous item in the completion list."
3621 (interactive "p")
3622 (next-completion (- n)))
3624 (defun next-completion (n)
3625 "Move to the next item in the completion list.
3626 With prefix argument N, move N items (negative N means move backward)."
3627 (interactive "p")
3628 (let ((beg (point-min)) (end (point-max)))
3629 (while (and (> n 0) (not (eobp)))
3630 ;; If in a completion, move to the end of it.
3631 (when (get-text-property (point) 'mouse-face)
3632 (goto-char (next-single-property-change (point) 'mouse-face nil end)))
3633 ;; Move to start of next one.
3634 (unless (get-text-property (point) 'mouse-face)
3635 (goto-char (next-single-property-change (point) 'mouse-face nil end)))
3636 (setq n (1- n)))
3637 (while (and (< n 0) (not (bobp)))
3638 (let ((prop (get-text-property (1- (point)) 'mouse-face)))
3639 ;; If in a completion, move to the start of it.
3640 (when (and prop (eq prop (get-text-property (point) 'mouse-face)))
3641 (goto-char (previous-single-property-change
3642 (point) 'mouse-face nil beg)))
3643 ;; Move to end of the previous completion.
3644 (unless (or (bobp) (get-text-property (1- (point)) 'mouse-face))
3645 (goto-char (previous-single-property-change
3646 (point) 'mouse-face nil beg)))
3647 ;; Move to the start of that one.
3648 (goto-char (previous-single-property-change
3649 (point) 'mouse-face nil beg))
3650 (setq n (1+ n))))))
3652 (defun choose-completion ()
3653 "Choose the completion that point is in or next to."
3654 (interactive)
3655 (let (beg end completion (buffer completion-reference-buffer)
3656 (base-size completion-base-size))
3657 (if (and (not (eobp)) (get-text-property (point) 'mouse-face))
3658 (setq end (point) beg (1+ (point))))
3659 (if (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face))
3660 (setq end (1- (point)) beg (point)))
3661 (if (null beg)
3662 (error "No completion here"))
3663 (setq beg (previous-single-property-change beg 'mouse-face))
3664 (setq end (or (next-single-property-change end 'mouse-face) (point-max)))
3665 (setq completion (buffer-substring beg end))
3666 (let ((owindow (selected-window)))
3667 (if (and (one-window-p t 'selected-frame)
3668 (window-dedicated-p (selected-window)))
3669 ;; This is a special buffer's frame
3670 (iconify-frame (selected-frame))
3671 (or (window-dedicated-p (selected-window))
3672 (bury-buffer)))
3673 (select-window owindow))
3674 (choose-completion-string completion buffer base-size)))
3676 ;; Delete the longest partial match for STRING
3677 ;; that can be found before POINT.
3678 (defun choose-completion-delete-max-match (string)
3679 (let ((opoint (point))
3680 (len (min (length string)
3681 (- (point) (point-min)))))
3682 (goto-char (- (point) (length string)))
3683 (if completion-ignore-case
3684 (setq string (downcase string)))
3685 (while (and (> len 0)
3686 (let ((tail (buffer-substring (point)
3687 (+ (point) len))))
3688 (if completion-ignore-case
3689 (setq tail (downcase tail)))
3690 (not (string= tail (substring string 0 len)))))
3691 (setq len (1- len))
3692 (forward-char 1))
3693 (delete-char len)))
3695 ;; Switch to BUFFER and insert the completion choice CHOICE.
3696 ;; BASE-SIZE, if non-nil, says how many characters of BUFFER's text
3697 ;; to keep. If it is nil, use choose-completion-delete-max-match instead.
3699 ;; If BUFFER is the minibuffer, exit the minibuffer
3700 ;; unless it is reading a file name and CHOICE is a directory,
3701 ;; or completion-no-auto-exit is non-nil.
3702 (defun choose-completion-string (choice &optional buffer base-size)
3703 (let ((buffer (or buffer completion-reference-buffer))
3704 (mini-p (string-match "\\` \\*Minibuf-[0-9]+\\*\\'" (buffer-name buffer))))
3705 ;; If BUFFER is a minibuffer, barf unless it's the currently
3706 ;; active minibuffer.
3707 (if (and mini-p
3708 (or (not (active-minibuffer-window))
3709 (not (equal buffer
3710 (window-buffer (active-minibuffer-window))))))
3711 (error "Minibuffer is not active for completion")
3712 ;; Insert the completion into the buffer where completion was requested.
3713 (set-buffer buffer)
3714 (if base-size
3715 (delete-region (+ base-size (if mini-p
3716 (minibuffer-prompt-end)
3717 (point-min)))
3718 (point))
3719 (choose-completion-delete-max-match choice))
3720 (insert choice)
3721 (remove-text-properties (- (point) (length choice)) (point)
3722 '(mouse-face nil))
3723 ;; Update point in the window that BUFFER is showing in.
3724 (let ((window (get-buffer-window buffer t)))
3725 (set-window-point window (point)))
3726 ;; If completing for the minibuffer, exit it with this choice.
3727 (and (not completion-no-auto-exit)
3728 (equal buffer (window-buffer (minibuffer-window)))
3729 minibuffer-completion-table
3730 ;; If this is reading a file name, and the file name chosen
3731 ;; is a directory, don't exit the minibuffer.
3732 (if (and (eq minibuffer-completion-table 'read-file-name-internal)
3733 (file-directory-p (field-string (point-max))))
3734 (let ((mini (active-minibuffer-window)))
3735 (select-window mini)
3736 (when minibuffer-auto-raise
3737 (raise-frame (window-frame mini))))
3738 (exit-minibuffer))))))
3740 (defun completion-list-mode ()
3741 "Major mode for buffers showing lists of possible completions.
3742 Type \\<completion-list-mode-map>\\[choose-completion] in the completion list\
3743 to select the completion near point.
3744 Use \\<completion-list-mode-map>\\[mouse-choose-completion] to select one\
3745 with the mouse."
3746 (interactive)
3747 (kill-all-local-variables)
3748 (use-local-map completion-list-mode-map)
3749 (setq mode-name "Completion List")
3750 (setq major-mode 'completion-list-mode)
3751 (make-local-variable 'completion-base-size)
3752 (setq completion-base-size nil)
3753 (run-hooks 'completion-list-mode-hook))
3755 (defun completion-list-mode-finish ()
3756 "Finish setup of the completions buffer.
3757 Called from `temp-buffer-show-hook'."
3758 (when (eq major-mode 'completion-list-mode)
3759 (toggle-read-only 1)))
3761 (add-hook 'temp-buffer-show-hook 'completion-list-mode-finish)
3763 (defvar completion-setup-hook nil
3764 "Normal hook run at the end of setting up a completion list buffer.
3765 When this hook is run, the current buffer is the one in which the
3766 command to display the completion list buffer was run.
3767 The completion list buffer is available as the value of `standard-output'.")
3769 ;; This function goes in completion-setup-hook, so that it is called
3770 ;; after the text of the completion list buffer is written.
3772 (defun completion-setup-function ()
3773 (save-excursion
3774 (let ((mainbuf (current-buffer)))
3775 (set-buffer standard-output)
3776 (completion-list-mode)
3777 (make-local-variable 'completion-reference-buffer)
3778 (setq completion-reference-buffer mainbuf)
3779 (if (eq minibuffer-completion-table 'read-file-name-internal)
3780 ;; For file name completion,
3781 ;; use the number of chars before the start of the
3782 ;; last file name component.
3783 (setq completion-base-size
3784 (save-excursion
3785 (set-buffer mainbuf)
3786 (goto-char (point-max))
3787 (skip-chars-backward (format "^%c" directory-sep-char))
3788 (- (point) (minibuffer-prompt-end))))
3789 ;; Otherwise, in minibuffer, the whole input is being completed.
3790 (save-match-data
3791 (if (string-match "\\` \\*Minibuf-[0-9]+\\*\\'"
3792 (buffer-name mainbuf))
3793 (setq completion-base-size 0))))
3794 (goto-char (point-min))
3795 (if (display-mouse-p)
3796 (insert (substitute-command-keys
3797 "Click \\[mouse-choose-completion] on a completion to select it.\n")))
3798 (insert (substitute-command-keys
3799 "In this buffer, type \\[choose-completion] to \
3800 select the completion near point.\n\n")))))
3802 (add-hook 'completion-setup-hook 'completion-setup-function)
3804 (define-key minibuffer-local-completion-map [prior]
3805 'switch-to-completions)
3806 (define-key minibuffer-local-must-match-map [prior]
3807 'switch-to-completions)
3808 (define-key minibuffer-local-completion-map "\M-v"
3809 'switch-to-completions)
3810 (define-key minibuffer-local-must-match-map "\M-v"
3811 'switch-to-completions)
3813 (defun switch-to-completions ()
3814 "Select the completion list window."
3815 (interactive)
3816 ;; Make sure we have a completions window.
3817 (or (get-buffer-window "*Completions*")
3818 (minibuffer-completion-help))
3819 (let ((window (get-buffer-window "*Completions*")))
3820 (when window
3821 (select-window window)
3822 (goto-char (point-min))
3823 (search-forward "\n\n")
3824 (forward-line 1))))
3826 ;; Support keyboard commands to turn on various modifiers.
3828 ;; These functions -- which are not commands -- each add one modifier
3829 ;; to the following event.
3831 (defun event-apply-alt-modifier (ignore-prompt)
3832 "Add the Alt modifier to the following event.
3833 For example, type \\[event-apply-alt-modifier] & to enter Alt-&."
3834 (vector (event-apply-modifier (read-event) 'alt 22 "A-")))
3835 (defun event-apply-super-modifier (ignore-prompt)
3836 "Add the Super modifier to the following event.
3837 For example, type \\[event-apply-super-modifier] & to enter Super-&."
3838 (vector (event-apply-modifier (read-event) 'super 23 "s-")))
3839 (defun event-apply-hyper-modifier (ignore-prompt)
3840 "Add the Hyper modifier to the following event.
3841 For example, type \\[event-apply-hyper-modifier] & to enter Hyper-&."
3842 (vector (event-apply-modifier (read-event) 'hyper 24 "H-")))
3843 (defun event-apply-shift-modifier (ignore-prompt)
3844 "Add the Shift modifier to the following event.
3845 For example, type \\[event-apply-shift-modifier] & to enter Shift-&."
3846 (vector (event-apply-modifier (read-event) 'shift 25 "S-")))
3847 (defun event-apply-control-modifier (ignore-prompt)
3848 "Add the Ctrl modifier to the following event.
3849 For example, type \\[event-apply-control-modifier] & to enter Ctrl-&."
3850 (vector (event-apply-modifier (read-event) 'control 26 "C-")))
3851 (defun event-apply-meta-modifier (ignore-prompt)
3852 "Add the Meta modifier to the following event.
3853 For example, type \\[event-apply-meta-modifier] & to enter Meta-&."
3854 (vector (event-apply-modifier (read-event) 'meta 27 "M-")))
3856 (defun event-apply-modifier (event symbol lshiftby prefix)
3857 "Apply a modifier flag to event EVENT.
3858 SYMBOL is the name of this modifier, as a symbol.
3859 LSHIFTBY is the numeric value of this modifier, in keyboard events.
3860 PREFIX is the string that represents this modifier in an event type symbol."
3861 (if (numberp event)
3862 (cond ((eq symbol 'control)
3863 (if (and (<= (downcase event) ?z)
3864 (>= (downcase event) ?a))
3865 (- (downcase event) ?a -1)
3866 (if (and (<= (downcase event) ?Z)
3867 (>= (downcase event) ?A))
3868 (- (downcase event) ?A -1)
3869 (logior (lsh 1 lshiftby) event))))
3870 ((eq symbol 'shift)
3871 (if (and (<= (downcase event) ?z)
3872 (>= (downcase event) ?a))
3873 (upcase event)
3874 (logior (lsh 1 lshiftby) event)))
3876 (logior (lsh 1 lshiftby) event)))
3877 (if (memq symbol (event-modifiers event))
3878 event
3879 (let ((event-type (if (symbolp event) event (car event))))
3880 (setq event-type (intern (concat prefix (symbol-name event-type))))
3881 (if (symbolp event)
3882 event-type
3883 (cons event-type (cdr event)))))))
3885 (define-key function-key-map [?\C-x ?@ ?h] 'event-apply-hyper-modifier)
3886 (define-key function-key-map [?\C-x ?@ ?s] 'event-apply-super-modifier)
3887 (define-key function-key-map [?\C-x ?@ ?m] 'event-apply-meta-modifier)
3888 (define-key function-key-map [?\C-x ?@ ?a] 'event-apply-alt-modifier)
3889 (define-key function-key-map [?\C-x ?@ ?S] 'event-apply-shift-modifier)
3890 (define-key function-key-map [?\C-x ?@ ?c] 'event-apply-control-modifier)
3892 ;;;; Keypad support.
3894 ;;; Make the keypad keys act like ordinary typing keys. If people add
3895 ;;; bindings for the function key symbols, then those bindings will
3896 ;;; override these, so this shouldn't interfere with any existing
3897 ;;; bindings.
3899 ;; Also tell read-char how to handle these keys.
3900 (mapc
3901 (lambda (keypad-normal)
3902 (let ((keypad (nth 0 keypad-normal))
3903 (normal (nth 1 keypad-normal)))
3904 (put keypad 'ascii-character normal)
3905 (define-key function-key-map (vector keypad) (vector normal))))
3906 '((kp-0 ?0) (kp-1 ?1) (kp-2 ?2) (kp-3 ?3) (kp-4 ?4)
3907 (kp-5 ?5) (kp-6 ?6) (kp-7 ?7) (kp-8 ?8) (kp-9 ?9)
3908 (kp-space ?\ )
3909 (kp-tab ?\t)
3910 (kp-enter ?\r)
3911 (kp-multiply ?*)
3912 (kp-add ?+)
3913 (kp-separator ?,)
3914 (kp-subtract ?-)
3915 (kp-decimal ?.)
3916 (kp-divide ?/)
3917 (kp-equal ?=)))
3919 ;;;;
3920 ;;;; forking a twin copy of a buffer.
3921 ;;;;
3923 (defvar clone-buffer-hook nil
3924 "Normal hook to run in the new buffer at the end of `clone-buffer'.")
3926 (defun clone-process (process &optional newname)
3927 "Create a twin copy of PROCESS.
3928 If NEWNAME is nil, it defaults to PROCESS' name;
3929 NEWNAME is modified by adding or incrementing <N> at the end as necessary.
3930 If PROCESS is associated with a buffer, the new process will be associated
3931 with the current buffer instead.
3932 Returns nil if PROCESS has already terminated."
3933 (setq newname (or newname (process-name process)))
3934 (if (string-match "<[0-9]+>\\'" newname)
3935 (setq newname (substring newname 0 (match-beginning 0))))
3936 (when (memq (process-status process) '(run stop open))
3937 (let* ((process-connection-type (process-tty-name process))
3938 (old-kwoq (process-kill-without-query process nil))
3939 (new-process
3940 (if (memq (process-status process) '(open))
3941 (apply 'open-network-stream newname
3942 (if (process-buffer process) (current-buffer))
3943 (process-contact process))
3944 (apply 'start-process newname
3945 (if (process-buffer process) (current-buffer))
3946 (process-command process)))))
3947 (process-kill-without-query new-process old-kwoq)
3948 (process-kill-without-query process old-kwoq)
3949 (set-process-inherit-coding-system-flag
3950 new-process (process-inherit-coding-system-flag process))
3951 (set-process-filter new-process (process-filter process))
3952 (set-process-sentinel new-process (process-sentinel process))
3953 new-process)))
3955 ;; things to maybe add (currently partly covered by `funcall mode':
3956 ;; - syntax-table
3957 ;; - overlays
3958 (defun clone-buffer (&optional newname display-flag)
3959 "Create a twin copy of the current buffer.
3960 If NEWNAME is nil, it defaults to the current buffer's name;
3961 NEWNAME is modified by adding or incrementing <N> at the end as necessary.
3963 If DISPLAY-FLAG is non-nil, the new buffer is shown with `pop-to-buffer'.
3964 This runs the normal hook `clone-buffer-hook' in the new buffer
3965 after it has been set up properly in other respects."
3966 (interactive
3967 (progn
3968 (if buffer-file-name
3969 (error "Cannot clone a file-visiting buffer"))
3970 (if (get major-mode 'no-clone)
3971 (error "Cannot clone a buffer in %s mode" mode-name))
3972 (list (if current-prefix-arg (read-string "Name: "))
3973 t)))
3974 (if buffer-file-name
3975 (error "Cannot clone a file-visiting buffer"))
3976 (if (get major-mode 'no-clone)
3977 (error "Cannot clone a buffer in %s mode" mode-name))
3978 (setq newname (or newname (buffer-name)))
3979 (if (string-match "<[0-9]+>\\'" newname)
3980 (setq newname (substring newname 0 (match-beginning 0))))
3981 (let ((buf (current-buffer))
3982 (ptmin (point-min))
3983 (ptmax (point-max))
3984 (pt (point))
3985 (mk (if mark-active (mark t)))
3986 (modified (buffer-modified-p))
3987 (mode major-mode)
3988 (lvars (buffer-local-variables))
3989 (process (get-buffer-process (current-buffer)))
3990 (new (generate-new-buffer (or newname (buffer-name)))))
3991 (save-restriction
3992 (widen)
3993 (with-current-buffer new
3994 (insert-buffer-substring buf)))
3995 (with-current-buffer new
3996 (narrow-to-region ptmin ptmax)
3997 (goto-char pt)
3998 (if mk (set-mark mk))
3999 (set-buffer-modified-p modified)
4001 ;; Clone the old buffer's process, if any.
4002 (when process (clone-process process))
4004 ;; Now set up the major mode.
4005 (funcall mode)
4007 ;; Set up other local variables.
4008 (mapcar (lambda (v)
4009 (condition-case () ;in case var is read-only
4010 (if (symbolp v)
4011 (makunbound v)
4012 (set (make-local-variable (car v)) (cdr v)))
4013 (error nil)))
4014 lvars)
4016 ;; Run any hooks (typically set up by the major mode
4017 ;; for cloning to work properly).
4018 (run-hooks 'clone-buffer-hook))
4019 (if display-flag (pop-to-buffer new))
4020 new))
4023 (defun clone-indirect-buffer (newname display-flag &optional norecord)
4024 "Create an indirect buffer that is a twin copy of the current buffer.
4026 Give the indirect buffer name NEWNAME. Interactively, read NEW-NAME
4027 from the minibuffer when invoked with a prefix arg. If NEWNAME is nil
4028 or if not called with a prefix arg, NEWNAME defaults to the current
4029 buffer's name. The name is modified by adding a `<N>' suffix to it
4030 or by incrementing the N in an existing suffix.
4032 DISPLAY-FLAG non-nil means show the new buffer with `pop-to-buffer'.
4033 This is always done when called interactively.
4035 Optional last arg NORECORD non-nil means do not put this buffer at the
4036 front of the list of recently selected ones."
4037 (interactive
4038 (progn
4039 (if (get major-mode 'no-clone-indirect)
4040 (error "Cannot indirectly clone a buffer in %s mode" mode-name))
4041 (list (if current-prefix-arg
4042 (read-string "BName of indirect buffer: "))
4043 t)))
4044 (if (get major-mode 'no-clone-indirect)
4045 (error "Cannot indirectly clone a buffer in %s mode" mode-name))
4046 (setq newname (or newname (buffer-name)))
4047 (if (string-match "<[0-9]+>\\'" newname)
4048 (setq newname (substring newname 0 (match-beginning 0))))
4049 (let* ((name (generate-new-buffer-name newname))
4050 (buffer (make-indirect-buffer (current-buffer) name t)))
4051 (when display-flag
4052 (pop-to-buffer buffer norecord))
4053 buffer))
4056 (defun clone-indirect-buffer-other-window (buffer &optional norecord)
4057 "Create an indirect buffer that is a twin copy of BUFFER.
4058 Select the new buffer in another window.
4059 Optional second arg NORECORD non-nil means do not put this buffer at
4060 the front of the list of recently selected ones."
4061 (interactive "bClone buffer in other window: ")
4062 (let ((popup-windows t))
4063 (set-buffer buffer)
4064 (clone-indirect-buffer nil t norecord)))
4066 (define-key ctl-x-4-map "c" 'clone-indirect-buffer-other-window)
4069 ;;; Syntax stuff.
4071 (defconst syntax-code-table
4072 '((?\ 0 "whitespace")
4073 (?- 0 "whitespace")
4074 (?. 1 "punctuation")
4075 (?w 2 "word")
4076 (?_ 3 "symbol")
4077 (?\( 4 "open parenthesis")
4078 (?\) 5 "close parenthesis")
4079 (?\' 6 "expression prefix")
4080 (?\" 7 "string quote")
4081 (?$ 8 "paired delimiter")
4082 (?\\ 9 "escape")
4083 (?/ 10 "character quote")
4084 (?< 11 "comment start")
4085 (?> 12 "comment end")
4086 (?@ 13 "inherit")
4087 (nil 14 "comment fence")
4088 (nil 15 "string fence"))
4089 "Alist of forms (CHAR CODE DESCRIPTION) mapping characters to syntax info.
4090 CHAR is a character that is allowed as first char in the string
4091 specifying the syntax when calling `modify-syntax-entry'. CODE is the
4092 corresponing syntax code as it is stored in a syntax cell, and
4093 can be used as value of a `syntax-table' property.
4094 DESCRIPTION is the descriptive string for the syntax.")
4097 ;;; Handling of Backspace and Delete keys.
4099 (defcustom normal-erase-is-backspace nil
4100 "If non-nil, Delete key deletes forward and Backspace key deletes backward.
4102 On window systems, the default value of this option is chosen
4103 according to the keyboard used. If the keyboard has both a Backspace
4104 key and a Delete key, and both are mapped to their usual meanings, the
4105 option's default value is set to t, so that Backspace can be used to
4106 delete backward, and Delete can be used to delete forward.
4108 If not running under a window system, customizing this option accomplishes
4109 a similar effect by mapping C-h, which is usually generated by the
4110 Backspace key, to DEL, and by mapping DEL to C-d via
4111 `keyboard-translate'. The former functionality of C-h is available on
4112 the F1 key. You should probably not use this setting if you don't
4113 have both Backspace, Delete and F1 keys.
4115 Setting this variable with setq doesn't take effect. Programmatically,
4116 call `normal-erase-is-backspace-mode' (which see) instead."
4117 :type 'boolean
4118 :group 'editing-basics
4119 :version "21.1"
4120 :set (lambda (symbol value)
4121 ;; The fboundp is because of a problem with :set when
4122 ;; dumping Emacs. It doesn't really matter.
4123 (if (fboundp 'normal-erase-is-backspace-mode)
4124 (normal-erase-is-backspace-mode (or value 0))
4125 (set-default symbol value))))
4128 (defun normal-erase-is-backspace-mode (&optional arg)
4129 "Toggle the Erase and Delete mode of the Backspace and Delete keys.
4131 With numeric arg, turn the mode on if and only if ARG is positive.
4133 On window systems, when this mode is on, Delete is mapped to C-d and
4134 Backspace is mapped to DEL; when this mode is off, both Delete and
4135 Backspace are mapped to DEL. (The remapping goes via
4136 `function-key-map', so binding Delete or Backspace in the global or
4137 local keymap will override that.)
4139 In addition, on window systems, the bindings of C-Delete, M-Delete,
4140 C-M-Delete, C-Backspace, M-Backspace, and C-M-Backspace are changed in
4141 the global keymap in accordance with the functionality of Delete and
4142 Backspace. For example, if Delete is remapped to C-d, which deletes
4143 forward, C-Delete is bound to `kill-word', but if Delete is remapped
4144 to DEL, which deletes backward, C-Delete is bound to
4145 `backward-kill-word'.
4147 If not running on a window system, a similar effect is accomplished by
4148 remapping C-h (normally produced by the Backspace key) and DEL via
4149 `keyboard-translate': if this mode is on, C-h is mapped to DEL and DEL
4150 to C-d; if it's off, the keys are not remapped.
4152 When not running on a window system, and this mode is turned on, the
4153 former functionality of C-h is available on the F1 key. You should
4154 probably not turn on this mode on a text-only terminal if you don't
4155 have both Backspace, Delete and F1 keys.
4157 See also `normal-erase-is-backspace'."
4158 (interactive "P")
4159 (setq normal-erase-is-backspace
4160 (if arg
4161 (> (prefix-numeric-value arg) 0)
4162 (not normal-erase-is-backspace)))
4164 (cond ((or (memq window-system '(x w32 mac pc))
4165 (memq system-type '(ms-dos windows-nt)))
4166 (let ((bindings
4167 `(([C-delete] [C-backspace])
4168 ([M-delete] [M-backspace])
4169 ([C-M-delete] [C-M-backspace])
4170 (,esc-map
4171 [C-delete] [C-backspace])))
4172 (old-state (lookup-key function-key-map [delete])))
4174 (if normal-erase-is-backspace
4175 (progn
4176 (define-key function-key-map [delete] [?\C-d])
4177 (define-key function-key-map [kp-delete] [?\C-d])
4178 (define-key function-key-map [backspace] [?\C-?]))
4179 (define-key function-key-map [delete] [?\C-?])
4180 (define-key function-key-map [kp-delete] [?\C-?])
4181 (define-key function-key-map [backspace] [?\C-?]))
4183 ;; Maybe swap bindings of C-delete and C-backspace, etc.
4184 (unless (equal old-state (lookup-key function-key-map [delete]))
4185 (dolist (binding bindings)
4186 (let ((map global-map))
4187 (when (keymapp (car binding))
4188 (setq map (car binding) binding (cdr binding)))
4189 (let* ((key1 (nth 0 binding))
4190 (key2 (nth 1 binding))
4191 (binding1 (lookup-key map key1))
4192 (binding2 (lookup-key map key2)))
4193 (define-key map key1 binding2)
4194 (define-key map key2 binding1)))))))
4196 (if normal-erase-is-backspace
4197 (progn
4198 (keyboard-translate ?\C-h ?\C-?)
4199 (keyboard-translate ?\C-? ?\C-d))
4200 (keyboard-translate ?\C-h ?\C-h)
4201 (keyboard-translate ?\C-? ?\C-?))))
4203 (run-hooks 'normal-erase-is-backspace-hook)
4204 (if (interactive-p)
4205 (message "Delete key deletes %s"
4206 (if normal-erase-is-backspace "forward" "backward"))))
4209 ;;; Misc
4211 (defun byte-compiling-files-p ()
4212 "Return t if currently byte-compiling files."
4213 (and (boundp 'byte-compile-current-file)
4214 (stringp byte-compile-current-file)))
4217 ;; Minibuffer prompt stuff.
4219 ;(defun minibuffer-prompt-modification (start end)
4220 ; (error "You cannot modify the prompt"))
4223 ;(defun minibuffer-prompt-insertion (start end)
4224 ; (let ((inhibit-modification-hooks t))
4225 ; (delete-region start end)
4226 ; ;; Discard undo information for the text insertion itself
4227 ; ;; and for the text deletion.above.
4228 ; (when (consp buffer-undo-list)
4229 ; (setq buffer-undo-list (cddr buffer-undo-list)))
4230 ; (message "You cannot modify the prompt")))
4233 ;(setq minibuffer-prompt-properties
4234 ; (list 'modification-hooks '(minibuffer-prompt-modification)
4235 ; 'insert-in-front-hooks '(minibuffer-prompt-insertion)))
4238 ;;; simple.el ends here