(python-open-block-statement-p): Fix
[emacs.git] / lisp / simple.el
blob2f056e9d462e4ec04b6c082c3b45e1946cb2316f
1 ;;; simple.el --- basic editing commands for Emacs
3 ;; Copyright (C) 1985, 86, 87, 93, 94, 95, 96, 97, 98, 99,
4 ;; 2000, 01, 02, 03, 04
5 ;; Free Software Foundation, Inc.
7 ;; Maintainer: FSF
8 ;; Keywords: internal
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
27 ;;; Commentary:
29 ;; A grab-bag of basic Emacs commands not specifically related to some
30 ;; major mode or to file-handling.
32 ;;; Code:
34 (eval-when-compile
35 (autoload 'widget-convert "wid-edit")
36 (autoload 'shell-mode "shell"))
39 (defgroup killing nil
40 "Killing and yanking commands."
41 :group 'editing)
43 (defgroup paren-matching nil
44 "Highlight (un)matching of parens and expressions."
45 :group 'matching)
47 (define-key global-map [?\C-x right] 'next-buffer)
48 (define-key global-map [?\C-x left] 'prev-buffer)
49 (defun next-buffer ()
50 "Switch to the next buffer in cyclic order."
51 (interactive)
52 (let ((buffer (current-buffer)))
53 (switch-to-buffer (other-buffer buffer))
54 (bury-buffer buffer)))
56 (defun prev-buffer ()
57 "Switch to the previous buffer in cyclic order."
58 (interactive)
59 (let ((list (nreverse (buffer-list)))
60 found)
61 (while (and (not found) list)
62 (let ((buffer (car list)))
63 (if (and (not (get-buffer-window buffer))
64 (not (string-match "\\` " (buffer-name buffer))))
65 (setq found buffer)))
66 (setq list (cdr list)))
67 (switch-to-buffer found)))
69 ;;; next-error support framework
70 (defvar next-error-last-buffer nil
71 "The most recent next-error buffer.
72 A buffer becomes most recent when its compilation, grep, or
73 similar mode is started, or when it is used with \\[next-error]
74 or \\[compile-goto-error].")
76 (defvar next-error-function nil
77 "Function to use to find the next error in the current buffer.
78 The function is called with 2 parameters:
79 ARG is an integer specifying by how many errors to move.
80 RESET is a boolean which, if non-nil, says to go back to the beginning
81 of the errors before moving.
82 Major modes providing compile-like functionality should set this variable
83 to indicate to `next-error' that this is a candidate buffer and how
84 to navigate in it.")
86 (make-variable-buffer-local 'next-error-function)
88 (defsubst next-error-buffer-p (buffer &optional extra-test)
89 "Test if BUFFER is a next-error capable buffer."
90 (with-current-buffer buffer
91 (or (and extra-test (funcall extra-test))
92 next-error-function)))
94 ;; Return a next-error capable buffer according to the following rules:
95 ;; 1. If the current buffer is a next-error capable buffer, return it.
96 ;; 2. If one window on the selected frame displays such buffer, return it.
97 ;; 3. If next-error-last-buffer is set to a live buffer, use that.
98 ;; 4. Otherwise, look for a next-error capable buffer in a buffer list.
99 ;; 5. Signal an error if there are none.
100 (defun next-error-find-buffer (&optional other-buffer extra-test)
101 (if (and (not other-buffer)
102 (next-error-buffer-p (current-buffer) extra-test))
103 ;; The current buffer is a next-error capable buffer.
104 (current-buffer)
106 (let ((window-buffers
107 (delete-dups
108 (delq nil
109 (mapcar (lambda (w)
110 (and (next-error-buffer-p (window-buffer w) extra-test)
111 (window-buffer w)))
112 (window-list))))))
113 (if other-buffer
114 (setq window-buffers (delq (current-buffer) window-buffers)))
115 (if (eq (length window-buffers) 1)
116 (car window-buffers)))
117 (if (and next-error-last-buffer (buffer-name next-error-last-buffer)
118 (next-error-buffer-p next-error-last-buffer extra-test)
119 (or (not other-buffer) (not (eq next-error-last-buffer
120 (current-buffer)))))
121 next-error-last-buffer
122 (let ((buffers (buffer-list)))
123 (while (and buffers (or (not (next-error-buffer-p (car buffers) extra-test))
124 (and other-buffer
125 (eq (car buffers) (current-buffer)))))
126 (setq buffers (cdr buffers)))
127 (if buffers
128 (car buffers)
129 (or (and other-buffer
130 (next-error-buffer-p (current-buffer) extra-test)
131 ;; The current buffer is a next-error capable buffer.
132 (progn
133 (if other-buffer
134 (message "This is the only next-error capable buffer."))
135 (current-buffer)))
136 (error "No next-error capable buffer found"))))))))
138 (defun next-error (arg &optional reset)
139 "Visit next next-error message and corresponding source code.
141 If all the error messages parsed so far have been processed already,
142 the message buffer is checked for new ones.
144 A prefix ARG specifies how many error messages to move;
145 negative means move back to previous error messages.
146 Just \\[universal-argument] as a prefix means reparse the error message buffer
147 and start at the first error.
149 The RESET argument specifies that we should restart from the beginning.
151 \\[next-error] normally uses the most recently started
152 compilation, grep, or occur buffer. It can also operate on any
153 buffer with output from the \\[compile], \\[grep] commands, or,
154 more generally, on any buffer in Compilation mode or with
155 Compilation Minor mode enabled, or any buffer in which
156 `next-error-function' is bound to an appropriate
157 function. To specify use of a particular buffer for error
158 messages, type \\[next-error] in that buffer.
160 Once \\[next-error] has chosen the buffer for error messages,
161 it stays with that buffer until you use it in some other buffer which
162 uses Compilation mode or Compilation Minor mode.
164 See variables `compilation-parse-errors-function' and
165 \`compilation-error-regexp-alist' for customization ideas."
166 (interactive "P")
167 (if (consp arg) (setq reset t arg nil))
168 (when (setq next-error-last-buffer (next-error-find-buffer))
169 ;; we know here that next-error-function is a valid symbol we can funcall
170 (with-current-buffer next-error-last-buffer
171 (funcall next-error-function (prefix-numeric-value arg) reset))))
173 (defalias 'goto-next-locus 'next-error)
174 (defalias 'next-match 'next-error)
176 (define-key ctl-x-map "`" 'next-error)
178 (defun previous-error (n)
179 "Visit previous next-error message and corresponding source code.
181 Prefix arg N says how many error messages to move backwards (or
182 forwards, if negative).
184 This operates on the output from the \\[compile] and \\[grep] commands."
185 (interactive "p")
186 (next-error (- n)))
188 (defun first-error (n)
189 "Restart at the first error.
190 Visit corresponding source code.
191 With prefix arg N, visit the source code of the Nth error.
192 This operates on the output from the \\[compile] command, for instance."
193 (interactive "p")
194 (next-error n t))
196 (defun next-error-no-select (n)
197 "Move point to the next error in the next-error buffer and highlight match.
198 Prefix arg N says how many error messages to move forwards (or
199 backwards, if negative).
200 Finds and highlights the source line like \\[next-error], but does not
201 select the source buffer."
202 (interactive "p")
203 (next-error n)
204 (pop-to-buffer next-error-last-buffer))
206 (defun previous-error-no-select (n)
207 "Move point to the previous error in the next-error buffer and highlight match.
208 Prefix arg N says how many error messages to move backwards (or
209 forwards, if negative).
210 Finds and highlights the source line like \\[previous-error], but does not
211 select the source buffer."
212 (interactive "p")
213 (next-error-no-select (- n)))
217 (defun fundamental-mode ()
218 "Major mode not specialized for anything in particular.
219 Other major modes are defined by comparison with this one."
220 (interactive)
221 (kill-all-local-variables))
223 ;; Making and deleting lines.
225 (defun newline (&optional arg)
226 "Insert a newline, and move to left margin of the new line if it's blank.
227 If `use-hard-newlines' is non-nil, the newline is marked with the
228 text-property `hard'.
229 With ARG, insert that many newlines.
230 Call `auto-fill-function' if the current column number is greater
231 than the value of `fill-column' and ARG is nil."
232 (interactive "*P")
233 (barf-if-buffer-read-only)
234 ;; Inserting a newline at the end of a line produces better redisplay in
235 ;; try_window_id than inserting at the beginning of a line, and the textual
236 ;; result is the same. So, if we're at beginning of line, pretend to be at
237 ;; the end of the previous line.
238 (let ((flag (and (not (bobp))
239 (bolp)
240 ;; Make sure no functions want to be told about
241 ;; the range of the changes.
242 (not after-change-functions)
243 (not before-change-functions)
244 ;; Make sure there are no markers here.
245 (not (buffer-has-markers-at (1- (point))))
246 (not (buffer-has-markers-at (point)))
247 ;; Make sure no text properties want to know
248 ;; where the change was.
249 (not (get-char-property (1- (point)) 'modification-hooks))
250 (not (get-char-property (1- (point)) 'insert-behind-hooks))
251 (or (eobp)
252 (not (get-char-property (point) 'insert-in-front-hooks)))
253 ;; Make sure the newline before point isn't intangible.
254 (not (get-char-property (1- (point)) 'intangible))
255 ;; Make sure the newline before point isn't read-only.
256 (not (get-char-property (1- (point)) 'read-only))
257 ;; Make sure the newline before point isn't invisible.
258 (not (get-char-property (1- (point)) 'invisible))
259 ;; Make sure the newline before point has the same
260 ;; properties as the char before it (if any).
261 (< (or (previous-property-change (point)) -2)
262 (- (point) 2))))
263 (was-page-start (and (bolp)
264 (looking-at page-delimiter)))
265 (beforepos (point)))
266 (if flag (backward-char 1))
267 ;; Call self-insert so that auto-fill, abbrev expansion etc. happens.
268 ;; Set last-command-char to tell self-insert what to insert.
269 (let ((last-command-char ?\n)
270 ;; Don't auto-fill if we have a numeric argument.
271 ;; Also not if flag is true (it would fill wrong line);
272 ;; there is no need to since we're at BOL.
273 (auto-fill-function (if (or arg flag) nil auto-fill-function)))
274 (unwind-protect
275 (self-insert-command (prefix-numeric-value arg))
276 ;; If we get an error in self-insert-command, put point at right place.
277 (if flag (forward-char 1))))
278 ;; Even if we did *not* get an error, keep that forward-char;
279 ;; all further processing should apply to the newline that the user
280 ;; thinks he inserted.
282 ;; Mark the newline(s) `hard'.
283 (if use-hard-newlines
284 (set-hard-newline-properties
285 (- (point) (if arg (prefix-numeric-value arg) 1)) (point)))
286 ;; If the newline leaves the previous line blank,
287 ;; and we have a left margin, delete that from the blank line.
288 (or flag
289 (save-excursion
290 (goto-char beforepos)
291 (beginning-of-line)
292 (and (looking-at "[ \t]$")
293 (> (current-left-margin) 0)
294 (delete-region (point) (progn (end-of-line) (point))))))
295 ;; Indent the line after the newline, except in one case:
296 ;; when we added the newline at the beginning of a line
297 ;; which starts a page.
298 (or was-page-start
299 (move-to-left-margin nil t)))
300 nil)
302 (defun set-hard-newline-properties (from to)
303 (let ((sticky (get-text-property from 'rear-nonsticky)))
304 (put-text-property from to 'hard 't)
305 ;; If rear-nonsticky is not "t", add 'hard to rear-nonsticky list
306 (if (and (listp sticky) (not (memq 'hard sticky)))
307 (put-text-property from (point) 'rear-nonsticky
308 (cons 'hard sticky)))))
310 (defun open-line (n)
311 "Insert a newline and leave point before it.
312 If there is a fill prefix and/or a left-margin, insert them on the new line
313 if the line would have been blank.
314 With arg N, insert N newlines."
315 (interactive "*p")
316 (let* ((do-fill-prefix (and fill-prefix (bolp)))
317 (do-left-margin (and (bolp) (> (current-left-margin) 0)))
318 (loc (point))
319 ;; Don't expand an abbrev before point.
320 (abbrev-mode nil))
321 (newline n)
322 (goto-char loc)
323 (while (> n 0)
324 (cond ((bolp)
325 (if do-left-margin (indent-to (current-left-margin)))
326 (if do-fill-prefix (insert-and-inherit fill-prefix))))
327 (forward-line 1)
328 (setq n (1- n)))
329 (goto-char loc)
330 (end-of-line)))
332 (defun split-line (&optional arg)
333 "Split current line, moving portion beyond point vertically down.
334 If the current line starts with `fill-prefix', insert it on the new
335 line as well. With prefix ARG, don't insert fill-prefix on new line.
337 When called from Lisp code, ARG may be a prefix string to copy."
338 (interactive "*P")
339 (skip-chars-forward " \t")
340 (let* ((col (current-column))
341 (pos (point))
342 ;; What prefix should we check for (nil means don't).
343 (prefix (cond ((stringp arg) arg)
344 (arg nil)
345 (t fill-prefix)))
346 ;; Does this line start with it?
347 (have-prfx (and prefix
348 (save-excursion
349 (beginning-of-line)
350 (looking-at (regexp-quote prefix))))))
351 (newline 1)
352 (if have-prfx (insert-and-inherit prefix))
353 (indent-to col 0)
354 (goto-char pos)))
356 (defun delete-indentation (&optional arg)
357 "Join this line to previous and fix up whitespace at join.
358 If there is a fill prefix, delete it from the beginning of this line.
359 With argument, join this line to following line."
360 (interactive "*P")
361 (beginning-of-line)
362 (if arg (forward-line 1))
363 (if (eq (preceding-char) ?\n)
364 (progn
365 (delete-region (point) (1- (point)))
366 ;; If the second line started with the fill prefix,
367 ;; delete the prefix.
368 (if (and fill-prefix
369 (<= (+ (point) (length fill-prefix)) (point-max))
370 (string= fill-prefix
371 (buffer-substring (point)
372 (+ (point) (length fill-prefix)))))
373 (delete-region (point) (+ (point) (length fill-prefix))))
374 (fixup-whitespace))))
376 (defalias 'join-line #'delete-indentation) ; easier to find
378 (defun delete-blank-lines ()
379 "On blank line, delete all surrounding blank lines, leaving just one.
380 On isolated blank line, delete that one.
381 On nonblank line, delete any immediately following blank lines."
382 (interactive "*")
383 (let (thisblank singleblank)
384 (save-excursion
385 (beginning-of-line)
386 (setq thisblank (looking-at "[ \t]*$"))
387 ;; Set singleblank if there is just one blank line here.
388 (setq singleblank
389 (and thisblank
390 (not (looking-at "[ \t]*\n[ \t]*$"))
391 (or (bobp)
392 (progn (forward-line -1)
393 (not (looking-at "[ \t]*$")))))))
394 ;; Delete preceding blank lines, and this one too if it's the only one.
395 (if thisblank
396 (progn
397 (beginning-of-line)
398 (if singleblank (forward-line 1))
399 (delete-region (point)
400 (if (re-search-backward "[^ \t\n]" nil t)
401 (progn (forward-line 1) (point))
402 (point-min)))))
403 ;; Delete following blank lines, unless the current line is blank
404 ;; and there are no following blank lines.
405 (if (not (and thisblank singleblank))
406 (save-excursion
407 (end-of-line)
408 (forward-line 1)
409 (delete-region (point)
410 (if (re-search-forward "[^ \t\n]" nil t)
411 (progn (beginning-of-line) (point))
412 (point-max)))))
413 ;; Handle the special case where point is followed by newline and eob.
414 ;; Delete the line, leaving point at eob.
415 (if (looking-at "^[ \t]*\n\\'")
416 (delete-region (point) (point-max)))))
418 (defun delete-trailing-whitespace ()
419 "Delete all the trailing whitespace across the current buffer.
420 All whitespace after the last non-whitespace character in a line is deleted.
421 This respects narrowing, created by \\[narrow-to-region] and friends.
422 A formfeed is not considered whitespace by this function."
423 (interactive "*")
424 (save-match-data
425 (save-excursion
426 (goto-char (point-min))
427 (while (re-search-forward "\\s-$" nil t)
428 (skip-syntax-backward "-" (save-excursion (forward-line 0) (point)))
429 ;; Don't delete formfeeds, even if they are considered whitespace.
430 (save-match-data
431 (if (looking-at ".*\f")
432 (goto-char (match-end 0))))
433 (delete-region (point) (match-end 0))))))
435 (defun newline-and-indent ()
436 "Insert a newline, then indent according to major mode.
437 Indentation is done using the value of `indent-line-function'.
438 In programming language modes, this is the same as TAB.
439 In some text modes, where TAB inserts a tab, this command indents to the
440 column specified by the function `current-left-margin'."
441 (interactive "*")
442 (delete-horizontal-space t)
443 (newline)
444 (indent-according-to-mode))
446 (defun reindent-then-newline-and-indent ()
447 "Reindent current line, insert newline, then indent the new line.
448 Indentation of both lines is done according to the current major mode,
449 which means calling the current value of `indent-line-function'.
450 In programming language modes, this is the same as TAB.
451 In some text modes, where TAB inserts a tab, this indents to the
452 column specified by the function `current-left-margin'."
453 (interactive "*")
454 (let ((pos (point)))
455 ;; Be careful to insert the newline before indenting the line.
456 ;; Otherwise, the indentation might be wrong.
457 (newline)
458 (save-excursion
459 (goto-char pos)
460 (indent-according-to-mode)
461 (delete-horizontal-space t))
462 (indent-according-to-mode)))
464 (defun quoted-insert (arg)
465 "Read next input character and insert it.
466 This is useful for inserting control characters.
468 If the first character you type after this command is an octal digit,
469 you should type a sequence of octal digits which specify a character code.
470 Any nondigit terminates the sequence. If the terminator is a RET,
471 it is discarded; any other terminator is used itself as input.
472 The variable `read-quoted-char-radix' specifies the radix for this feature;
473 set it to 10 or 16 to use decimal or hex instead of octal.
475 In overwrite mode, this function inserts the character anyway, and
476 does not handle octal digits specially. This means that if you use
477 overwrite as your normal editing mode, you can use this function to
478 insert characters when necessary.
480 In binary overwrite mode, this function does overwrite, and octal
481 digits are interpreted as a character code. This is intended to be
482 useful for editing binary files."
483 (interactive "*p")
484 (let* ((char (let (translation-table-for-input)
485 (if (or (not overwrite-mode)
486 (eq overwrite-mode 'overwrite-mode-binary))
487 (read-quoted-char)
488 (read-char)))))
489 ;; Assume character codes 0240 - 0377 stand for characters in some
490 ;; single-byte character set, and convert them to Emacs
491 ;; characters.
492 (if (and enable-multibyte-characters
493 (>= char ?\240)
494 (<= char ?\377))
495 (setq char (unibyte-char-to-multibyte char)))
496 (if (> arg 0)
497 (if (eq overwrite-mode 'overwrite-mode-binary)
498 (delete-char arg)))
499 (while (> arg 0)
500 (insert-and-inherit char)
501 (setq arg (1- arg)))))
503 (defun forward-to-indentation (&optional arg)
504 "Move forward ARG lines and position at first nonblank character."
505 (interactive "p")
506 (forward-line (or arg 1))
507 (skip-chars-forward " \t"))
509 (defun backward-to-indentation (&optional arg)
510 "Move backward ARG lines and position at first nonblank character."
511 (interactive "p")
512 (forward-line (- (or arg 1)))
513 (skip-chars-forward " \t"))
515 (defun back-to-indentation ()
516 "Move point to the first non-whitespace character on this line."
517 (interactive)
518 (beginning-of-line 1)
519 (skip-syntax-forward " " (line-end-position))
520 ;; Move back over chars that have whitespace syntax but have the p flag.
521 (backward-prefix-chars))
523 (defun fixup-whitespace ()
524 "Fixup white space between objects around point.
525 Leave one space or none, according to the context."
526 (interactive "*")
527 (save-excursion
528 (delete-horizontal-space)
529 (if (or (looking-at "^\\|\\s)")
530 (save-excursion (forward-char -1)
531 (looking-at "$\\|\\s(\\|\\s'")))
533 (insert ?\ ))))
535 (defun delete-horizontal-space (&optional backward-only)
536 "Delete all spaces and tabs around point.
537 If BACKWARD-ONLY is non-nil, only delete spaces before point."
538 (interactive "*")
539 (let ((orig-pos (point)))
540 (delete-region
541 (if backward-only
542 orig-pos
543 (progn
544 (skip-chars-forward " \t")
545 (constrain-to-field nil orig-pos t)))
546 (progn
547 (skip-chars-backward " \t")
548 (constrain-to-field nil orig-pos)))))
550 (defun just-one-space ()
551 "Delete all spaces and tabs around point, leaving one space."
552 (interactive "*")
553 (let ((orig-pos (point)))
554 (skip-chars-backward " \t")
555 (constrain-to-field nil orig-pos)
556 (if (= (following-char) ? )
557 (forward-char 1)
558 (insert ? ))
559 (delete-region
560 (point)
561 (progn
562 (skip-chars-forward " \t")
563 (constrain-to-field nil orig-pos t)))))
565 (defun beginning-of-buffer (&optional arg)
566 "Move point to the beginning of the buffer; leave mark at previous position.
567 With arg N, put point N/10 of the way from the beginning.
569 If the buffer is narrowed, this command uses the beginning and size
570 of the accessible part of the buffer.
572 Don't use this command in Lisp programs!
573 \(goto-char (point-min)) is faster and avoids clobbering the mark."
574 (interactive "P")
575 (push-mark)
576 (let ((size (- (point-max) (point-min))))
577 (goto-char (if arg
578 (+ (point-min)
579 (if (> size 10000)
580 ;; Avoid overflow for large buffer sizes!
581 (* (prefix-numeric-value arg)
582 (/ size 10))
583 (/ (+ 10 (* size (prefix-numeric-value arg))) 10)))
584 (point-min))))
585 (if arg (forward-line 1)))
587 (defun end-of-buffer (&optional arg)
588 "Move point to the end of the buffer; leave mark at previous position.
589 With arg N, put point N/10 of the way from the end.
591 If the buffer is narrowed, this command uses the beginning and size
592 of the accessible part of the buffer.
594 Don't use this command in Lisp programs!
595 \(goto-char (point-max)) is faster and avoids clobbering the mark."
596 (interactive "P")
597 (push-mark)
598 (let ((size (- (point-max) (point-min))))
599 (goto-char (if arg
600 (- (point-max)
601 (if (> size 10000)
602 ;; Avoid overflow for large buffer sizes!
603 (* (prefix-numeric-value arg)
604 (/ size 10))
605 (/ (* size (prefix-numeric-value arg)) 10)))
606 (point-max))))
607 ;; If we went to a place in the middle of the buffer,
608 ;; adjust it to the beginning of a line.
609 (cond (arg (forward-line 1))
610 ((> (point) (window-end nil t))
611 ;; If the end of the buffer is not already on the screen,
612 ;; then scroll specially to put it near, but not at, the bottom.
613 (overlay-recenter (point))
614 (recenter -3))))
616 (defun mark-whole-buffer ()
617 "Put point at beginning and mark at end of buffer.
618 You probably should not use this function in Lisp programs;
619 it is usually a mistake for a Lisp function to use any subroutine
620 that uses or sets the mark."
621 (interactive)
622 (push-mark (point))
623 (push-mark (point-max) nil t)
624 (goto-char (point-min)))
627 ;; Counting lines, one way or another.
629 (defun goto-line (arg)
630 "Goto line ARG, counting from line 1 at beginning of buffer."
631 (interactive "NGoto line: ")
632 (setq arg (prefix-numeric-value arg))
633 (save-restriction
634 (widen)
635 (goto-char 1)
636 (if (eq selective-display t)
637 (re-search-forward "[\n\C-m]" nil 'end (1- arg))
638 (forward-line (1- arg)))))
640 (defun count-lines-region (start end)
641 "Print number of lines and characters in the region."
642 (interactive "r")
643 (message "Region has %d lines, %d characters"
644 (count-lines start end) (- end start)))
646 (defun what-line ()
647 "Print the current buffer line number and narrowed line number of point."
648 (interactive)
649 (let ((opoint (point)) (start (point-min))
650 (n (line-number-at-pos)))
651 (if (= start 1)
652 (message "Line %d" n)
653 (save-excursion
654 (save-restriction
655 (widen)
656 (message "line %d (narrowed line %d)"
657 (+ n (line-number-at-pos start) -1) n))))))
659 (defun count-lines (start end)
660 "Return number of lines between START and END.
661 This is usually the number of newlines between them,
662 but can be one more if START is not equal to END
663 and the greater of them is not at the start of a line."
664 (save-excursion
665 (save-restriction
666 (narrow-to-region start end)
667 (goto-char (point-min))
668 (if (eq selective-display t)
669 (save-match-data
670 (let ((done 0))
671 (while (re-search-forward "[\n\C-m]" nil t 40)
672 (setq done (+ 40 done)))
673 (while (re-search-forward "[\n\C-m]" nil t 1)
674 (setq done (+ 1 done)))
675 (goto-char (point-max))
676 (if (and (/= start end)
677 (not (bolp)))
678 (1+ done)
679 done)))
680 (- (buffer-size) (forward-line (buffer-size)))))))
682 (defun line-number-at-pos (&optional pos)
683 "Return (narrowed) buffer line number at position POS.
684 If POS is nil, use current buffer location."
685 (let ((opoint (or pos (point))) start)
686 (save-excursion
687 (goto-char (point-min))
688 (setq start (point))
689 (goto-char opoint)
690 (forward-line 0)
691 (1+ (count-lines start (point))))))
693 (defun what-cursor-position (&optional detail)
694 "Print info on cursor position (on screen and within buffer).
695 Also describe the character after point, and give its character code
696 in octal, decimal and hex.
698 For a non-ASCII multibyte character, also give its encoding in the
699 buffer's selected coding system if the coding system encodes the
700 character safely. If the character is encoded into one byte, that
701 code is shown in hex. If the character is encoded into more than one
702 byte, just \"...\" is shown.
704 In addition, with prefix argument, show details about that character
705 in *Help* buffer. See also the command `describe-char'."
706 (interactive "P")
707 (let* ((char (following-char))
708 (beg (point-min))
709 (end (point-max))
710 (pos (point))
711 (total (buffer-size))
712 (percent (if (> total 50000)
713 ;; Avoid overflow from multiplying by 100!
714 (/ (+ (/ total 200) (1- pos)) (max (/ total 100) 1))
715 (/ (+ (/ total 2) (* 100 (1- pos))) (max total 1))))
716 (hscroll (if (= (window-hscroll) 0)
718 (format " Hscroll=%d" (window-hscroll))))
719 (col (current-column)))
720 (if (= pos end)
721 (if (or (/= beg 1) (/= end (1+ total)))
722 (message "point=%d of %d (%d%%) <%d - %d> column %d %s"
723 pos total percent beg end col hscroll)
724 (message "point=%d of %d (%d%%) column %d %s"
725 pos total percent col hscroll))
726 (let ((coding buffer-file-coding-system)
727 encoded encoding-msg)
728 (if (or (not coding)
729 (eq (coding-system-type coding) t))
730 (setq coding default-buffer-file-coding-system))
731 (if (not (char-valid-p char))
732 (setq encoding-msg
733 (format "(0%o, %d, 0x%x, invalid)" char char char))
734 (setq encoded (and (>= char 128) (encode-coding-char char coding)))
735 (setq encoding-msg
736 (if encoded
737 (format "(0%o, %d, 0x%x, file %s)"
738 char char char
739 (if (> (length encoded) 1)
740 "..."
741 (encoded-string-description encoded coding)))
742 (format "(0%o, %d, 0x%x)" char char char))))
743 (if detail
744 ;; We show the detailed information about CHAR.
745 (describe-char (point)))
746 (if (or (/= beg 1) (/= end (1+ total)))
747 (message "Char: %s %s point=%d of %d (%d%%) <%d - %d> column %d %s"
748 (if (< char 256)
749 (single-key-description char)
750 (buffer-substring-no-properties (point) (1+ (point))))
751 encoding-msg pos total percent beg end col hscroll)
752 (message "Char: %s %s point=%d of %d (%d%%) column %d %s"
753 (if (< char 256)
754 (single-key-description char)
755 (buffer-substring-no-properties (point) (1+ (point))))
756 encoding-msg pos total percent col hscroll))))))
758 (defvar read-expression-map
759 (let ((m (make-sparse-keymap)))
760 (define-key m "\M-\t" 'lisp-complete-symbol)
761 (set-keymap-parent m minibuffer-local-map)
763 "Minibuffer keymap used for reading Lisp expressions.")
765 (defvar read-expression-history nil)
767 (defcustom eval-expression-print-level 4
768 "*Value to use for `print-level' when printing value in `eval-expression'.
769 A value of nil means no limit."
770 :group 'lisp
771 :type '(choice (const :tag "No Limit" nil) integer)
772 :version "21.1")
774 (defcustom eval-expression-print-length 12
775 "*Value to use for `print-length' when printing value in `eval-expression'.
776 A value of nil means no limit."
777 :group 'lisp
778 :type '(choice (const :tag "No Limit" nil) integer)
779 :version "21.1")
781 (defcustom eval-expression-debug-on-error t
782 "*Non-nil means set `debug-on-error' when evaluating in `eval-expression'.
783 If nil, don't change the value of `debug-on-error'."
784 :group 'lisp
785 :type 'boolean
786 :version "21.1")
788 (defun eval-expression-print-format (value)
789 "Format VALUE as a result of evaluated expression.
790 Return a formatted string which is displayed in the echo area
791 in addition to the value printed by prin1 in functions which
792 display the result of expression evaluation."
793 (if (and (integerp value)
794 (or (not (memq this-command '(eval-last-sexp eval-print-last-sexp)))
795 (eq this-command last-command)
796 (and (boundp 'edebug-active) edebug-active)))
797 (let ((char-string
798 (if (or (and (boundp 'edebug-active) edebug-active)
799 (memq this-command '(eval-last-sexp eval-print-last-sexp)))
800 (prin1-char value))))
801 (if char-string
802 (format " (0%o, 0x%x) = %s" value value char-string)
803 (format " (0%o, 0x%x)" value value)))))
805 ;; We define this, rather than making `eval' interactive,
806 ;; for the sake of completion of names like eval-region, eval-current-buffer.
807 (defun eval-expression (eval-expression-arg
808 &optional eval-expression-insert-value)
809 "Evaluate EVAL-EXPRESSION-ARG and print value in the echo area.
810 Value is also consed on to front of the variable `values'.
811 Optional argument EVAL-EXPRESSION-INSERT-VALUE, if non-nil, means
812 insert the result into the current buffer instead of printing it in
813 the echo area."
814 (interactive
815 (list (read-from-minibuffer "Eval: "
816 nil read-expression-map t
817 'read-expression-history)
818 current-prefix-arg))
820 (if (null eval-expression-debug-on-error)
821 (setq values (cons (eval eval-expression-arg) values))
822 (let ((old-value (make-symbol "t")) new-value)
823 ;; Bind debug-on-error to something unique so that we can
824 ;; detect when evaled code changes it.
825 (let ((debug-on-error old-value))
826 (setq values (cons (eval eval-expression-arg) values))
827 (setq new-value debug-on-error))
828 ;; If evaled code has changed the value of debug-on-error,
829 ;; propagate that change to the global binding.
830 (unless (eq old-value new-value)
831 (setq debug-on-error new-value))))
833 (let ((print-length eval-expression-print-length)
834 (print-level eval-expression-print-level))
835 (if eval-expression-insert-value
836 (with-no-warnings
837 (let ((standard-output (current-buffer)))
838 (eval-last-sexp-print-value (car values))))
839 (prog1
840 (prin1 (car values) t)
841 (let ((str (eval-expression-print-format (car values))))
842 (if str (princ str t)))))))
844 (defun edit-and-eval-command (prompt command)
845 "Prompting with PROMPT, let user edit COMMAND and eval result.
846 COMMAND is a Lisp expression. Let user edit that expression in
847 the minibuffer, then read and evaluate the result."
848 (let ((command
849 (let ((print-level nil)
850 (minibuffer-history-sexp-flag (1+ (minibuffer-depth))))
851 (unwind-protect
852 (read-from-minibuffer prompt
853 (prin1-to-string command)
854 read-expression-map t
855 'command-history)
856 ;; If command was added to command-history as a string,
857 ;; get rid of that. We want only evaluable expressions there.
858 (if (stringp (car command-history))
859 (setq command-history (cdr command-history)))))))
861 ;; If command to be redone does not match front of history,
862 ;; add it to the history.
863 (or (equal command (car command-history))
864 (setq command-history (cons command command-history)))
865 (eval command)))
867 (defun repeat-complex-command (arg)
868 "Edit and re-evaluate last complex command, or ARGth from last.
869 A complex command is one which used the minibuffer.
870 The command is placed in the minibuffer as a Lisp form for editing.
871 The result is executed, repeating the command as changed.
872 If the command has been changed or is not the most recent previous command
873 it is added to the front of the command history.
874 You can use the minibuffer history commands \\<minibuffer-local-map>\\[next-history-element] and \\[previous-history-element]
875 to get different commands to edit and resubmit."
876 (interactive "p")
877 (let ((elt (nth (1- arg) command-history))
878 newcmd)
879 (if elt
880 (progn
881 (setq newcmd
882 (let ((print-level nil)
883 (minibuffer-history-position arg)
884 (minibuffer-history-sexp-flag (1+ (minibuffer-depth))))
885 (unwind-protect
886 (read-from-minibuffer
887 "Redo: " (prin1-to-string elt) read-expression-map t
888 (cons 'command-history arg))
890 ;; If command was added to command-history as a
891 ;; string, get rid of that. We want only
892 ;; evaluable expressions there.
893 (if (stringp (car command-history))
894 (setq command-history (cdr command-history))))))
896 ;; If command to be redone does not match front of history,
897 ;; add it to the history.
898 (or (equal newcmd (car command-history))
899 (setq command-history (cons newcmd command-history)))
900 (eval newcmd))
901 (if command-history
902 (error "Argument %d is beyond length of command history" arg)
903 (error "There are no previous complex commands to repeat")))))
905 (defvar minibuffer-history nil
906 "Default minibuffer history list.
907 This is used for all minibuffer input
908 except when an alternate history list is specified.")
909 (defvar minibuffer-history-sexp-flag nil
910 "Control whether history list elements are expressions or strings.
911 If the value of this variable equals current minibuffer depth,
912 they are expressions; otherwise they are strings.
913 \(That convention is designed to do the right thing fora
914 recursive uses of the minibuffer.)")
915 (setq minibuffer-history-variable 'minibuffer-history)
916 (setq minibuffer-history-position nil)
917 (defvar minibuffer-history-search-history nil)
919 (defvar minibuffer-text-before-history nil
920 "Text that was in this minibuffer before any history commands.
921 This is nil if there have not yet been any history commands
922 in this use of the minibuffer.")
924 (add-hook 'minibuffer-setup-hook 'minibuffer-history-initialize)
926 (defun minibuffer-history-initialize ()
927 (setq minibuffer-text-before-history nil))
929 (defun minibuffer-avoid-prompt (new old)
930 "A point-motion hook for the minibuffer, that moves point out of the prompt."
931 (constrain-to-field nil (point-max)))
933 (defcustom minibuffer-history-case-insensitive-variables nil
934 "*Minibuffer history variables for which matching should ignore case.
935 If a history variable is a member of this list, then the
936 \\[previous-matching-history-element] and \\[next-matching-history-element]\
937 commands ignore case when searching it, regardless of `case-fold-search'."
938 :type '(repeat variable)
939 :group 'minibuffer)
941 (defun previous-matching-history-element (regexp n)
942 "Find the previous history element that matches REGEXP.
943 \(Previous history elements refer to earlier actions.)
944 With prefix argument N, search for Nth previous match.
945 If N is negative, find the next or Nth next match.
946 Normally, history elements are matched case-insensitively if
947 `case-fold-search' is non-nil, but an uppercase letter in REGEXP
948 makes the search case-sensitive.
949 See also `minibuffer-history-case-insensitive-variables'."
950 (interactive
951 (let* ((enable-recursive-minibuffers t)
952 (regexp (read-from-minibuffer "Previous element matching (regexp): "
954 minibuffer-local-map
956 'minibuffer-history-search-history)))
957 ;; Use the last regexp specified, by default, if input is empty.
958 (list (if (string= regexp "")
959 (if minibuffer-history-search-history
960 (car minibuffer-history-search-history)
961 (error "No previous history search regexp"))
962 regexp)
963 (prefix-numeric-value current-prefix-arg))))
964 (unless (zerop n)
965 (if (and (zerop minibuffer-history-position)
966 (null minibuffer-text-before-history))
967 (setq minibuffer-text-before-history
968 (minibuffer-contents-no-properties)))
969 (let ((history (symbol-value minibuffer-history-variable))
970 (case-fold-search
971 (if (isearch-no-upper-case-p regexp t) ; assume isearch.el is dumped
972 ;; On some systems, ignore case for file names.
973 (if (memq minibuffer-history-variable
974 minibuffer-history-case-insensitive-variables)
976 ;; Respect the user's setting for case-fold-search:
977 case-fold-search)
978 nil))
979 prevpos
980 match-string
981 match-offset
982 (pos minibuffer-history-position))
983 (while (/= n 0)
984 (setq prevpos pos)
985 (setq pos (min (max 1 (+ pos (if (< n 0) -1 1))) (length history)))
986 (when (= pos prevpos)
987 (error (if (= pos 1)
988 "No later matching history item"
989 "No earlier matching history item")))
990 (setq match-string
991 (if (eq minibuffer-history-sexp-flag (minibuffer-depth))
992 (let ((print-level nil))
993 (prin1-to-string (nth (1- pos) history)))
994 (nth (1- pos) history)))
995 (setq match-offset
996 (if (< n 0)
997 (and (string-match regexp match-string)
998 (match-end 0))
999 (and (string-match (concat ".*\\(" regexp "\\)") match-string)
1000 (match-beginning 1))))
1001 (when match-offset
1002 (setq n (+ n (if (< n 0) 1 -1)))))
1003 (setq minibuffer-history-position pos)
1004 (goto-char (point-max))
1005 (delete-minibuffer-contents)
1006 (insert match-string)
1007 (goto-char (+ (minibuffer-prompt-end) match-offset))))
1008 (if (memq (car (car command-history)) '(previous-matching-history-element
1009 next-matching-history-element))
1010 (setq command-history (cdr command-history))))
1012 (defun next-matching-history-element (regexp n)
1013 "Find the next history element that matches REGEXP.
1014 \(The next history element refers to a more recent action.)
1015 With prefix argument N, search for Nth next match.
1016 If N is negative, find the previous or Nth previous match.
1017 Normally, history elements are matched case-insensitively if
1018 `case-fold-search' is non-nil, but an uppercase letter in REGEXP
1019 makes the search case-sensitive."
1020 (interactive
1021 (let* ((enable-recursive-minibuffers t)
1022 (regexp (read-from-minibuffer "Next element matching (regexp): "
1024 minibuffer-local-map
1026 'minibuffer-history-search-history)))
1027 ;; Use the last regexp specified, by default, if input is empty.
1028 (list (if (string= regexp "")
1029 (setcar minibuffer-history-search-history
1030 (nth 1 minibuffer-history-search-history))
1031 regexp)
1032 (prefix-numeric-value current-prefix-arg))))
1033 (previous-matching-history-element regexp (- n)))
1035 (defvar minibuffer-temporary-goal-position nil)
1037 (defun next-history-element (n)
1038 "Insert the next element of the minibuffer history into the minibuffer."
1039 (interactive "p")
1040 (or (zerop n)
1041 (let ((narg (- minibuffer-history-position n))
1042 (minimum (if minibuffer-default -1 0))
1043 elt minibuffer-returned-to-present)
1044 (if (and (zerop minibuffer-history-position)
1045 (null minibuffer-text-before-history))
1046 (setq minibuffer-text-before-history
1047 (minibuffer-contents-no-properties)))
1048 (if (< narg minimum)
1049 (if minibuffer-default
1050 (error "End of history; no next item")
1051 (error "End of history; no default available")))
1052 (if (> narg (length (symbol-value minibuffer-history-variable)))
1053 (error "Beginning of history; no preceding item"))
1054 (unless (memq last-command '(next-history-element
1055 previous-history-element))
1056 (let ((prompt-end (minibuffer-prompt-end)))
1057 (set (make-local-variable 'minibuffer-temporary-goal-position)
1058 (cond ((<= (point) prompt-end) prompt-end)
1059 ((eobp) nil)
1060 (t (point))))))
1061 (goto-char (point-max))
1062 (delete-minibuffer-contents)
1063 (setq minibuffer-history-position narg)
1064 (cond ((= narg -1)
1065 (setq elt minibuffer-default))
1066 ((= narg 0)
1067 (setq elt (or minibuffer-text-before-history ""))
1068 (setq minibuffer-returned-to-present t)
1069 (setq minibuffer-text-before-history nil))
1070 (t (setq elt (nth (1- minibuffer-history-position)
1071 (symbol-value minibuffer-history-variable)))))
1072 (insert
1073 (if (and (eq minibuffer-history-sexp-flag (minibuffer-depth))
1074 (not minibuffer-returned-to-present))
1075 (let ((print-level nil))
1076 (prin1-to-string elt))
1077 elt))
1078 (goto-char (or minibuffer-temporary-goal-position (point-max))))))
1080 (defun previous-history-element (n)
1081 "Inserts the previous element of the minibuffer history into the minibuffer."
1082 (interactive "p")
1083 (next-history-element (- n)))
1085 (defun next-complete-history-element (n)
1086 "Get next history element which completes the minibuffer before the point.
1087 The contents of the minibuffer after the point are deleted, and replaced
1088 by the new completion."
1089 (interactive "p")
1090 (let ((point-at-start (point)))
1091 (next-matching-history-element
1092 (concat
1093 "^" (regexp-quote (buffer-substring (minibuffer-prompt-end) (point))))
1095 ;; next-matching-history-element always puts us at (point-min).
1096 ;; Move to the position we were at before changing the buffer contents.
1097 ;; This is still sensical, because the text before point has not changed.
1098 (goto-char point-at-start)))
1100 (defun previous-complete-history-element (n)
1102 Get previous history element which completes the minibuffer before the point.
1103 The contents of the minibuffer after the point are deleted, and replaced
1104 by the new completion."
1105 (interactive "p")
1106 (next-complete-history-element (- n)))
1108 ;; For compatibility with the old subr of the same name.
1109 (defun minibuffer-prompt-width ()
1110 "Return the display width of the minibuffer prompt.
1111 Return 0 if current buffer is not a mini-buffer."
1112 ;; Return the width of everything before the field at the end of
1113 ;; the buffer; this should be 0 for normal buffers.
1114 (1- (minibuffer-prompt-end)))
1116 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
1117 (defalias 'advertised-undo 'undo)
1119 (defconst undo-equiv-table (make-hash-table :test 'eq :weakness t)
1120 "Table mapping redo records to the corresponding undo one.")
1122 (defvar undo-in-region nil
1123 "Non-nil if `pending-undo-list' is not just a tail of `buffer-undo-list'.")
1125 (defvar undo-no-redo nil
1126 "If t, `undo' doesn't go through redo entries.")
1128 (defun undo (&optional arg)
1129 "Undo some previous changes.
1130 Repeat this command to undo more changes.
1131 A numeric argument serves as a repeat count.
1133 In Transient Mark mode when the mark is active, only undo changes within
1134 the current region. Similarly, when not in Transient Mark mode, just \\[universal-argument]
1135 as an argument limits undo to changes within the current region."
1136 (interactive "*P")
1137 ;; Make last-command indicate for the next command that this was an undo.
1138 ;; That way, another undo will undo more.
1139 ;; If we get to the end of the undo history and get an error,
1140 ;; another undo command will find the undo history empty
1141 ;; and will get another error. To begin undoing the undos,
1142 ;; you must type some other command.
1143 (let ((modified (buffer-modified-p))
1144 (recent-save (recent-auto-save-p)))
1145 ;; If we get an error in undo-start,
1146 ;; the next command should not be a "consecutive undo".
1147 ;; So set `this-command' to something other than `undo'.
1148 (setq this-command 'undo-start)
1150 (unless (eq last-command 'undo)
1151 (setq undo-in-region
1152 (if transient-mark-mode mark-active (and arg (not (numberp arg)))))
1153 (if undo-in-region
1154 (undo-start (region-beginning) (region-end))
1155 (undo-start))
1156 ;; get rid of initial undo boundary
1157 (undo-more 1))
1158 ;; If we got this far, the next command should be a consecutive undo.
1159 (setq this-command 'undo)
1160 ;; Check to see whether we're hitting a redo record, and if
1161 ;; so, ask the user whether she wants to skip the redo/undo pair.
1162 (let ((equiv (gethash pending-undo-list undo-equiv-table)))
1163 (or (eq (selected-window) (minibuffer-window))
1164 (message (if undo-in-region
1165 (if equiv "Redo in region!" "Undo in region!")
1166 (if equiv "Redo!" "Undo!"))))
1167 (when (and equiv undo-no-redo)
1168 ;; The equiv entry might point to another redo record if we have done
1169 ;; undo-redo-undo-redo-... so skip to the very last equiv.
1170 (while (let ((next (gethash equiv undo-equiv-table)))
1171 (if next (setq equiv next))))
1172 (setq pending-undo-list equiv)))
1173 (undo-more
1174 (if (or transient-mark-mode (numberp arg))
1175 (prefix-numeric-value arg)
1177 ;; Record the fact that the just-generated undo records come from an
1178 ;; undo operation, so we can skip them later on.
1179 ;; I don't know how to do that in the undo-in-region case.
1180 (unless undo-in-region
1181 (puthash buffer-undo-list pending-undo-list undo-equiv-table))
1182 ;; Don't specify a position in the undo record for the undo command.
1183 ;; Instead, undoing this should move point to where the change is.
1184 (let ((tail buffer-undo-list)
1185 (prev nil))
1186 (while (car tail)
1187 (when (integerp (car tail))
1188 (let ((pos (car tail)))
1189 (if prev
1190 (setcdr prev (cdr tail))
1191 (setq buffer-undo-list (cdr tail)))
1192 (setq tail (cdr tail))
1193 (while (car tail)
1194 (if (eq pos (car tail))
1195 (if prev
1196 (setcdr prev (cdr tail))
1197 (setq buffer-undo-list (cdr tail)))
1198 (setq prev tail))
1199 (setq tail (cdr tail)))
1200 (setq tail nil)))
1201 (setq prev tail tail (cdr tail))))
1203 (and modified (not (buffer-modified-p))
1204 (delete-auto-save-file-if-necessary recent-save))))
1206 (defun undo-only (&optional arg)
1207 "Undo some previous changes.
1208 Repeat this command to undo more changes.
1209 A numeric argument serves as a repeat count.
1210 Contrary to `undo', this will not redo a previous undo."
1211 (interactive "*p")
1212 (let ((undo-no-redo t)) (undo arg)))
1213 ;; Richard said that we should not use C-x <uppercase letter> and I have
1214 ;; no idea whereas to bind it. Any suggestion welcome. -stef
1215 ;; (define-key ctl-x-map "U" 'undo-only)
1217 (defvar pending-undo-list nil
1218 "Within a run of consecutive undo commands, list remaining to be undone.")
1220 (defvar undo-in-progress nil
1221 "Non-nil while performing an undo.
1222 Some change-hooks test this variable to do something different.")
1224 (defun undo-more (count)
1225 "Undo back N undo-boundaries beyond what was already undone recently.
1226 Call `undo-start' to get ready to undo recent changes,
1227 then call `undo-more' one or more times to undo them."
1228 (or pending-undo-list
1229 (error (format "No further undo information%s"
1230 (if (and transient-mark-mode mark-active)
1231 " for region" ""))))
1232 (let ((undo-in-progress t))
1233 (setq pending-undo-list (primitive-undo count pending-undo-list))))
1235 ;; Deep copy of a list
1236 (defun undo-copy-list (list)
1237 "Make a copy of undo list LIST."
1238 (mapcar 'undo-copy-list-1 list))
1240 (defun undo-copy-list-1 (elt)
1241 (if (consp elt)
1242 (cons (car elt) (undo-copy-list-1 (cdr elt)))
1243 elt))
1245 (defun undo-start (&optional beg end)
1246 "Set `pending-undo-list' to the front of the undo list.
1247 The next call to `undo-more' will undo the most recently made change.
1248 If BEG and END are specified, then only undo elements
1249 that apply to text between BEG and END are used; other undo elements
1250 are ignored. If BEG and END are nil, all undo elements are used."
1251 (if (eq buffer-undo-list t)
1252 (error "No undo information in this buffer"))
1253 (setq pending-undo-list
1254 (if (and beg end (not (= beg end)))
1255 (undo-make-selective-list (min beg end) (max beg end))
1256 buffer-undo-list)))
1258 (defvar undo-adjusted-markers)
1260 (defun undo-make-selective-list (start end)
1261 "Return a list of undo elements for the region START to END.
1262 The elements come from `buffer-undo-list', but we keep only
1263 the elements inside this region, and discard those outside this region.
1264 If we find an element that crosses an edge of this region,
1265 we stop and ignore all further elements."
1266 (let ((undo-list-copy (undo-copy-list buffer-undo-list))
1267 (undo-list (list nil))
1268 undo-adjusted-markers
1269 some-rejected
1270 undo-elt undo-elt temp-undo-list delta)
1271 (while undo-list-copy
1272 (setq undo-elt (car undo-list-copy))
1273 (let ((keep-this
1274 (cond ((and (consp undo-elt) (eq (car undo-elt) t))
1275 ;; This is a "was unmodified" element.
1276 ;; Keep it if we have kept everything thus far.
1277 (not some-rejected))
1279 (undo-elt-in-region undo-elt start end)))))
1280 (if keep-this
1281 (progn
1282 (setq end (+ end (cdr (undo-delta undo-elt))))
1283 ;; Don't put two nils together in the list
1284 (if (not (and (eq (car undo-list) nil)
1285 (eq undo-elt nil)))
1286 (setq undo-list (cons undo-elt undo-list))))
1287 (if (undo-elt-crosses-region undo-elt start end)
1288 (setq undo-list-copy nil)
1289 (setq some-rejected t)
1290 (setq temp-undo-list (cdr undo-list-copy))
1291 (setq delta (undo-delta undo-elt))
1293 (when (/= (cdr delta) 0)
1294 (let ((position (car delta))
1295 (offset (cdr delta)))
1297 ;; Loop down the earlier events adjusting their buffer
1298 ;; positions to reflect the fact that a change to the buffer
1299 ;; isn't being undone. We only need to process those element
1300 ;; types which undo-elt-in-region will return as being in
1301 ;; the region since only those types can ever get into the
1302 ;; output
1304 (while temp-undo-list
1305 (setq undo-elt (car temp-undo-list))
1306 (cond ((integerp undo-elt)
1307 (if (>= undo-elt position)
1308 (setcar temp-undo-list (- undo-elt offset))))
1309 ((atom undo-elt) nil)
1310 ((stringp (car undo-elt))
1311 ;; (TEXT . POSITION)
1312 (let ((text-pos (abs (cdr undo-elt)))
1313 (point-at-end (< (cdr undo-elt) 0 )))
1314 (if (>= text-pos position)
1315 (setcdr undo-elt (* (if point-at-end -1 1)
1316 (- text-pos offset))))))
1317 ((integerp (car undo-elt))
1318 ;; (BEGIN . END)
1319 (when (>= (car undo-elt) position)
1320 (setcar undo-elt (- (car undo-elt) offset))
1321 (setcdr undo-elt (- (cdr undo-elt) offset))))
1322 ((null (car undo-elt))
1323 ;; (nil PROPERTY VALUE BEG . END)
1324 (let ((tail (nthcdr 3 undo-elt)))
1325 (when (>= (car tail) position)
1326 (setcar tail (- (car tail) offset))
1327 (setcdr tail (- (cdr tail) offset))))))
1328 (setq temp-undo-list (cdr temp-undo-list))))))))
1329 (setq undo-list-copy (cdr undo-list-copy)))
1330 (nreverse undo-list)))
1332 (defun undo-elt-in-region (undo-elt start end)
1333 "Determine whether UNDO-ELT falls inside the region START ... END.
1334 If it crosses the edge, we return nil."
1335 (cond ((integerp undo-elt)
1336 (and (>= undo-elt start)
1337 (<= undo-elt end)))
1338 ((eq undo-elt nil)
1340 ((atom undo-elt)
1341 nil)
1342 ((stringp (car undo-elt))
1343 ;; (TEXT . POSITION)
1344 (and (>= (abs (cdr undo-elt)) start)
1345 (< (abs (cdr undo-elt)) end)))
1346 ((and (consp undo-elt) (markerp (car undo-elt)))
1347 ;; This is a marker-adjustment element (MARKER . ADJUSTMENT).
1348 ;; See if MARKER is inside the region.
1349 (let ((alist-elt (assq (car undo-elt) undo-adjusted-markers)))
1350 (unless alist-elt
1351 (setq alist-elt (cons (car undo-elt)
1352 (marker-position (car undo-elt))))
1353 (setq undo-adjusted-markers
1354 (cons alist-elt undo-adjusted-markers)))
1355 (and (cdr alist-elt)
1356 (>= (cdr alist-elt) start)
1357 (<= (cdr alist-elt) end))))
1358 ((null (car undo-elt))
1359 ;; (nil PROPERTY VALUE BEG . END)
1360 (let ((tail (nthcdr 3 undo-elt)))
1361 (and (>= (car tail) start)
1362 (<= (cdr tail) end))))
1363 ((integerp (car undo-elt))
1364 ;; (BEGIN . END)
1365 (and (>= (car undo-elt) start)
1366 (<= (cdr undo-elt) end)))))
1368 (defun undo-elt-crosses-region (undo-elt start end)
1369 "Test whether UNDO-ELT crosses one edge of that region START ... END.
1370 This assumes we have already decided that UNDO-ELT
1371 is not *inside* the region START...END."
1372 (cond ((atom undo-elt) nil)
1373 ((null (car undo-elt))
1374 ;; (nil PROPERTY VALUE BEG . END)
1375 (let ((tail (nthcdr 3 undo-elt)))
1376 (not (or (< (car tail) end)
1377 (> (cdr tail) start)))))
1378 ((integerp (car undo-elt))
1379 ;; (BEGIN . END)
1380 (not (or (< (car undo-elt) end)
1381 (> (cdr undo-elt) start))))))
1383 ;; Return the first affected buffer position and the delta for an undo element
1384 ;; delta is defined as the change in subsequent buffer positions if we *did*
1385 ;; the undo.
1386 (defun undo-delta (undo-elt)
1387 (if (consp undo-elt)
1388 (cond ((stringp (car undo-elt))
1389 ;; (TEXT . POSITION)
1390 (cons (abs (cdr undo-elt)) (length (car undo-elt))))
1391 ((integerp (car undo-elt))
1392 ;; (BEGIN . END)
1393 (cons (car undo-elt) (- (car undo-elt) (cdr undo-elt))))
1395 '(0 . 0)))
1396 '(0 . 0)))
1398 (defvar shell-command-history nil
1399 "History list for some commands that read shell commands.")
1401 (defvar shell-command-switch "-c"
1402 "Switch used to have the shell execute its command line argument.")
1404 (defvar shell-command-default-error-buffer nil
1405 "*Buffer name for `shell-command' and `shell-command-on-region' error output.
1406 This buffer is used when `shell-command' or `shell-command-on-region'
1407 is run interactively. A value of nil means that output to stderr and
1408 stdout will be intermixed in the output stream.")
1410 (defun shell-command (command &optional output-buffer error-buffer)
1411 "Execute string COMMAND in inferior shell; display output, if any.
1412 With prefix argument, insert the COMMAND's output at point.
1414 If COMMAND ends in ampersand, execute it asynchronously.
1415 The output appears in the buffer `*Async Shell Command*'.
1416 That buffer is in shell mode.
1418 Otherwise, COMMAND is executed synchronously. The output appears in
1419 the buffer `*Shell Command Output*'. If the output is short enough to
1420 display in the echo area (which is determined by the variables
1421 `resize-mini-windows' and `max-mini-window-height'), it is shown
1422 there, but it is nonetheless available in buffer `*Shell Command
1423 Output*' even though that buffer is not automatically displayed.
1425 To specify a coding system for converting non-ASCII characters
1426 in the shell command output, use \\[universal-coding-system-argument]
1427 before this command.
1429 Noninteractive callers can specify coding systems by binding
1430 `coding-system-for-read' and `coding-system-for-write'.
1432 The optional second argument OUTPUT-BUFFER, if non-nil,
1433 says to put the output in some other buffer.
1434 If OUTPUT-BUFFER is a buffer or buffer name, put the output there.
1435 If OUTPUT-BUFFER is not a buffer and not nil,
1436 insert output in current buffer. (This cannot be done asynchronously.)
1437 In either case, the output is inserted after point (leaving mark after it).
1439 If the command terminates without error, but generates output,
1440 and you did not specify \"insert it in the current buffer\",
1441 the output can be displayed in the echo area or in its buffer.
1442 If the output is short enough to display in the echo area
1443 \(determined by the variable `max-mini-window-height' if
1444 `resize-mini-windows' is non-nil), it is shown there. Otherwise,
1445 the buffer containing the output is displayed.
1447 If there is output and an error, and you did not specify \"insert it
1448 in the current buffer\", a message about the error goes at the end
1449 of the output.
1451 If there is no output, or if output is inserted in the current buffer,
1452 then `*Shell Command Output*' is deleted.
1454 If the optional third argument ERROR-BUFFER is non-nil, it is a buffer
1455 or buffer name to which to direct the command's standard error output.
1456 If it is nil, error output is mingled with regular output.
1457 In an interactive call, the variable `shell-command-default-error-buffer'
1458 specifies the value of ERROR-BUFFER."
1460 (interactive (list (read-from-minibuffer "Shell command: "
1461 nil nil nil 'shell-command-history)
1462 current-prefix-arg
1463 shell-command-default-error-buffer))
1464 ;; Look for a handler in case default-directory is a remote file name.
1465 (let ((handler
1466 (find-file-name-handler (directory-file-name default-directory)
1467 'shell-command)))
1468 (if handler
1469 (funcall handler 'shell-command command output-buffer error-buffer)
1470 (if (and output-buffer
1471 (not (or (bufferp output-buffer) (stringp output-buffer))))
1472 ;; Output goes in current buffer.
1473 (let ((error-file
1474 (if error-buffer
1475 (make-temp-file
1476 (expand-file-name "scor"
1477 (or small-temporary-file-directory
1478 temporary-file-directory)))
1479 nil)))
1480 (barf-if-buffer-read-only)
1481 (push-mark nil t)
1482 ;; We do not use -f for csh; we will not support broken use of
1483 ;; .cshrcs. Even the BSD csh manual says to use
1484 ;; "if ($?prompt) exit" before things which are not useful
1485 ;; non-interactively. Besides, if someone wants their other
1486 ;; aliases for shell commands then they can still have them.
1487 (call-process shell-file-name nil
1488 (if error-file
1489 (list t error-file)
1491 nil shell-command-switch command)
1492 (when (and error-file (file-exists-p error-file))
1493 (if (< 0 (nth 7 (file-attributes error-file)))
1494 (with-current-buffer (get-buffer-create error-buffer)
1495 (let ((pos-from-end (- (point-max) (point))))
1496 (or (bobp)
1497 (insert "\f\n"))
1498 ;; Do no formatting while reading error file,
1499 ;; because that can run a shell command, and we
1500 ;; don't want that to cause an infinite recursion.
1501 (format-insert-file error-file nil)
1502 ;; Put point after the inserted errors.
1503 (goto-char (- (point-max) pos-from-end)))
1504 (display-buffer (current-buffer))))
1505 (delete-file error-file))
1506 ;; This is like exchange-point-and-mark, but doesn't
1507 ;; activate the mark. It is cleaner to avoid activation,
1508 ;; even though the command loop would deactivate the mark
1509 ;; because we inserted text.
1510 (goto-char (prog1 (mark t)
1511 (set-marker (mark-marker) (point)
1512 (current-buffer)))))
1513 ;; Output goes in a separate buffer.
1514 ;; Preserve the match data in case called from a program.
1515 (save-match-data
1516 (if (string-match "[ \t]*&[ \t]*\\'" command)
1517 ;; Command ending with ampersand means asynchronous.
1518 (let ((buffer (get-buffer-create
1519 (or output-buffer "*Async Shell Command*")))
1520 (directory default-directory)
1521 proc)
1522 ;; Remove the ampersand.
1523 (setq command (substring command 0 (match-beginning 0)))
1524 ;; If will kill a process, query first.
1525 (setq proc (get-buffer-process buffer))
1526 (if proc
1527 (if (yes-or-no-p "A command is running. Kill it? ")
1528 (kill-process proc)
1529 (error "Shell command in progress")))
1530 (with-current-buffer buffer
1531 (setq buffer-read-only nil)
1532 (erase-buffer)
1533 (display-buffer buffer)
1534 (setq default-directory directory)
1535 (setq proc (start-process "Shell" buffer shell-file-name
1536 shell-command-switch command))
1537 (setq mode-line-process '(":%s"))
1538 (require 'shell) (shell-mode)
1539 (set-process-sentinel proc 'shell-command-sentinel)
1541 (shell-command-on-region (point) (point) command
1542 output-buffer nil error-buffer)))))))
1544 (defun display-message-or-buffer (message
1545 &optional buffer-name not-this-window frame)
1546 "Display MESSAGE in the echo area if possible, otherwise in a pop-up buffer.
1547 MESSAGE may be either a string or a buffer.
1549 A buffer is displayed using `display-buffer' if MESSAGE is too long for
1550 the maximum height of the echo area, as defined by `max-mini-window-height'
1551 if `resize-mini-windows' is non-nil.
1553 Returns either the string shown in the echo area, or when a pop-up
1554 buffer is used, the window used to display it.
1556 If MESSAGE is a string, then the optional argument BUFFER-NAME is the
1557 name of the buffer used to display it in the case where a pop-up buffer
1558 is used, defaulting to `*Message*'. In the case where MESSAGE is a
1559 string and it is displayed in the echo area, it is not specified whether
1560 the contents are inserted into the buffer anyway.
1562 Optional arguments NOT-THIS-WINDOW and FRAME are as for `display-buffer',
1563 and only used if a buffer is displayed."
1564 (cond ((and (stringp message) (not (string-match "\n" message)))
1565 ;; Trivial case where we can use the echo area
1566 (message "%s" message))
1567 ((and (stringp message)
1568 (= (string-match "\n" message) (1- (length message))))
1569 ;; Trivial case where we can just remove single trailing newline
1570 (message "%s" (substring message 0 (1- (length message)))))
1572 ;; General case
1573 (with-current-buffer
1574 (if (bufferp message)
1575 message
1576 (get-buffer-create (or buffer-name "*Message*")))
1578 (unless (bufferp message)
1579 (erase-buffer)
1580 (insert message))
1582 (let ((lines
1583 (if (= (buffer-size) 0)
1585 (count-lines (point-min) (point-max)))))
1586 (cond ((= lines 0))
1587 ((and (or (<= lines 1)
1588 (<= lines
1589 (if resize-mini-windows
1590 (cond ((floatp max-mini-window-height)
1591 (* (frame-height)
1592 max-mini-window-height))
1593 ((integerp max-mini-window-height)
1594 max-mini-window-height)
1597 1)))
1598 ;; Don't use the echo area if the output buffer is
1599 ;; already dispayed in the selected frame.
1600 (not (get-buffer-window (current-buffer))))
1601 ;; Echo area
1602 (goto-char (point-max))
1603 (when (bolp)
1604 (backward-char 1))
1605 (message "%s" (buffer-substring (point-min) (point))))
1607 ;; Buffer
1608 (goto-char (point-min))
1609 (display-buffer (current-buffer)
1610 not-this-window frame))))))))
1613 ;; We have a sentinel to prevent insertion of a termination message
1614 ;; in the buffer itself.
1615 (defun shell-command-sentinel (process signal)
1616 (if (memq (process-status process) '(exit signal))
1617 (message "%s: %s."
1618 (car (cdr (cdr (process-command process))))
1619 (substring signal 0 -1))))
1621 (defun shell-command-on-region (start end command
1622 &optional output-buffer replace
1623 error-buffer)
1624 "Execute string COMMAND in inferior shell with region as input.
1625 Normally display output (if any) in temp buffer `*Shell Command Output*';
1626 Prefix arg means replace the region with it. Return the exit code of
1627 COMMAND.
1629 To specify a coding system for converting non-ASCII characters
1630 in the input and output to the shell command, use \\[universal-coding-system-argument]
1631 before this command. By default, the input (from the current buffer)
1632 is encoded in the same coding system that will be used to save the file,
1633 `buffer-file-coding-system'. If the output is going to replace the region,
1634 then it is decoded from that same coding system.
1636 The noninteractive arguments are START, END, COMMAND, OUTPUT-BUFFER,
1637 REPLACE, ERROR-BUFFER. Noninteractive callers can specify coding
1638 systems by binding `coding-system-for-read' and
1639 `coding-system-for-write'.
1641 If the command generates output, the output may be displayed
1642 in the echo area or in a buffer.
1643 If the output is short enough to display in the echo area
1644 \(determined by the variable `max-mini-window-height' if
1645 `resize-mini-windows' is non-nil), it is shown there. Otherwise
1646 it is displayed in the buffer `*Shell Command Output*'. The output
1647 is available in that buffer in both cases.
1649 If there is output and an error, a message about the error
1650 appears at the end of the output.
1652 If there is no output, or if output is inserted in the current buffer,
1653 then `*Shell Command Output*' is deleted.
1655 If the optional fourth argument OUTPUT-BUFFER is non-nil,
1656 that says to put the output in some other buffer.
1657 If OUTPUT-BUFFER is a buffer or buffer name, put the output there.
1658 If OUTPUT-BUFFER is not a buffer and not nil,
1659 insert output in the current buffer.
1660 In either case, the output is inserted after point (leaving mark after it).
1662 If REPLACE, the optional fifth argument, is non-nil, that means insert
1663 the output in place of text from START to END, putting point and mark
1664 around it.
1666 If optional sixth argument ERROR-BUFFER is non-nil, it is a buffer
1667 or buffer name to which to direct the command's standard error output.
1668 If it is nil, error output is mingled with regular output.
1669 In an interactive call, the variable `shell-command-default-error-buffer'
1670 specifies the value of ERROR-BUFFER."
1671 (interactive (let (string)
1672 (unless (mark)
1673 (error "The mark is not set now, so there is no region"))
1674 ;; Do this before calling region-beginning
1675 ;; and region-end, in case subprocess output
1676 ;; relocates them while we are in the minibuffer.
1677 (setq string (read-from-minibuffer "Shell command on region: "
1678 nil nil nil
1679 'shell-command-history))
1680 ;; call-interactively recognizes region-beginning and
1681 ;; region-end specially, leaving them in the history.
1682 (list (region-beginning) (region-end)
1683 string
1684 current-prefix-arg
1685 current-prefix-arg
1686 shell-command-default-error-buffer)))
1687 (let ((error-file
1688 (if error-buffer
1689 (make-temp-file
1690 (expand-file-name "scor"
1691 (or small-temporary-file-directory
1692 temporary-file-directory)))
1693 nil))
1694 exit-status)
1695 (if (or replace
1696 (and output-buffer
1697 (not (or (bufferp output-buffer) (stringp output-buffer)))))
1698 ;; Replace specified region with output from command.
1699 (let ((swap (and replace (< start end))))
1700 ;; Don't muck with mark unless REPLACE says we should.
1701 (goto-char start)
1702 (and replace (push-mark (point) 'nomsg))
1703 (setq exit-status
1704 (call-process-region start end shell-file-name t
1705 (if error-file
1706 (list t error-file)
1708 nil shell-command-switch command))
1709 ;; It is rude to delete a buffer which the command is not using.
1710 ;; (let ((shell-buffer (get-buffer "*Shell Command Output*")))
1711 ;; (and shell-buffer (not (eq shell-buffer (current-buffer)))
1712 ;; (kill-buffer shell-buffer)))
1713 ;; Don't muck with mark unless REPLACE says we should.
1714 (and replace swap (exchange-point-and-mark)))
1715 ;; No prefix argument: put the output in a temp buffer,
1716 ;; replacing its entire contents.
1717 (let ((buffer (get-buffer-create
1718 (or output-buffer "*Shell Command Output*"))))
1719 (unwind-protect
1720 (if (eq buffer (current-buffer))
1721 ;; If the input is the same buffer as the output,
1722 ;; delete everything but the specified region,
1723 ;; then replace that region with the output.
1724 (progn (setq buffer-read-only nil)
1725 (delete-region (max start end) (point-max))
1726 (delete-region (point-min) (min start end))
1727 (setq exit-status
1728 (call-process-region (point-min) (point-max)
1729 shell-file-name t
1730 (if error-file
1731 (list t error-file)
1733 nil shell-command-switch
1734 command)))
1735 ;; Clear the output buffer, then run the command with
1736 ;; output there.
1737 (let ((directory default-directory))
1738 (save-excursion
1739 (set-buffer buffer)
1740 (setq buffer-read-only nil)
1741 (if (not output-buffer)
1742 (setq default-directory directory))
1743 (erase-buffer)))
1744 (setq exit-status
1745 (call-process-region start end shell-file-name nil
1746 (if error-file
1747 (list buffer error-file)
1748 buffer)
1749 nil shell-command-switch command)))
1750 ;; Report the output.
1751 (with-current-buffer buffer
1752 (setq mode-line-process
1753 (cond ((null exit-status)
1754 " - Error")
1755 ((stringp exit-status)
1756 (format " - Signal [%s]" exit-status))
1757 ((not (equal 0 exit-status))
1758 (format " - Exit [%d]" exit-status)))))
1759 (if (with-current-buffer buffer (> (point-max) (point-min)))
1760 ;; There's some output, display it
1761 (display-message-or-buffer buffer)
1762 ;; No output; error?
1763 (let ((output
1764 (if (and error-file
1765 (< 0 (nth 7 (file-attributes error-file))))
1766 "some error output"
1767 "no output")))
1768 (cond ((null exit-status)
1769 (message "(Shell command failed with error)"))
1770 ((equal 0 exit-status)
1771 (message "(Shell command succeeded with %s)"
1772 output))
1773 ((stringp exit-status)
1774 (message "(Shell command killed by signal %s)"
1775 exit-status))
1777 (message "(Shell command failed with code %d and %s)"
1778 exit-status output))))
1779 ;; Don't kill: there might be useful info in the undo-log.
1780 ;; (kill-buffer buffer)
1781 ))))
1783 (when (and error-file (file-exists-p error-file))
1784 (if (< 0 (nth 7 (file-attributes error-file)))
1785 (with-current-buffer (get-buffer-create error-buffer)
1786 (let ((pos-from-end (- (point-max) (point))))
1787 (or (bobp)
1788 (insert "\f\n"))
1789 ;; Do no formatting while reading error file,
1790 ;; because that can run a shell command, and we
1791 ;; don't want that to cause an infinite recursion.
1792 (format-insert-file error-file nil)
1793 ;; Put point after the inserted errors.
1794 (goto-char (- (point-max) pos-from-end)))
1795 (display-buffer (current-buffer))))
1796 (delete-file error-file))
1797 exit-status))
1799 (defun shell-command-to-string (command)
1800 "Execute shell command COMMAND and return its output as a string."
1801 (with-output-to-string
1802 (with-current-buffer
1803 standard-output
1804 (call-process shell-file-name nil t nil shell-command-switch command))))
1806 (defvar universal-argument-map
1807 (let ((map (make-sparse-keymap)))
1808 (define-key map [t] 'universal-argument-other-key)
1809 (define-key map (vector meta-prefix-char t) 'universal-argument-other-key)
1810 (define-key map [switch-frame] nil)
1811 (define-key map [?\C-u] 'universal-argument-more)
1812 (define-key map [?-] 'universal-argument-minus)
1813 (define-key map [?0] 'digit-argument)
1814 (define-key map [?1] 'digit-argument)
1815 (define-key map [?2] 'digit-argument)
1816 (define-key map [?3] 'digit-argument)
1817 (define-key map [?4] 'digit-argument)
1818 (define-key map [?5] 'digit-argument)
1819 (define-key map [?6] 'digit-argument)
1820 (define-key map [?7] 'digit-argument)
1821 (define-key map [?8] 'digit-argument)
1822 (define-key map [?9] 'digit-argument)
1823 (define-key map [kp-0] 'digit-argument)
1824 (define-key map [kp-1] 'digit-argument)
1825 (define-key map [kp-2] 'digit-argument)
1826 (define-key map [kp-3] 'digit-argument)
1827 (define-key map [kp-4] 'digit-argument)
1828 (define-key map [kp-5] 'digit-argument)
1829 (define-key map [kp-6] 'digit-argument)
1830 (define-key map [kp-7] 'digit-argument)
1831 (define-key map [kp-8] 'digit-argument)
1832 (define-key map [kp-9] 'digit-argument)
1833 (define-key map [kp-subtract] 'universal-argument-minus)
1834 map)
1835 "Keymap used while processing \\[universal-argument].")
1837 (defvar universal-argument-num-events nil
1838 "Number of argument-specifying events read by `universal-argument'.
1839 `universal-argument-other-key' uses this to discard those events
1840 from (this-command-keys), and reread only the final command.")
1842 (defvar overriding-map-is-bound nil
1843 "Non-nil when `overriding-terminal-local-map' is `universal-argument-map'.")
1845 (defvar saved-overriding-map nil
1846 "The saved value of `overriding-terminal-local-map'.
1847 That variable gets restored to this value on exiting \"universal
1848 argument mode\".")
1850 (defun ensure-overriding-map-is-bound ()
1851 "Check `overriding-terminal-local-map' is `universal-argument-map'."
1852 (unless overriding-map-is-bound
1853 (setq saved-overriding-map overriding-terminal-local-map)
1854 (setq overriding-terminal-local-map universal-argument-map)
1855 (setq overriding-map-is-bound t)))
1857 (defun restore-overriding-map ()
1858 "Restore `overriding-terminal-local-map' to its saved value."
1859 (setq overriding-terminal-local-map saved-overriding-map)
1860 (setq overriding-map-is-bound nil))
1862 (defun universal-argument ()
1863 "Begin a numeric argument for the following command.
1864 Digits or minus sign following \\[universal-argument] make up the numeric argument.
1865 \\[universal-argument] following the digits or minus sign ends the argument.
1866 \\[universal-argument] without digits or minus sign provides 4 as argument.
1867 Repeating \\[universal-argument] without digits or minus sign
1868 multiplies the argument by 4 each time.
1869 For some commands, just \\[universal-argument] by itself serves as a flag
1870 which is different in effect from any particular numeric argument.
1871 These commands include \\[set-mark-command] and \\[start-kbd-macro]."
1872 (interactive)
1873 (setq prefix-arg (list 4))
1874 (setq universal-argument-num-events (length (this-command-keys)))
1875 (ensure-overriding-map-is-bound))
1877 ;; A subsequent C-u means to multiply the factor by 4 if we've typed
1878 ;; nothing but C-u's; otherwise it means to terminate the prefix arg.
1879 (defun universal-argument-more (arg)
1880 (interactive "P")
1881 (if (consp arg)
1882 (setq prefix-arg (list (* 4 (car arg))))
1883 (if (eq arg '-)
1884 (setq prefix-arg (list -4))
1885 (setq prefix-arg arg)
1886 (restore-overriding-map)))
1887 (setq universal-argument-num-events (length (this-command-keys))))
1889 (defun negative-argument (arg)
1890 "Begin a negative numeric argument for the next command.
1891 \\[universal-argument] following digits or minus sign ends the argument."
1892 (interactive "P")
1893 (cond ((integerp arg)
1894 (setq prefix-arg (- arg)))
1895 ((eq arg '-)
1896 (setq prefix-arg nil))
1898 (setq prefix-arg '-)))
1899 (setq universal-argument-num-events (length (this-command-keys)))
1900 (ensure-overriding-map-is-bound))
1902 (defun digit-argument (arg)
1903 "Part of the numeric argument for the next command.
1904 \\[universal-argument] following digits or minus sign ends the argument."
1905 (interactive "P")
1906 (let* ((char (if (integerp last-command-char)
1907 last-command-char
1908 (get last-command-char 'ascii-character)))
1909 (digit (- (logand char ?\177) ?0)))
1910 (cond ((integerp arg)
1911 (setq prefix-arg (+ (* arg 10)
1912 (if (< arg 0) (- digit) digit))))
1913 ((eq arg '-)
1914 ;; Treat -0 as just -, so that -01 will work.
1915 (setq prefix-arg (if (zerop digit) '- (- digit))))
1917 (setq prefix-arg digit))))
1918 (setq universal-argument-num-events (length (this-command-keys)))
1919 (ensure-overriding-map-is-bound))
1921 ;; For backward compatibility, minus with no modifiers is an ordinary
1922 ;; command if digits have already been entered.
1923 (defun universal-argument-minus (arg)
1924 (interactive "P")
1925 (if (integerp arg)
1926 (universal-argument-other-key arg)
1927 (negative-argument arg)))
1929 ;; Anything else terminates the argument and is left in the queue to be
1930 ;; executed as a command.
1931 (defun universal-argument-other-key (arg)
1932 (interactive "P")
1933 (setq prefix-arg arg)
1934 (let* ((key (this-command-keys))
1935 (keylist (listify-key-sequence key)))
1936 (setq unread-command-events
1937 (append (nthcdr universal-argument-num-events keylist)
1938 unread-command-events)))
1939 (reset-this-command-lengths)
1940 (restore-overriding-map))
1942 ;;;; Window system cut and paste hooks.
1944 (defvar interprogram-cut-function nil
1945 "Function to call to make a killed region available to other programs.
1947 Most window systems provide some sort of facility for cutting and
1948 pasting text between the windows of different programs.
1949 This variable holds a function that Emacs calls whenever text
1950 is put in the kill ring, to make the new kill available to other
1951 programs.
1953 The function takes one or two arguments.
1954 The first argument, TEXT, is a string containing
1955 the text which should be made available.
1956 The second, optional, argument PUSH, has the same meaning as the
1957 similar argument to `x-set-cut-buffer', which see.")
1959 (defvar interprogram-paste-function nil
1960 "Function to call to get text cut from other programs.
1962 Most window systems provide some sort of facility for cutting and
1963 pasting text between the windows of different programs.
1964 This variable holds a function that Emacs calls to obtain
1965 text that other programs have provided for pasting.
1967 The function should be called with no arguments. If the function
1968 returns nil, then no other program has provided such text, and the top
1969 of the Emacs kill ring should be used. If the function returns a
1970 string, then the caller of the function \(usually `current-kill')
1971 should put this string in the kill ring as the latest kill.
1973 Note that the function should return a string only if a program other
1974 than Emacs has provided a string for pasting; if Emacs provided the
1975 most recent string, the function should return nil. If it is
1976 difficult to tell whether Emacs or some other program provided the
1977 current string, it is probably good enough to return nil if the string
1978 is equal (according to `string=') to the last text Emacs provided.")
1982 ;;;; The kill ring data structure.
1984 (defvar kill-ring nil
1985 "List of killed text sequences.
1986 Since the kill ring is supposed to interact nicely with cut-and-paste
1987 facilities offered by window systems, use of this variable should
1988 interact nicely with `interprogram-cut-function' and
1989 `interprogram-paste-function'. The functions `kill-new',
1990 `kill-append', and `current-kill' are supposed to implement this
1991 interaction; you may want to use them instead of manipulating the kill
1992 ring directly.")
1994 (defcustom kill-ring-max 60
1995 "*Maximum length of kill ring before oldest elements are thrown away."
1996 :type 'integer
1997 :group 'killing)
1999 (defvar kill-ring-yank-pointer nil
2000 "The tail of the kill ring whose car is the last thing yanked.")
2002 (defun kill-new (string &optional replace yank-handler)
2003 "Make STRING the latest kill in the kill ring.
2004 Set `kill-ring-yank-pointer' to point to it.
2005 If `interprogram-cut-function' is non-nil, apply it to STRING.
2006 Optional second argument REPLACE non-nil means that STRING will replace
2007 the front of the kill ring, rather than being added to the list.
2009 Optional third arguments YANK-HANDLER controls how the STRING is later
2010 inserted into a buffer; see `insert-for-yank' for details.
2011 When a yank handler is specified, STRING must be non-empty (the yank
2012 handler, if non-nil, is stored as a `yank-handler' text property on STRING).
2014 When the yank handler has a non-nil PARAM element, the original STRING
2015 argument is not used by `insert-for-yank'. However, since Lisp code
2016 may access and use elements from the kill-ring directly, the STRING
2017 argument should still be a \"useful\" string for such uses."
2018 (if (> (length string) 0)
2019 (if yank-handler
2020 (put-text-property 0 (length string)
2021 'yank-handler yank-handler string))
2022 (if yank-handler
2023 (signal 'args-out-of-range
2024 (list string "yank-handler specified for empty string"))))
2025 (if (fboundp 'menu-bar-update-yank-menu)
2026 (menu-bar-update-yank-menu string (and replace (car kill-ring))))
2027 (if (and replace kill-ring)
2028 (setcar kill-ring string)
2029 (setq kill-ring (cons string kill-ring))
2030 (if (> (length kill-ring) kill-ring-max)
2031 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)))
2032 (setq kill-ring-yank-pointer kill-ring)
2033 (if interprogram-cut-function
2034 (funcall interprogram-cut-function string (not replace))))
2036 (defun kill-append (string before-p &optional yank-handler)
2037 "Append STRING to the end of the latest kill in the kill ring.
2038 If BEFORE-P is non-nil, prepend STRING to the kill.
2039 Optional third argument YANK-HANDLER, if non-nil, specifies the
2040 yank-handler text property to be set on the combined kill ring
2041 string. If the specified yank-handler arg differs from the
2042 yank-handler property of the latest kill string, this function
2043 adds the combined string to the kill ring as a new element,
2044 instead of replacing the last kill with it.
2045 If `interprogram-cut-function' is set, pass the resulting kill to it."
2046 (let* ((cur (car kill-ring)))
2047 (kill-new (if before-p (concat string cur) (concat cur string))
2048 (or (= (length cur) 0)
2049 (equal yank-handler (get-text-property 0 'yank-handler cur)))
2050 yank-handler)))
2052 (defun current-kill (n &optional do-not-move)
2053 "Rotate the yanking point by N places, and then return that kill.
2054 If N is zero, `interprogram-paste-function' is set, and calling it
2055 returns a string, then that string is added to the front of the
2056 kill ring and returned as the latest kill.
2057 If optional arg DO-NOT-MOVE is non-nil, then don't actually move the
2058 yanking point; just return the Nth kill forward."
2059 (let ((interprogram-paste (and (= n 0)
2060 interprogram-paste-function
2061 (funcall interprogram-paste-function))))
2062 (if interprogram-paste
2063 (progn
2064 ;; Disable the interprogram cut function when we add the new
2065 ;; text to the kill ring, so Emacs doesn't try to own the
2066 ;; selection, with identical text.
2067 (let ((interprogram-cut-function nil))
2068 (kill-new interprogram-paste))
2069 interprogram-paste)
2070 (or kill-ring (error "Kill ring is empty"))
2071 (let ((ARGth-kill-element
2072 (nthcdr (mod (- n (length kill-ring-yank-pointer))
2073 (length kill-ring))
2074 kill-ring)))
2075 (or do-not-move
2076 (setq kill-ring-yank-pointer ARGth-kill-element))
2077 (car ARGth-kill-element)))))
2081 ;;;; Commands for manipulating the kill ring.
2083 (defcustom kill-read-only-ok nil
2084 "*Non-nil means don't signal an error for killing read-only text."
2085 :type 'boolean
2086 :group 'killing)
2088 (put 'text-read-only 'error-conditions
2089 '(text-read-only buffer-read-only error))
2090 (put 'text-read-only 'error-message "Text is read-only")
2092 (defun kill-region (beg end &optional yank-handler)
2093 "Kill between point and mark.
2094 The text is deleted but saved in the kill ring.
2095 The command \\[yank] can retrieve it from there.
2096 \(If you want to kill and then yank immediately, use \\[kill-ring-save].)
2098 If you want to append the killed region to the last killed text,
2099 use \\[append-next-kill] before \\[kill-region].
2101 If the buffer is read-only, Emacs will beep and refrain from deleting
2102 the text, but put the text in the kill ring anyway. This means that
2103 you can use the killing commands to copy text from a read-only buffer.
2105 This is the primitive for programs to kill text (as opposed to deleting it).
2106 Supply two arguments, character positions indicating the stretch of text
2107 to be killed.
2108 Any command that calls this function is a \"kill command\".
2109 If the previous command was also a kill command,
2110 the text killed this time appends to the text killed last time
2111 to make one entry in the kill ring.
2113 In Lisp code, optional third arg YANK-HANDLER, if non-nil,
2114 specifies the yank-handler text property to be set on the killed
2115 text. See `insert-for-yank'."
2116 (interactive "r")
2117 (condition-case nil
2118 (let ((string (delete-and-extract-region beg end)))
2119 (when string ;STRING is nil if BEG = END
2120 ;; Add that string to the kill ring, one way or another.
2121 (if (eq last-command 'kill-region)
2122 (kill-append string (< end beg) yank-handler)
2123 (kill-new string nil yank-handler)))
2124 (when (or string (eq last-command 'kill-region))
2125 (setq this-command 'kill-region))
2126 nil)
2127 ((buffer-read-only text-read-only)
2128 ;; The code above failed because the buffer, or some of the characters
2129 ;; in the region, are read-only.
2130 ;; We should beep, in case the user just isn't aware of this.
2131 ;; However, there's no harm in putting
2132 ;; the region's text in the kill ring, anyway.
2133 (copy-region-as-kill beg end)
2134 ;; Set this-command now, so it will be set even if we get an error.
2135 (setq this-command 'kill-region)
2136 ;; This should barf, if appropriate, and give us the correct error.
2137 (if kill-read-only-ok
2138 (progn (message "Read only text copied to kill ring") nil)
2139 ;; Signal an error if the buffer is read-only.
2140 (barf-if-buffer-read-only)
2141 ;; If the buffer isn't read-only, the text is.
2142 (signal 'text-read-only (list (current-buffer)))))))
2144 ;; copy-region-as-kill no longer sets this-command, because it's confusing
2145 ;; to get two copies of the text when the user accidentally types M-w and
2146 ;; then corrects it with the intended C-w.
2147 (defun copy-region-as-kill (beg end)
2148 "Save the region as if killed, but don't kill it.
2149 In Transient Mark mode, deactivate the mark.
2150 If `interprogram-cut-function' is non-nil, also save the text for a window
2151 system cut and paste."
2152 (interactive "r")
2153 (if (eq last-command 'kill-region)
2154 (kill-append (buffer-substring beg end) (< end beg))
2155 (kill-new (buffer-substring beg end)))
2156 (if transient-mark-mode
2157 (setq deactivate-mark t))
2158 nil)
2160 (defun kill-ring-save (beg end)
2161 "Save the region as if killed, but don't kill it.
2162 In Transient Mark mode, deactivate the mark.
2163 If `interprogram-cut-function' is non-nil, also save the text for a window
2164 system cut and paste.
2166 If you want to append the killed line to the last killed text,
2167 use \\[append-next-kill] before \\[kill-ring-save].
2169 This command is similar to `copy-region-as-kill', except that it gives
2170 visual feedback indicating the extent of the region being copied."
2171 (interactive "r")
2172 (copy-region-as-kill beg end)
2173 (if (interactive-p)
2174 (let ((other-end (if (= (point) beg) end beg))
2175 (opoint (point))
2176 ;; Inhibit quitting so we can make a quit here
2177 ;; look like a C-g typed as a command.
2178 (inhibit-quit t))
2179 (if (pos-visible-in-window-p other-end (selected-window))
2180 (unless (and transient-mark-mode
2181 (face-background 'region))
2182 ;; Swap point and mark.
2183 (set-marker (mark-marker) (point) (current-buffer))
2184 (goto-char other-end)
2185 (sit-for blink-matching-delay)
2186 ;; Swap back.
2187 (set-marker (mark-marker) other-end (current-buffer))
2188 (goto-char opoint)
2189 ;; If user quit, deactivate the mark
2190 ;; as C-g would as a command.
2191 (and quit-flag mark-active
2192 (deactivate-mark)))
2193 (let* ((killed-text (current-kill 0))
2194 (message-len (min (length killed-text) 40)))
2195 (if (= (point) beg)
2196 ;; Don't say "killed"; that is misleading.
2197 (message "Saved text until \"%s\""
2198 (substring killed-text (- message-len)))
2199 (message "Saved text from \"%s\""
2200 (substring killed-text 0 message-len))))))))
2202 (defun append-next-kill (&optional interactive)
2203 "Cause following command, if it kills, to append to previous kill.
2204 The argument is used for internal purposes; do not supply one."
2205 (interactive "p")
2206 ;; We don't use (interactive-p), since that breaks kbd macros.
2207 (if interactive
2208 (progn
2209 (setq this-command 'kill-region)
2210 (message "If the next command is a kill, it will append"))
2211 (setq last-command 'kill-region)))
2213 ;; Yanking.
2215 ;; This is actually used in subr.el but defcustom does not work there.
2216 (defcustom yank-excluded-properties
2217 '(read-only invisible intangible field mouse-face help-echo local-map keymap
2218 yank-handler)
2219 "*Text properties to discard when yanking.
2220 The value should be a list of text properties to discard or t,
2221 which means to discard all text properties."
2222 :type '(choice (const :tag "All" t) (repeat symbol))
2223 :group 'killing
2224 :version "21.4")
2226 (defvar yank-window-start nil)
2227 (defvar yank-undo-function nil
2228 "If non-nil, function used by `yank-pop' to delete last stretch of yanked text.
2229 Function is called with two parameters, START and END corresponding to
2230 the value of the mark and point; it is guaranteed that START <= END.
2231 Normally set from the UNDO element of a yank-handler; see `insert-for-yank'.")
2233 (defun yank-pop (&optional arg)
2234 "Replace just-yanked stretch of killed text with a different stretch.
2235 This command is allowed only immediately after a `yank' or a `yank-pop'.
2236 At such a time, the region contains a stretch of reinserted
2237 previously-killed text. `yank-pop' deletes that text and inserts in its
2238 place a different stretch of killed text.
2240 With no argument, the previous kill is inserted.
2241 With argument N, insert the Nth previous kill.
2242 If N is negative, this is a more recent kill.
2244 The sequence of kills wraps around, so that after the oldest one
2245 comes the newest one."
2246 (interactive "*p")
2247 (if (not (eq last-command 'yank))
2248 (error "Previous command was not a yank"))
2249 (setq this-command 'yank)
2250 (unless arg (setq arg 1))
2251 (let ((inhibit-read-only t)
2252 (before (< (point) (mark t))))
2253 (if before
2254 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
2255 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
2256 (setq yank-undo-function nil)
2257 (set-marker (mark-marker) (point) (current-buffer))
2258 (insert-for-yank (current-kill arg))
2259 ;; Set the window start back where it was in the yank command,
2260 ;; if possible.
2261 (set-window-start (selected-window) yank-window-start t)
2262 (if before
2263 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
2264 ;; It is cleaner to avoid activation, even though the command
2265 ;; loop would deactivate the mark because we inserted text.
2266 (goto-char (prog1 (mark t)
2267 (set-marker (mark-marker) (point) (current-buffer))))))
2268 nil)
2270 (defun yank (&optional arg)
2271 "Reinsert the last stretch of killed text.
2272 More precisely, reinsert the stretch of killed text most recently
2273 killed OR yanked. Put point at end, and set mark at beginning.
2274 With just \\[universal-argument] as argument, same but put point at beginning (and mark at end).
2275 With argument N, reinsert the Nth most recently killed stretch of killed
2276 text.
2277 See also the command \\[yank-pop]."
2278 (interactive "*P")
2279 (setq yank-window-start (window-start))
2280 ;; If we don't get all the way thru, make last-command indicate that
2281 ;; for the following command.
2282 (setq this-command t)
2283 (push-mark (point))
2284 (insert-for-yank (current-kill (cond
2285 ((listp arg) 0)
2286 ((eq arg '-) -2)
2287 (t (1- arg)))))
2288 (if (consp arg)
2289 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
2290 ;; It is cleaner to avoid activation, even though the command
2291 ;; loop would deactivate the mark because we inserted text.
2292 (goto-char (prog1 (mark t)
2293 (set-marker (mark-marker) (point) (current-buffer)))))
2294 ;; If we do get all the way thru, make this-command indicate that.
2295 (if (eq this-command t)
2296 (setq this-command 'yank))
2297 nil)
2299 (defun rotate-yank-pointer (arg)
2300 "Rotate the yanking point in the kill ring.
2301 With argument, rotate that many kills forward (or backward, if negative)."
2302 (interactive "p")
2303 (current-kill arg))
2305 ;; Some kill commands.
2307 ;; Internal subroutine of delete-char
2308 (defun kill-forward-chars (arg)
2309 (if (listp arg) (setq arg (car arg)))
2310 (if (eq arg '-) (setq arg -1))
2311 (kill-region (point) (forward-point arg)))
2313 ;; Internal subroutine of backward-delete-char
2314 (defun kill-backward-chars (arg)
2315 (if (listp arg) (setq arg (car arg)))
2316 (if (eq arg '-) (setq arg -1))
2317 (kill-region (point) (forward-point (- arg))))
2319 (defcustom backward-delete-char-untabify-method 'untabify
2320 "*The method for untabifying when deleting backward.
2321 Can be `untabify' -- turn a tab to many spaces, then delete one space;
2322 `hungry' -- delete all whitespace, both tabs and spaces;
2323 `all' -- delete all whitespace, including tabs, spaces and newlines;
2324 nil -- just delete one character."
2325 :type '(choice (const untabify) (const hungry) (const all) (const nil))
2326 :version "20.3"
2327 :group 'killing)
2329 (defun backward-delete-char-untabify (arg &optional killp)
2330 "Delete characters backward, changing tabs into spaces.
2331 The exact behavior depends on `backward-delete-char-untabify-method'.
2332 Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil.
2333 Interactively, ARG is the prefix arg (default 1)
2334 and KILLP is t if a prefix arg was specified."
2335 (interactive "*p\nP")
2336 (when (eq backward-delete-char-untabify-method 'untabify)
2337 (let ((count arg))
2338 (save-excursion
2339 (while (and (> count 0) (not (bobp)))
2340 (if (= (preceding-char) ?\t)
2341 (let ((col (current-column)))
2342 (forward-char -1)
2343 (setq col (- col (current-column)))
2344 (insert-char ?\ col)
2345 (delete-char 1)))
2346 (forward-char -1)
2347 (setq count (1- count))))))
2348 (delete-backward-char
2349 (let ((skip (cond ((eq backward-delete-char-untabify-method 'hungry) " \t")
2350 ((eq backward-delete-char-untabify-method 'all)
2351 " \t\n\r"))))
2352 (if skip
2353 (let ((wh (- (point) (save-excursion (skip-chars-backward skip)
2354 (point)))))
2355 (+ arg (if (zerop wh) 0 (1- wh))))
2356 arg))
2357 killp))
2359 (defun zap-to-char (arg char)
2360 "Kill up to and including ARG'th occurrence of CHAR.
2361 Case is ignored if `case-fold-search' is non-nil in the current buffer.
2362 Goes backward if ARG is negative; error if CHAR not found."
2363 (interactive "p\ncZap to char: ")
2364 (kill-region (point) (progn
2365 (search-forward (char-to-string char) nil nil arg)
2366 ; (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
2367 (point))))
2369 ;; kill-line and its subroutines.
2371 (defcustom kill-whole-line nil
2372 "*If non-nil, `kill-line' with no arg at beg of line kills the whole line."
2373 :type 'boolean
2374 :group 'killing)
2376 (defun kill-line (&optional arg)
2377 "Kill the rest of the current line; if no nonblanks there, kill thru newline.
2378 With prefix argument, kill that many lines from point.
2379 Negative arguments kill lines backward.
2380 With zero argument, kills the text before point on the current line.
2382 When calling from a program, nil means \"no arg\",
2383 a number counts as a prefix arg.
2385 To kill a whole line, when point is not at the beginning, type \
2386 \\[beginning-of-line] \\[kill-line] \\[kill-line].
2388 If `kill-whole-line' is non-nil, then this command kills the whole line
2389 including its terminating newline, when used at the beginning of a line
2390 with no argument. As a consequence, you can always kill a whole line
2391 by typing \\[beginning-of-line] \\[kill-line].
2393 If you want to append the killed line to the last killed text,
2394 use \\[append-next-kill] before \\[kill-line].
2396 If the buffer is read-only, Emacs will beep and refrain from deleting
2397 the line, but put the line in the kill ring anyway. This means that
2398 you can use this command to copy text from a read-only buffer.
2399 \(If the variable `kill-read-only-ok' is non-nil, then this won't
2400 even beep.)"
2401 (interactive "P")
2402 (kill-region (point)
2403 ;; It is better to move point to the other end of the kill
2404 ;; before killing. That way, in a read-only buffer, point
2405 ;; moves across the text that is copied to the kill ring.
2406 ;; The choice has no effect on undo now that undo records
2407 ;; the value of point from before the command was run.
2408 (progn
2409 (if arg
2410 (forward-visible-line (prefix-numeric-value arg))
2411 (if (eobp)
2412 (signal 'end-of-buffer nil))
2413 (let ((end
2414 (save-excursion
2415 (end-of-visible-line) (point))))
2416 (if (or (save-excursion
2417 ;; If trailing whitespace is visible,
2418 ;; don't treat it as nothing.
2419 (unless show-trailing-whitespace
2420 (skip-chars-forward " \t" end))
2421 (= (point) end))
2422 (and kill-whole-line (bolp)))
2423 (forward-visible-line 1)
2424 (goto-char end))))
2425 (point))))
2427 (defun kill-whole-line (&optional arg)
2428 "Kill current line.
2429 With prefix arg, kill that many lines starting from the current line.
2430 If arg is negative, kill backward. Also kill the preceding newline.
2431 \(This is meant to make C-x z work well with negative arguments.\)
2432 If arg is zero, kill current line but exclude the trailing newline."
2433 (interactive "p")
2434 (if (and (> arg 0) (eobp) (save-excursion (forward-visible-line 0) (eobp)))
2435 (signal 'end-of-buffer nil))
2436 (if (and (< arg 0) (bobp) (save-excursion (end-of-visible-line) (bobp)))
2437 (signal 'beginning-of-buffer nil))
2438 (unless (eq last-command 'kill-region)
2439 (kill-new "")
2440 (setq last-command 'kill-region))
2441 (cond ((zerop arg)
2442 ;; We need to kill in two steps, because the previous command
2443 ;; could have been a kill command, in which case the text
2444 ;; before point needs to be prepended to the current kill
2445 ;; ring entry and the text after point appended. Also, we
2446 ;; need to use save-excursion to avoid copying the same text
2447 ;; twice to the kill ring in read-only buffers.
2448 (save-excursion
2449 (kill-region (point) (progn (forward-visible-line 0) (point))))
2450 (kill-region (point) (progn (end-of-visible-line) (point))))
2451 ((< arg 0)
2452 (save-excursion
2453 (kill-region (point) (progn (end-of-visible-line) (point))))
2454 (kill-region (point)
2455 (progn (forward-visible-line (1+ arg))
2456 (unless (bobp) (backward-char))
2457 (point))))
2459 (save-excursion
2460 (kill-region (point) (progn (forward-visible-line 0) (point))))
2461 (kill-region (point)
2462 (progn (forward-visible-line arg) (point))))))
2464 (defun forward-visible-line (arg)
2465 "Move forward by ARG lines, ignoring currently invisible newlines only.
2466 If ARG is negative, move backward -ARG lines.
2467 If ARG is zero, move to the beginning of the current line."
2468 (condition-case nil
2469 (if (> arg 0)
2470 (progn
2471 (while (> arg 0)
2472 (or (zerop (forward-line 1))
2473 (signal 'end-of-buffer nil))
2474 ;; If the newline we just skipped is invisible,
2475 ;; don't count it.
2476 (let ((prop
2477 (get-char-property (1- (point)) 'invisible)))
2478 (if (if (eq buffer-invisibility-spec t)
2479 prop
2480 (or (memq prop buffer-invisibility-spec)
2481 (assq prop buffer-invisibility-spec)))
2482 (setq arg (1+ arg))))
2483 (setq arg (1- arg)))
2484 ;; If invisible text follows, and it is a number of complete lines,
2485 ;; skip it.
2486 (let ((opoint (point)))
2487 (while (and (not (eobp))
2488 (let ((prop
2489 (get-char-property (point) 'invisible)))
2490 (if (eq buffer-invisibility-spec t)
2491 prop
2492 (or (memq prop buffer-invisibility-spec)
2493 (assq prop buffer-invisibility-spec)))))
2494 (goto-char
2495 (if (get-text-property (point) 'invisible)
2496 (or (next-single-property-change (point) 'invisible)
2497 (point-max))
2498 (next-overlay-change (point)))))
2499 (unless (bolp)
2500 (goto-char opoint))))
2501 (let ((first t))
2502 (while (or first (<= arg 0))
2503 (if first
2504 (beginning-of-line)
2505 (or (zerop (forward-line -1))
2506 (signal 'beginning-of-buffer nil)))
2507 ;; If the newline we just moved to is invisible,
2508 ;; don't count it.
2509 (unless (bobp)
2510 (let ((prop
2511 (get-char-property (1- (point)) 'invisible)))
2512 (unless (if (eq buffer-invisibility-spec t)
2513 prop
2514 (or (memq prop buffer-invisibility-spec)
2515 (assq prop buffer-invisibility-spec)))
2516 (setq arg (1+ arg)))))
2517 (setq first nil))
2518 ;; If invisible text follows, and it is a number of complete lines,
2519 ;; skip it.
2520 (let ((opoint (point)))
2521 (while (and (not (bobp))
2522 (let ((prop
2523 (get-char-property (1- (point)) 'invisible)))
2524 (if (eq buffer-invisibility-spec t)
2525 prop
2526 (or (memq prop buffer-invisibility-spec)
2527 (assq prop buffer-invisibility-spec)))))
2528 (goto-char
2529 (if (get-text-property (1- (point)) 'invisible)
2530 (or (previous-single-property-change (point) 'invisible)
2531 (point-min))
2532 (previous-overlay-change (point)))))
2533 (unless (bolp)
2534 (goto-char opoint)))))
2535 ((beginning-of-buffer end-of-buffer)
2536 nil)))
2538 (defun end-of-visible-line ()
2539 "Move to end of current visible line."
2540 (end-of-line)
2541 ;; If the following character is currently invisible,
2542 ;; skip all characters with that same `invisible' property value,
2543 ;; then find the next newline.
2544 (while (and (not (eobp))
2545 (save-excursion
2546 (skip-chars-forward "^\n")
2547 (let ((prop
2548 (get-char-property (point) 'invisible)))
2549 (if (eq buffer-invisibility-spec t)
2550 prop
2551 (or (memq prop buffer-invisibility-spec)
2552 (assq prop buffer-invisibility-spec))))))
2553 (skip-chars-forward "^\n")
2554 (if (get-text-property (point) 'invisible)
2555 (goto-char (next-single-property-change (point) 'invisible))
2556 (goto-char (next-overlay-change (point))))
2557 (end-of-line)))
2559 (defun insert-buffer (buffer)
2560 "Insert after point the contents of BUFFER.
2561 Puts mark after the inserted text.
2562 BUFFER may be a buffer or a buffer name.
2564 This function is meant for the user to run interactively.
2565 Don't call it from programs: use `insert-buffer-substring' instead!"
2566 (interactive
2567 (list
2568 (progn
2569 (barf-if-buffer-read-only)
2570 (read-buffer "Insert buffer: "
2571 (if (eq (selected-window) (next-window (selected-window)))
2572 (other-buffer (current-buffer))
2573 (window-buffer (next-window (selected-window))))
2574 t))))
2575 (push-mark
2576 (save-excursion
2577 (insert-buffer-substring (get-buffer buffer))
2578 (point)))
2579 nil)
2581 (defun append-to-buffer (buffer start end)
2582 "Append to specified buffer the text of the region.
2583 It is inserted into that buffer before its point.
2585 When calling from a program, give three arguments:
2586 BUFFER (or buffer name), START and END.
2587 START and END specify the portion of the current buffer to be copied."
2588 (interactive
2589 (list (read-buffer "Append to buffer: " (other-buffer (current-buffer) t))
2590 (region-beginning) (region-end)))
2591 (let ((oldbuf (current-buffer)))
2592 (save-excursion
2593 (let* ((append-to (get-buffer-create buffer))
2594 (windows (get-buffer-window-list append-to t t))
2595 point)
2596 (set-buffer append-to)
2597 (setq point (point))
2598 (barf-if-buffer-read-only)
2599 (insert-buffer-substring oldbuf start end)
2600 (dolist (window windows)
2601 (when (= (window-point window) point)
2602 (set-window-point window (point))))))))
2604 (defun prepend-to-buffer (buffer start end)
2605 "Prepend to specified buffer the text of the region.
2606 It is inserted into that buffer after its point.
2608 When calling from a program, give three arguments:
2609 BUFFER (or buffer name), START and END.
2610 START and END specify the portion of the current buffer to be copied."
2611 (interactive "BPrepend to buffer: \nr")
2612 (let ((oldbuf (current-buffer)))
2613 (save-excursion
2614 (set-buffer (get-buffer-create buffer))
2615 (barf-if-buffer-read-only)
2616 (save-excursion
2617 (insert-buffer-substring oldbuf start end)))))
2619 (defun copy-to-buffer (buffer start end)
2620 "Copy to specified buffer the text of the region.
2621 It is inserted into that buffer, replacing existing text there.
2623 When calling from a program, give three arguments:
2624 BUFFER (or buffer name), START and END.
2625 START and END specify the portion of the current buffer to be copied."
2626 (interactive "BCopy to buffer: \nr")
2627 (let ((oldbuf (current-buffer)))
2628 (save-excursion
2629 (set-buffer (get-buffer-create buffer))
2630 (barf-if-buffer-read-only)
2631 (erase-buffer)
2632 (save-excursion
2633 (insert-buffer-substring oldbuf start end)))))
2635 (put 'mark-inactive 'error-conditions '(mark-inactive error))
2636 (put 'mark-inactive 'error-message "The mark is not active now")
2638 (defun mark (&optional force)
2639 "Return this buffer's mark value as integer; error if mark inactive.
2640 If optional argument FORCE is non-nil, access the mark value
2641 even if the mark is not currently active, and return nil
2642 if there is no mark at all.
2644 If you are using this in an editing command, you are most likely making
2645 a mistake; see the documentation of `set-mark'."
2646 (if (or force (not transient-mark-mode) mark-active mark-even-if-inactive)
2647 (marker-position (mark-marker))
2648 (signal 'mark-inactive nil)))
2650 ;; Many places set mark-active directly, and several of them failed to also
2651 ;; run deactivate-mark-hook. This shorthand should simplify.
2652 (defsubst deactivate-mark ()
2653 "Deactivate the mark by setting `mark-active' to nil.
2654 \(That makes a difference only in Transient Mark mode.)
2655 Also runs the hook `deactivate-mark-hook'."
2656 (cond
2657 ((eq transient-mark-mode 'lambda)
2658 (setq transient-mark-mode nil))
2659 (transient-mark-mode
2660 (setq mark-active nil)
2661 (run-hooks 'deactivate-mark-hook))))
2663 (defun set-mark (pos)
2664 "Set this buffer's mark to POS. Don't use this function!
2665 That is to say, don't use this function unless you want
2666 the user to see that the mark has moved, and you want the previous
2667 mark position to be lost.
2669 Normally, when a new mark is set, the old one should go on the stack.
2670 This is why most applications should use push-mark, not set-mark.
2672 Novice Emacs Lisp programmers often try to use the mark for the wrong
2673 purposes. The mark saves a location for the user's convenience.
2674 Most editing commands should not alter the mark.
2675 To remember a location for internal use in the Lisp program,
2676 store it in a Lisp variable. Example:
2678 (let ((beg (point))) (forward-line 1) (delete-region beg (point)))."
2680 (if pos
2681 (progn
2682 (setq mark-active t)
2683 (run-hooks 'activate-mark-hook)
2684 (set-marker (mark-marker) pos (current-buffer)))
2685 ;; Normally we never clear mark-active except in Transient Mark mode.
2686 ;; But when we actually clear out the mark value too,
2687 ;; we must clear mark-active in any mode.
2688 (setq mark-active nil)
2689 (run-hooks 'deactivate-mark-hook)
2690 (set-marker (mark-marker) nil)))
2692 (defvar mark-ring nil
2693 "The list of former marks of the current buffer, most recent first.")
2694 (make-variable-buffer-local 'mark-ring)
2695 (put 'mark-ring 'permanent-local t)
2697 (defcustom mark-ring-max 16
2698 "*Maximum size of mark ring. Start discarding off end if gets this big."
2699 :type 'integer
2700 :group 'editing-basics)
2702 (defvar global-mark-ring nil
2703 "The list of saved global marks, most recent first.")
2705 (defcustom global-mark-ring-max 16
2706 "*Maximum size of global mark ring. \
2707 Start discarding off end if gets this big."
2708 :type 'integer
2709 :group 'editing-basics)
2711 (defun pop-to-mark-command ()
2712 "Jump to mark, and pop a new position for mark off the ring
2713 \(does not affect global mark ring\)."
2714 (interactive)
2715 (if (null (mark t))
2716 (error "No mark set in this buffer")
2717 (goto-char (mark t))
2718 (pop-mark)))
2720 (defun push-mark-command (arg &optional nomsg)
2721 "Set mark at where point is.
2722 If no prefix arg and mark is already set there, just activate it.
2723 Display `Mark set' unless the optional second arg NOMSG is non-nil."
2724 (interactive "P")
2725 (let ((mark (marker-position (mark-marker))))
2726 (if (or arg (null mark) (/= mark (point)))
2727 (push-mark nil nomsg t)
2728 (setq mark-active t)
2729 (unless nomsg
2730 (message "Mark activated")))))
2732 (defun set-mark-command (arg)
2733 "Set mark at where point is, or jump to mark.
2734 With no prefix argument, set mark, and push old mark position on local
2735 mark ring; also push mark on global mark ring if last mark was set in
2736 another buffer. Immediately repeating the command activates
2737 `transient-mark-mode' temporarily.
2739 With argument, e.g. \\[universal-argument] \\[set-mark-command], \
2740 jump to mark, and pop a new position
2741 for mark off the local mark ring \(this does not affect the global
2742 mark ring\). Use \\[pop-global-mark] to jump to a mark off the global
2743 mark ring \(see `pop-global-mark'\).
2745 Repeating the \\[set-mark-command] command without the prefix jumps to
2746 the next position off the local (or global) mark ring.
2748 With a double \\[universal-argument] prefix argument, e.g. \\[universal-argument] \
2749 \\[universal-argument] \\[set-mark-command], unconditionally
2750 set mark where point is.
2752 Novice Emacs Lisp programmers often try to use the mark for the wrong
2753 purposes. See the documentation of `set-mark' for more information."
2754 (interactive "P")
2755 (if (eq transient-mark-mode 'lambda)
2756 (setq transient-mark-mode nil))
2757 (cond
2758 ((and (consp arg) (> (prefix-numeric-value arg) 4))
2759 (push-mark-command nil))
2760 ((not (eq this-command 'set-mark-command))
2761 (if arg
2762 (pop-to-mark-command)
2763 (push-mark-command t)))
2764 ((eq last-command 'pop-to-mark-command)
2765 (setq this-command 'pop-to-mark-command)
2766 (pop-to-mark-command))
2767 ((and (eq last-command 'pop-global-mark) (not arg))
2768 (setq this-command 'pop-global-mark)
2769 (pop-global-mark))
2770 (arg
2771 (setq this-command 'pop-to-mark-command)
2772 (pop-to-mark-command))
2773 ((and (eq last-command 'set-mark-command)
2774 mark-active (null transient-mark-mode))
2775 (setq transient-mark-mode 'lambda)
2776 (message "Transient-mark-mode temporarily enabled"))
2778 (push-mark-command nil))))
2780 (defun push-mark (&optional location nomsg activate)
2781 "Set mark at LOCATION (point, by default) and push old mark on mark ring.
2782 If the last global mark pushed was not in the current buffer,
2783 also push LOCATION on the global mark ring.
2784 Display `Mark set' unless the optional second arg NOMSG is non-nil.
2785 In Transient Mark mode, activate mark if optional third arg ACTIVATE non-nil.
2787 Novice Emacs Lisp programmers often try to use the mark for the wrong
2788 purposes. See the documentation of `set-mark' for more information.
2790 In Transient Mark mode, this does not activate the mark."
2791 (unless (null (mark t))
2792 (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring))
2793 (when (> (length mark-ring) mark-ring-max)
2794 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil)
2795 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil)))
2796 (set-marker (mark-marker) (or location (point)) (current-buffer))
2797 ;; Now push the mark on the global mark ring.
2798 (if (and global-mark-ring
2799 (eq (marker-buffer (car global-mark-ring)) (current-buffer)))
2800 ;; The last global mark pushed was in this same buffer.
2801 ;; Don't push another one.
2803 (setq global-mark-ring (cons (copy-marker (mark-marker)) global-mark-ring))
2804 (when (> (length global-mark-ring) global-mark-ring-max)
2805 (move-marker (car (nthcdr global-mark-ring-max global-mark-ring)) nil)
2806 (setcdr (nthcdr (1- global-mark-ring-max) global-mark-ring) nil)))
2807 (or nomsg executing-kbd-macro (> (minibuffer-depth) 0)
2808 (message "Mark set"))
2809 (if (or activate (not transient-mark-mode))
2810 (set-mark (mark t)))
2811 nil)
2813 (defun pop-mark ()
2814 "Pop off mark ring into the buffer's actual mark.
2815 Does not set point. Does nothing if mark ring is empty."
2816 (when mark-ring
2817 (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker)))))
2818 (set-marker (mark-marker) (+ 0 (car mark-ring)) (current-buffer))
2819 (deactivate-mark)
2820 (move-marker (car mark-ring) nil)
2821 (if (null (mark t)) (ding))
2822 (setq mark-ring (cdr mark-ring))))
2824 (defalias 'exchange-dot-and-mark 'exchange-point-and-mark)
2825 (defun exchange-point-and-mark (&optional arg)
2826 "Put the mark where point is now, and point where the mark is now.
2827 This command works even when the mark is not active,
2828 and it reactivates the mark.
2829 With prefix arg, `transient-mark-mode' is enabled temporarily."
2830 (interactive "P")
2831 (if arg
2832 (if mark-active
2833 (if (null transient-mark-mode)
2834 (setq transient-mark-mode 'lambda))
2835 (setq arg nil)))
2836 (unless arg
2837 (let ((omark (mark t)))
2838 (if (null omark)
2839 (error "No mark set in this buffer"))
2840 (set-mark (point))
2841 (goto-char omark)
2842 nil)))
2844 (define-minor-mode transient-mark-mode
2845 "Toggle Transient Mark mode.
2846 With arg, turn Transient Mark mode on if arg is positive, off otherwise.
2848 In Transient Mark mode, when the mark is active, the region is highlighted.
2849 Changing the buffer \"deactivates\" the mark.
2850 So do certain other operations that set the mark
2851 but whose main purpose is something else--for example,
2852 incremental search, \\[beginning-of-buffer], and \\[end-of-buffer].
2854 You can also deactivate the mark by typing \\[keyboard-quit] or
2855 \\[keyboard-escape-quit].
2857 Many commands change their behavior when Transient Mark mode is in effect
2858 and the mark is active, by acting on the region instead of their usual
2859 default part of the buffer's text. Examples of such commands include
2860 \\[comment-dwim], \\[flush-lines], \\[ispell], \\[keep-lines],
2861 \\[query-replace], \\[query-replace-regexp], and \\[undo]. Invoke
2862 \\[apropos-documentation] and type \"transient\" or \"mark.*active\" at
2863 the prompt, to see the documentation of commands which are sensitive to
2864 the Transient Mark mode."
2865 :global t :group 'editing-basics :require nil)
2867 (defun pop-global-mark ()
2868 "Pop off global mark ring and jump to the top location."
2869 (interactive)
2870 ;; Pop entries which refer to non-existent buffers.
2871 (while (and global-mark-ring (not (marker-buffer (car global-mark-ring))))
2872 (setq global-mark-ring (cdr global-mark-ring)))
2873 (or global-mark-ring
2874 (error "No global mark set"))
2875 (let* ((marker (car global-mark-ring))
2876 (buffer (marker-buffer marker))
2877 (position (marker-position marker)))
2878 (setq global-mark-ring (nconc (cdr global-mark-ring)
2879 (list (car global-mark-ring))))
2880 (set-buffer buffer)
2881 (or (and (>= position (point-min))
2882 (<= position (point-max)))
2883 (widen))
2884 (goto-char position)
2885 (switch-to-buffer buffer)))
2887 (defcustom next-line-add-newlines nil
2888 "*If non-nil, `next-line' inserts newline to avoid `end of buffer' error."
2889 :type 'boolean
2890 :version "21.1"
2891 :group 'editing-basics)
2893 (defun next-line (&optional arg)
2894 "Move cursor vertically down ARG lines.
2895 If there is no character in the target line exactly under the current column,
2896 the cursor is positioned after the character in that line which spans this
2897 column, or at the end of the line if it is not long enough.
2898 If there is no line in the buffer after this one, behavior depends on the
2899 value of `next-line-add-newlines'. If non-nil, it inserts a newline character
2900 to create a line, and moves the cursor to that line. Otherwise it moves the
2901 cursor to the end of the buffer.
2903 The command \\[set-goal-column] can be used to create
2904 a semipermanent goal column for this command.
2905 Then instead of trying to move exactly vertically (or as close as possible),
2906 this command moves to the specified goal column (or as close as possible).
2907 The goal column is stored in the variable `goal-column', which is nil
2908 when there is no goal column.
2910 If you are thinking of using this in a Lisp program, consider
2911 using `forward-line' instead. It is usually easier to use
2912 and more reliable (no dependence on goal column, etc.)."
2913 (interactive "p")
2914 (or arg (setq arg 1))
2915 (if (and next-line-add-newlines (= arg 1))
2916 (if (save-excursion (end-of-line) (eobp))
2917 ;; When adding a newline, don't expand an abbrev.
2918 (let ((abbrev-mode nil))
2919 (end-of-line)
2920 (insert "\n"))
2921 (line-move arg))
2922 (if (interactive-p)
2923 (condition-case nil
2924 (line-move arg)
2925 ((beginning-of-buffer end-of-buffer) (ding)))
2926 (line-move arg)))
2927 nil)
2929 (defun previous-line (&optional arg)
2930 "Move cursor vertically up ARG lines.
2931 If there is no character in the target line exactly over the current column,
2932 the cursor is positioned after the character in that line which spans this
2933 column, or at the end of the line if it is not long enough.
2935 The command \\[set-goal-column] can be used to create
2936 a semipermanent goal column for this command.
2937 Then instead of trying to move exactly vertically (or as close as possible),
2938 this command moves to the specified goal column (or as close as possible).
2939 The goal column is stored in the variable `goal-column', which is nil
2940 when there is no goal column.
2942 If you are thinking of using this in a Lisp program, consider using
2943 `forward-line' with a negative argument instead. It is usually easier
2944 to use and more reliable (no dependence on goal column, etc.)."
2945 (interactive "p")
2946 (or arg (setq arg 1))
2947 (if (interactive-p)
2948 (condition-case nil
2949 (line-move (- arg))
2950 ((beginning-of-buffer end-of-buffer) (ding)))
2951 (line-move (- arg)))
2952 nil)
2954 (defcustom track-eol nil
2955 "*Non-nil means vertical motion starting at end of line keeps to ends of lines.
2956 This means moving to the end of each line moved onto.
2957 The beginning of a blank line does not count as the end of a line."
2958 :type 'boolean
2959 :group 'editing-basics)
2961 (defcustom goal-column nil
2962 "*Semipermanent goal column for vertical motion, as set by \\[set-goal-column], or nil."
2963 :type '(choice integer
2964 (const :tag "None" nil))
2965 :group 'editing-basics)
2966 (make-variable-buffer-local 'goal-column)
2968 (defvar temporary-goal-column 0
2969 "Current goal column for vertical motion.
2970 It is the column where point was
2971 at the start of current run of vertical motion commands.
2972 When the `track-eol' feature is doing its job, the value is 9999.")
2974 (defcustom line-move-ignore-invisible nil
2975 "*Non-nil means \\[next-line] and \\[previous-line] ignore invisible lines.
2976 Outline mode sets this."
2977 :type 'boolean
2978 :group 'editing-basics)
2980 (defun line-move-invisible (pos)
2981 "Return non-nil if the character after POS is currently invisible."
2982 (let ((prop
2983 (get-char-property pos 'invisible)))
2984 (if (eq buffer-invisibility-spec t)
2985 prop
2986 (or (memq prop buffer-invisibility-spec)
2987 (assq prop buffer-invisibility-spec)))))
2989 ;; This is the guts of next-line and previous-line.
2990 ;; Arg says how many lines to move.
2991 (defun line-move (arg)
2992 ;; Don't run any point-motion hooks, and disregard intangibility,
2993 ;; for intermediate positions.
2994 (let ((inhibit-point-motion-hooks t)
2995 (opoint (point))
2996 new line-end line-beg)
2997 (unwind-protect
2998 (progn
2999 (if (not (memq last-command '(next-line previous-line)))
3000 (setq temporary-goal-column
3001 (if (and track-eol (eolp)
3002 ;; Don't count beg of empty line as end of line
3003 ;; unless we just did explicit end-of-line.
3004 (or (not (bolp)) (eq last-command 'end-of-line)))
3005 9999
3006 (current-column))))
3007 (if (and (not (integerp selective-display))
3008 (not line-move-ignore-invisible))
3009 ;; Use just newline characters.
3010 ;; Set ARG to 0 if we move as many lines as requested.
3011 (or (if (> arg 0)
3012 (progn (if (> arg 1) (forward-line (1- arg)))
3013 ;; This way of moving forward ARG lines
3014 ;; verifies that we have a newline after the last one.
3015 ;; It doesn't get confused by intangible text.
3016 (end-of-line)
3017 (if (zerop (forward-line 1))
3018 (setq arg 0)))
3019 (and (zerop (forward-line arg))
3020 (bolp)
3021 (setq arg 0)))
3022 (signal (if (< arg 0)
3023 'beginning-of-buffer
3024 'end-of-buffer)
3025 nil))
3026 ;; Move by arg lines, but ignore invisible ones.
3027 (while (> arg 0)
3028 ;; If the following character is currently invisible,
3029 ;; skip all characters with that same `invisible' property value.
3030 (while (and (not (eobp)) (line-move-invisible (point)))
3031 (goto-char (next-char-property-change (point))))
3032 ;; Now move a line.
3033 (end-of-line)
3034 (and (zerop (vertical-motion 1))
3035 (signal 'end-of-buffer nil))
3036 (setq arg (1- arg)))
3037 (while (< arg 0)
3038 (beginning-of-line)
3039 (and (zerop (vertical-motion -1))
3040 (signal 'beginning-of-buffer nil))
3041 (setq arg (1+ arg))
3042 (while (and (not (bobp)) (line-move-invisible (1- (point))))
3043 (goto-char (previous-char-property-change (point)))))))
3045 (cond ((> arg 0)
3046 ;; If we did not move down as far as desired,
3047 ;; at least go to end of line.
3048 (end-of-line))
3049 ((< arg 0)
3050 ;; If we did not move down as far as desired,
3051 ;; at least go to end of line.
3052 (beginning-of-line))
3054 (line-move-finish (or goal-column temporary-goal-column) opoint)))))
3055 nil)
3057 (defun line-move-finish (column opoint)
3058 (let ((repeat t))
3059 (while repeat
3060 ;; Set REPEAT to t to repeat the whole thing.
3061 (setq repeat nil)
3063 (let (new
3064 (line-beg (save-excursion (beginning-of-line) (point)))
3065 (line-end
3066 ;; Compute the end of the line
3067 ;; ignoring effectively intangible newlines.
3068 (let ((inhibit-point-motion-hooks nil)
3069 (inhibit-field-text-motion t))
3070 (save-excursion (end-of-line) (point)))))
3072 ;; Move to the desired column.
3073 (line-move-to-column column)
3074 (setq new (point))
3076 ;; Process intangibility within a line.
3077 ;; Move to the chosen destination position from above,
3078 ;; with intangibility processing enabled.
3080 (goto-char (point-min))
3081 (let ((inhibit-point-motion-hooks nil))
3082 (goto-char new)
3084 ;; If intangibility moves us to a different (later) place
3085 ;; in the same line, use that as the destination.
3086 (if (<= (point) line-end)
3087 (setq new (point))
3088 ;; If that position is "too late",
3089 ;; try the previous allowable position.
3090 ;; See if it is ok.
3091 (backward-char)
3092 (if (<= (point) line-end)
3093 (setq new (point))
3094 ;; As a last resort, use the end of the line.
3095 (setq new line-end))))
3097 ;; Now move to the updated destination, processing fields
3098 ;; as well as intangibility.
3099 (goto-char opoint)
3100 (let ((inhibit-point-motion-hooks nil))
3101 (goto-char
3102 (constrain-to-field new opoint nil t
3103 'inhibit-line-move-field-capture)))
3105 ;; If all this moved us to a different line,
3106 ;; retry everything within that new line.
3107 (when (or (< (point) line-beg) (> (point) line-end))
3108 ;; Repeat the intangibility and field processing.
3109 (setq repeat t))))))
3111 (defun line-move-to-column (col)
3112 "Try to find column COL, considering invisibility.
3113 This function works only in certain cases,
3114 because what we really need is for `move-to-column'
3115 and `current-column' to be able to ignore invisible text."
3116 (if (zerop col)
3117 (beginning-of-line)
3118 (move-to-column col))
3120 (when (and line-move-ignore-invisible
3121 (not (bolp)) (line-move-invisible (1- (point))))
3122 (let ((normal-location (point))
3123 (normal-column (current-column)))
3124 ;; If the following character is currently invisible,
3125 ;; skip all characters with that same `invisible' property value.
3126 (while (and (not (eobp))
3127 (line-move-invisible (point)))
3128 (goto-char (next-char-property-change (point))))
3129 ;; Have we advanced to a larger column position?
3130 (if (> (current-column) normal-column)
3131 ;; We have made some progress towards the desired column.
3132 ;; See if we can make any further progress.
3133 (line-move-to-column (+ (current-column) (- col normal-column)))
3134 ;; Otherwise, go to the place we originally found
3135 ;; and move back over invisible text.
3136 ;; that will get us to the same place on the screen
3137 ;; but with a more reasonable buffer position.
3138 (goto-char normal-location)
3139 (let ((line-beg (save-excursion (beginning-of-line) (point))))
3140 (while (and (not (bolp)) (line-move-invisible (1- (point))))
3141 (goto-char (previous-char-property-change (point) line-beg))))))))
3143 ;;; Many people have said they rarely use this feature, and often type
3144 ;;; it by accident. Maybe it shouldn't even be on a key.
3145 (put 'set-goal-column 'disabled t)
3147 (defun set-goal-column (arg)
3148 "Set the current horizontal position as a goal for \\[next-line] and \\[previous-line].
3149 Those commands will move to this position in the line moved to
3150 rather than trying to keep the same horizontal position.
3151 With a non-nil argument, clears out the goal column
3152 so that \\[next-line] and \\[previous-line] resume vertical motion.
3153 The goal column is stored in the variable `goal-column'."
3154 (interactive "P")
3155 (if arg
3156 (progn
3157 (setq goal-column nil)
3158 (message "No goal column"))
3159 (setq goal-column (current-column))
3160 (message (substitute-command-keys
3161 "Goal column %d (use \\[set-goal-column] with an arg to unset it)")
3162 goal-column))
3163 nil)
3166 (defun scroll-other-window-down (lines)
3167 "Scroll the \"other window\" down.
3168 For more details, see the documentation for `scroll-other-window'."
3169 (interactive "P")
3170 (scroll-other-window
3171 ;; Just invert the argument's meaning.
3172 ;; We can do that without knowing which window it will be.
3173 (if (eq lines '-) nil
3174 (if (null lines) '-
3175 (- (prefix-numeric-value lines))))))
3176 (define-key esc-map [?\C-\S-v] 'scroll-other-window-down)
3178 (defun beginning-of-buffer-other-window (arg)
3179 "Move point to the beginning of the buffer in the other window.
3180 Leave mark at previous position.
3181 With arg N, put point N/10 of the way from the true beginning."
3182 (interactive "P")
3183 (let ((orig-window (selected-window))
3184 (window (other-window-for-scrolling)))
3185 ;; We use unwind-protect rather than save-window-excursion
3186 ;; because the latter would preserve the things we want to change.
3187 (unwind-protect
3188 (progn
3189 (select-window window)
3190 ;; Set point and mark in that window's buffer.
3191 (beginning-of-buffer arg)
3192 ;; Set point accordingly.
3193 (recenter '(t)))
3194 (select-window orig-window))))
3196 (defun end-of-buffer-other-window (arg)
3197 "Move point to the end of the buffer in the other window.
3198 Leave mark at previous position.
3199 With arg N, put point N/10 of the way from the true end."
3200 (interactive "P")
3201 ;; See beginning-of-buffer-other-window for comments.
3202 (let ((orig-window (selected-window))
3203 (window (other-window-for-scrolling)))
3204 (unwind-protect
3205 (progn
3206 (select-window window)
3207 (end-of-buffer arg)
3208 (recenter '(t)))
3209 (select-window orig-window))))
3211 (defun transpose-chars (arg)
3212 "Interchange characters around point, moving forward one character.
3213 With prefix arg ARG, effect is to take character before point
3214 and drag it forward past ARG other characters (backward if ARG negative).
3215 If no argument and at end of line, the previous two chars are exchanged."
3216 (interactive "*P")
3217 (and (null arg) (eolp) (forward-char -1))
3218 (transpose-subr 'forward-char (prefix-numeric-value arg)))
3220 (defun transpose-words (arg)
3221 "Interchange words around point, leaving point at end of them.
3222 With prefix arg ARG, effect is to take word before or around point
3223 and drag it forward past ARG other words (backward if ARG negative).
3224 If ARG is zero, the words around or after point and around or after mark
3225 are interchanged."
3226 ;; FIXME: `foo a!nd bar' should transpose into `bar and foo'.
3227 (interactive "*p")
3228 (transpose-subr 'forward-word arg))
3230 (defun transpose-sexps (arg)
3231 "Like \\[transpose-words] but applies to sexps.
3232 Does not work on a sexp that point is in the middle of
3233 if it is a list or string."
3234 (interactive "*p")
3235 (transpose-subr
3236 (lambda (arg)
3237 ;; Here we should try to simulate the behavior of
3238 ;; (cons (progn (forward-sexp x) (point))
3239 ;; (progn (forward-sexp (- x)) (point)))
3240 ;; Except that we don't want to rely on the second forward-sexp
3241 ;; putting us back to where we want to be, since forward-sexp-function
3242 ;; might do funny things like infix-precedence.
3243 (if (if (> arg 0)
3244 (looking-at "\\sw\\|\\s_")
3245 (and (not (bobp))
3246 (save-excursion (forward-char -1) (looking-at "\\sw\\|\\s_"))))
3247 ;; Jumping over a symbol. We might be inside it, mind you.
3248 (progn (funcall (if (> arg 0)
3249 'skip-syntax-backward 'skip-syntax-forward)
3250 "w_")
3251 (cons (save-excursion (forward-sexp arg) (point)) (point)))
3252 ;; Otherwise, we're between sexps. Take a step back before jumping
3253 ;; to make sure we'll obey the same precedence no matter which direction
3254 ;; we're going.
3255 (funcall (if (> arg 0) 'skip-syntax-backward 'skip-syntax-forward) " .")
3256 (cons (save-excursion (forward-sexp arg) (point))
3257 (progn (while (or (forward-comment (if (> arg 0) 1 -1))
3258 (not (zerop (funcall (if (> arg 0)
3259 'skip-syntax-forward
3260 'skip-syntax-backward)
3261 ".")))))
3262 (point)))))
3263 arg 'special))
3265 (defun transpose-lines (arg)
3266 "Exchange current line and previous line, leaving point after both.
3267 With argument ARG, takes previous line and moves it past ARG lines.
3268 With argument 0, interchanges line point is in with line mark is in."
3269 (interactive "*p")
3270 (transpose-subr (function
3271 (lambda (arg)
3272 (if (> arg 0)
3273 (progn
3274 ;; Move forward over ARG lines,
3275 ;; but create newlines if necessary.
3276 (setq arg (forward-line arg))
3277 (if (/= (preceding-char) ?\n)
3278 (setq arg (1+ arg)))
3279 (if (> arg 0)
3280 (newline arg)))
3281 (forward-line arg))))
3282 arg))
3284 (defun transpose-subr (mover arg &optional special)
3285 (let ((aux (if special mover
3286 (lambda (x)
3287 (cons (progn (funcall mover x) (point))
3288 (progn (funcall mover (- x)) (point))))))
3289 pos1 pos2)
3290 (cond
3291 ((= arg 0)
3292 (save-excursion
3293 (setq pos1 (funcall aux 1))
3294 (goto-char (mark))
3295 (setq pos2 (funcall aux 1))
3296 (transpose-subr-1 pos1 pos2))
3297 (exchange-point-and-mark))
3298 ((> arg 0)
3299 (setq pos1 (funcall aux -1))
3300 (setq pos2 (funcall aux arg))
3301 (transpose-subr-1 pos1 pos2)
3302 (goto-char (car pos2)))
3304 (setq pos1 (funcall aux -1))
3305 (goto-char (car pos1))
3306 (setq pos2 (funcall aux arg))
3307 (transpose-subr-1 pos1 pos2)))))
3309 (defun transpose-subr-1 (pos1 pos2)
3310 (when (> (car pos1) (cdr pos1)) (setq pos1 (cons (cdr pos1) (car pos1))))
3311 (when (> (car pos2) (cdr pos2)) (setq pos2 (cons (cdr pos2) (car pos2))))
3312 (when (> (car pos1) (car pos2))
3313 (let ((swap pos1))
3314 (setq pos1 pos2 pos2 swap)))
3315 (if (> (cdr pos1) (car pos2)) (error "Don't have two things to transpose"))
3316 (atomic-change-group
3317 (let (word2)
3318 ;; FIXME: We first delete the two pieces of text, so markers that
3319 ;; used to point to after the text end up pointing to before it :-(
3320 (setq word2 (delete-and-extract-region (car pos2) (cdr pos2)))
3321 (goto-char (car pos2))
3322 (insert (delete-and-extract-region (car pos1) (cdr pos1)))
3323 (goto-char (car pos1))
3324 (insert word2))))
3326 (defun backward-word (&optional arg)
3327 "Move backward until encountering the beginning of a word.
3328 With argument, do this that many times."
3329 (interactive "p")
3330 (forward-word (- (or arg 1))))
3332 (defun mark-word (arg)
3333 "Set mark arg words away from point.
3334 If this command is repeated, it marks the next ARG words after the ones
3335 already marked."
3336 (interactive "p")
3337 (cond ((and (eq last-command this-command) (mark t))
3338 (set-mark
3339 (save-excursion
3340 (goto-char (mark))
3341 (forward-word arg)
3342 (point))))
3344 (push-mark
3345 (save-excursion
3346 (forward-word arg)
3347 (point))
3348 nil t))))
3350 (defun kill-word (arg)
3351 "Kill characters forward until encountering the end of a word.
3352 With argument, do this that many times."
3353 (interactive "p")
3354 (kill-region (point) (progn (forward-word arg) (point))))
3356 (defun backward-kill-word (arg)
3357 "Kill characters backward until encountering the end of a word.
3358 With argument, do this that many times."
3359 (interactive "p")
3360 (kill-word (- arg)))
3362 (defun current-word (&optional strict really-word)
3363 "Return the symbol or word that point is on (or a nearby one) as a string.
3364 The return value includes no text properties.
3365 If optional arg STRICT is non-nil, return nil unless point is within
3366 or adjacent to a symbol or word.
3367 The function, belying its name, normally finds a symbol.
3368 If optional arg REALLY-WORD is non-nil, it finds just a word."
3369 (save-excursion
3370 (let* ((oldpoint (point)) (start (point)) (end (point))
3371 (syntaxes (if really-word "w" "w_"))
3372 (not-syntaxes (concat "^" syntaxes)))
3373 (skip-syntax-backward syntaxes) (setq start (point))
3374 (goto-char oldpoint)
3375 (skip-syntax-forward syntaxes) (setq end (point))
3376 (when (and (eq start oldpoint) (eq end oldpoint)
3377 ;; Point is neither within nor adjacent to a word.
3378 (not strict))
3379 ;; Look for preceding word in same line.
3380 (skip-syntax-backward not-syntaxes
3381 (save-excursion (beginning-of-line)
3382 (point)))
3383 (if (bolp)
3384 ;; No preceding word in same line.
3385 ;; Look for following word in same line.
3386 (progn
3387 (skip-syntax-forward not-syntaxes
3388 (save-excursion (end-of-line)
3389 (point)))
3390 (setq start (point))
3391 (skip-syntax-forward syntaxes)
3392 (setq end (point)))
3393 (setq end (point))
3394 (skip-syntax-backward syntaxes)
3395 (setq start (point))))
3396 ;; If we found something nonempty, return it as a string.
3397 (unless (= start end)
3398 (buffer-substring-no-properties start end)))))
3400 (defcustom fill-prefix nil
3401 "*String for filling to insert at front of new line, or nil for none."
3402 :type '(choice (const :tag "None" nil)
3403 string)
3404 :group 'fill)
3405 (make-variable-buffer-local 'fill-prefix)
3407 (defcustom auto-fill-inhibit-regexp nil
3408 "*Regexp to match lines which should not be auto-filled."
3409 :type '(choice (const :tag "None" nil)
3410 regexp)
3411 :group 'fill)
3413 (defvar comment-line-break-function 'comment-indent-new-line
3414 "*Mode-specific function which line breaks and continues a comment.
3416 This function is only called during auto-filling of a comment section.
3417 The function should take a single optional argument, which is a flag
3418 indicating whether it should use soft newlines.
3420 Setting this variable automatically makes it local to the current buffer.")
3422 ;; This function is used as the auto-fill-function of a buffer
3423 ;; when Auto-Fill mode is enabled.
3424 ;; It returns t if it really did any work.
3425 ;; (Actually some major modes use a different auto-fill function,
3426 ;; but this one is the default one.)
3427 (defun do-auto-fill ()
3428 (let (fc justify give-up
3429 (fill-prefix fill-prefix))
3430 (if (or (not (setq justify (current-justification)))
3431 (null (setq fc (current-fill-column)))
3432 (and (eq justify 'left)
3433 (<= (current-column) fc))
3434 (and auto-fill-inhibit-regexp
3435 (save-excursion (beginning-of-line)
3436 (looking-at auto-fill-inhibit-regexp))))
3437 nil ;; Auto-filling not required
3438 (if (memq justify '(full center right))
3439 (save-excursion (unjustify-current-line)))
3441 ;; Choose a fill-prefix automatically.
3442 (when (and adaptive-fill-mode
3443 (or (null fill-prefix) (string= fill-prefix "")))
3444 (let ((prefix
3445 (fill-context-prefix
3446 (save-excursion (backward-paragraph 1) (point))
3447 (save-excursion (forward-paragraph 1) (point)))))
3448 (and prefix (not (equal prefix ""))
3449 ;; Use auto-indentation rather than a guessed empty prefix.
3450 (not (and fill-indent-according-to-mode
3451 (string-match "\\`[ \t]*\\'" prefix)))
3452 (setq fill-prefix prefix))))
3454 (while (and (not give-up) (> (current-column) fc))
3455 ;; Determine where to split the line.
3456 (let* (after-prefix
3457 (fill-point
3458 (save-excursion
3459 (beginning-of-line)
3460 (setq after-prefix (point))
3461 (and fill-prefix
3462 (looking-at (regexp-quote fill-prefix))
3463 (setq after-prefix (match-end 0)))
3464 (move-to-column (1+ fc))
3465 (fill-move-to-break-point after-prefix)
3466 (point))))
3468 ;; See whether the place we found is any good.
3469 (if (save-excursion
3470 (goto-char fill-point)
3471 (or (bolp)
3472 ;; There is no use breaking at end of line.
3473 (save-excursion (skip-chars-forward " ") (eolp))
3474 ;; It is futile to split at the end of the prefix
3475 ;; since we would just insert the prefix again.
3476 (and after-prefix (<= (point) after-prefix))
3477 ;; Don't split right after a comment starter
3478 ;; since we would just make another comment starter.
3479 (and comment-start-skip
3480 (let ((limit (point)))
3481 (beginning-of-line)
3482 (and (re-search-forward comment-start-skip
3483 limit t)
3484 (eq (point) limit))))))
3485 ;; No good place to break => stop trying.
3486 (setq give-up t)
3487 ;; Ok, we have a useful place to break the line. Do it.
3488 (let ((prev-column (current-column)))
3489 ;; If point is at the fill-point, do not `save-excursion'.
3490 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
3491 ;; point will end up before it rather than after it.
3492 (if (save-excursion
3493 (skip-chars-backward " \t")
3494 (= (point) fill-point))
3495 (funcall comment-line-break-function t)
3496 (save-excursion
3497 (goto-char fill-point)
3498 (funcall comment-line-break-function t)))
3499 ;; Now do justification, if required
3500 (if (not (eq justify 'left))
3501 (save-excursion
3502 (end-of-line 0)
3503 (justify-current-line justify nil t)))
3504 ;; If making the new line didn't reduce the hpos of
3505 ;; the end of the line, then give up now;
3506 ;; trying again will not help.
3507 (if (>= (current-column) prev-column)
3508 (setq give-up t))))))
3509 ;; Justify last line.
3510 (justify-current-line justify t t)
3511 t)))
3513 (defvar normal-auto-fill-function 'do-auto-fill
3514 "The function to use for `auto-fill-function' if Auto Fill mode is turned on.
3515 Some major modes set this.")
3517 ;; FIXME: turn into a proper minor mode.
3518 ;; Add a global minor mode version of it.
3519 (defun auto-fill-mode (&optional arg)
3520 "Toggle Auto Fill mode.
3521 With arg, turn Auto Fill mode on if and only if arg is positive.
3522 In Auto Fill mode, inserting a space at a column beyond `current-fill-column'
3523 automatically breaks the line at a previous space.
3525 The value of `normal-auto-fill-function' specifies the function to use
3526 for `auto-fill-function' when turning Auto Fill mode on."
3527 (interactive "P")
3528 (prog1 (setq auto-fill-function
3529 (if (if (null arg)
3530 (not auto-fill-function)
3531 (> (prefix-numeric-value arg) 0))
3532 normal-auto-fill-function
3533 nil))
3534 (force-mode-line-update)))
3536 ;; This holds a document string used to document auto-fill-mode.
3537 (defun auto-fill-function ()
3538 "Automatically break line at a previous space, in insertion of text."
3539 nil)
3541 (defun turn-on-auto-fill ()
3542 "Unconditionally turn on Auto Fill mode."
3543 (auto-fill-mode 1))
3545 (defun turn-off-auto-fill ()
3546 "Unconditionally turn off Auto Fill mode."
3547 (auto-fill-mode -1))
3549 (custom-add-option 'text-mode-hook 'turn-on-auto-fill)
3551 (defun set-fill-column (arg)
3552 "Set `fill-column' to specified argument.
3553 Use \\[universal-argument] followed by a number to specify a column.
3554 Just \\[universal-argument] as argument means to use the current column."
3555 (interactive "P")
3556 (if (consp arg)
3557 (setq arg (current-column)))
3558 (if (not (integerp arg))
3559 ;; Disallow missing argument; it's probably a typo for C-x C-f.
3560 (error "Set-fill-column requires an explicit argument")
3561 (message "Fill column set to %d (was %d)" arg fill-column)
3562 (setq fill-column arg)))
3564 (defun set-selective-display (arg)
3565 "Set `selective-display' to ARG; clear it if no arg.
3566 When the value of `selective-display' is a number > 0,
3567 lines whose indentation is >= that value are not displayed.
3568 The variable `selective-display' has a separate value for each buffer."
3569 (interactive "P")
3570 (if (eq selective-display t)
3571 (error "selective-display already in use for marked lines"))
3572 (let ((current-vpos
3573 (save-restriction
3574 (narrow-to-region (point-min) (point))
3575 (goto-char (window-start))
3576 (vertical-motion (window-height)))))
3577 (setq selective-display
3578 (and arg (prefix-numeric-value arg)))
3579 (recenter current-vpos))
3580 (set-window-start (selected-window) (window-start (selected-window)))
3581 (princ "selective-display set to " t)
3582 (prin1 selective-display t)
3583 (princ "." t))
3585 (defvaralias 'indicate-unused-lines 'indicate-empty-lines)
3586 (defvaralias 'default-indicate-unused-lines 'default-indicate-empty-lines)
3588 (defun toggle-truncate-lines (arg)
3589 "Toggle whether to fold or truncate long lines on the screen.
3590 With arg, truncate long lines iff arg is positive.
3591 Note that in side-by-side windows, truncation is always enabled."
3592 (interactive "P")
3593 (setq truncate-lines
3594 (if (null arg)
3595 (not truncate-lines)
3596 (> (prefix-numeric-value arg) 0)))
3597 (force-mode-line-update)
3598 (unless truncate-lines
3599 (let ((buffer (current-buffer)))
3600 (walk-windows (lambda (window)
3601 (if (eq buffer (window-buffer window))
3602 (set-window-hscroll window 0)))
3603 nil t)))
3604 (message "Truncate long lines %s"
3605 (if truncate-lines "enabled" "disabled")))
3607 (defvar overwrite-mode-textual " Ovwrt"
3608 "The string displayed in the mode line when in overwrite mode.")
3609 (defvar overwrite-mode-binary " Bin Ovwrt"
3610 "The string displayed in the mode line when in binary overwrite mode.")
3612 (defun overwrite-mode (arg)
3613 "Toggle overwrite mode.
3614 With arg, turn overwrite mode on iff arg is positive.
3615 In overwrite mode, printing characters typed in replace existing text
3616 on a one-for-one basis, rather than pushing it to the right. At the
3617 end of a line, such characters extend the line. Before a tab,
3618 such characters insert until the tab is filled in.
3619 \\[quoted-insert] still inserts characters in overwrite mode; this
3620 is supposed to make it easier to insert characters when necessary."
3621 (interactive "P")
3622 (setq overwrite-mode
3623 (if (if (null arg) (not overwrite-mode)
3624 (> (prefix-numeric-value arg) 0))
3625 'overwrite-mode-textual))
3626 (force-mode-line-update))
3628 (defun binary-overwrite-mode (arg)
3629 "Toggle binary overwrite mode.
3630 With arg, turn binary overwrite mode on iff arg is positive.
3631 In binary overwrite mode, printing characters typed in replace
3632 existing text. Newlines are not treated specially, so typing at the
3633 end of a line joins the line to the next, with the typed character
3634 between them. Typing before a tab character simply replaces the tab
3635 with the character typed.
3636 \\[quoted-insert] replaces the text at the cursor, just as ordinary
3637 typing characters do.
3639 Note that binary overwrite mode is not its own minor mode; it is a
3640 specialization of overwrite-mode, entered by setting the
3641 `overwrite-mode' variable to `overwrite-mode-binary'."
3642 (interactive "P")
3643 (setq overwrite-mode
3644 (if (if (null arg)
3645 (not (eq overwrite-mode 'overwrite-mode-binary))
3646 (> (prefix-numeric-value arg) 0))
3647 'overwrite-mode-binary))
3648 (force-mode-line-update))
3650 (define-minor-mode line-number-mode
3651 "Toggle Line Number mode.
3652 With arg, turn Line Number mode on iff arg is positive.
3653 When Line Number mode is enabled, the line number appears
3654 in the mode line.
3656 Line numbers do not appear for very large buffers and buffers
3657 with very long lines; see variables `line-number-display-limit'
3658 and `line-number-display-limit-width'."
3659 :init-value t :global t :group 'editing-basics :require nil)
3661 (define-minor-mode column-number-mode
3662 "Toggle Column Number mode.
3663 With arg, turn Column Number mode on iff arg is positive.
3664 When Column Number mode is enabled, the column number appears
3665 in the mode line."
3666 :global t :group 'editing-basics :require nil)
3668 (define-minor-mode size-indication-mode
3669 "Toggle Size Indication mode.
3670 With arg, turn Size Indication mode on iff arg is positive. When
3671 Size Indication mode is enabled, the size of the accessible part
3672 of the buffer appears in the mode line."
3673 :global t :group 'editing-basics :require nil)
3675 (defgroup paren-blinking nil
3676 "Blinking matching of parens and expressions."
3677 :prefix "blink-matching-"
3678 :group 'paren-matching)
3680 (defcustom blink-matching-paren t
3681 "*Non-nil means show matching open-paren when close-paren is inserted."
3682 :type 'boolean
3683 :group 'paren-blinking)
3685 (defcustom blink-matching-paren-on-screen t
3686 "*Non-nil means show matching open-paren when it is on screen.
3687 If nil, means don't show it (but the open-paren can still be shown
3688 when it is off screen)."
3689 :type 'boolean
3690 :group 'paren-blinking)
3692 (defcustom blink-matching-paren-distance (* 25 1024)
3693 "*If non-nil, is maximum distance to search for matching open-paren."
3694 :type 'integer
3695 :group 'paren-blinking)
3697 (defcustom blink-matching-delay 1
3698 "*Time in seconds to delay after showing a matching paren."
3699 :type 'number
3700 :group 'paren-blinking)
3702 (defcustom blink-matching-paren-dont-ignore-comments nil
3703 "*Non-nil means `blink-matching-paren' will not ignore comments."
3704 :type 'boolean
3705 :group 'paren-blinking)
3707 (defun blink-matching-open ()
3708 "Move cursor momentarily to the beginning of the sexp before point."
3709 (interactive)
3710 (and (> (point) (1+ (point-min)))
3711 blink-matching-paren
3712 ;; Verify an even number of quoting characters precede the close.
3713 (= 1 (logand 1 (- (point)
3714 (save-excursion
3715 (forward-char -1)
3716 (skip-syntax-backward "/\\")
3717 (point)))))
3718 (let* ((oldpos (point))
3719 (blinkpos)
3720 (mismatch)
3721 matching-paren)
3722 (save-excursion
3723 (save-restriction
3724 (if blink-matching-paren-distance
3725 (narrow-to-region (max (point-min)
3726 (- (point) blink-matching-paren-distance))
3727 oldpos))
3728 (condition-case ()
3729 (let ((parse-sexp-ignore-comments
3730 (and parse-sexp-ignore-comments
3731 (not blink-matching-paren-dont-ignore-comments))))
3732 (setq blinkpos (scan-sexps oldpos -1)))
3733 (error nil)))
3734 (and blinkpos
3735 (save-excursion
3736 (goto-char blinkpos)
3737 (not (looking-at "\\s$")))
3738 (setq matching-paren
3739 (or (and parse-sexp-lookup-properties
3740 (let ((prop (get-text-property blinkpos 'syntax-table)))
3741 (and (consp prop)
3742 (eq (car prop) 4)
3743 (cdr prop))))
3744 (matching-paren (char-after blinkpos)))
3745 mismatch
3746 (or (null matching-paren)
3747 (/= (char-after (1- oldpos))
3748 matching-paren))))
3749 (if mismatch (setq blinkpos nil))
3750 (if blinkpos
3751 ;; Don't log messages about paren matching.
3752 (let (message-log-max)
3753 (goto-char blinkpos)
3754 (if (pos-visible-in-window-p)
3755 (and blink-matching-paren-on-screen
3756 (sit-for blink-matching-delay))
3757 (goto-char blinkpos)
3758 (message
3759 "Matches %s"
3760 ;; Show what precedes the open in its line, if anything.
3761 (if (save-excursion
3762 (skip-chars-backward " \t")
3763 (not (bolp)))
3764 (buffer-substring (progn (beginning-of-line) (point))
3765 (1+ blinkpos))
3766 ;; Show what follows the open in its line, if anything.
3767 (if (save-excursion
3768 (forward-char 1)
3769 (skip-chars-forward " \t")
3770 (not (eolp)))
3771 (buffer-substring blinkpos
3772 (progn (end-of-line) (point)))
3773 ;; Otherwise show the previous nonblank line,
3774 ;; if there is one.
3775 (if (save-excursion
3776 (skip-chars-backward "\n \t")
3777 (not (bobp)))
3778 (concat
3779 (buffer-substring (progn
3780 (skip-chars-backward "\n \t")
3781 (beginning-of-line)
3782 (point))
3783 (progn (end-of-line)
3784 (skip-chars-backward " \t")
3785 (point)))
3786 ;; Replace the newline and other whitespace with `...'.
3787 "..."
3788 (buffer-substring blinkpos (1+ blinkpos)))
3789 ;; There is nothing to show except the char itself.
3790 (buffer-substring blinkpos (1+ blinkpos))))))))
3791 (cond (mismatch
3792 (message "Mismatched parentheses"))
3793 ((not blink-matching-paren-distance)
3794 (message "Unmatched parenthesis"))))))))
3796 ;Turned off because it makes dbx bomb out.
3797 (setq blink-paren-function 'blink-matching-open)
3799 ;; This executes C-g typed while Emacs is waiting for a command.
3800 ;; Quitting out of a program does not go through here;
3801 ;; that happens in the QUIT macro at the C code level.
3802 (defun keyboard-quit ()
3803 "Signal a `quit' condition.
3804 During execution of Lisp code, this character causes a quit directly.
3805 At top-level, as an editor command, this simply beeps."
3806 (interactive)
3807 (deactivate-mark)
3808 (setq defining-kbd-macro nil)
3809 (signal 'quit nil))
3811 (define-key global-map "\C-g" 'keyboard-quit)
3813 (defvar buffer-quit-function nil
3814 "Function to call to \"quit\" the current buffer, or nil if none.
3815 \\[keyboard-escape-quit] calls this function when its more local actions
3816 \(such as cancelling a prefix argument, minibuffer or region) do not apply.")
3818 (defun keyboard-escape-quit ()
3819 "Exit the current \"mode\" (in a generalized sense of the word).
3820 This command can exit an interactive command such as `query-replace',
3821 can clear out a prefix argument or a region,
3822 can get out of the minibuffer or other recursive edit,
3823 cancel the use of the current buffer (for special-purpose buffers),
3824 or go back to just one window (by deleting all but the selected window)."
3825 (interactive)
3826 (cond ((eq last-command 'mode-exited) nil)
3827 ((> (minibuffer-depth) 0)
3828 (abort-recursive-edit))
3829 (current-prefix-arg
3830 nil)
3831 ((and transient-mark-mode
3832 mark-active)
3833 (deactivate-mark))
3834 ((> (recursion-depth) 0)
3835 (exit-recursive-edit))
3836 (buffer-quit-function
3837 (funcall buffer-quit-function))
3838 ((not (one-window-p t))
3839 (delete-other-windows))
3840 ((string-match "^ \\*" (buffer-name (current-buffer)))
3841 (bury-buffer))))
3843 (defun play-sound-file (file &optional volume device)
3844 "Play sound stored in FILE.
3845 VOLUME and DEVICE correspond to the keywords of the sound
3846 specification for `play-sound'."
3847 (interactive "fPlay sound file: ")
3848 (let ((sound (list :file file)))
3849 (if volume
3850 (plist-put sound :volume volume))
3851 (if device
3852 (plist-put sound :device device))
3853 (push 'sound sound)
3854 (play-sound sound)))
3856 (define-key global-map "\e\e\e" 'keyboard-escape-quit)
3858 (defcustom read-mail-command 'rmail
3859 "*Your preference for a mail reading package.
3860 This is used by some keybindings which support reading mail.
3861 See also `mail-user-agent' concerning sending mail."
3862 :type '(choice (function-item rmail)
3863 (function-item gnus)
3864 (function-item mh-rmail)
3865 (function :tag "Other"))
3866 :version "21.1"
3867 :group 'mail)
3869 (defcustom mail-user-agent 'sendmail-user-agent
3870 "*Your preference for a mail composition package.
3871 Various Emacs Lisp packages (e.g. Reporter) require you to compose an
3872 outgoing email message. This variable lets you specify which
3873 mail-sending package you prefer.
3875 Valid values include:
3877 `sendmail-user-agent' -- use the default Emacs Mail package.
3878 See Info node `(emacs)Sending Mail'.
3879 `mh-e-user-agent' -- use the Emacs interface to the MH mail system.
3880 See Info node `(mh-e)'.
3881 `message-user-agent' -- use the Gnus Message package.
3882 See Info node `(message)'.
3883 `gnus-user-agent' -- like `message-user-agent', but with Gnus
3884 paraphernalia, particularly the Gcc: header for
3885 archiving.
3887 Additional valid symbols may be available; check with the author of
3888 your package for details. The function should return non-nil if it
3889 succeeds.
3891 See also `read-mail-command' concerning reading mail."
3892 :type '(radio (function-item :tag "Default Emacs mail"
3893 :format "%t\n"
3894 sendmail-user-agent)
3895 (function-item :tag "Emacs interface to MH"
3896 :format "%t\n"
3897 mh-e-user-agent)
3898 (function-item :tag "Gnus Message package"
3899 :format "%t\n"
3900 message-user-agent)
3901 (function-item :tag "Gnus Message with full Gnus features"
3902 :format "%t\n"
3903 gnus-user-agent)
3904 (function :tag "Other"))
3905 :group 'mail)
3907 (define-mail-user-agent 'sendmail-user-agent
3908 'sendmail-user-agent-compose
3909 'mail-send-and-exit)
3911 (defun rfc822-goto-eoh ()
3912 ;; Go to header delimiter line in a mail message, following RFC822 rules
3913 (goto-char (point-min))
3914 (when (re-search-forward
3915 "^\\([:\n]\\|[^: \t\n]+[ \t\n]\\)" nil 'move)
3916 (goto-char (match-beginning 0))))
3918 (defun sendmail-user-agent-compose (&optional to subject other-headers continue
3919 switch-function yank-action
3920 send-actions)
3921 (if switch-function
3922 (let ((special-display-buffer-names nil)
3923 (special-display-regexps nil)
3924 (same-window-buffer-names nil)
3925 (same-window-regexps nil))
3926 (funcall switch-function "*mail*")))
3927 (let ((cc (cdr (assoc-string "cc" other-headers t)))
3928 (in-reply-to (cdr (assoc-string "in-reply-to" other-headers t)))
3929 (body (cdr (assoc-string "body" other-headers t))))
3930 (or (mail continue to subject in-reply-to cc yank-action send-actions)
3931 continue
3932 (error "Message aborted"))
3933 (save-excursion
3934 (rfc822-goto-eoh)
3935 (while other-headers
3936 (unless (member-ignore-case (car (car other-headers))
3937 '("in-reply-to" "cc" "body"))
3938 (insert (car (car other-headers)) ": "
3939 (cdr (car other-headers)) "\n"))
3940 (setq other-headers (cdr other-headers)))
3941 (when body
3942 (forward-line 1)
3943 (insert body))
3944 t)))
3946 (define-mail-user-agent 'mh-e-user-agent
3947 'mh-smail-batch 'mh-send-letter 'mh-fully-kill-draft
3948 'mh-before-send-letter-hook)
3950 (defun compose-mail (&optional to subject other-headers continue
3951 switch-function yank-action send-actions)
3952 "Start composing a mail message to send.
3953 This uses the user's chosen mail composition package
3954 as selected with the variable `mail-user-agent'.
3955 The optional arguments TO and SUBJECT specify recipients
3956 and the initial Subject field, respectively.
3958 OTHER-HEADERS is an alist specifying additional
3959 header fields. Elements look like (HEADER . VALUE) where both
3960 HEADER and VALUE are strings.
3962 CONTINUE, if non-nil, says to continue editing a message already
3963 being composed.
3965 SWITCH-FUNCTION, if non-nil, is a function to use to
3966 switch to and display the buffer used for mail composition.
3968 YANK-ACTION, if non-nil, is an action to perform, if and when necessary,
3969 to insert the raw text of the message being replied to.
3970 It has the form (FUNCTION . ARGS). The user agent will apply
3971 FUNCTION to ARGS, to insert the raw text of the original message.
3972 \(The user agent will also run `mail-citation-hook', *after* the
3973 original text has been inserted in this way.)
3975 SEND-ACTIONS is a list of actions to call when the message is sent.
3976 Each action has the form (FUNCTION . ARGS)."
3977 (interactive
3978 (list nil nil nil current-prefix-arg))
3979 (let ((function (get mail-user-agent 'composefunc)))
3980 (funcall function to subject other-headers continue
3981 switch-function yank-action send-actions)))
3983 (defun compose-mail-other-window (&optional to subject other-headers continue
3984 yank-action send-actions)
3985 "Like \\[compose-mail], but edit the outgoing message in another window."
3986 (interactive
3987 (list nil nil nil current-prefix-arg))
3988 (compose-mail to subject other-headers continue
3989 'switch-to-buffer-other-window yank-action send-actions))
3992 (defun compose-mail-other-frame (&optional to subject other-headers continue
3993 yank-action send-actions)
3994 "Like \\[compose-mail], but edit the outgoing message in another frame."
3995 (interactive
3996 (list nil nil nil current-prefix-arg))
3997 (compose-mail to subject other-headers continue
3998 'switch-to-buffer-other-frame yank-action send-actions))
4000 (defvar set-variable-value-history nil
4001 "History of values entered with `set-variable'.")
4003 (defun set-variable (var val &optional make-local)
4004 "Set VARIABLE to VALUE. VALUE is a Lisp object.
4005 When using this interactively, enter a Lisp object for VALUE.
4006 If you want VALUE to be a string, you must surround it with doublequotes.
4007 VALUE is used literally, not evaluated.
4009 If VARIABLE has a `variable-interactive' property, that is used as if
4010 it were the arg to `interactive' (which see) to interactively read VALUE.
4012 If VARIABLE has been defined with `defcustom', then the type information
4013 in the definition is used to check that VALUE is valid.
4015 With a prefix argument, set VARIABLE to VALUE buffer-locally."
4016 (interactive
4017 (let* ((default-var (variable-at-point))
4018 (var (if (symbolp default-var)
4019 (read-variable (format "Set variable (default %s): " default-var)
4020 default-var)
4021 (read-variable "Set variable: ")))
4022 (minibuffer-help-form '(describe-variable var))
4023 (prop (get var 'variable-interactive))
4024 (prompt (format "Set %s%s to value: " var
4025 (cond ((local-variable-p var)
4026 " (buffer-local)")
4027 ((or current-prefix-arg
4028 (local-variable-if-set-p var))
4029 " buffer-locally")
4030 (t " globally"))))
4031 (val (if prop
4032 ;; Use VAR's `variable-interactive' property
4033 ;; as an interactive spec for prompting.
4034 (call-interactively `(lambda (arg)
4035 (interactive ,prop)
4036 arg))
4037 (read
4038 (read-string prompt nil
4039 'set-variable-value-history)))))
4040 (list var val current-prefix-arg)))
4042 (and (custom-variable-p var)
4043 (not (get var 'custom-type))
4044 (custom-load-symbol var))
4045 (let ((type (get var 'custom-type)))
4046 (when type
4047 ;; Match with custom type.
4048 (require 'cus-edit)
4049 (setq type (widget-convert type))
4050 (unless (widget-apply type :match val)
4051 (error "Value `%S' does not match type %S of %S"
4052 val (car type) var))))
4054 (if make-local
4055 (make-local-variable var))
4057 (set var val)
4059 ;; Force a thorough redisplay for the case that the variable
4060 ;; has an effect on the display, like `tab-width' has.
4061 (force-mode-line-update))
4063 ;; Define the major mode for lists of completions.
4065 (defvar completion-list-mode-map nil
4066 "Local map for completion list buffers.")
4067 (or completion-list-mode-map
4068 (let ((map (make-sparse-keymap)))
4069 (define-key map [mouse-2] 'mouse-choose-completion)
4070 (define-key map [down-mouse-2] nil)
4071 (define-key map "\C-m" 'choose-completion)
4072 (define-key map "\e\e\e" 'delete-completion-window)
4073 (define-key map [left] 'previous-completion)
4074 (define-key map [right] 'next-completion)
4075 (setq completion-list-mode-map map)))
4077 ;; Completion mode is suitable only for specially formatted data.
4078 (put 'completion-list-mode 'mode-class 'special)
4080 (defvar completion-reference-buffer nil
4081 "Record the buffer that was current when the completion list was requested.
4082 This is a local variable in the completion list buffer.
4083 Initial value is nil to avoid some compiler warnings.")
4085 (defvar completion-no-auto-exit nil
4086 "Non-nil means `choose-completion-string' should never exit the minibuffer.
4087 This also applies to other functions such as `choose-completion'
4088 and `mouse-choose-completion'.")
4090 (defvar completion-base-size nil
4091 "Number of chars at beginning of minibuffer not involved in completion.
4092 This is a local variable in the completion list buffer
4093 but it talks about the buffer in `completion-reference-buffer'.
4094 If this is nil, it means to compare text to determine which part
4095 of the tail end of the buffer's text is involved in completion.")
4097 (defun delete-completion-window ()
4098 "Delete the completion list window.
4099 Go to the window from which completion was requested."
4100 (interactive)
4101 (let ((buf completion-reference-buffer))
4102 (if (one-window-p t)
4103 (if (window-dedicated-p (selected-window))
4104 (delete-frame (selected-frame)))
4105 (delete-window (selected-window))
4106 (if (get-buffer-window buf)
4107 (select-window (get-buffer-window buf))))))
4109 (defun previous-completion (n)
4110 "Move to the previous item in the completion list."
4111 (interactive "p")
4112 (next-completion (- n)))
4114 (defun next-completion (n)
4115 "Move to the next item in the completion list.
4116 With prefix argument N, move N items (negative N means move backward)."
4117 (interactive "p")
4118 (let ((beg (point-min)) (end (point-max)))
4119 (while (and (> n 0) (not (eobp)))
4120 ;; If in a completion, move to the end of it.
4121 (when (get-text-property (point) 'mouse-face)
4122 (goto-char (next-single-property-change (point) 'mouse-face nil end)))
4123 ;; Move to start of next one.
4124 (unless (get-text-property (point) 'mouse-face)
4125 (goto-char (next-single-property-change (point) 'mouse-face nil end)))
4126 (setq n (1- n)))
4127 (while (and (< n 0) (not (bobp)))
4128 (let ((prop (get-text-property (1- (point)) 'mouse-face)))
4129 ;; If in a completion, move to the start of it.
4130 (when (and prop (eq prop (get-text-property (point) 'mouse-face)))
4131 (goto-char (previous-single-property-change
4132 (point) 'mouse-face nil beg)))
4133 ;; Move to end of the previous completion.
4134 (unless (or (bobp) (get-text-property (1- (point)) 'mouse-face))
4135 (goto-char (previous-single-property-change
4136 (point) 'mouse-face nil beg)))
4137 ;; Move to the start of that one.
4138 (goto-char (previous-single-property-change
4139 (point) 'mouse-face nil beg))
4140 (setq n (1+ n))))))
4142 (defun choose-completion ()
4143 "Choose the completion that point is in or next to."
4144 (interactive)
4145 (let (beg end completion (buffer completion-reference-buffer)
4146 (base-size completion-base-size))
4147 (if (and (not (eobp)) (get-text-property (point) 'mouse-face))
4148 (setq end (point) beg (1+ (point))))
4149 (if (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face))
4150 (setq end (1- (point)) beg (point)))
4151 (if (null beg)
4152 (error "No completion here"))
4153 (setq beg (previous-single-property-change beg 'mouse-face))
4154 (setq end (or (next-single-property-change end 'mouse-face) (point-max)))
4155 (setq completion (buffer-substring beg end))
4156 (let ((owindow (selected-window)))
4157 (if (and (one-window-p t 'selected-frame)
4158 (window-dedicated-p (selected-window)))
4159 ;; This is a special buffer's frame
4160 (iconify-frame (selected-frame))
4161 (or (window-dedicated-p (selected-window))
4162 (bury-buffer)))
4163 (select-window owindow))
4164 (choose-completion-string completion buffer base-size)))
4166 ;; Delete the longest partial match for STRING
4167 ;; that can be found before POINT.
4168 (defun choose-completion-delete-max-match (string)
4169 (let ((opoint (point))
4170 len)
4171 ;; Try moving back by the length of the string.
4172 (goto-char (max (- (point) (length string))
4173 (minibuffer-prompt-end)))
4174 ;; See how far back we were actually able to move. That is the
4175 ;; upper bound on how much we can match and delete.
4176 (setq len (- opoint (point)))
4177 (if completion-ignore-case
4178 (setq string (downcase string)))
4179 (while (and (> len 0)
4180 (let ((tail (buffer-substring (point) opoint)))
4181 (if completion-ignore-case
4182 (setq tail (downcase tail)))
4183 (not (string= tail (substring string 0 len)))))
4184 (setq len (1- len))
4185 (forward-char 1))
4186 (delete-char len)))
4188 (defvar choose-completion-string-functions nil
4189 "Functions that may override the normal insertion of a completion choice.
4190 These functions are called in order with four arguments:
4191 CHOICE - the string to insert in the buffer,
4192 BUFFER - the buffer in which the choice should be inserted,
4193 MINI-P - non-nil iff BUFFER is a minibuffer, and
4194 BASE-SIZE - the number of characters in BUFFER before
4195 the string being completed.
4197 If a function in the list returns non-nil, that function is supposed
4198 to have inserted the CHOICE in the BUFFER, and possibly exited
4199 the minibuffer; no further functions will be called.
4201 If all functions in the list return nil, that means to use
4202 the default method of inserting the completion in BUFFER.")
4204 (defun choose-completion-string (choice &optional buffer base-size)
4205 "Switch to BUFFER and insert the completion choice CHOICE.
4206 BASE-SIZE, if non-nil, says how many characters of BUFFER's text
4207 to keep. If it is nil, we call `choose-completion-delete-max-match'
4208 to decide what to delete."
4210 ;; If BUFFER is the minibuffer, exit the minibuffer
4211 ;; unless it is reading a file name and CHOICE is a directory,
4212 ;; or completion-no-auto-exit is non-nil.
4214 (let* ((buffer (or buffer completion-reference-buffer))
4215 (mini-p (minibufferp buffer)))
4216 ;; If BUFFER is a minibuffer, barf unless it's the currently
4217 ;; active minibuffer.
4218 (if (and mini-p
4219 (or (not (active-minibuffer-window))
4220 (not (equal buffer
4221 (window-buffer (active-minibuffer-window))))))
4222 (error "Minibuffer is not active for completion")
4223 (unless (run-hook-with-args-until-success
4224 'choose-completion-string-functions
4225 choice buffer mini-p base-size)
4226 ;; Insert the completion into the buffer where it was requested.
4227 (set-buffer buffer)
4228 (if base-size
4229 (delete-region (+ base-size (if mini-p
4230 (minibuffer-prompt-end)
4231 (point-min)))
4232 (point))
4233 (choose-completion-delete-max-match choice))
4234 (insert choice)
4235 (remove-text-properties (- (point) (length choice)) (point)
4236 '(mouse-face nil))
4237 ;; Update point in the window that BUFFER is showing in.
4238 (let ((window (get-buffer-window buffer t)))
4239 (set-window-point window (point)))
4240 ;; If completing for the minibuffer, exit it with this choice.
4241 (and (not completion-no-auto-exit)
4242 (equal buffer (window-buffer (minibuffer-window)))
4243 minibuffer-completion-table
4244 ;; If this is reading a file name, and the file name chosen
4245 ;; is a directory, don't exit the minibuffer.
4246 (if (and (eq minibuffer-completion-table 'read-file-name-internal)
4247 (file-directory-p (field-string (point-max))))
4248 (let ((mini (active-minibuffer-window)))
4249 (select-window mini)
4250 (when minibuffer-auto-raise
4251 (raise-frame (window-frame mini))))
4252 (exit-minibuffer)))))))
4254 (defun completion-list-mode ()
4255 "Major mode for buffers showing lists of possible completions.
4256 Type \\<completion-list-mode-map>\\[choose-completion] in the completion list\
4257 to select the completion near point.
4258 Use \\<completion-list-mode-map>\\[mouse-choose-completion] to select one\
4259 with the mouse."
4260 (interactive)
4261 (kill-all-local-variables)
4262 (use-local-map completion-list-mode-map)
4263 (setq mode-name "Completion List")
4264 (setq major-mode 'completion-list-mode)
4265 (make-local-variable 'completion-base-size)
4266 (setq completion-base-size nil)
4267 (run-hooks 'completion-list-mode-hook))
4269 (defun completion-list-mode-finish ()
4270 "Finish setup of the completions buffer.
4271 Called from `temp-buffer-show-hook'."
4272 (when (eq major-mode 'completion-list-mode)
4273 (toggle-read-only 1)))
4275 (add-hook 'temp-buffer-show-hook 'completion-list-mode-finish)
4277 (defvar completion-setup-hook nil
4278 "Normal hook run at the end of setting up a completion list buffer.
4279 When this hook is run, the current buffer is the one in which the
4280 command to display the completion list buffer was run.
4281 The completion list buffer is available as the value of `standard-output'.")
4283 ;; This function goes in completion-setup-hook, so that it is called
4284 ;; after the text of the completion list buffer is written.
4285 (defface completions-first-difference
4286 '((t (:inherit bold)))
4287 "Face put on the first uncommon character in completions in *Completions* buffer."
4288 :group 'completion)
4290 (defface completions-common-part
4291 '((t (:inherit default)))
4292 "Face put on the common prefix substring in completions in *Completions* buffer.
4293 The idea of `completions-common-part' is that you can use it to
4294 make the common parts less visible than normal, so that the rest
4295 of the differing parts is, by contrast, slightly highlighted."
4296 :group 'completion)
4298 (defun completion-setup-function ()
4299 (let ((mainbuf (current-buffer))
4300 (mbuf-contents (minibuffer-contents)))
4301 ;; When reading a file name in the minibuffer,
4302 ;; set default-directory in the minibuffer
4303 ;; so it will get copied into the completion list buffer.
4304 (if minibuffer-completing-file-name
4305 (with-current-buffer mainbuf
4306 (setq default-directory (file-name-directory mbuf-contents))))
4307 (with-current-buffer standard-output
4308 (completion-list-mode)
4309 (make-local-variable 'completion-reference-buffer)
4310 (setq completion-reference-buffer mainbuf)
4311 (if minibuffer-completing-file-name
4312 ;; For file name completion,
4313 ;; use the number of chars before the start of the
4314 ;; last file name component.
4315 (setq completion-base-size
4316 (with-current-buffer mainbuf
4317 (save-excursion
4318 (goto-char (point-max))
4319 (skip-chars-backward "^/")
4320 (- (point) (minibuffer-prompt-end)))))
4321 ;; Otherwise, in minibuffer, the whole input is being completed.
4322 (if (minibufferp mainbuf)
4323 (setq completion-base-size 0)))
4324 ;; Put faces on first uncommon characters and common parts.
4325 (when completion-base-size
4326 (let* ((common-string-length
4327 (- (length mbuf-contents) completion-base-size))
4328 (element-start (next-single-property-change
4329 (point-min)
4330 'mouse-face))
4331 (element-common-end
4332 (+ (or element-start nil) common-string-length))
4333 (maxp (point-max)))
4334 (while (and element-start (< element-common-end maxp))
4335 (when (and (get-char-property element-start 'mouse-face)
4336 (get-char-property element-common-end 'mouse-face))
4337 (put-text-property element-start element-common-end
4338 'font-lock-face 'completions-common-part)
4339 (put-text-property element-common-end (1+ element-common-end)
4340 'font-lock-face 'completions-first-difference))
4341 (setq element-start (next-single-property-change
4342 element-start
4343 'mouse-face))
4344 (if element-start
4345 (setq element-common-end (+ element-start common-string-length))))))
4346 ;; Insert help string.
4347 (goto-char (point-min))
4348 (if (display-mouse-p)
4349 (insert (substitute-command-keys
4350 "Click \\[mouse-choose-completion] on a completion to select it.\n")))
4351 (insert (substitute-command-keys
4352 "In this buffer, type \\[choose-completion] to \
4353 select the completion near point.\n\n")))))
4355 (add-hook 'completion-setup-hook 'completion-setup-function)
4357 (define-key minibuffer-local-completion-map [prior]
4358 'switch-to-completions)
4359 (define-key minibuffer-local-must-match-map [prior]
4360 'switch-to-completions)
4361 (define-key minibuffer-local-completion-map "\M-v"
4362 'switch-to-completions)
4363 (define-key minibuffer-local-must-match-map "\M-v"
4364 'switch-to-completions)
4366 (defun switch-to-completions ()
4367 "Select the completion list window."
4368 (interactive)
4369 ;; Make sure we have a completions window.
4370 (or (get-buffer-window "*Completions*")
4371 (minibuffer-completion-help))
4372 (let ((window (get-buffer-window "*Completions*")))
4373 (when window
4374 (select-window window)
4375 (goto-char (point-min))
4376 (search-forward "\n\n")
4377 (forward-line 1))))
4379 ;; Support keyboard commands to turn on various modifiers.
4381 ;; These functions -- which are not commands -- each add one modifier
4382 ;; to the following event.
4384 (defun event-apply-alt-modifier (ignore-prompt)
4385 "\\<function-key-map>Add the Alt modifier to the following event.
4386 For example, type \\[event-apply-alt-modifier] & to enter Alt-&."
4387 (vector (event-apply-modifier (read-event) 'alt 22 "A-")))
4388 (defun event-apply-super-modifier (ignore-prompt)
4389 "\\<function-key-map>Add the Super modifier to the following event.
4390 For example, type \\[event-apply-super-modifier] & to enter Super-&."
4391 (vector (event-apply-modifier (read-event) 'super 23 "s-")))
4392 (defun event-apply-hyper-modifier (ignore-prompt)
4393 "\\<function-key-map>Add the Hyper modifier to the following event.
4394 For example, type \\[event-apply-hyper-modifier] & to enter Hyper-&."
4395 (vector (event-apply-modifier (read-event) 'hyper 24 "H-")))
4396 (defun event-apply-shift-modifier (ignore-prompt)
4397 "\\<function-key-map>Add the Shift modifier to the following event.
4398 For example, type \\[event-apply-shift-modifier] & to enter Shift-&."
4399 (vector (event-apply-modifier (read-event) 'shift 25 "S-")))
4400 (defun event-apply-control-modifier (ignore-prompt)
4401 "\\<function-key-map>Add the Ctrl modifier to the following event.
4402 For example, type \\[event-apply-control-modifier] & to enter Ctrl-&."
4403 (vector (event-apply-modifier (read-event) 'control 26 "C-")))
4404 (defun event-apply-meta-modifier (ignore-prompt)
4405 "\\<function-key-map>Add the Meta modifier to the following event.
4406 For example, type \\[event-apply-meta-modifier] & to enter Meta-&."
4407 (vector (event-apply-modifier (read-event) 'meta 27 "M-")))
4409 (defun event-apply-modifier (event symbol lshiftby prefix)
4410 "Apply a modifier flag to event EVENT.
4411 SYMBOL is the name of this modifier, as a symbol.
4412 LSHIFTBY is the numeric value of this modifier, in keyboard events.
4413 PREFIX is the string that represents this modifier in an event type symbol."
4414 (if (numberp event)
4415 (cond ((eq symbol 'control)
4416 (if (and (<= (downcase event) ?z)
4417 (>= (downcase event) ?a))
4418 (- (downcase event) ?a -1)
4419 (if (and (<= (downcase event) ?Z)
4420 (>= (downcase event) ?A))
4421 (- (downcase event) ?A -1)
4422 (logior (lsh 1 lshiftby) event))))
4423 ((eq symbol 'shift)
4424 (if (and (<= (downcase event) ?z)
4425 (>= (downcase event) ?a))
4426 (upcase event)
4427 (logior (lsh 1 lshiftby) event)))
4429 (logior (lsh 1 lshiftby) event)))
4430 (if (memq symbol (event-modifiers event))
4431 event
4432 (let ((event-type (if (symbolp event) event (car event))))
4433 (setq event-type (intern (concat prefix (symbol-name event-type))))
4434 (if (symbolp event)
4435 event-type
4436 (cons event-type (cdr event)))))))
4438 (define-key function-key-map [?\C-x ?@ ?h] 'event-apply-hyper-modifier)
4439 (define-key function-key-map [?\C-x ?@ ?s] 'event-apply-super-modifier)
4440 (define-key function-key-map [?\C-x ?@ ?m] 'event-apply-meta-modifier)
4441 (define-key function-key-map [?\C-x ?@ ?a] 'event-apply-alt-modifier)
4442 (define-key function-key-map [?\C-x ?@ ?S] 'event-apply-shift-modifier)
4443 (define-key function-key-map [?\C-x ?@ ?c] 'event-apply-control-modifier)
4445 ;;;; Keypad support.
4447 ;;; Make the keypad keys act like ordinary typing keys. If people add
4448 ;;; bindings for the function key symbols, then those bindings will
4449 ;;; override these, so this shouldn't interfere with any existing
4450 ;;; bindings.
4452 ;; Also tell read-char how to handle these keys.
4453 (mapc
4454 (lambda (keypad-normal)
4455 (let ((keypad (nth 0 keypad-normal))
4456 (normal (nth 1 keypad-normal)))
4457 (put keypad 'ascii-character normal)
4458 (define-key function-key-map (vector keypad) (vector normal))))
4459 '((kp-0 ?0) (kp-1 ?1) (kp-2 ?2) (kp-3 ?3) (kp-4 ?4)
4460 (kp-5 ?5) (kp-6 ?6) (kp-7 ?7) (kp-8 ?8) (kp-9 ?9)
4461 (kp-space ?\ )
4462 (kp-tab ?\t)
4463 (kp-enter ?\r)
4464 (kp-multiply ?*)
4465 (kp-add ?+)
4466 (kp-separator ?,)
4467 (kp-subtract ?-)
4468 (kp-decimal ?.)
4469 (kp-divide ?/)
4470 (kp-equal ?=)))
4472 ;;;;
4473 ;;;; forking a twin copy of a buffer.
4474 ;;;;
4476 (defvar clone-buffer-hook nil
4477 "Normal hook to run in the new buffer at the end of `clone-buffer'.")
4479 (defun clone-process (process &optional newname)
4480 "Create a twin copy of PROCESS.
4481 If NEWNAME is nil, it defaults to PROCESS' name;
4482 NEWNAME is modified by adding or incrementing <N> at the end as necessary.
4483 If PROCESS is associated with a buffer, the new process will be associated
4484 with the current buffer instead.
4485 Returns nil if PROCESS has already terminated."
4486 (setq newname (or newname (process-name process)))
4487 (if (string-match "<[0-9]+>\\'" newname)
4488 (setq newname (substring newname 0 (match-beginning 0))))
4489 (when (memq (process-status process) '(run stop open))
4490 (let* ((process-connection-type (process-tty-name process))
4491 (new-process
4492 (if (memq (process-status process) '(open))
4493 (let ((args (process-contact process t)))
4494 (setq args (plist-put args :name newname))
4495 (setq args (plist-put args :buffer
4496 (if (process-buffer process)
4497 (current-buffer))))
4498 (apply 'make-network-process args))
4499 (apply 'start-process newname
4500 (if (process-buffer process) (current-buffer))
4501 (process-command process)))))
4502 (set-process-query-on-exit-flag
4503 new-process (process-query-on-exit-flag process))
4504 (set-process-inherit-coding-system-flag
4505 new-process (process-inherit-coding-system-flag process))
4506 (set-process-filter new-process (process-filter process))
4507 (set-process-sentinel new-process (process-sentinel process))
4508 (set-process-plist new-process (copy-sequence (process-plist process)))
4509 new-process)))
4511 ;; things to maybe add (currently partly covered by `funcall mode'):
4512 ;; - syntax-table
4513 ;; - overlays
4514 (defun clone-buffer (&optional newname display-flag)
4515 "Create and return a twin copy of the current buffer.
4516 Unlike an indirect buffer, the new buffer can be edited
4517 independently of the old one (if it is not read-only).
4518 NEWNAME is the name of the new buffer. It may be modified by
4519 adding or incrementing <N> at the end as necessary to create a
4520 unique buffer name. If nil, it defaults to the name of the
4521 current buffer, with the proper suffix. If DISPLAY-FLAG is
4522 non-nil, the new buffer is shown with `pop-to-buffer'. Trying to
4523 clone a file-visiting buffer, or a buffer whose major mode symbol
4524 has a non-nil `no-clone' property, results in an error.
4526 Interactively, DISPLAY-FLAG is t and NEWNAME is the name of the
4527 current buffer with appropriate suffix. However, if a prefix
4528 argument is given, then the command prompts for NEWNAME in the
4529 minibuffer.
4531 This runs the normal hook `clone-buffer-hook' in the new buffer
4532 after it has been set up properly in other respects."
4533 (interactive
4534 (progn
4535 (if buffer-file-name
4536 (error "Cannot clone a file-visiting buffer"))
4537 (if (get major-mode 'no-clone)
4538 (error "Cannot clone a buffer in %s mode" mode-name))
4539 (list (if current-prefix-arg (read-string "Name: "))
4540 t)))
4541 (if buffer-file-name
4542 (error "Cannot clone a file-visiting buffer"))
4543 (if (get major-mode 'no-clone)
4544 (error "Cannot clone a buffer in %s mode" mode-name))
4545 (setq newname (or newname (buffer-name)))
4546 (if (string-match "<[0-9]+>\\'" newname)
4547 (setq newname (substring newname 0 (match-beginning 0))))
4548 (let ((buf (current-buffer))
4549 (ptmin (point-min))
4550 (ptmax (point-max))
4551 (pt (point))
4552 (mk (if mark-active (mark t)))
4553 (modified (buffer-modified-p))
4554 (mode major-mode)
4555 (lvars (buffer-local-variables))
4556 (process (get-buffer-process (current-buffer)))
4557 (new (generate-new-buffer (or newname (buffer-name)))))
4558 (save-restriction
4559 (widen)
4560 (with-current-buffer new
4561 (insert-buffer-substring buf)))
4562 (with-current-buffer new
4563 (narrow-to-region ptmin ptmax)
4564 (goto-char pt)
4565 (if mk (set-mark mk))
4566 (set-buffer-modified-p modified)
4568 ;; Clone the old buffer's process, if any.
4569 (when process (clone-process process))
4571 ;; Now set up the major mode.
4572 (funcall mode)
4574 ;; Set up other local variables.
4575 (mapcar (lambda (v)
4576 (condition-case () ;in case var is read-only
4577 (if (symbolp v)
4578 (makunbound v)
4579 (set (make-local-variable (car v)) (cdr v)))
4580 (error nil)))
4581 lvars)
4583 ;; Run any hooks (typically set up by the major mode
4584 ;; for cloning to work properly).
4585 (run-hooks 'clone-buffer-hook))
4586 (if display-flag (pop-to-buffer new))
4587 new))
4590 (defun clone-indirect-buffer (newname display-flag &optional norecord)
4591 "Create an indirect buffer that is a twin copy of the current buffer.
4593 Give the indirect buffer name NEWNAME. Interactively, read NEW-NAME
4594 from the minibuffer when invoked with a prefix arg. If NEWNAME is nil
4595 or if not called with a prefix arg, NEWNAME defaults to the current
4596 buffer's name. The name is modified by adding a `<N>' suffix to it
4597 or by incrementing the N in an existing suffix.
4599 DISPLAY-FLAG non-nil means show the new buffer with `pop-to-buffer'.
4600 This is always done when called interactively.
4602 Optional last arg NORECORD non-nil means do not put this buffer at the
4603 front of the list of recently selected ones."
4604 (interactive
4605 (progn
4606 (if (get major-mode 'no-clone-indirect)
4607 (error "Cannot indirectly clone a buffer in %s mode" mode-name))
4608 (list (if current-prefix-arg
4609 (read-string "BName of indirect buffer: "))
4610 t)))
4611 (if (get major-mode 'no-clone-indirect)
4612 (error "Cannot indirectly clone a buffer in %s mode" mode-name))
4613 (setq newname (or newname (buffer-name)))
4614 (if (string-match "<[0-9]+>\\'" newname)
4615 (setq newname (substring newname 0 (match-beginning 0))))
4616 (let* ((name (generate-new-buffer-name newname))
4617 (buffer (make-indirect-buffer (current-buffer) name t)))
4618 (when display-flag
4619 (pop-to-buffer buffer norecord))
4620 buffer))
4623 (defun clone-indirect-buffer-other-window (buffer &optional norecord)
4624 "Create an indirect buffer that is a twin copy of BUFFER.
4625 Select the new buffer in another window.
4626 Optional second arg NORECORD non-nil means do not put this buffer at
4627 the front of the list of recently selected ones."
4628 (interactive "bClone buffer in other window: ")
4629 (let ((pop-up-windows t))
4630 (set-buffer buffer)
4631 (clone-indirect-buffer nil t norecord)))
4633 (define-key ctl-x-4-map "c" 'clone-indirect-buffer-other-window)
4635 ;;; Handling of Backspace and Delete keys.
4637 (defcustom normal-erase-is-backspace nil
4638 "If non-nil, Delete key deletes forward and Backspace key deletes backward.
4640 On window systems, the default value of this option is chosen
4641 according to the keyboard used. If the keyboard has both a Backspace
4642 key and a Delete key, and both are mapped to their usual meanings, the
4643 option's default value is set to t, so that Backspace can be used to
4644 delete backward, and Delete can be used to delete forward.
4646 If not running under a window system, customizing this option accomplishes
4647 a similar effect by mapping C-h, which is usually generated by the
4648 Backspace key, to DEL, and by mapping DEL to C-d via
4649 `keyboard-translate'. The former functionality of C-h is available on
4650 the F1 key. You should probably not use this setting if you don't
4651 have both Backspace, Delete and F1 keys.
4653 Setting this variable with setq doesn't take effect. Programmatically,
4654 call `normal-erase-is-backspace-mode' (which see) instead."
4655 :type 'boolean
4656 :group 'editing-basics
4657 :version "21.1"
4658 :set (lambda (symbol value)
4659 ;; The fboundp is because of a problem with :set when
4660 ;; dumping Emacs. It doesn't really matter.
4661 (if (fboundp 'normal-erase-is-backspace-mode)
4662 (normal-erase-is-backspace-mode (or value 0))
4663 (set-default symbol value))))
4666 (defun normal-erase-is-backspace-mode (&optional arg)
4667 "Toggle the Erase and Delete mode of the Backspace and Delete keys.
4669 With numeric arg, turn the mode on if and only if ARG is positive.
4671 On window systems, when this mode is on, Delete is mapped to C-d and
4672 Backspace is mapped to DEL; when this mode is off, both Delete and
4673 Backspace are mapped to DEL. (The remapping goes via
4674 `function-key-map', so binding Delete or Backspace in the global or
4675 local keymap will override that.)
4677 In addition, on window systems, the bindings of C-Delete, M-Delete,
4678 C-M-Delete, C-Backspace, M-Backspace, and C-M-Backspace are changed in
4679 the global keymap in accordance with the functionality of Delete and
4680 Backspace. For example, if Delete is remapped to C-d, which deletes
4681 forward, C-Delete is bound to `kill-word', but if Delete is remapped
4682 to DEL, which deletes backward, C-Delete is bound to
4683 `backward-kill-word'.
4685 If not running on a window system, a similar effect is accomplished by
4686 remapping C-h (normally produced by the Backspace key) and DEL via
4687 `keyboard-translate': if this mode is on, C-h is mapped to DEL and DEL
4688 to C-d; if it's off, the keys are not remapped.
4690 When not running on a window system, and this mode is turned on, the
4691 former functionality of C-h is available on the F1 key. You should
4692 probably not turn on this mode on a text-only terminal if you don't
4693 have both Backspace, Delete and F1 keys.
4695 See also `normal-erase-is-backspace'."
4696 (interactive "P")
4697 (setq normal-erase-is-backspace
4698 (if arg
4699 (> (prefix-numeric-value arg) 0)
4700 (not normal-erase-is-backspace)))
4702 (cond ((or (memq window-system '(x w32 mac pc))
4703 (memq system-type '(ms-dos windows-nt)))
4704 (let ((bindings
4705 `(([C-delete] [C-backspace])
4706 ([M-delete] [M-backspace])
4707 ([C-M-delete] [C-M-backspace])
4708 (,esc-map
4709 [C-delete] [C-backspace])))
4710 (old-state (lookup-key function-key-map [delete])))
4712 (if normal-erase-is-backspace
4713 (progn
4714 (define-key function-key-map [delete] [?\C-d])
4715 (define-key function-key-map [kp-delete] [?\C-d])
4716 (define-key function-key-map [backspace] [?\C-?]))
4717 (define-key function-key-map [delete] [?\C-?])
4718 (define-key function-key-map [kp-delete] [?\C-?])
4719 (define-key function-key-map [backspace] [?\C-?]))
4721 ;; Maybe swap bindings of C-delete and C-backspace, etc.
4722 (unless (equal old-state (lookup-key function-key-map [delete]))
4723 (dolist (binding bindings)
4724 (let ((map global-map))
4725 (when (keymapp (car binding))
4726 (setq map (car binding) binding (cdr binding)))
4727 (let* ((key1 (nth 0 binding))
4728 (key2 (nth 1 binding))
4729 (binding1 (lookup-key map key1))
4730 (binding2 (lookup-key map key2)))
4731 (define-key map key1 binding2)
4732 (define-key map key2 binding1)))))))
4734 (if normal-erase-is-backspace
4735 (progn
4736 (keyboard-translate ?\C-h ?\C-?)
4737 (keyboard-translate ?\C-? ?\C-d))
4738 (keyboard-translate ?\C-h ?\C-h)
4739 (keyboard-translate ?\C-? ?\C-?))))
4741 (run-hooks 'normal-erase-is-backspace-hook)
4742 (if (interactive-p)
4743 (message "Delete key deletes %s"
4744 (if normal-erase-is-backspace "forward" "backward"))))
4746 (defcustom idle-update-delay 0.5
4747 "*Idle time delay before updating various things on the screen.
4748 Various Emacs features that update auxiliary information when point moves
4749 wait this many seconds after Emacs becomes idle before doing an update."
4750 :type 'number
4751 :group 'display
4752 :version "21.4")
4754 (defvar vis-mode-saved-buffer-invisibility-spec nil
4755 "Saved value of `buffer-invisibility-spec' when Visible mode is on.")
4757 (define-minor-mode visible-mode
4758 "Toggle Visible mode.
4759 With argument ARG turn Visible mode on iff ARG is positive.
4761 Enabling Visible mode makes all invisible text temporarily visible.
4762 Disabling Visible mode turns off that effect. Visible mode
4763 works by saving the value of `buffer-invisibility-spec' and setting it to nil."
4764 :lighter " Vis"
4765 (when (local-variable-p 'vis-mode-saved-buffer-invisibility-spec)
4766 (setq buffer-invisibility-spec vis-mode-saved-buffer-invisibility-spec)
4767 (kill-local-variable 'vis-mode-saved-buffer-invisibility-spec))
4768 (when visible-mode
4769 (set (make-local-variable 'vis-mode-saved-buffer-invisibility-spec)
4770 buffer-invisibility-spec)
4771 (setq buffer-invisibility-spec nil)))
4773 ;; Minibuffer prompt stuff.
4775 ;(defun minibuffer-prompt-modification (start end)
4776 ; (error "You cannot modify the prompt"))
4779 ;(defun minibuffer-prompt-insertion (start end)
4780 ; (let ((inhibit-modification-hooks t))
4781 ; (delete-region start end)
4782 ; ;; Discard undo information for the text insertion itself
4783 ; ;; and for the text deletion.above.
4784 ; (when (consp buffer-undo-list)
4785 ; (setq buffer-undo-list (cddr buffer-undo-list)))
4786 ; (message "You cannot modify the prompt")))
4789 ;(setq minibuffer-prompt-properties
4790 ; (list 'modification-hooks '(minibuffer-prompt-modification)
4791 ; 'insert-in-front-hooks '(minibuffer-prompt-insertion)))
4794 (provide 'simple)
4796 ;; arch-tag: 24af67c0-2a49-44f6-b3b1-312d8b570dfd
4797 ;;; simple.el ends here