1 ;;; simple.el --- basic editing commands for Emacs
3 ;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
5 ;; Free Software Foundation, Inc.
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 3, or (at your option)
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., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; A grab-bag of basic Emacs commands not specifically related to some
30 ;; major mode or to file-handling.
35 (autoload 'widget-convert
"wid-edit")
36 (autoload 'shell-mode
"shell"))
38 (defvar compilation-current-error
)
40 (defcustom idle-update-delay
0.5
41 "*Idle time delay before updating various things on the screen.
42 Various Emacs features that update auxiliary information when point moves
43 wait this many seconds after Emacs becomes idle before doing an update."
49 "Killing and yanking commands."
52 (defgroup paren-matching nil
53 "Highlight (un)matching of parens and expressions."
56 (defun get-next-valid-buffer (list &optional buffer visible-ok frame
)
57 "Search LIST for a valid buffer to display in FRAME.
58 Return nil when all buffers in LIST are undesirable for display,
59 otherwise return the first suitable buffer in LIST.
61 Buffers not visible in windows are preferred to visible buffers,
62 unless VISIBLE-OK is non-nil.
63 If the optional argument FRAME is nil, it defaults to the selected frame.
64 If BUFFER is non-nil, ignore occurrences of that buffer in LIST."
65 ;; This logic is more or less copied from other-buffer.
66 (setq frame
(or frame
(selected-frame)))
67 (let ((pred (frame-parameter frame
'buffer-predicate
))
69 (while (and (not found
) list
)
71 (if (and (not (eq buffer buf
))
73 (or (null pred
) (funcall pred buf
))
74 (not (eq (aref (buffer-name buf
) 0) ?\s
))
75 (or visible-ok
(null (get-buffer-window buf
'visible
))))
77 (setq list
(cdr list
))))
80 (defun last-buffer (&optional buffer visible-ok frame
)
81 "Return the last non-hidden displayable buffer in the buffer list.
82 If BUFFER is non-nil, last-buffer will ignore that buffer.
83 Buffers not visible in windows are preferred to visible buffers,
84 unless optional argument VISIBLE-OK is non-nil.
85 If the optional third argument FRAME is non-nil, use that frame's
86 buffer list instead of the selected frame's buffer list.
87 If no other buffer exists, the buffer `*scratch*' is returned."
88 (setq frame
(or frame
(selected-frame)))
89 (or (get-next-valid-buffer (nreverse (buffer-list frame
))
90 buffer visible-ok frame
)
92 (set-buffer-major-mode (get-buffer-create "*scratch*"))
93 (get-buffer "*scratch*"))))
95 "Switch to the next buffer in cyclic order."
97 (let ((buffer (current-buffer)))
98 (switch-to-buffer (other-buffer buffer t
))
99 (bury-buffer buffer
)))
101 (defun previous-buffer ()
102 "Switch to the previous buffer in cyclic order."
104 (switch-to-buffer (last-buffer (current-buffer) t
)))
107 ;;; next-error support framework
109 (defgroup next-error nil
110 "`next-error' support framework."
115 '((t (:inherit region
)))
116 "Face used to highlight next error locus."
120 (defcustom next-error-highlight
0.5
121 "*Highlighting of locations in selected source buffers.
122 If a number, highlight the locus in `next-error' face for the given time
123 in seconds, or until the next command is executed.
124 If t, highlight the locus until the next command is executed, or until
125 some other locus replaces it.
126 If nil, don't highlight the locus in the source buffer.
127 If `fringe-arrow', indicate the locus by the fringe arrow."
128 :type
'(choice (number :tag
"Highlight for specified time")
129 (const :tag
"Semipermanent highlighting" t
)
130 (const :tag
"No highlighting" nil
)
131 (const :tag
"Fringe arrow" fringe-arrow
))
135 (defcustom next-error-highlight-no-select
0.5
136 "*Highlighting of locations in `next-error-no-select'.
137 If number, highlight the locus in `next-error' face for given time in seconds.
138 If t, highlight the locus indefinitely until some other locus replaces it.
139 If nil, don't highlight the locus in the source buffer.
140 If `fringe-arrow', indicate the locus by the fringe arrow."
141 :type
'(choice (number :tag
"Highlight for specified time")
142 (const :tag
"Semipermanent highlighting" t
)
143 (const :tag
"No highlighting" nil
)
144 (const :tag
"Fringe arrow" fringe-arrow
))
148 (defcustom next-error-recenter nil
149 "*Display the line in the visited source file recentered as specified.
150 If non-nil, the value is passed directly to `recenter'."
151 :type
'(choice (integer :tag
"Line to recenter to")
152 (const :tag
"Center of window" (4))
153 (const :tag
"No recentering" nil
))
157 (defcustom next-error-hook nil
158 "*List of hook functions run by `next-error' after visiting source file."
162 (defvar next-error-highlight-timer nil
)
164 (defvar next-error-overlay-arrow-position nil
)
165 (put 'next-error-overlay-arrow-position
'overlay-arrow-string
"=>")
166 (add-to-list 'overlay-arrow-variable-list
'next-error-overlay-arrow-position
)
168 (defvar next-error-last-buffer nil
169 "The most recent `next-error' buffer.
170 A buffer becomes most recent when its compilation, grep, or
171 similar mode is started, or when it is used with \\[next-error]
172 or \\[compile-goto-error].")
174 (defvar next-error-function nil
175 "Function to use to find the next error in the current buffer.
176 The function is called with 2 parameters:
177 ARG is an integer specifying by how many errors to move.
178 RESET is a boolean which, if non-nil, says to go back to the beginning
179 of the errors before moving.
180 Major modes providing compile-like functionality should set this variable
181 to indicate to `next-error' that this is a candidate buffer and how
184 (make-variable-buffer-local 'next-error-function
)
186 (defsubst next-error-buffer-p
(buffer
187 &optional avoid-current
189 extra-test-exclusive
)
190 "Test if BUFFER is a `next-error' capable buffer.
192 If AVOID-CURRENT is non-nil, treat the current buffer
193 as an absolute last resort only.
195 The function EXTRA-TEST-INCLUSIVE, if non-nil, is called in each buffer
196 that normally would not qualify. If it returns t, the buffer
197 in question is treated as usable.
199 The function EXTRA-TEST-EXCLUSIVE, if non-nil, is called in each buffer
200 that would normally be considered usable. If it returns nil,
201 that buffer is rejected."
202 (and (buffer-name buffer
) ;First make sure it's live.
203 (not (and avoid-current
(eq buffer
(current-buffer))))
204 (with-current-buffer buffer
205 (if next-error-function
; This is the normal test.
206 ;; Optionally reject some buffers.
207 (if extra-test-exclusive
208 (funcall extra-test-exclusive
)
210 ;; Optionally accept some other buffers.
211 (and extra-test-inclusive
212 (funcall extra-test-inclusive
))))))
214 (defun next-error-find-buffer (&optional avoid-current
216 extra-test-exclusive
)
217 "Return a `next-error' capable buffer.
219 If AVOID-CURRENT is non-nil, treat the current buffer
220 as an absolute last resort only.
222 The function EXTRA-TEST-INCLUSIVE, if non-nil, is called in each buffer
223 that normally would not qualify. If it returns t, the buffer
224 in question is treated as usable.
226 The function EXTRA-TEST-EXCLUSIVE, if non-nil, is called in each buffer
227 that would normally be considered usable. If it returns nil,
228 that buffer is rejected."
230 ;; 1. If one window on the selected frame displays such buffer, return it.
231 (let ((window-buffers
233 (delq nil
(mapcar (lambda (w)
234 (if (next-error-buffer-p
237 extra-test-inclusive extra-test-exclusive
)
240 (if (eq (length window-buffers
) 1)
241 (car window-buffers
)))
242 ;; 2. If next-error-last-buffer is an acceptable buffer, use that.
243 (if (and next-error-last-buffer
244 (next-error-buffer-p next-error-last-buffer avoid-current
245 extra-test-inclusive extra-test-exclusive
))
246 next-error-last-buffer
)
247 ;; 3. If the current buffer is acceptable, choose it.
248 (if (next-error-buffer-p (current-buffer) avoid-current
249 extra-test-inclusive extra-test-exclusive
)
251 ;; 4. Look for any acceptable buffer.
252 (let ((buffers (buffer-list)))
254 (not (next-error-buffer-p
255 (car buffers
) avoid-current
256 extra-test-inclusive extra-test-exclusive
)))
257 (setq buffers
(cdr buffers
)))
259 ;; 5. Use the current buffer as a last resort if it qualifies,
260 ;; even despite AVOID-CURRENT.
262 (next-error-buffer-p (current-buffer) nil
263 extra-test-inclusive extra-test-exclusive
)
265 (message "This is the only buffer with error message locations")
268 (error "No buffers contain error message locations")))
270 (defun next-error (&optional arg reset
)
271 "Visit next `next-error' message and corresponding source code.
273 If all the error messages parsed so far have been processed already,
274 the message buffer is checked for new ones.
276 A prefix ARG specifies how many error messages to move;
277 negative means move back to previous error messages.
278 Just \\[universal-argument] as a prefix means reparse the error message buffer
279 and start at the first error.
281 The RESET argument specifies that we should restart from the beginning.
283 \\[next-error] normally uses the most recently started
284 compilation, grep, or occur buffer. It can also operate on any
285 buffer with output from the \\[compile], \\[grep] commands, or,
286 more generally, on any buffer in Compilation mode or with
287 Compilation Minor mode enabled, or any buffer in which
288 `next-error-function' is bound to an appropriate function.
289 To specify use of a particular buffer for error messages, type
290 \\[next-error] in that buffer when it is the only one displayed
291 in the current frame.
293 Once \\[next-error] has chosen the buffer for error messages, it
294 runs `next-error-hook' with `run-hooks', and stays with that buffer
295 until you use it in some other buffer which uses Compilation mode
296 or Compilation Minor mode.
298 See variables `compilation-parse-errors-function' and
299 \`compilation-error-regexp-alist' for customization ideas."
301 (if (consp arg
) (setq reset t arg nil
))
302 (when (setq next-error-last-buffer
(next-error-find-buffer))
303 ;; we know here that next-error-function is a valid symbol we can funcall
304 (with-current-buffer next-error-last-buffer
305 (funcall next-error-function
(prefix-numeric-value arg
) reset
)
306 (when next-error-recenter
307 (recenter next-error-recenter
))
308 (run-hooks 'next-error-hook
))))
310 (defun next-error-internal ()
311 "Visit the source code corresponding to the `next-error' message at point."
312 (setq next-error-last-buffer
(current-buffer))
313 ;; we know here that next-error-function is a valid symbol we can funcall
314 (with-current-buffer next-error-last-buffer
315 (funcall next-error-function
0 nil
)
316 (when next-error-recenter
317 (recenter next-error-recenter
))
318 (run-hooks 'next-error-hook
)))
320 (defalias 'goto-next-locus
'next-error
)
321 (defalias 'next-match
'next-error
)
323 (defun previous-error (&optional n
)
324 "Visit previous `next-error' message and corresponding source code.
326 Prefix arg N says how many error messages to move backwards (or
327 forwards, if negative).
329 This operates on the output from the \\[compile] and \\[grep] commands."
331 (next-error (- (or n
1))))
333 (defun first-error (&optional n
)
334 "Restart at the first error.
335 Visit corresponding source code.
336 With prefix arg N, visit the source code of the Nth error.
337 This operates on the output from the \\[compile] command, for instance."
341 (defun next-error-no-select (&optional n
)
342 "Move point to the next error in the `next-error' buffer and highlight match.
343 Prefix arg N says how many error messages to move forwards (or
344 backwards, if negative).
345 Finds and highlights the source line like \\[next-error], but does not
346 select the source buffer."
348 (let ((next-error-highlight next-error-highlight-no-select
))
350 (pop-to-buffer next-error-last-buffer
))
352 (defun previous-error-no-select (&optional n
)
353 "Move point to the previous error in the `next-error' buffer and highlight match.
354 Prefix arg N says how many error messages to move backwards (or
355 forwards, if negative).
356 Finds and highlights the source line like \\[previous-error], but does not
357 select the source buffer."
359 (next-error-no-select (- (or n
1))))
361 ;;; Internal variable for `next-error-follow-mode-post-command-hook'.
362 (defvar next-error-follow-last-line nil
)
364 (define-minor-mode next-error-follow-minor-mode
365 "Minor mode for compilation, occur and diff modes.
366 When turned on, cursor motion in the compilation, grep, occur or diff
367 buffer causes automatic display of the corresponding source code
369 :group
'next-error
:init-value nil
:lighter
" Fol"
370 (if (not next-error-follow-minor-mode
)
371 (remove-hook 'post-command-hook
'next-error-follow-mode-post-command-hook t
)
372 (add-hook 'post-command-hook
'next-error-follow-mode-post-command-hook nil t
)
373 (make-local-variable 'next-error-follow-last-line
)))
375 ;;; Used as a `post-command-hook' by `next-error-follow-mode'
376 ;;; for the *Compilation* *grep* and *Occur* buffers.
377 (defun next-error-follow-mode-post-command-hook ()
378 (unless (equal next-error-follow-last-line
(line-number-at-pos))
379 (setq next-error-follow-last-line
(line-number-at-pos))
381 (let ((compilation-context-lines nil
))
382 (setq compilation-current-error
(point))
383 (next-error-no-select 0))
389 (defun fundamental-mode ()
390 "Major mode not specialized for anything in particular.
391 Other major modes are defined by comparison with this one."
393 (kill-all-local-variables)
394 (unless delay-mode-hooks
395 (run-hooks 'after-change-major-mode-hook
)))
397 ;; Making and deleting lines.
399 (defvar hard-newline
(propertize "\n" 'hard t
'rear-nonsticky
'(hard)))
401 (defun newline (&optional arg
)
402 "Insert a newline, and move to left margin of the new line if it's blank.
403 If `use-hard-newlines' is non-nil, the newline is marked with the
404 text-property `hard'.
405 With ARG, insert that many newlines.
406 Call `auto-fill-function' if the current column number is greater
407 than the value of `fill-column' and ARG is nil."
409 (barf-if-buffer-read-only)
410 ;; Inserting a newline at the end of a line produces better redisplay in
411 ;; try_window_id than inserting at the beginning of a line, and the textual
412 ;; result is the same. So, if we're at beginning of line, pretend to be at
413 ;; the end of the previous line.
414 (let ((flag (and (not (bobp))
416 ;; Make sure no functions want to be told about
417 ;; the range of the changes.
418 (not after-change-functions
)
419 (not before-change-functions
)
420 ;; Make sure there are no markers here.
421 (not (buffer-has-markers-at (1- (point))))
422 (not (buffer-has-markers-at (point)))
423 ;; Make sure no text properties want to know
424 ;; where the change was.
425 (not (get-char-property (1- (point)) 'modification-hooks
))
426 (not (get-char-property (1- (point)) 'insert-behind-hooks
))
428 (not (get-char-property (point) 'insert-in-front-hooks
)))
429 ;; Make sure the newline before point isn't intangible.
430 (not (get-char-property (1- (point)) 'intangible
))
431 ;; Make sure the newline before point isn't read-only.
432 (not (get-char-property (1- (point)) 'read-only
))
433 ;; Make sure the newline before point isn't invisible.
434 (not (get-char-property (1- (point)) 'invisible
))
435 ;; Make sure the newline before point has the same
436 ;; properties as the char before it (if any).
437 (< (or (previous-property-change (point)) -
2)
439 (was-page-start (and (bolp)
440 (looking-at page-delimiter
)))
442 (if flag
(backward-char 1))
443 ;; Call self-insert so that auto-fill, abbrev expansion etc. happens.
444 ;; Set last-command-char to tell self-insert what to insert.
445 (let ((last-command-char ?
\n)
446 ;; Don't auto-fill if we have a numeric argument.
447 ;; Also not if flag is true (it would fill wrong line);
448 ;; there is no need to since we're at BOL.
449 (auto-fill-function (if (or arg flag
) nil auto-fill-function
)))
451 (self-insert-command (prefix-numeric-value arg
))
452 ;; If we get an error in self-insert-command, put point at right place.
453 (if flag
(forward-char 1))))
454 ;; Even if we did *not* get an error, keep that forward-char;
455 ;; all further processing should apply to the newline that the user
456 ;; thinks he inserted.
458 ;; Mark the newline(s) `hard'.
459 (if use-hard-newlines
460 (set-hard-newline-properties
461 (- (point) (prefix-numeric-value arg
)) (point)))
462 ;; If the newline leaves the previous line blank,
463 ;; and we have a left margin, delete that from the blank line.
466 (goto-char beforepos
)
468 (and (looking-at "[ \t]$")
469 (> (current-left-margin) 0)
470 (delete-region (point) (progn (end-of-line) (point))))))
471 ;; Indent the line after the newline, except in one case:
472 ;; when we added the newline at the beginning of a line
473 ;; which starts a page.
475 (move-to-left-margin nil t
)))
478 (defun set-hard-newline-properties (from to
)
479 (let ((sticky (get-text-property from
'rear-nonsticky
)))
480 (put-text-property from to
'hard
't
)
481 ;; If rear-nonsticky is not "t", add 'hard to rear-nonsticky list
482 (if (and (listp sticky
) (not (memq 'hard sticky
)))
483 (put-text-property from
(point) 'rear-nonsticky
484 (cons 'hard sticky
)))))
487 "Insert a newline and leave point before it.
488 If there is a fill prefix and/or a `left-margin', insert them
489 on the new line if the line would have been blank.
490 With arg N, insert N newlines."
492 (let* ((do-fill-prefix (and fill-prefix
(bolp)))
493 (do-left-margin (and (bolp) (> (current-left-margin) 0)))
495 ;; Don't expand an abbrev before point.
501 (if do-left-margin
(indent-to (current-left-margin)))
502 (if do-fill-prefix
(insert-and-inherit fill-prefix
))))
508 (defun split-line (&optional arg
)
509 "Split current line, moving portion beyond point vertically down.
510 If the current line starts with `fill-prefix', insert it on the new
511 line as well. With prefix ARG, don't insert `fill-prefix' on new line.
513 When called from Lisp code, ARG may be a prefix string to copy."
515 (skip-chars-forward " \t")
516 (let* ((col (current-column))
518 ;; What prefix should we check for (nil means don't).
519 (prefix (cond ((stringp arg
) arg
)
522 ;; Does this line start with it?
523 (have-prfx (and prefix
526 (looking-at (regexp-quote prefix
))))))
528 (if have-prfx
(insert-and-inherit prefix
))
532 (defun delete-indentation (&optional arg
)
533 "Join this line to previous and fix up whitespace at join.
534 If there is a fill prefix, delete it from the beginning of this line.
535 With argument, join this line to following line."
538 (if arg
(forward-line 1))
539 (if (eq (preceding-char) ?
\n)
541 (delete-region (point) (1- (point)))
542 ;; If the second line started with the fill prefix,
543 ;; delete the prefix.
545 (<= (+ (point) (length fill-prefix
)) (point-max))
547 (buffer-substring (point)
548 (+ (point) (length fill-prefix
)))))
549 (delete-region (point) (+ (point) (length fill-prefix
))))
550 (fixup-whitespace))))
552 (defalias 'join-line
#'delete-indentation
) ; easier to find
554 (defun delete-blank-lines ()
555 "On blank line, delete all surrounding blank lines, leaving just one.
556 On isolated blank line, delete that one.
557 On nonblank line, delete any immediately following blank lines."
559 (let (thisblank singleblank
)
562 (setq thisblank
(looking-at "[ \t]*$"))
563 ;; Set singleblank if there is just one blank line here.
566 (not (looking-at "[ \t]*\n[ \t]*$"))
568 (progn (forward-line -
1)
569 (not (looking-at "[ \t]*$")))))))
570 ;; Delete preceding blank lines, and this one too if it's the only one.
574 (if singleblank
(forward-line 1))
575 (delete-region (point)
576 (if (re-search-backward "[^ \t\n]" nil t
)
577 (progn (forward-line 1) (point))
579 ;; Delete following blank lines, unless the current line is blank
580 ;; and there are no following blank lines.
581 (if (not (and thisblank singleblank
))
585 (delete-region (point)
586 (if (re-search-forward "[^ \t\n]" nil t
)
587 (progn (beginning-of-line) (point))
589 ;; Handle the special case where point is followed by newline and eob.
590 ;; Delete the line, leaving point at eob.
591 (if (looking-at "^[ \t]*\n\\'")
592 (delete-region (point) (point-max)))))
594 (defun delete-trailing-whitespace ()
595 "Delete all the trailing whitespace across the current buffer.
596 All whitespace after the last non-whitespace character in a line is deleted.
597 This respects narrowing, created by \\[narrow-to-region] and friends.
598 A formfeed is not considered whitespace by this function."
602 (goto-char (point-min))
603 (while (re-search-forward "\\s-$" nil t
)
604 (skip-syntax-backward "-" (save-excursion (forward-line 0) (point)))
605 ;; Don't delete formfeeds, even if they are considered whitespace.
607 (if (looking-at ".*\f")
608 (goto-char (match-end 0))))
609 (delete-region (point) (match-end 0))))))
611 (defun newline-and-indent ()
612 "Insert a newline, then indent according to major mode.
613 Indentation is done using the value of `indent-line-function'.
614 In programming language modes, this is the same as TAB.
615 In some text modes, where TAB inserts a tab, this command indents to the
616 column specified by the function `current-left-margin'."
618 (delete-horizontal-space t
)
620 (indent-according-to-mode))
622 (defun reindent-then-newline-and-indent ()
623 "Reindent current line, insert newline, then indent the new line.
624 Indentation of both lines is done according to the current major mode,
625 which means calling the current value of `indent-line-function'.
626 In programming language modes, this is the same as TAB.
627 In some text modes, where TAB inserts a tab, this indents to the
628 column specified by the function `current-left-margin'."
631 ;; Be careful to insert the newline before indenting the line.
632 ;; Otherwise, the indentation might be wrong.
636 ;; We are at EOL before the call to indent-according-to-mode, and
637 ;; after it we usually are as well, but not always. We tried to
638 ;; address it with `save-excursion' but that uses a normal marker
639 ;; whereas we need `move after insertion', so we do the save/restore
641 (setq pos
(copy-marker pos t
))
642 (indent-according-to-mode)
644 ;; Remove the trailing white-space after indentation because
645 ;; indentation may introduce the whitespace.
646 (delete-horizontal-space t
))
647 (indent-according-to-mode)))
649 (defun quoted-insert (arg)
650 "Read next input character and insert it.
651 This is useful for inserting control characters.
653 If the first character you type after this command is an octal digit,
654 you should type a sequence of octal digits which specify a character code.
655 Any nondigit terminates the sequence. If the terminator is a RET,
656 it is discarded; any other terminator is used itself as input.
657 The variable `read-quoted-char-radix' specifies the radix for this feature;
658 set it to 10 or 16 to use decimal or hex instead of octal.
660 In overwrite mode, this function inserts the character anyway, and
661 does not handle octal digits specially. This means that if you use
662 overwrite as your normal editing mode, you can use this function to
663 insert characters when necessary.
665 In binary overwrite mode, this function does overwrite, and octal
666 digits are interpreted as a character code. This is intended to be
667 useful for editing binary files."
669 (let* ((char (let (translation-table-for-input input-method-function
)
670 (if (or (not overwrite-mode
)
671 (eq overwrite-mode
'overwrite-mode-binary
))
674 ;; Assume character codes 0240 - 0377 stand for characters in some
675 ;; single-byte character set, and convert them to Emacs
677 (if (and enable-multibyte-characters
680 (setq char
(unibyte-char-to-multibyte char
)))
682 (if (eq overwrite-mode
'overwrite-mode-binary
)
685 (insert-and-inherit char
)
686 (setq arg
(1- arg
)))))
688 (defun forward-to-indentation (&optional arg
)
689 "Move forward ARG lines and position at first nonblank character."
691 (forward-line (or arg
1))
692 (skip-chars-forward " \t"))
694 (defun backward-to-indentation (&optional arg
)
695 "Move backward ARG lines and position at first nonblank character."
697 (forward-line (- (or arg
1)))
698 (skip-chars-forward " \t"))
700 (defun back-to-indentation ()
701 "Move point to the first non-whitespace character on this line."
703 (beginning-of-line 1)
704 (skip-syntax-forward " " (line-end-position))
705 ;; Move back over chars that have whitespace syntax but have the p flag.
706 (backward-prefix-chars))
708 (defun fixup-whitespace ()
709 "Fixup white space between objects around point.
710 Leave one space or none, according to the context."
713 (delete-horizontal-space)
714 (if (or (looking-at "^\\|\\s)")
715 (save-excursion (forward-char -
1)
716 (looking-at "$\\|\\s(\\|\\s'")))
720 (defun delete-horizontal-space (&optional backward-only
)
721 "Delete all spaces and tabs around point.
722 If BACKWARD-ONLY is non-nil, only delete them before point."
724 (let ((orig-pos (point)))
729 (skip-chars-forward " \t")
730 (constrain-to-field nil orig-pos t
)))
732 (skip-chars-backward " \t")
733 (constrain-to-field nil orig-pos
)))))
735 (defun just-one-space (&optional n
)
736 "Delete all spaces and tabs around point, leaving one space (or N spaces)."
738 (let ((orig-pos (point)))
739 (skip-chars-backward " \t")
740 (constrain-to-field nil orig-pos
)
741 (dotimes (i (or n
1))
742 (if (= (following-char) ?\s
)
748 (skip-chars-forward " \t")
749 (constrain-to-field nil orig-pos t
)))))
751 (defun beginning-of-buffer (&optional arg
)
752 "Move point to the beginning of the buffer; leave mark at previous position.
753 With \\[universal-argument] prefix, do not set mark at previous position.
754 With numeric arg N, put point N/10 of the way from the beginning.
756 If the buffer is narrowed, this command uses the beginning and size
757 of the accessible part of the buffer.
759 Don't use this command in Lisp programs!
760 \(goto-char (point-min)) is faster and avoids clobbering the mark."
763 (and transient-mark-mode mark-active
)
765 (let ((size (- (point-max) (point-min))))
766 (goto-char (if (and arg
(not (consp arg
)))
769 ;; Avoid overflow for large buffer sizes!
770 (* (prefix-numeric-value arg
)
772 (/ (+ 10 (* size
(prefix-numeric-value arg
))) 10)))
774 (if (and arg
(not (consp arg
))) (forward-line 1)))
776 (defun end-of-buffer (&optional arg
)
777 "Move point to the end of the buffer; leave mark at previous position.
778 With \\[universal-argument] prefix, do not set mark at previous position.
779 With numeric arg N, put point N/10 of the way from the end.
781 If the buffer is narrowed, this command uses the beginning and size
782 of the accessible part of the buffer.
784 Don't use this command in Lisp programs!
785 \(goto-char (point-max)) is faster and avoids clobbering the mark."
788 (and transient-mark-mode mark-active
)
790 (let ((size (- (point-max) (point-min))))
791 (goto-char (if (and arg
(not (consp arg
)))
794 ;; Avoid overflow for large buffer sizes!
795 (* (prefix-numeric-value arg
)
797 (/ (* size
(prefix-numeric-value arg
)) 10)))
799 ;; If we went to a place in the middle of the buffer,
800 ;; adjust it to the beginning of a line.
801 (cond ((and arg
(not (consp arg
))) (forward-line 1))
802 ((> (point) (window-end nil t
))
803 ;; If the end of the buffer is not already on the screen,
804 ;; then scroll specially to put it near, but not at, the bottom.
805 (overlay-recenter (point))
808 (defun mark-whole-buffer ()
809 "Put point at beginning and mark at end of buffer.
810 You probably should not use this function in Lisp programs;
811 it is usually a mistake for a Lisp function to use any subroutine
812 that uses or sets the mark."
815 (push-mark (point-max) nil t
)
816 (goto-char (point-min)))
819 ;; Counting lines, one way or another.
821 (defun goto-line (arg &optional buffer
)
822 "Goto line ARG, counting from line 1 at beginning of buffer.
823 Normally, move point in the current buffer.
824 With just \\[universal-argument] as argument, move point in the most recently
825 displayed other buffer, and switch to it. When called from Lisp code,
826 the optional argument BUFFER specifies a buffer to switch to.
828 If there's a number in the buffer at point, it is the default for ARG."
830 (if (and current-prefix-arg
(not (consp current-prefix-arg
)))
831 (list (prefix-numeric-value current-prefix-arg
))
832 ;; Look for a default, a number in the buffer at point.
835 (skip-chars-backward "0-9")
836 (if (looking-at "[0-9]")
837 (buffer-substring-no-properties
839 (progn (skip-chars-forward "0-9")
841 ;; Decide if we're switching buffers.
843 (if (consp current-prefix-arg
)
844 (other-buffer (current-buffer) t
)))
847 (concat " in " (buffer-name buffer
))
849 ;; Read the argument, offering that number (if any) as default.
850 (list (read-from-minibuffer (format (if default
"Goto line%s (%s): "
858 ;; Switch to the desired buffer, one way or another.
860 (let ((window (get-buffer-window buffer
)))
861 (if window
(select-window window
)
862 (switch-to-buffer-other-window buffer
))))
863 ;; Move to the specified line number in that buffer.
867 (if (eq selective-display t
)
868 (re-search-forward "[\n\C-m]" nil
'end
(1- arg
))
869 (forward-line (1- arg
)))))
871 (defun count-lines-region (start end
)
872 "Print number of lines and characters in the region."
874 (message "Region has %d lines, %d characters"
875 (count-lines start end
) (- end start
)))
878 "Print the current buffer line number and narrowed line number of point."
880 (let ((start (point-min))
881 (n (line-number-at-pos)))
883 (message "Line %d" n
)
887 (message "line %d (narrowed line %d)"
888 (+ n
(line-number-at-pos start
) -
1) n
))))))
890 (defun count-lines (start end
)
891 "Return number of lines between START and END.
892 This is usually the number of newlines between them,
893 but can be one more if START is not equal to END
894 and the greater of them is not at the start of a line."
897 (narrow-to-region start end
)
898 (goto-char (point-min))
899 (if (eq selective-display t
)
902 (while (re-search-forward "[\n\C-m]" nil t
40)
903 (setq done
(+ 40 done
)))
904 (while (re-search-forward "[\n\C-m]" nil t
1)
905 (setq done
(+ 1 done
)))
906 (goto-char (point-max))
907 (if (and (/= start end
)
911 (- (buffer-size) (forward-line (buffer-size)))))))
913 (defun line-number-at-pos (&optional pos
)
914 "Return (narrowed) buffer line number at position POS.
915 If POS is nil, use current buffer location.
916 Counting starts at (point-min), so the value refers
917 to the contents of the accessible portion of the buffer."
918 (let ((opoint (or pos
(point))) start
)
920 (goto-char (point-min))
924 (1+ (count-lines start
(point))))))
926 (defun what-cursor-position (&optional detail
)
927 "Print info on cursor position (on screen and within buffer).
928 Also describe the character after point, and give its character code
929 in octal, decimal and hex.
931 For a non-ASCII multibyte character, also give its encoding in the
932 buffer's selected coding system if the coding system encodes the
933 character safely. If the character is encoded into one byte, that
934 code is shown in hex. If the character is encoded into more than one
935 byte, just \"...\" is shown.
937 In addition, with prefix argument, show details about that character
938 in *Help* buffer. See also the command `describe-char'."
940 (let* ((char (following-char))
944 (total (buffer-size))
945 (percent (if (> total
50000)
946 ;; Avoid overflow from multiplying by 100!
947 (/ (+ (/ total
200) (1- pos
)) (max (/ total
100) 1))
948 (/ (+ (/ total
2) (* 100 (1- pos
))) (max total
1))))
949 (hscroll (if (= (window-hscroll) 0)
951 (format " Hscroll=%d" (window-hscroll))))
952 (col (current-column)))
954 (if (or (/= beg
1) (/= end
(1+ total
)))
955 (message "point=%d of %d (%d%%) <%d-%d> column=%d%s"
956 pos total percent beg end col hscroll
)
957 (message "point=%d of %d (EOB) column=%d%s"
958 pos total col hscroll
))
959 (let ((coding buffer-file-coding-system
)
960 encoded encoding-msg display-prop under-display
)
962 (eq (coding-system-type coding
) t
))
963 (setq coding default-buffer-file-coding-system
))
964 (if (not (char-valid-p char
))
966 (format "(%d, #o%o, #x%x, invalid)" char char char
))
967 ;; Check if the character is displayed with some `display'
968 ;; text property. In that case, set under-display to the
969 ;; buffer substring covered by that property.
970 (setq display-prop
(get-text-property pos
'display
))
972 (let ((to (or (next-single-property-change pos
'display
)
975 (setq under-display
"")
976 (setq under-display
"..."
979 (concat (buffer-substring-no-properties pos to
)
981 (setq encoded
(and (>= char
128) (encode-coding-char char coding
))))
984 (if (not (stringp display-prop
))
985 (format "(%d, #o%o, #x%x, part of display \"%s\")"
986 char char char under-display
)
987 (format "(%d, #o%o, #x%x, part of display \"%s\"->\"%s\")"
988 char char char under-display display-prop
))
990 (format "(%d, #o%o, #x%x, file %s)"
992 (if (> (length encoded
) 1)
994 (encoded-string-description encoded coding
)))
995 (format "(%d, #o%o, #x%x)" char char char
)))))
997 ;; We show the detailed information about CHAR.
998 (describe-char (point)))
999 (if (or (/= beg
1) (/= end
(1+ total
)))
1000 (message "Char: %s %s point=%d of %d (%d%%) <%d-%d> column=%d%s"
1002 (single-key-description char
)
1003 (buffer-substring-no-properties (point) (1+ (point))))
1004 encoding-msg pos total percent beg end col hscroll
)
1005 (message "Char: %s %s point=%d of %d (%d%%) column=%d%s"
1006 (if enable-multibyte-characters
1008 (single-key-description char
)
1009 (buffer-substring-no-properties (point) (1+ (point))))
1010 (single-key-description char
))
1011 encoding-msg pos total percent col hscroll
))))))
1013 ;; Initialize read-expression-map. It is defined at C level.
1014 (let ((m (make-sparse-keymap)))
1015 (define-key m
"\M-\t" 'lisp-complete-symbol
)
1016 (set-keymap-parent m minibuffer-local-map
)
1017 (setq read-expression-map m
))
1019 (defvar read-expression-history nil
)
1021 (defvar minibuffer-completing-symbol nil
1022 "Non-nil means completing a Lisp symbol in the minibuffer.")
1024 (defcustom eval-expression-print-level
4
1025 "Value for `print-level' while printing value in `eval-expression'.
1026 A value of nil means no limit."
1028 :type
'(choice (const :tag
"No Limit" nil
) integer
)
1031 (defcustom eval-expression-print-length
12
1032 "Value for `print-length' while printing value in `eval-expression'.
1033 A value of nil means no limit."
1035 :type
'(choice (const :tag
"No Limit" nil
) integer
)
1038 (defcustom eval-expression-debug-on-error t
1039 "If non-nil set `debug-on-error' to t in `eval-expression'.
1040 If nil, don't change the value of `debug-on-error'."
1045 (defun eval-expression-print-format (value)
1046 "Format VALUE as a result of evaluated expression.
1047 Return a formatted string which is displayed in the echo area
1048 in addition to the value printed by prin1 in functions which
1049 display the result of expression evaluation."
1050 (if (and (integerp value
)
1051 (or (not (memq this-command
'(eval-last-sexp eval-print-last-sexp
)))
1052 (eq this-command last-command
)
1053 (if (boundp 'edebug-active
) edebug-active
)))
1055 (if (or (if (boundp 'edebug-active
) edebug-active
)
1056 (memq this-command
'(eval-last-sexp eval-print-last-sexp
)))
1057 (prin1-char value
))))
1059 (format " (#o%o, #x%x, %s)" value value char-string
)
1060 (format " (#o%o, #x%x)" value value
)))))
1062 ;; We define this, rather than making `eval' interactive,
1063 ;; for the sake of completion of names like eval-region, eval-buffer.
1064 (defun eval-expression (eval-expression-arg
1065 &optional eval-expression-insert-value
)
1066 "Evaluate EVAL-EXPRESSION-ARG and print value in the echo area.
1067 Value is also consed on to front of the variable `values'.
1068 Optional argument EVAL-EXPRESSION-INSERT-VALUE, if non-nil, means
1069 insert the result into the current buffer instead of printing it in
1072 If `eval-expression-debug-on-error' is non-nil, which is the default,
1073 this command arranges for all errors to enter the debugger."
1075 (list (let ((minibuffer-completing-symbol t
))
1076 (read-from-minibuffer "Eval: "
1077 nil read-expression-map t
1078 'read-expression-history
))
1079 current-prefix-arg
))
1081 (if (null eval-expression-debug-on-error
)
1082 (setq values
(cons (eval eval-expression-arg
) values
))
1083 (let ((old-value (make-symbol "t")) new-value
)
1084 ;; Bind debug-on-error to something unique so that we can
1085 ;; detect when evaled code changes it.
1086 (let ((debug-on-error old-value
))
1087 (setq values
(cons (eval eval-expression-arg
) values
))
1088 (setq new-value debug-on-error
))
1089 ;; If evaled code has changed the value of debug-on-error,
1090 ;; propagate that change to the global binding.
1091 (unless (eq old-value new-value
)
1092 (setq debug-on-error new-value
))))
1094 (let ((print-length eval-expression-print-length
)
1095 (print-level eval-expression-print-level
))
1096 (if eval-expression-insert-value
1098 (let ((standard-output (current-buffer)))
1099 (prin1 (car values
))))
1101 (prin1 (car values
) t
)
1102 (let ((str (eval-expression-print-format (car values
))))
1103 (if str
(princ str t
)))))))
1105 (defun edit-and-eval-command (prompt command
)
1106 "Prompting with PROMPT, let user edit COMMAND and eval result.
1107 COMMAND is a Lisp expression. Let user edit that expression in
1108 the minibuffer, then read and evaluate the result."
1110 (let ((print-level nil
)
1111 (minibuffer-history-sexp-flag (1+ (minibuffer-depth))))
1113 (read-from-minibuffer prompt
1114 (prin1-to-string command
)
1115 read-expression-map t
1117 ;; If command was added to command-history as a string,
1118 ;; get rid of that. We want only evaluable expressions there.
1119 (if (stringp (car command-history
))
1120 (setq command-history
(cdr command-history
)))))))
1122 ;; If command to be redone does not match front of history,
1123 ;; add it to the history.
1124 (or (equal command
(car command-history
))
1125 (setq command-history
(cons command command-history
)))
1128 (defun repeat-complex-command (arg)
1129 "Edit and re-evaluate last complex command, or ARGth from last.
1130 A complex command is one which used the minibuffer.
1131 The command is placed in the minibuffer as a Lisp form for editing.
1132 The result is executed, repeating the command as changed.
1133 If the command has been changed or is not the most recent previous command
1134 it is added to the front of the command history.
1135 You can use the minibuffer history commands \\<minibuffer-local-map>\\[next-history-element] and \\[previous-history-element]
1136 to get different commands to edit and resubmit."
1138 (let ((elt (nth (1- arg
) command-history
))
1143 (let ((print-level nil
)
1144 (minibuffer-history-position arg
)
1145 (minibuffer-history-sexp-flag (1+ (minibuffer-depth))))
1147 (read-from-minibuffer
1148 "Redo: " (prin1-to-string elt
) read-expression-map t
1149 (cons 'command-history arg
))
1151 ;; If command was added to command-history as a
1152 ;; string, get rid of that. We want only
1153 ;; evaluable expressions there.
1154 (if (stringp (car command-history
))
1155 (setq command-history
(cdr command-history
))))))
1157 ;; If command to be redone does not match front of history,
1158 ;; add it to the history.
1159 (or (equal newcmd
(car command-history
))
1160 (setq command-history
(cons newcmd command-history
)))
1163 (error "Argument %d is beyond length of command history" arg
)
1164 (error "There are no previous complex commands to repeat")))))
1166 (defvar minibuffer-history nil
1167 "Default minibuffer history list.
1168 This is used for all minibuffer input
1169 except when an alternate history list is specified.")
1170 (defvar minibuffer-history-sexp-flag nil
1171 "Control whether history list elements are expressions or strings.
1172 If the value of this variable equals current minibuffer depth,
1173 they are expressions; otherwise they are strings.
1174 \(That convention is designed to do the right thing for
1175 recursive uses of the minibuffer.)")
1176 (setq minibuffer-history-variable
'minibuffer-history
)
1177 (setq minibuffer-history-position nil
) ;; Defvar is in C code.
1178 (defvar minibuffer-history-search-history nil
)
1180 (defvar minibuffer-text-before-history nil
1181 "Text that was in this minibuffer before any history commands.
1182 This is nil if there have not yet been any history commands
1183 in this use of the minibuffer.")
1185 (add-hook 'minibuffer-setup-hook
'minibuffer-history-initialize
)
1187 (defun minibuffer-history-initialize ()
1188 (setq minibuffer-text-before-history nil
))
1190 (defun minibuffer-avoid-prompt (new old
)
1191 "A point-motion hook for the minibuffer, that moves point out of the prompt."
1192 (constrain-to-field nil
(point-max)))
1194 (defcustom minibuffer-history-case-insensitive-variables nil
1195 "*Minibuffer history variables for which matching should ignore case.
1196 If a history variable is a member of this list, then the
1197 \\[previous-matching-history-element] and \\[next-matching-history-element]\
1198 commands ignore case when searching it, regardless of `case-fold-search'."
1199 :type
'(repeat variable
)
1202 (defun previous-matching-history-element (regexp n
)
1203 "Find the previous history element that matches REGEXP.
1204 \(Previous history elements refer to earlier actions.)
1205 With prefix argument N, search for Nth previous match.
1206 If N is negative, find the next or Nth next match.
1207 Normally, history elements are matched case-insensitively if
1208 `case-fold-search' is non-nil, but an uppercase letter in REGEXP
1209 makes the search case-sensitive.
1210 See also `minibuffer-history-case-insensitive-variables'."
1212 (let* ((enable-recursive-minibuffers t
)
1213 (regexp (read-from-minibuffer "Previous element matching (regexp): "
1215 minibuffer-local-map
1217 'minibuffer-history-search-history
1218 (car minibuffer-history-search-history
))))
1219 ;; Use the last regexp specified, by default, if input is empty.
1220 (list (if (string= regexp
"")
1221 (if minibuffer-history-search-history
1222 (car minibuffer-history-search-history
)
1223 (error "No previous history search regexp"))
1225 (prefix-numeric-value current-prefix-arg
))))
1227 (if (and (zerop minibuffer-history-position
)
1228 (null minibuffer-text-before-history
))
1229 (setq minibuffer-text-before-history
1230 (minibuffer-contents-no-properties)))
1231 (let ((history (symbol-value minibuffer-history-variable
))
1233 (if (isearch-no-upper-case-p regexp t
) ; assume isearch.el is dumped
1234 ;; On some systems, ignore case for file names.
1235 (if (memq minibuffer-history-variable
1236 minibuffer-history-case-insensitive-variables
)
1238 ;; Respect the user's setting for case-fold-search:
1244 (pos minibuffer-history-position
))
1247 (setq pos
(min (max 1 (+ pos
(if (< n
0) -
1 1))) (length history
)))
1248 (when (= pos prevpos
)
1249 (error (if (= pos
1)
1250 "No later matching history item"
1251 "No earlier matching history item")))
1253 (if (eq minibuffer-history-sexp-flag
(minibuffer-depth))
1254 (let ((print-level nil
))
1255 (prin1-to-string (nth (1- pos
) history
)))
1256 (nth (1- pos
) history
)))
1259 (and (string-match regexp match-string
)
1261 (and (string-match (concat ".*\\(" regexp
"\\)") match-string
)
1262 (match-beginning 1))))
1264 (setq n
(+ n
(if (< n
0) 1 -
1)))))
1265 (setq minibuffer-history-position pos
)
1266 (goto-char (point-max))
1267 (delete-minibuffer-contents)
1268 (insert match-string
)
1269 (goto-char (+ (minibuffer-prompt-end) match-offset
))))
1270 (if (memq (car (car command-history
)) '(previous-matching-history-element
1271 next-matching-history-element
))
1272 (setq command-history
(cdr command-history
))))
1274 (defun next-matching-history-element (regexp n
)
1275 "Find the next history element that matches REGEXP.
1276 \(The next history element refers to a more recent action.)
1277 With prefix argument N, search for Nth next match.
1278 If N is negative, find the previous or Nth previous match.
1279 Normally, history elements are matched case-insensitively if
1280 `case-fold-search' is non-nil, but an uppercase letter in REGEXP
1281 makes the search case-sensitive."
1283 (let* ((enable-recursive-minibuffers t
)
1284 (regexp (read-from-minibuffer "Next element matching (regexp): "
1286 minibuffer-local-map
1288 'minibuffer-history-search-history
1289 (car minibuffer-history-search-history
))))
1290 ;; Use the last regexp specified, by default, if input is empty.
1291 (list (if (string= regexp
"")
1292 (if minibuffer-history-search-history
1293 (car minibuffer-history-search-history
)
1294 (error "No previous history search regexp"))
1296 (prefix-numeric-value current-prefix-arg
))))
1297 (previous-matching-history-element regexp
(- n
)))
1299 (defvar minibuffer-temporary-goal-position nil
)
1301 (defun goto-history-element (nabs)
1302 "Puts element of the minibuffer history in the minibuffer.
1303 The argument NABS specifies the absolute history position."
1305 (let ((minimum (if minibuffer-default
1306 (- (if (listp minibuffer-default
)
1307 (length minibuffer-default
)
1310 elt minibuffer-returned-to-present
)
1311 (if (and (zerop minibuffer-history-position
)
1312 (null minibuffer-text-before-history
))
1313 (setq minibuffer-text-before-history
1314 (minibuffer-contents-no-properties)))
1315 (if (< nabs minimum
)
1316 (if minibuffer-default
1317 (error "End of history; no next item")
1318 (error "End of history; no default available")))
1319 (if (> nabs
(length (symbol-value minibuffer-history-variable
)))
1320 (error "Beginning of history; no preceding item"))
1321 (unless (memq last-command
'(next-history-element
1322 previous-history-element
))
1323 (let ((prompt-end (minibuffer-prompt-end)))
1324 (set (make-local-variable 'minibuffer-temporary-goal-position
)
1325 (cond ((<= (point) prompt-end
) prompt-end
)
1328 (goto-char (point-max))
1329 (delete-minibuffer-contents)
1330 (setq minibuffer-history-position nabs
)
1332 (setq elt
(if (listp minibuffer-default
)
1333 (nth (1- (abs nabs
)) minibuffer-default
)
1334 minibuffer-default
)))
1336 (setq elt
(or minibuffer-text-before-history
""))
1337 (setq minibuffer-returned-to-present t
)
1338 (setq minibuffer-text-before-history nil
))
1339 (t (setq elt
(nth (1- minibuffer-history-position
)
1340 (symbol-value minibuffer-history-variable
)))))
1342 (if (and (eq minibuffer-history-sexp-flag
(minibuffer-depth))
1343 (not minibuffer-returned-to-present
))
1344 (let ((print-level nil
))
1345 (prin1-to-string elt
))
1347 (goto-char (or minibuffer-temporary-goal-position
(point-max)))))
1349 (defun next-history-element (n)
1350 "Puts next element of the minibuffer history in the minibuffer.
1351 With argument N, it uses the Nth following element."
1354 (goto-history-element (- minibuffer-history-position n
))))
1356 (defun previous-history-element (n)
1357 "Puts previous element of the minibuffer history in the minibuffer.
1358 With argument N, it uses the Nth previous element."
1361 (goto-history-element (+ minibuffer-history-position n
))))
1363 (defun next-complete-history-element (n)
1364 "Get next history element which completes the minibuffer before the point.
1365 The contents of the minibuffer after the point are deleted, and replaced
1366 by the new completion."
1368 (let ((point-at-start (point)))
1369 (next-matching-history-element
1371 "^" (regexp-quote (buffer-substring (minibuffer-prompt-end) (point))))
1373 ;; next-matching-history-element always puts us at (point-min).
1374 ;; Move to the position we were at before changing the buffer contents.
1375 ;; This is still sensical, because the text before point has not changed.
1376 (goto-char point-at-start
)))
1378 (defun previous-complete-history-element (n)
1380 Get previous history element which completes the minibuffer before the point.
1381 The contents of the minibuffer after the point are deleted, and replaced
1382 by the new completion."
1384 (next-complete-history-element (- n
)))
1386 ;; For compatibility with the old subr of the same name.
1387 (defun minibuffer-prompt-width ()
1388 "Return the display width of the minibuffer prompt.
1389 Return 0 if current buffer is not a minibuffer."
1390 ;; Return the width of everything before the field at the end of
1391 ;; the buffer; this should be 0 for normal buffers.
1392 (1- (minibuffer-prompt-end)))
1394 ;; isearch minibuffer history
1395 (add-hook 'minibuffer-setup-hook
'minibuffer-history-isearch-setup
)
1397 (defvar minibuffer-history-isearch-message-overlay
)
1398 (make-variable-buffer-local 'minibuffer-history-isearch-message-overlay
)
1400 (defun minibuffer-history-isearch-setup ()
1401 "Set up a minibuffer for using isearch to search the minibuffer history.
1402 Intended to be added to `minibuffer-setup-hook'."
1403 (set (make-local-variable 'isearch-search-fun-function
)
1404 'minibuffer-history-isearch-search
)
1405 (set (make-local-variable 'isearch-message-function
)
1406 'minibuffer-history-isearch-message
)
1407 (set (make-local-variable 'isearch-wrap-function
)
1408 'minibuffer-history-isearch-wrap
)
1409 (set (make-local-variable 'isearch-push-state-function
)
1410 'minibuffer-history-isearch-push-state
)
1411 (add-hook 'isearch-mode-end-hook
'minibuffer-history-isearch-end nil t
))
1413 (defun minibuffer-history-isearch-end ()
1414 "Clean up the minibuffer after terminating isearch in the minibuffer."
1415 (if minibuffer-history-isearch-message-overlay
1416 (delete-overlay minibuffer-history-isearch-message-overlay
)))
1418 (defun minibuffer-history-isearch-search ()
1419 "Return the proper search function, for isearch in minibuffer history."
1422 (if isearch-forward
'word-search-forward
'word-search-backward
))
1424 (lambda (string bound noerror
)
1426 ;; Use standard functions to search within minibuffer text
1429 (if isearch-forward
're-search-forward
're-search-backward
))
1431 (if isearch-forward
'search-forward
'search-backward
))))
1433 ;; Avoid lazy-highlighting matches in the minibuffer prompt when
1434 ;; searching forward. Lazy-highlight calls this lambda with the
1435 ;; bound arg, so skip the minibuffer prompt.
1436 (if (and bound isearch-forward
(< (point) (minibuffer-prompt-end)))
1437 (goto-char (minibuffer-prompt-end)))
1439 ;; 1. First try searching in the initial minibuffer text
1440 (funcall search-fun string
1441 (if isearch-forward bound
(minibuffer-prompt-end))
1443 ;; 2. If the above search fails, start putting next/prev history
1444 ;; elements in the minibuffer successively, and search the string
1445 ;; in them. Do this only when bound is nil (i.e. not while
1446 ;; lazy-highlighting search strings in the current minibuffer text).
1451 (cond (isearch-forward
1452 (next-history-element 1)
1453 (goto-char (minibuffer-prompt-end)))
1455 (previous-history-element 1)
1456 (goto-char (point-max))))
1457 (setq isearch-barrier
(point) isearch-opoint
(point))
1458 ;; After putting the next/prev history element, search
1459 ;; the string in them again, until next-history-element
1460 ;; or previous-history-element raises an error at the
1461 ;; beginning/end of history.
1462 (setq found
(funcall search-fun string
1463 (unless isearch-forward
1464 ;; For backward search, don't search
1465 ;; in the minibuffer prompt
1466 (minibuffer-prompt-end))
1468 ;; Return point of the new search result
1470 ;; Return nil when next(prev)-history-element fails
1473 (defun minibuffer-history-isearch-message (&optional c-q-hack ellipsis
)
1474 "Display the minibuffer history search prompt.
1475 If there are no search errors, this function displays an overlay with
1476 the isearch prompt which replaces the original minibuffer prompt.
1477 Otherwise, it displays the standard isearch message returned from
1479 (if (not (and (minibufferp) isearch-success
(not isearch-error
)))
1480 ;; Use standard function `isearch-message' when not in the minibuffer,
1481 ;; or search fails, or has an error (like incomplete regexp).
1482 ;; This function overwrites minibuffer text with isearch message,
1483 ;; so it's possible to see what is wrong in the search string.
1484 (isearch-message c-q-hack ellipsis
)
1485 ;; Otherwise, put the overlay with the standard isearch prompt over
1486 ;; the initial minibuffer prompt.
1487 (if (overlayp minibuffer-history-isearch-message-overlay
)
1488 (move-overlay minibuffer-history-isearch-message-overlay
1489 (point-min) (minibuffer-prompt-end))
1490 (setq minibuffer-history-isearch-message-overlay
1491 (make-overlay (point-min) (minibuffer-prompt-end)))
1492 (overlay-put minibuffer-history-isearch-message-overlay
'evaporate t
))
1493 (overlay-put minibuffer-history-isearch-message-overlay
1494 'display
(isearch-message-prefix c-q-hack ellipsis
))
1495 ;; And clear any previous isearch message.
1498 (defun minibuffer-history-isearch-wrap ()
1499 "Wrap the minibuffer history search when search is failed.
1500 Move point to the first history element for a forward search,
1501 or to the last history element for a backward search."
1502 (unless isearch-word
1503 ;; When `minibuffer-history-isearch-search' fails on reaching the
1504 ;; beginning/end of the history, wrap the search to the first/last
1505 ;; minibuffer history element.
1507 (goto-history-element (length (symbol-value minibuffer-history-variable
)))
1508 (goto-history-element 0))
1509 (setq isearch-success t
))
1510 (goto-char (if isearch-forward
(minibuffer-prompt-end) (point-max))))
1512 (defun minibuffer-history-isearch-push-state ()
1513 "Save a function restoring the state of minibuffer history search.
1514 Save `minibuffer-history-position' to the additional state parameter
1515 in the search status stack."
1517 (minibuffer-history-isearch-pop-state cmd
,minibuffer-history-position
)))
1519 (defun minibuffer-history-isearch-pop-state (cmd hist-pos
)
1520 "Restore the minibuffer history search state.
1521 Go to the history element by the absolute history position `hist-pos'."
1522 (goto-history-element hist-pos
))
1525 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
1526 (defalias 'advertised-undo
'undo
)
1528 (defconst undo-equiv-table
(make-hash-table :test
'eq
:weakness t
)
1529 "Table mapping redo records to the corresponding undo one.
1530 A redo record for undo-in-region maps to t.
1531 A redo record for ordinary undo maps to the following (earlier) undo.")
1533 (defvar undo-in-region nil
1534 "Non-nil if `pending-undo-list' is not just a tail of `buffer-undo-list'.")
1536 (defvar undo-no-redo nil
1537 "If t, `undo' doesn't go through redo entries.")
1539 (defvar pending-undo-list nil
1540 "Within a run of consecutive undo commands, list remaining to be undone.
1541 If t, we undid all the way to the end of it.")
1543 (defun undo (&optional arg
)
1544 "Undo some previous changes.
1545 Repeat this command to undo more changes.
1546 A numeric argument serves as a repeat count.
1548 In Transient Mark mode when the mark is active, only undo changes within
1549 the current region. Similarly, when not in Transient Mark mode, just \\[universal-argument]
1550 as an argument limits undo to changes within the current region."
1552 ;; Make last-command indicate for the next command that this was an undo.
1553 ;; That way, another undo will undo more.
1554 ;; If we get to the end of the undo history and get an error,
1555 ;; another undo command will find the undo history empty
1556 ;; and will get another error. To begin undoing the undos,
1557 ;; you must type some other command.
1558 (let ((modified (buffer-modified-p))
1559 (recent-save (recent-auto-save-p))
1561 ;; If we get an error in undo-start,
1562 ;; the next command should not be a "consecutive undo".
1563 ;; So set `this-command' to something other than `undo'.
1564 (setq this-command
'undo-start
)
1566 (unless (and (eq last-command
'undo
)
1567 (or (eq pending-undo-list t
)
1568 ;; If something (a timer or filter?) changed the buffer
1569 ;; since the previous command, don't continue the undo seq.
1570 (let ((list buffer-undo-list
))
1571 (while (eq (car list
) nil
)
1572 (setq list
(cdr list
)))
1573 ;; If the last undo record made was made by undo
1574 ;; it shows nothing else happened in between.
1575 (gethash list undo-equiv-table
))))
1576 (setq undo-in-region
1577 (if transient-mark-mode mark-active
(and arg
(not (numberp arg
)))))
1579 (undo-start (region-beginning) (region-end))
1581 ;; get rid of initial undo boundary
1583 ;; If we got this far, the next command should be a consecutive undo.
1584 (setq this-command
'undo
)
1585 ;; Check to see whether we're hitting a redo record, and if
1586 ;; so, ask the user whether she wants to skip the redo/undo pair.
1587 (let ((equiv (gethash pending-undo-list undo-equiv-table
)))
1588 (or (eq (selected-window) (minibuffer-window))
1589 (setq message
(if undo-in-region
1590 (if equiv
"Redo in region!" "Undo in region!")
1591 (if equiv
"Redo!" "Undo!"))))
1592 (when (and (consp equiv
) undo-no-redo
)
1593 ;; The equiv entry might point to another redo record if we have done
1594 ;; undo-redo-undo-redo-... so skip to the very last equiv.
1595 (while (let ((next (gethash equiv undo-equiv-table
)))
1596 (if next
(setq equiv next
))))
1597 (setq pending-undo-list equiv
)))
1599 (if (or transient-mark-mode
(numberp arg
))
1600 (prefix-numeric-value arg
)
1602 ;; Record the fact that the just-generated undo records come from an
1603 ;; undo operation--that is, they are redo records.
1604 ;; In the ordinary case (not within a region), map the redo
1605 ;; record to the following undos.
1606 ;; I don't know how to do that in the undo-in-region case.
1607 (puthash buffer-undo-list
1608 (if undo-in-region t pending-undo-list
)
1610 ;; Don't specify a position in the undo record for the undo command.
1611 ;; Instead, undoing this should move point to where the change is.
1612 (let ((tail buffer-undo-list
)
1615 (when (integerp (car tail
))
1616 (let ((pos (car tail
)))
1618 (setcdr prev
(cdr tail
))
1619 (setq buffer-undo-list
(cdr tail
)))
1620 (setq tail
(cdr tail
))
1622 (if (eq pos
(car tail
))
1624 (setcdr prev
(cdr tail
))
1625 (setq buffer-undo-list
(cdr tail
)))
1627 (setq tail
(cdr tail
)))
1629 (setq prev tail tail
(cdr tail
))))
1630 ;; Record what the current undo list says,
1631 ;; so the next command can tell if the buffer was modified in between.
1632 (and modified
(not (buffer-modified-p))
1633 (delete-auto-save-file-if-necessary recent-save
))
1634 ;; Display a message announcing success.
1636 (message message
))))
1638 (defun buffer-disable-undo (&optional buffer
)
1639 "Make BUFFER stop keeping undo information.
1640 No argument or nil as argument means do this for the current buffer."
1642 (with-current-buffer (if buffer
(get-buffer buffer
) (current-buffer))
1643 (setq buffer-undo-list t
)))
1645 (defun undo-only (&optional arg
)
1646 "Undo some previous changes.
1647 Repeat this command to undo more changes.
1648 A numeric argument serves as a repeat count.
1649 Contrary to `undo', this will not redo a previous undo."
1651 (let ((undo-no-redo t
)) (undo arg
)))
1653 (defvar undo-in-progress nil
1654 "Non-nil while performing an undo.
1655 Some change-hooks test this variable to do something different.")
1657 (defun undo-more (n)
1658 "Undo back N undo-boundaries beyond what was already undone recently.
1659 Call `undo-start' to get ready to undo recent changes,
1660 then call `undo-more' one or more times to undo them."
1661 (or (listp pending-undo-list
)
1662 (error (concat "No further undo information"
1663 (and undo-in-region
" for region"))))
1664 (let ((undo-in-progress t
))
1665 (setq pending-undo-list
(primitive-undo n pending-undo-list
))
1666 (if (null pending-undo-list
)
1667 (setq pending-undo-list t
))))
1669 ;; Deep copy of a list
1670 (defun undo-copy-list (list)
1671 "Make a copy of undo list LIST."
1672 (mapcar 'undo-copy-list-1 list
))
1674 (defun undo-copy-list-1 (elt)
1676 (cons (car elt
) (undo-copy-list-1 (cdr elt
)))
1679 (defun undo-start (&optional beg end
)
1680 "Set `pending-undo-list' to the front of the undo list.
1681 The next call to `undo-more' will undo the most recently made change.
1682 If BEG and END are specified, then only undo elements
1683 that apply to text between BEG and END are used; other undo elements
1684 are ignored. If BEG and END are nil, all undo elements are used."
1685 (if (eq buffer-undo-list t
)
1686 (error "No undo information in this buffer"))
1687 (setq pending-undo-list
1688 (if (and beg end
(not (= beg end
)))
1689 (undo-make-selective-list (min beg end
) (max beg end
))
1692 (defvar undo-adjusted-markers
)
1694 (defun undo-make-selective-list (start end
)
1695 "Return a list of undo elements for the region START to END.
1696 The elements come from `buffer-undo-list', but we keep only
1697 the elements inside this region, and discard those outside this region.
1698 If we find an element that crosses an edge of this region,
1699 we stop and ignore all further elements."
1700 (let ((undo-list-copy (undo-copy-list buffer-undo-list
))
1701 (undo-list (list nil
))
1702 undo-adjusted-markers
1704 undo-elt undo-elt temp-undo-list delta
)
1705 (while undo-list-copy
1706 (setq undo-elt
(car undo-list-copy
))
1708 (cond ((and (consp undo-elt
) (eq (car undo-elt
) t
))
1709 ;; This is a "was unmodified" element.
1710 ;; Keep it if we have kept everything thus far.
1711 (not some-rejected
))
1713 (undo-elt-in-region undo-elt start end
)))))
1716 (setq end
(+ end
(cdr (undo-delta undo-elt
))))
1717 ;; Don't put two nils together in the list
1718 (if (not (and (eq (car undo-list
) nil
)
1720 (setq undo-list
(cons undo-elt undo-list
))))
1721 (if (undo-elt-crosses-region undo-elt start end
)
1722 (setq undo-list-copy nil
)
1723 (setq some-rejected t
)
1724 (setq temp-undo-list
(cdr undo-list-copy
))
1725 (setq delta
(undo-delta undo-elt
))
1727 (when (/= (cdr delta
) 0)
1728 (let ((position (car delta
))
1729 (offset (cdr delta
)))
1731 ;; Loop down the earlier events adjusting their buffer
1732 ;; positions to reflect the fact that a change to the buffer
1733 ;; isn't being undone. We only need to process those element
1734 ;; types which undo-elt-in-region will return as being in
1735 ;; the region since only those types can ever get into the
1738 (while temp-undo-list
1739 (setq undo-elt
(car temp-undo-list
))
1740 (cond ((integerp undo-elt
)
1741 (if (>= undo-elt position
)
1742 (setcar temp-undo-list
(- undo-elt offset
))))
1743 ((atom undo-elt
) nil
)
1744 ((stringp (car undo-elt
))
1745 ;; (TEXT . POSITION)
1746 (let ((text-pos (abs (cdr undo-elt
)))
1747 (point-at-end (< (cdr undo-elt
) 0 )))
1748 (if (>= text-pos position
)
1749 (setcdr undo-elt
(* (if point-at-end -
1 1)
1750 (- text-pos offset
))))))
1751 ((integerp (car undo-elt
))
1753 (when (>= (car undo-elt
) position
)
1754 (setcar undo-elt
(- (car undo-elt
) offset
))
1755 (setcdr undo-elt
(- (cdr undo-elt
) offset
))))
1756 ((null (car undo-elt
))
1757 ;; (nil PROPERTY VALUE BEG . END)
1758 (let ((tail (nthcdr 3 undo-elt
)))
1759 (when (>= (car tail
) position
)
1760 (setcar tail
(- (car tail
) offset
))
1761 (setcdr tail
(- (cdr tail
) offset
))))))
1762 (setq temp-undo-list
(cdr temp-undo-list
))))))))
1763 (setq undo-list-copy
(cdr undo-list-copy
)))
1764 (nreverse undo-list
)))
1766 (defun undo-elt-in-region (undo-elt start end
)
1767 "Determine whether UNDO-ELT falls inside the region START ... END.
1768 If it crosses the edge, we return nil."
1769 (cond ((integerp undo-elt
)
1770 (and (>= undo-elt start
)
1776 ((stringp (car undo-elt
))
1777 ;; (TEXT . POSITION)
1778 (and (>= (abs (cdr undo-elt
)) start
)
1779 (< (abs (cdr undo-elt
)) end
)))
1780 ((and (consp undo-elt
) (markerp (car undo-elt
)))
1781 ;; This is a marker-adjustment element (MARKER . ADJUSTMENT).
1782 ;; See if MARKER is inside the region.
1783 (let ((alist-elt (assq (car undo-elt
) undo-adjusted-markers
)))
1785 (setq alist-elt
(cons (car undo-elt
)
1786 (marker-position (car undo-elt
))))
1787 (setq undo-adjusted-markers
1788 (cons alist-elt undo-adjusted-markers
)))
1789 (and (cdr alist-elt
)
1790 (>= (cdr alist-elt
) start
)
1791 (<= (cdr alist-elt
) end
))))
1792 ((null (car undo-elt
))
1793 ;; (nil PROPERTY VALUE BEG . END)
1794 (let ((tail (nthcdr 3 undo-elt
)))
1795 (and (>= (car tail
) start
)
1796 (<= (cdr tail
) end
))))
1797 ((integerp (car undo-elt
))
1799 (and (>= (car undo-elt
) start
)
1800 (<= (cdr undo-elt
) end
)))))
1802 (defun undo-elt-crosses-region (undo-elt start end
)
1803 "Test whether UNDO-ELT crosses one edge of that region START ... END.
1804 This assumes we have already decided that UNDO-ELT
1805 is not *inside* the region START...END."
1806 (cond ((atom undo-elt
) nil
)
1807 ((null (car undo-elt
))
1808 ;; (nil PROPERTY VALUE BEG . END)
1809 (let ((tail (nthcdr 3 undo-elt
)))
1810 (and (< (car tail
) end
)
1811 (> (cdr tail
) start
))))
1812 ((integerp (car undo-elt
))
1814 (and (< (car undo-elt
) end
)
1815 (> (cdr undo-elt
) start
)))))
1817 ;; Return the first affected buffer position and the delta for an undo element
1818 ;; delta is defined as the change in subsequent buffer positions if we *did*
1820 (defun undo-delta (undo-elt)
1821 (if (consp undo-elt
)
1822 (cond ((stringp (car undo-elt
))
1823 ;; (TEXT . POSITION)
1824 (cons (abs (cdr undo-elt
)) (length (car undo-elt
))))
1825 ((integerp (car undo-elt
))
1827 (cons (car undo-elt
) (- (car undo-elt
) (cdr undo-elt
))))
1832 (defcustom undo-ask-before-discard nil
1833 "If non-nil ask about discarding undo info for the current command.
1834 Normally, Emacs discards the undo info for the current command if
1835 it exceeds `undo-outer-limit'. But if you set this option
1836 non-nil, it asks in the echo area whether to discard the info.
1837 If you answer no, there is a slight risk that Emacs might crash, so
1838 only do it if you really want to undo the command.
1840 This option is mainly intended for debugging. You have to be
1841 careful if you use it for other purposes. Garbage collection is
1842 inhibited while the question is asked, meaning that Emacs might
1843 leak memory. So you should make sure that you do not wait
1844 excessively long before answering the question."
1849 (defvar undo-extra-outer-limit nil
1850 "If non-nil, an extra level of size that's ok in an undo item.
1851 We don't ask the user about truncating the undo list until the
1852 current item gets bigger than this amount.
1854 This variable only matters if `undo-ask-before-discard' is non-nil.")
1855 (make-variable-buffer-local 'undo-extra-outer-limit
)
1857 ;; When the first undo batch in an undo list is longer than
1858 ;; undo-outer-limit, this function gets called to warn the user that
1859 ;; the undo info for the current command was discarded. Garbage
1860 ;; collection is inhibited around the call, so it had better not do a
1862 (setq undo-outer-limit-function
'undo-outer-limit-truncate
)
1863 (defun undo-outer-limit-truncate (size)
1864 (if undo-ask-before-discard
1865 (when (or (null undo-extra-outer-limit
)
1866 (> size undo-extra-outer-limit
))
1867 ;; Don't ask the question again unless it gets even bigger.
1868 ;; This applies, in particular, if the user quits from the question.
1869 ;; Such a quit quits out of GC, but something else will call GC
1870 ;; again momentarily. It will call this function again,
1871 ;; but we don't want to ask the question again.
1872 (setq undo-extra-outer-limit
(+ size
50000))
1873 (if (let (use-dialog-box track-mouse executing-kbd-macro
)
1874 (yes-or-no-p (format "Buffer `%s' undo info is %d bytes long; discard it? "
1875 (buffer-name) size
)))
1876 (progn (setq buffer-undo-list nil
)
1877 (setq undo-extra-outer-limit nil
)
1880 (display-warning '(undo discard-info
)
1882 (format "Buffer `%s' undo info was %d bytes long.\n"
1884 "The undo info was discarded because it exceeded \
1887 This is normal if you executed a command that made a huge change
1888 to the buffer. In that case, to prevent similar problems in the
1889 future, set `undo-outer-limit' to a value that is large enough to
1890 cover the maximum size of normal changes you expect a single
1891 command to make, but not so large that it might exceed the
1892 maximum memory allotted to Emacs.
1894 If you did not execute any such command, the situation is
1895 probably due to a bug and you should report it.
1897 You can disable the popping up of this buffer by adding the entry
1898 \(undo discard-info) to the user option `warning-suppress-types'.\n")
1900 (setq buffer-undo-list nil
)
1903 (defvar shell-command-history nil
1904 "History list for some commands that read shell commands.")
1906 (defvar shell-command-switch
"-c"
1907 "Switch used to have the shell execute its command line argument.")
1909 (defvar shell-command-default-error-buffer nil
1910 "*Buffer name for `shell-command' and `shell-command-on-region' error output.
1911 This buffer is used when `shell-command' or `shell-command-on-region'
1912 is run interactively. A value of nil means that output to stderr and
1913 stdout will be intermixed in the output stream.")
1915 (defun shell-command (command &optional output-buffer error-buffer
)
1916 "Execute string COMMAND in inferior shell; display output, if any.
1917 With prefix argument, insert the COMMAND's output at point.
1919 If COMMAND ends in ampersand, execute it asynchronously.
1920 The output appears in the buffer `*Async Shell Command*'.
1921 That buffer is in shell mode.
1923 Otherwise, COMMAND is executed synchronously. The output appears in
1924 the buffer `*Shell Command Output*'. If the output is short enough to
1925 display in the echo area (which is determined by the variables
1926 `resize-mini-windows' and `max-mini-window-height'), it is shown
1927 there, but it is nonetheless available in buffer `*Shell Command
1928 Output*' even though that buffer is not automatically displayed.
1930 To specify a coding system for converting non-ASCII characters
1931 in the shell command output, use \\[universal-coding-system-argument]
1932 before this command.
1934 Noninteractive callers can specify coding systems by binding
1935 `coding-system-for-read' and `coding-system-for-write'.
1937 The optional second argument OUTPUT-BUFFER, if non-nil,
1938 says to put the output in some other buffer.
1939 If OUTPUT-BUFFER is a buffer or buffer name, put the output there.
1940 If OUTPUT-BUFFER is not a buffer and not nil,
1941 insert output in current buffer. (This cannot be done asynchronously.)
1942 In either case, the output is inserted after point (leaving mark after it).
1944 If the command terminates without error, but generates output,
1945 and you did not specify \"insert it in the current buffer\",
1946 the output can be displayed in the echo area or in its buffer.
1947 If the output is short enough to display in the echo area
1948 \(determined by the variable `max-mini-window-height' if
1949 `resize-mini-windows' is non-nil), it is shown there. Otherwise,
1950 the buffer containing the output is displayed.
1952 If there is output and an error, and you did not specify \"insert it
1953 in the current buffer\", a message about the error goes at the end
1956 If there is no output, or if output is inserted in the current buffer,
1957 then `*Shell Command Output*' is deleted.
1959 If the optional third argument ERROR-BUFFER is non-nil, it is a buffer
1960 or buffer name to which to direct the command's standard error output.
1961 If it is nil, error output is mingled with regular output.
1962 In an interactive call, the variable `shell-command-default-error-buffer'
1963 specifies the value of ERROR-BUFFER."
1965 (interactive (list (read-from-minibuffer "Shell command: "
1966 nil nil nil
'shell-command-history
)
1968 shell-command-default-error-buffer
))
1969 ;; Look for a handler in case default-directory is a remote file name.
1971 (find-file-name-handler (directory-file-name default-directory
)
1974 (funcall handler
'shell-command command output-buffer error-buffer
)
1975 (if (and output-buffer
1976 (not (or (bufferp output-buffer
) (stringp output-buffer
))))
1977 ;; Output goes in current buffer.
1981 (expand-file-name "scor"
1982 (or small-temporary-file-directory
1983 temporary-file-directory
)))
1985 (barf-if-buffer-read-only)
1987 ;; We do not use -f for csh; we will not support broken use of
1988 ;; .cshrcs. Even the BSD csh manual says to use
1989 ;; "if ($?prompt) exit" before things which are not useful
1990 ;; non-interactively. Besides, if someone wants their other
1991 ;; aliases for shell commands then they can still have them.
1992 (call-process shell-file-name nil
1996 nil shell-command-switch command
)
1997 (when (and error-file
(file-exists-p error-file
))
1998 (if (< 0 (nth 7 (file-attributes error-file
)))
1999 (with-current-buffer (get-buffer-create error-buffer
)
2000 (let ((pos-from-end (- (point-max) (point))))
2003 ;; Do no formatting while reading error file,
2004 ;; because that can run a shell command, and we
2005 ;; don't want that to cause an infinite recursion.
2006 (format-insert-file error-file nil
)
2007 ;; Put point after the inserted errors.
2008 (goto-char (- (point-max) pos-from-end
)))
2009 (display-buffer (current-buffer))))
2010 (delete-file error-file
))
2011 ;; This is like exchange-point-and-mark, but doesn't
2012 ;; activate the mark. It is cleaner to avoid activation,
2013 ;; even though the command loop would deactivate the mark
2014 ;; because we inserted text.
2015 (goto-char (prog1 (mark t
)
2016 (set-marker (mark-marker) (point)
2017 (current-buffer)))))
2018 ;; Output goes in a separate buffer.
2019 ;; Preserve the match data in case called from a program.
2021 (if (string-match "[ \t]*&[ \t]*\\'" command
)
2022 ;; Command ending with ampersand means asynchronous.
2023 (let ((buffer (get-buffer-create
2024 (or output-buffer
"*Async Shell Command*")))
2025 (directory default-directory
)
2027 ;; Remove the ampersand.
2028 (setq command
(substring command
0 (match-beginning 0)))
2029 ;; If will kill a process, query first.
2030 (setq proc
(get-buffer-process buffer
))
2032 (if (yes-or-no-p "A command is running. Kill it? ")
2034 (error "Shell command in progress")))
2035 (with-current-buffer buffer
2036 (setq buffer-read-only nil
)
2038 (display-buffer buffer
)
2039 (setq default-directory directory
)
2040 (setq proc
(start-process "Shell" buffer shell-file-name
2041 shell-command-switch command
))
2042 (setq mode-line-process
'(":%s"))
2043 (require 'shell
) (shell-mode)
2044 (set-process-sentinel proc
'shell-command-sentinel
)
2046 (shell-command-on-region (point) (point) command
2047 output-buffer nil error-buffer
)))))))
2049 (defun display-message-or-buffer (message
2050 &optional buffer-name not-this-window frame
)
2051 "Display MESSAGE in the echo area if possible, otherwise in a pop-up buffer.
2052 MESSAGE may be either a string or a buffer.
2054 A buffer is displayed using `display-buffer' if MESSAGE is too long for
2055 the maximum height of the echo area, as defined by `max-mini-window-height'
2056 if `resize-mini-windows' is non-nil.
2058 Returns either the string shown in the echo area, or when a pop-up
2059 buffer is used, the window used to display it.
2061 If MESSAGE is a string, then the optional argument BUFFER-NAME is the
2062 name of the buffer used to display it in the case where a pop-up buffer
2063 is used, defaulting to `*Message*'. In the case where MESSAGE is a
2064 string and it is displayed in the echo area, it is not specified whether
2065 the contents are inserted into the buffer anyway.
2067 Optional arguments NOT-THIS-WINDOW and FRAME are as for `display-buffer',
2068 and only used if a buffer is displayed."
2069 (cond ((and (stringp message
) (not (string-match "\n" message
)))
2070 ;; Trivial case where we can use the echo area
2071 (message "%s" message
))
2072 ((and (stringp message
)
2073 (= (string-match "\n" message
) (1- (length message
))))
2074 ;; Trivial case where we can just remove single trailing newline
2075 (message "%s" (substring message
0 (1- (length message
)))))
2078 (with-current-buffer
2079 (if (bufferp message
)
2081 (get-buffer-create (or buffer-name
"*Message*")))
2083 (unless (bufferp message
)
2088 (if (= (buffer-size) 0)
2090 (count-screen-lines nil nil nil
(minibuffer-window)))))
2092 ((and (or (<= lines
1)
2094 (if resize-mini-windows
2095 (cond ((floatp max-mini-window-height
)
2097 max-mini-window-height
))
2098 ((integerp max-mini-window-height
)
2099 max-mini-window-height
)
2103 ;; Don't use the echo area if the output buffer is
2104 ;; already dispayed in the selected frame.
2105 (not (get-buffer-window (current-buffer))))
2107 (goto-char (point-max))
2110 (message "%s" (buffer-substring (point-min) (point))))
2113 (goto-char (point-min))
2114 (display-buffer (current-buffer)
2115 not-this-window frame
))))))))
2118 ;; We have a sentinel to prevent insertion of a termination message
2119 ;; in the buffer itself.
2120 (defun shell-command-sentinel (process signal
)
2121 (if (memq (process-status process
) '(exit signal
))
2123 (car (cdr (cdr (process-command process
))))
2124 (substring signal
0 -
1))))
2126 (defun shell-command-on-region (start end command
2127 &optional output-buffer replace
2128 error-buffer display-error-buffer
)
2129 "Execute string COMMAND in inferior shell with region as input.
2130 Normally display output (if any) in temp buffer `*Shell Command Output*';
2131 Prefix arg means replace the region with it. Return the exit code of
2134 To specify a coding system for converting non-ASCII characters
2135 in the input and output to the shell command, use \\[universal-coding-system-argument]
2136 before this command. By default, the input (from the current buffer)
2137 is encoded in the same coding system that will be used to save the file,
2138 `buffer-file-coding-system'. If the output is going to replace the region,
2139 then it is decoded from that same coding system.
2141 The noninteractive arguments are START, END, COMMAND,
2142 OUTPUT-BUFFER, REPLACE, ERROR-BUFFER, and DISPLAY-ERROR-BUFFER.
2143 Noninteractive callers can specify coding systems by binding
2144 `coding-system-for-read' and `coding-system-for-write'.
2146 If the command generates output, the output may be displayed
2147 in the echo area or in a buffer.
2148 If the output is short enough to display in the echo area
2149 \(determined by the variable `max-mini-window-height' if
2150 `resize-mini-windows' is non-nil), it is shown there. Otherwise
2151 it is displayed in the buffer `*Shell Command Output*'. The output
2152 is available in that buffer in both cases.
2154 If there is output and an error, a message about the error
2155 appears at the end of the output.
2157 If there is no output, or if output is inserted in the current buffer,
2158 then `*Shell Command Output*' is deleted.
2160 If the optional fourth argument OUTPUT-BUFFER is non-nil,
2161 that says to put the output in some other buffer.
2162 If OUTPUT-BUFFER is a buffer or buffer name, put the output there.
2163 If OUTPUT-BUFFER is not a buffer and not nil,
2164 insert output in the current buffer.
2165 In either case, the output is inserted after point (leaving mark after it).
2167 If REPLACE, the optional fifth argument, is non-nil, that means insert
2168 the output in place of text from START to END, putting point and mark
2171 If optional sixth argument ERROR-BUFFER is non-nil, it is a buffer
2172 or buffer name to which to direct the command's standard error output.
2173 If it is nil, error output is mingled with regular output.
2174 If DISPLAY-ERROR-BUFFER is non-nil, display the error buffer if there
2175 were any errors. (This is always t, interactively.)
2176 In an interactive call, the variable `shell-command-default-error-buffer'
2177 specifies the value of ERROR-BUFFER."
2178 (interactive (let (string)
2180 (error "The mark is not set now, so there is no region"))
2181 ;; Do this before calling region-beginning
2182 ;; and region-end, in case subprocess output
2183 ;; relocates them while we are in the minibuffer.
2184 (setq string
(read-from-minibuffer "Shell command on region: "
2186 'shell-command-history
))
2187 ;; call-interactively recognizes region-beginning and
2188 ;; region-end specially, leaving them in the history.
2189 (list (region-beginning) (region-end)
2193 shell-command-default-error-buffer
2198 (expand-file-name "scor"
2199 (or small-temporary-file-directory
2200 temporary-file-directory
)))
2205 (not (or (bufferp output-buffer
) (stringp output-buffer
)))))
2206 ;; Replace specified region with output from command.
2207 (let ((swap (and replace
(< start end
))))
2208 ;; Don't muck with mark unless REPLACE says we should.
2210 (and replace
(push-mark (point) 'nomsg
))
2212 (call-process-region start end shell-file-name t
2216 nil shell-command-switch command
))
2217 ;; It is rude to delete a buffer which the command is not using.
2218 ;; (let ((shell-buffer (get-buffer "*Shell Command Output*")))
2219 ;; (and shell-buffer (not (eq shell-buffer (current-buffer)))
2220 ;; (kill-buffer shell-buffer)))
2221 ;; Don't muck with mark unless REPLACE says we should.
2222 (and replace swap
(exchange-point-and-mark)))
2223 ;; No prefix argument: put the output in a temp buffer,
2224 ;; replacing its entire contents.
2225 (let ((buffer (get-buffer-create
2226 (or output-buffer
"*Shell Command Output*"))))
2228 (if (eq buffer
(current-buffer))
2229 ;; If the input is the same buffer as the output,
2230 ;; delete everything but the specified region,
2231 ;; then replace that region with the output.
2232 (progn (setq buffer-read-only nil
)
2233 (delete-region (max start end
) (point-max))
2234 (delete-region (point-min) (min start end
))
2236 (call-process-region (point-min) (point-max)
2241 nil shell-command-switch
2243 ;; Clear the output buffer, then run the command with
2245 (let ((directory default-directory
))
2248 (setq buffer-read-only nil
)
2249 (if (not output-buffer
)
2250 (setq default-directory directory
))
2253 (call-process-region start end shell-file-name nil
2255 (list buffer error-file
)
2257 nil shell-command-switch command
)))
2258 ;; Report the output.
2259 (with-current-buffer buffer
2260 (setq mode-line-process
2261 (cond ((null exit-status
)
2263 ((stringp exit-status
)
2264 (format " - Signal [%s]" exit-status
))
2265 ((not (equal 0 exit-status
))
2266 (format " - Exit [%d]" exit-status
)))))
2267 (if (with-current-buffer buffer
(> (point-max) (point-min)))
2268 ;; There's some output, display it
2269 (display-message-or-buffer buffer
)
2270 ;; No output; error?
2273 (< 0 (nth 7 (file-attributes error-file
))))
2276 (cond ((null exit-status
)
2277 (message "(Shell command failed with error)"))
2278 ((equal 0 exit-status
)
2279 (message "(Shell command succeeded with %s)"
2281 ((stringp exit-status
)
2282 (message "(Shell command killed by signal %s)"
2285 (message "(Shell command failed with code %d and %s)"
2286 exit-status output
))))
2287 ;; Don't kill: there might be useful info in the undo-log.
2288 ;; (kill-buffer buffer)
2291 (when (and error-file
(file-exists-p error-file
))
2292 (if (< 0 (nth 7 (file-attributes error-file
)))
2293 (with-current-buffer (get-buffer-create error-buffer
)
2294 (let ((pos-from-end (- (point-max) (point))))
2297 ;; Do no formatting while reading error file,
2298 ;; because that can run a shell command, and we
2299 ;; don't want that to cause an infinite recursion.
2300 (format-insert-file error-file nil
)
2301 ;; Put point after the inserted errors.
2302 (goto-char (- (point-max) pos-from-end
)))
2303 (and display-error-buffer
2304 (display-buffer (current-buffer)))))
2305 (delete-file error-file
))
2308 (defun shell-command-to-string (command)
2309 "Execute shell command COMMAND and return its output as a string."
2310 (with-output-to-string
2311 (with-current-buffer
2313 (call-process shell-file-name nil t nil shell-command-switch command
))))
2315 (defun process-file (program &optional infile buffer display
&rest args
)
2316 "Process files synchronously in a separate process.
2317 Similar to `call-process', but may invoke a file handler based on
2318 `default-directory'. The current working directory of the
2319 subprocess is `default-directory'.
2321 File names in INFILE and BUFFER are handled normally, but file
2322 names in ARGS should be relative to `default-directory', as they
2323 are passed to the process verbatim. \(This is a difference to
2324 `call-process' which does not support file handlers for INFILE
2327 Some file handlers might not support all variants, for example
2328 they might behave as if DISPLAY was nil, regardless of the actual
2330 (let ((fh (find-file-name-handler default-directory
'process-file
))
2333 (if fh
(apply fh
'process-file program infile buffer display args
)
2334 (when infile
(setq lc
(file-local-copy infile
)))
2335 (setq stderr-file
(when (and (consp buffer
) (stringp (cadr buffer
)))
2336 (make-temp-file "emacs")))
2338 (apply 'call-process program
2340 (if stderr-file
(list (car buffer
) stderr-file
) buffer
)
2342 (when stderr-file
(copy-file stderr-file
(cadr buffer
)))))
2343 (when stderr-file
(delete-file stderr-file
))
2344 (when lc
(delete-file lc
)))))
2346 (defun start-file-process (name buffer program
&rest program-args
)
2347 "Start a program in a subprocess. Return the process object for it.
2348 Similar to `start-process', but may invoke a file handler based on
2349 `default-directory'. The current working directory of the
2350 subprocess is `default-directory'.
2352 PROGRAM and PROGRAM-ARGS might be file names. They are not
2353 objects of file handler invocation."
2354 (let ((fh (find-file-name-handler default-directory
'start-file-process
)))
2355 (if fh
(apply fh
'start-file-process name buffer program program-args
)
2356 (apply 'start-process name buffer program program-args
))))
2360 (defvar universal-argument-map
2361 (let ((map (make-sparse-keymap)))
2362 (define-key map
[t] 'universal-argument-other-key)
2363 (define-key map (vector meta-prefix-char t) 'universal-argument-other-key)
2364 (define-key map [switch-frame] nil)
2365 (define-key map [?\C-u] 'universal-argument-more)
2366 (define-key map [?-] 'universal-argument-minus)
2367 (define-key map [?0] 'digit-argument)
2368 (define-key map [?1] 'digit-argument)
2369 (define-key map [?2] 'digit-argument)
2370 (define-key map [?3] 'digit-argument)
2371 (define-key map [?4] 'digit-argument)
2372 (define-key map [?5] 'digit-argument)
2373 (define-key map [?6] 'digit-argument)
2374 (define-key map [?7] 'digit-argument)
2375 (define-key map [?8] 'digit-argument)
2376 (define-key map [?9] 'digit-argument)
2377 (define-key map [kp-0] 'digit-argument)
2378 (define-key map [kp-1] 'digit-argument)
2379 (define-key map [kp-2] 'digit-argument)
2380 (define-key map [kp-3] 'digit-argument)
2381 (define-key map [kp-4] 'digit-argument)
2382 (define-key map [kp-5] 'digit-argument)
2383 (define-key map [kp-6] 'digit-argument)
2384 (define-key map [kp-7] 'digit-argument)
2385 (define-key map [kp-8] 'digit-argument)
2386 (define-key map [kp-9] 'digit-argument)
2387 (define-key map [kp-subtract] 'universal-argument-minus)
2389 "Keymap used while processing \\[universal-argument].")
2391 (defvar universal-argument-num-events nil
2392 "Number of argument-specifying events read by `universal-argument'.
2393 `universal-argument-other-key' uses this to discard those events
2394 from (this-command-keys), and reread only the final command.")
2396 (defvar overriding-map-is-bound nil
2397 "Non-nil when `overriding-terminal-local-map' is `universal-argument-map'.")
2399 (defvar saved-overriding-map nil
2400 "The saved value of `overriding-terminal-local-map'.
2401 That variable gets restored to this value on exiting \"universal
2404 (defun ensure-overriding-map-is-bound ()
2405 "Check `overriding-terminal-local-map' is `universal-argument-map'."
2406 (unless overriding-map-is-bound
2407 (setq saved-overriding-map overriding-terminal-local-map)
2408 (setq overriding-terminal-local-map universal-argument-map)
2409 (setq overriding-map-is-bound t)))
2411 (defun restore-overriding-map ()
2412 "Restore `overriding-terminal-local-map' to its saved value."
2413 (setq overriding-terminal-local-map saved-overriding-map)
2414 (setq overriding-map-is-bound nil))
2416 (defun universal-argument ()
2417 "Begin a numeric argument for the following command.
2418 Digits or minus sign following \\[universal-argument] make up the numeric argument.
2419 \\[universal-argument] following the digits or minus sign ends the argument.
2420 \\[universal-argument] without digits or minus sign provides 4 as argument.
2421 Repeating \\[universal-argument] without digits or minus sign
2422 multiplies the argument by 4 each time.
2423 For some commands, just \\[universal-argument] by itself serves as a flag
2424 which is different in effect from any particular numeric argument.
2425 These commands include \\[set-mark-command] and \\[start-kbd-macro]."
2427 (setq prefix-arg (list 4))
2428 (setq universal-argument-num-events (length (this-command-keys)))
2429 (ensure-overriding-map-is-bound))
2431 ;; A subsequent C-u means to multiply the factor by 4 if we've typed
2432 ;; nothing but C-u's; otherwise it means to terminate the prefix arg.
2433 (defun universal-argument-more (arg)
2436 (setq prefix-arg (list (* 4 (car arg))))
2438 (setq prefix-arg (list -4))
2439 (setq prefix-arg arg)
2440 (restore-overriding-map)))
2441 (setq universal-argument-num-events (length (this-command-keys))))
2443 (defun negative-argument (arg)
2444 "Begin a negative numeric argument for the next command.
2445 \\[universal-argument] following digits or minus sign ends the argument."
2447 (cond ((integerp arg)
2448 (setq prefix-arg (- arg)))
2450 (setq prefix-arg nil))
2452 (setq prefix-arg '-)))
2453 (setq universal-argument-num-events (length (this-command-keys)))
2454 (ensure-overriding-map-is-bound))
2456 (defun digit-argument (arg)
2457 "Part of the numeric argument for the next command.
2458 \\[universal-argument] following digits or minus sign ends the argument."
2460 (let* ((char (if (integerp last-command-char)
2462 (get last-command-char 'ascii-character)))
2463 (digit (- (logand char ?\177) ?0)))
2464 (cond ((integerp arg)
2465 (setq prefix-arg (+ (* arg 10)
2466 (if (< arg 0) (- digit) digit))))
2468 ;; Treat -0 as just -, so that -01 will work.
2469 (setq prefix-arg (if (zerop digit) '- (- digit))))
2471 (setq prefix-arg digit))))
2472 (setq universal-argument-num-events (length (this-command-keys)))
2473 (ensure-overriding-map-is-bound))
2475 ;; For backward compatibility, minus with no modifiers is an ordinary
2476 ;; command if digits have already been entered.
2477 (defun universal-argument-minus (arg)
2480 (universal-argument-other-key arg)
2481 (negative-argument arg)))
2483 ;; Anything else terminates the argument and is left in the queue to be
2484 ;; executed as a command.
2485 (defun universal-argument-other-key (arg)
2487 (setq prefix-arg arg)
2488 (let* ((key (this-command-keys))
2489 (keylist (listify-key-sequence key)))
2490 (setq unread-command-events
2491 (append (nthcdr universal-argument-num-events keylist)
2492 unread-command-events)))
2493 (reset-this-command-lengths)
2494 (restore-overriding-map))
2496 (defvar buffer-substring-filters nil
2497 "List of filter functions for `filter-buffer-substring'.
2498 Each function must accept a single argument, a string, and return
2499 a string. The buffer substring is passed to the first function
2500 in the list, and the return value of each function is passed to
2501 the next. The return value of the last function is used as the
2502 return value of `filter-buffer-substring'.
2504 If this variable is nil, no filtering is performed.")
2506 (defun filter-buffer-substring (beg end &optional delete noprops)
2507 "Return the buffer substring between BEG and END, after filtering.
2508 The buffer substring is passed through each of the filter
2509 functions in `buffer-substring-filters', and the value from the
2510 last filter function is returned. If `buffer-substring-filters'
2511 is nil, the buffer substring is returned unaltered.
2513 If DELETE is non-nil, the text between BEG and END is deleted
2516 If NOPROPS is non-nil, final string returned does not include
2517 text properties, while the string passed to the filters still
2518 includes text properties from the buffer text.
2520 Point is temporarily set to BEG before calling
2521 `buffer-substring-filters', in case the functions need to know
2522 where the text came from.
2524 This function should be used instead of `buffer-substring',
2525 `buffer-substring-no-properties', or `delete-and-extract-region'
2526 when you want to allow filtering to take place. For example,
2527 major or minor modes can use `buffer-substring-filters' to
2528 extract characters that are special to a buffer, and should not
2529 be copied into other buffers."
2531 ((or delete buffer-substring-filters)
2534 (let ((string (if delete (delete-and-extract-region beg end)
2535 (buffer-substring beg end))))
2536 (dolist (filter buffer-substring-filters)
2537 (setq string (funcall filter string)))
2539 (set-text-properties 0 (length string) nil string))
2542 (buffer-substring-no-properties beg end))
2544 (buffer-substring beg end))))
2547 ;;;; Window system cut and paste hooks.
2549 (defvar interprogram-cut-function nil
2550 "Function to call to make a killed region available to other programs.
2552 Most window systems provide some sort of facility for cutting and
2553 pasting text between the windows of different programs.
2554 This variable holds a function that Emacs calls whenever text
2555 is put in the kill ring, to make the new kill available to other
2558 The function takes one or two arguments.
2559 The first argument, TEXT, is a string containing
2560 the text which should be made available.
2561 The second, optional, argument PUSH, has the same meaning as the
2562 similar argument to `x-set-cut-buffer', which see.")
2564 (make-variable-frame-local 'interprogram-cut-function)
2566 (defvar interprogram-paste-function nil
2567 "Function to call to get text cut from other programs.
2569 Most window systems provide some sort of facility for cutting and
2570 pasting text between the windows of different programs.
2571 This variable holds a function that Emacs calls to obtain
2572 text that other programs have provided for pasting.
2574 The function should be called with no arguments. If the function
2575 returns nil, then no other program has provided such text, and the top
2576 of the Emacs kill ring should be used. If the function returns a
2577 string, then the caller of the function \(usually `current-kill')
2578 should put this string in the kill ring as the latest kill.
2580 This function may also return a list of strings if the window
2581 system supports multiple selections. The first string will be
2582 used as the pasted text, but the other will be placed in the
2583 kill ring for easy access via `yank-pop'.
2585 Note that the function should return a string only if a program other
2586 than Emacs has provided a string for pasting; if Emacs provided the
2587 most recent string, the function should return nil. If it is
2588 difficult to tell whether Emacs or some other program provided the
2589 current string, it is probably good enough to return nil if the string
2590 is equal (according to `string=') to the last text Emacs provided.")
2592 (make-variable-frame-local 'interprogram-paste-function)
2596 ;;;; The kill ring data structure.
2598 (defvar kill-ring nil
2599 "List of killed text sequences.
2600 Since the kill ring is supposed to interact nicely with cut-and-paste
2601 facilities offered by window systems, use of this variable should
2602 interact nicely with `interprogram-cut-function' and
2603 `interprogram-paste-function'. The functions `kill-new',
2604 `kill-append', and `current-kill' are supposed to implement this
2605 interaction; you may want to use them instead of manipulating the kill
2608 (defcustom kill-ring-max 60
2609 "*Maximum length of kill ring before oldest elements are thrown away."
2613 (defvar kill-ring-yank-pointer nil
2614 "The tail of the kill ring whose car is the last thing yanked.")
2616 (defun kill-new (string &optional replace yank-handler)
2617 "Make STRING the latest kill in the kill ring.
2618 Set `kill-ring-yank-pointer' to point to it.
2619 If `interprogram-cut-function' is non-nil, apply it to STRING.
2620 Optional second argument REPLACE non-nil means that STRING will replace
2621 the front of the kill ring, rather than being added to the list.
2623 Optional third arguments YANK-HANDLER controls how the STRING is later
2624 inserted into a buffer; see `insert-for-yank' for details.
2625 When a yank handler is specified, STRING must be non-empty (the yank
2626 handler, if non-nil, is stored as a `yank-handler' text property on STRING).
2628 When the yank handler has a non-nil PARAM element, the original STRING
2629 argument is not used by `insert-for-yank'. However, since Lisp code
2630 may access and use elements from the kill ring directly, the STRING
2631 argument should still be a \"useful\" string for such uses."
2632 (if (> (length string) 0)
2634 (put-text-property 0 (length string)
2635 'yank-handler yank-handler string))
2637 (signal 'args-out-of-range
2638 (list string "yank-handler specified for empty string"))))
2639 (if (fboundp 'menu-bar-update-yank-menu)
2640 (menu-bar-update-yank-menu string (and replace (car kill-ring))))
2641 (if (and replace kill-ring)
2642 (setcar kill-ring string)
2643 (push string kill-ring)
2644 (if (> (length kill-ring) kill-ring-max)
2645 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)))
2646 (setq kill-ring-yank-pointer kill-ring)
2647 (if interprogram-cut-function
2648 (funcall interprogram-cut-function string (not replace))))
2650 (defun kill-append (string before-p &optional yank-handler)
2651 "Append STRING to the end of the latest kill in the kill ring.
2652 If BEFORE-P is non-nil, prepend STRING to the kill.
2653 Optional third argument YANK-HANDLER, if non-nil, specifies the
2654 yank-handler text property to be set on the combined kill ring
2655 string. If the specified yank-handler arg differs from the
2656 yank-handler property of the latest kill string, this function
2657 adds the combined string to the kill ring as a new element,
2658 instead of replacing the last kill with it.
2659 If `interprogram-cut-function' is set, pass the resulting kill to it."
2660 (let* ((cur (car kill-ring)))
2661 (kill-new (if before-p (concat string cur) (concat cur string))
2662 (or (= (length cur) 0)
2663 (equal yank-handler (get-text-property 0 'yank-handler cur)))
2666 (defun current-kill (n &optional do-not-move)
2667 "Rotate the yanking point by N places, and then return that kill.
2668 If N is zero, `interprogram-paste-function' is set, and calling it returns a
2669 string or list of strings, then that string (or list) is added to the front
2670 of the kill ring and the string (or first string in the list) is returned as
2671 the latest kill. If optional arg DO-NOT-MOVE is non-nil, then don't
2672 actually move the yanking point; just return the Nth kill forward."
2673 (let ((interprogram-paste (and (= n 0)
2674 interprogram-paste-function
2675 (funcall interprogram-paste-function))))
2676 (if interprogram-paste
2678 ;; Disable the interprogram cut function when we add the new
2679 ;; text to the kill ring, so Emacs doesn't try to own the
2680 ;; selection, with identical text.
2681 (let ((interprogram-cut-function nil))
2682 (if (listp interprogram-paste)
2683 (mapc 'kill-new (nreverse interprogram-paste))
2684 (kill-new interprogram-paste)))
2686 (or kill-ring (error "Kill ring is empty"))
2687 (let ((ARGth-kill-element
2688 (nthcdr (mod (- n (length kill-ring-yank-pointer))
2692 (setq kill-ring-yank-pointer ARGth-kill-element))
2693 (car ARGth-kill-element)))))
2697 ;;;; Commands for manipulating the kill ring.
2699 (defcustom kill-read-only-ok nil
2700 "*Non-nil means don't signal an error for killing read-only text."
2704 (put 'text-read-only 'error-conditions
2705 '(text-read-only buffer-read-only error))
2706 (put 'text-read-only 'error-message "Text is read-only")
2708 (defun kill-region (beg end &optional yank-handler)
2709 "Kill (\"cut\") text between point and mark.
2710 This deletes the text from the buffer and saves it in the kill ring.
2711 The command \\[yank] can retrieve it from there.
2712 \(If you want to kill and then yank immediately, use \\[kill-ring-save].)
2714 If you want to append the killed region to the last killed text,
2715 use \\[append-next-kill] before \\[kill-region].
2717 If the buffer is read-only, Emacs will beep and refrain from deleting
2718 the text, but put the text in the kill ring anyway. This means that
2719 you can use the killing commands to copy text from a read-only buffer.
2721 This is the primitive for programs to kill text (as opposed to deleting it).
2722 Supply two arguments, character positions indicating the stretch of text
2724 Any command that calls this function is a \"kill command\".
2725 If the previous command was also a kill command,
2726 the text killed this time appends to the text killed last time
2727 to make one entry in the kill ring.
2729 In Lisp code, optional third arg YANK-HANDLER, if non-nil,
2730 specifies the yank-handler text property to be set on the killed
2731 text. See `insert-for-yank'."
2732 ;; Pass point first, then mark, because the order matters
2733 ;; when calling kill-append.
2734 (interactive (list (point) (mark)))
2735 (unless (and beg end)
2736 (error "The mark is not set now, so there is no region"))
2738 (let ((string (filter-buffer-substring beg end t)))
2739 (when string ;STRING is nil if BEG = END
2740 ;; Add that string to the kill ring, one way or another.
2741 (if (eq last-command 'kill-region)
2742 (kill-append string (< end beg) yank-handler)
2743 (kill-new string nil yank-handler)))
2744 (when (or string (eq last-command 'kill-region))
2745 (setq this-command 'kill-region))
2747 ((buffer-read-only text-read-only)
2748 ;; The code above failed because the buffer, or some of the characters
2749 ;; in the region, are read-only.
2750 ;; We should beep, in case the user just isn't aware of this.
2751 ;; However, there's no harm in putting
2752 ;; the region's text in the kill ring, anyway.
2753 (copy-region-as-kill beg end)
2754 ;; Set this-command now, so it will be set even if we get an error.
2755 (setq this-command 'kill-region)
2756 ;; This should barf, if appropriate, and give us the correct error.
2757 (if kill-read-only-ok
2758 (progn (message "Read only text copied to kill ring") nil)
2759 ;; Signal an error if the buffer is read-only.
2760 (barf-if-buffer-read-only)
2761 ;; If the buffer isn't read-only, the text is.
2762 (signal 'text-read-only (list (current-buffer)))))))
2764 ;; copy-region-as-kill no longer sets this-command, because it's confusing
2765 ;; to get two copies of the text when the user accidentally types M-w and
2766 ;; then corrects it with the intended C-w.
2767 (defun copy-region-as-kill (beg end)
2768 "Save the region as if killed, but don't kill it.
2769 In Transient Mark mode, deactivate the mark.
2770 If `interprogram-cut-function' is non-nil, also save the text for a window
2771 system cut and paste.
2773 This command's old key binding has been given to `kill-ring-save'."
2775 (if (eq last-command 'kill-region)
2776 (kill-append (filter-buffer-substring beg end) (< end beg))
2777 (kill-new (filter-buffer-substring beg end)))
2778 (if transient-mark-mode
2779 (setq deactivate-mark t))
2782 (defun kill-ring-save (beg end)
2783 "Save the region as if killed, but don't kill it.
2784 In Transient Mark mode, deactivate the mark.
2785 If `interprogram-cut-function' is non-nil, also save the text for a window
2786 system cut and paste.
2788 If you want to append the killed line to the last killed text,
2789 use \\[append-next-kill] before \\[kill-ring-save].
2791 This command is similar to `copy-region-as-kill', except that it gives
2792 visual feedback indicating the extent of the region being copied."
2794 (copy-region-as-kill beg end)
2795 ;; This use of interactive-p is correct
2796 ;; because the code it controls just gives the user visual feedback.
2798 (let ((other-end (if (= (point) beg) end beg))
2800 ;; Inhibit quitting so we can make a quit here
2801 ;; look like a C-g typed as a command.
2803 (if (pos-visible-in-window-p other-end (selected-window))
2804 (unless (and transient-mark-mode
2805 (face-background 'region))
2806 ;; Swap point and mark.
2807 (set-marker (mark-marker) (point) (current-buffer))
2808 (goto-char other-end)
2809 (sit-for blink-matching-delay)
2811 (set-marker (mark-marker) other-end (current-buffer))
2813 ;; If user quit, deactivate the mark
2814 ;; as C-g would as a command.
2815 (and quit-flag mark-active
2817 (let* ((killed-text (current-kill 0))
2818 (message-len (min (length killed-text) 40)))
2820 ;; Don't say "killed"; that is misleading.
2821 (message "Saved text until \"%s\""
2822 (substring killed-text (- message-len)))
2823 (message "Saved text from \"%s\""
2824 (substring killed-text 0 message-len))))))))
2826 (defun append-next-kill (&optional interactive)
2827 "Cause following command, if it kills, to append to previous kill.
2828 The argument is used for internal purposes; do not supply one."
2830 ;; We don't use (interactive-p), since that breaks kbd macros.
2833 (setq this-command 'kill-region)
2834 (message "If the next command is a kill, it will append"))
2835 (setq last-command 'kill-region)))
2839 ;; This is actually used in subr.el but defcustom does not work there.
2840 (defcustom yank-excluded-properties
2841 '(read-only invisible intangible field mouse-face help-echo local-map keymap
2842 yank-handler follow-link fontified)
2843 "Text properties to discard when yanking.
2844 The value should be a list of text properties to discard or t,
2845 which means to discard all text properties."
2846 :type '(choice (const :tag "All" t) (repeat symbol))
2850 (defvar yank-window-start nil)
2851 (defvar yank-undo-function nil
2852 "If non-nil, function used by `yank-pop' to delete last stretch of yanked text.
2853 Function is called with two parameters, START and END corresponding to
2854 the value of the mark and point; it is guaranteed that START <= END.
2855 Normally set from the UNDO element of a yank-handler; see `insert-for-yank'.")
2857 (defun yank-pop (&optional arg)
2858 "Replace just-yanked stretch of killed text with a different stretch.
2859 This command is allowed only immediately after a `yank' or a `yank-pop'.
2860 At such a time, the region contains a stretch of reinserted
2861 previously-killed text. `yank-pop' deletes that text and inserts in its
2862 place a different stretch of killed text.
2864 With no argument, the previous kill is inserted.
2865 With argument N, insert the Nth previous kill.
2866 If N is negative, this is a more recent kill.
2868 The sequence of kills wraps around, so that after the oldest one
2869 comes the newest one.
2871 When this command inserts killed text into the buffer, it honors
2872 `yank-excluded-properties' and `yank-handler' as described in the
2873 doc string for `insert-for-yank-1', which see."
2875 (if (not (eq last-command 'yank))
2876 (error "Previous command was not a yank"))
2877 (setq this-command 'yank)
2878 (unless arg (setq arg 1))
2879 (let ((inhibit-read-only t)
2880 (before (< (point) (mark t))))
2882 (funcall (or yank-undo-function 'delete-region) (point) (mark t))
2883 (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
2884 (setq yank-undo-function nil)
2885 (set-marker (mark-marker) (point) (current-buffer))
2886 (insert-for-yank (current-kill arg))
2887 ;; Set the window start back where it was in the yank command,
2889 (set-window-start (selected-window) yank-window-start t)
2891 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
2892 ;; It is cleaner to avoid activation, even though the command
2893 ;; loop would deactivate the mark because we inserted text.
2894 (goto-char (prog1 (mark t)
2895 (set-marker (mark-marker) (point) (current-buffer))))))
2898 (defun yank (&optional arg)
2899 "Reinsert (\"paste\") the last stretch of killed text.
2900 More precisely, reinsert the stretch of killed text most recently
2901 killed OR yanked. Put point at end, and set mark at beginning.
2902 With just \\[universal-argument] as argument, same but put point at beginning (and mark at end).
2903 With argument N, reinsert the Nth most recently killed stretch of killed
2906 When this command inserts killed text into the buffer, it honors
2907 `yank-excluded-properties' and `yank-handler' as described in the
2908 doc string for `insert-for-yank-1', which see.
2910 See also the command `yank-pop' (\\[yank-pop])."
2912 (setq yank-window-start (window-start))
2913 ;; If we don't get all the way thru, make last-command indicate that
2914 ;; for the following command.
2915 (setq this-command t)
2917 (insert-for-yank (current-kill (cond
2922 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
2923 ;; It is cleaner to avoid activation, even though the command
2924 ;; loop would deactivate the mark because we inserted text.
2925 (goto-char (prog1 (mark t)
2926 (set-marker (mark-marker) (point) (current-buffer)))))
2927 ;; If we do get all the way thru, make this-command indicate that.
2928 (if (eq this-command t)
2929 (setq this-command 'yank))
2932 (defun rotate-yank-pointer (arg)
2933 "Rotate the yanking point in the kill ring.
2934 With argument, rotate that many kills forward (or backward, if negative)."
2938 ;; Some kill commands.
2940 ;; Internal subroutine of delete-char
2941 (defun kill-forward-chars (arg)
2942 (if (listp arg) (setq arg (car arg)))
2943 (if (eq arg '-) (setq arg -1))
2944 (kill-region (point) (forward-point arg)))
2946 ;; Internal subroutine of backward-delete-char
2947 (defun kill-backward-chars (arg)
2948 (if (listp arg) (setq arg (car arg)))
2949 (if (eq arg '-) (setq arg -1))
2950 (kill-region (point) (forward-point (- arg))))
2952 (defcustom backward-delete-char-untabify-method 'untabify
2953 "*The method for untabifying when deleting backward.
2954 Can be `untabify' -- turn a tab to many spaces, then delete one space;
2955 `hungry' -- delete all whitespace, both tabs and spaces;
2956 `all' -- delete all whitespace, including tabs, spaces and newlines;
2957 nil -- just delete one character."
2958 :type '(choice (const untabify) (const hungry) (const all) (const nil))
2962 (defun backward-delete-char-untabify (arg &optional killp)
2963 "Delete characters backward, changing tabs into spaces.
2964 The exact behavior depends on `backward-delete-char-untabify-method'.
2965 Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil.
2966 Interactively, ARG is the prefix arg (default 1)
2967 and KILLP is t if a prefix arg was specified."
2968 (interactive "*p\nP")
2969 (when (eq backward-delete-char-untabify-method 'untabify)
2972 (while (and (> count 0) (not (bobp)))
2973 (if (= (preceding-char) ?\t)
2974 (let ((col (current-column)))
2976 (setq col (- col (current-column)))
2977 (insert-char ?\s col)
2980 (setq count (1- count))))))
2981 (delete-backward-char
2982 (let ((skip (cond ((eq backward-delete-char-untabify-method 'hungry) " \t")
2983 ((eq backward-delete-char-untabify-method 'all)
2986 (let ((wh (- (point) (save-excursion (skip-chars-backward skip)
2988 (+ arg (if (zerop wh) 0 (1- wh))))
2992 (defun zap-to-char (arg char)
2993 "Kill up to and including ARG'th occurrence of CHAR.
2994 Case is ignored if `case-fold-search' is non-nil in the current buffer.
2995 Goes backward if ARG is negative; error if CHAR not found."
2996 (interactive "p\ncZap to char: ")
2997 (if (char-table-p translation-table-for-input)
2998 (setq char (or (aref translation-table-for-input char) char)))
2999 (kill-region (point) (progn
3000 (search-forward (char-to-string char) nil nil arg)
3001 ; (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
3004 ;; kill-line and its subroutines.
3006 (defcustom kill-whole-line nil
3007 "*If non-nil, `kill-line' with no arg at beg of line kills the whole line."
3011 (defun kill-line (&optional arg)
3012 "Kill the rest of the current line; if no nonblanks there, kill thru newline.
3013 With prefix argument, kill that many lines from point.
3014 Negative arguments kill lines backward.
3015 With zero argument, kills the text before point on the current line.
3017 When calling from a program, nil means \"no arg\",
3018 a number counts as a prefix arg.
3020 To kill a whole line, when point is not at the beginning, type \
3021 \\[move-beginning-of-line] \\[kill-line] \\[kill-line].
3023 If `kill-whole-line' is non-nil, then this command kills the whole line
3024 including its terminating newline, when used at the beginning of a line
3025 with no argument. As a consequence, you can always kill a whole line
3026 by typing \\[move-beginning-of-line] \\[kill-line].
3028 If you want to append the killed line to the last killed text,
3029 use \\[append-next-kill] before \\[kill-line].
3031 If the buffer is read-only, Emacs will beep and refrain from deleting
3032 the line, but put the line in the kill ring anyway. This means that
3033 you can use this command to copy text from a read-only buffer.
3034 \(If the variable `kill-read-only-ok' is non-nil, then this won't
3037 (kill-region (point)
3038 ;; It is better to move point to the other end of the kill
3039 ;; before killing. That way, in a read-only buffer, point
3040 ;; moves across the text that is copied to the kill ring.
3041 ;; The choice has no effect on undo now that undo records
3042 ;; the value of point from before the command was run.
3045 (forward-visible-line (prefix-numeric-value arg))
3047 (signal 'end-of-buffer nil))
3050 (end-of-visible-line) (point))))
3051 (if (or (save-excursion
3052 ;; If trailing whitespace is visible,
3053 ;; don't treat it as nothing.
3054 (unless show-trailing-whitespace
3055 (skip-chars-forward " \t" end))
3057 (and kill-whole-line (bolp)))
3058 (forward-visible-line 1)
3062 (defun kill-whole-line (&optional arg)
3064 With prefix arg, kill that many lines starting from the current line.
3065 If arg is negative, kill backward. Also kill the preceding newline.
3066 \(This is meant to make \\[repeat] work well with negative arguments.\)
3067 If arg is zero, kill current line but exclude the trailing newline."
3069 (if (and (> arg 0) (eobp) (save-excursion (forward-visible-line 0) (eobp)))
3070 (signal 'end-of-buffer nil))
3071 (if (and (< arg 0) (bobp) (save-excursion (end-of-visible-line) (bobp)))
3072 (signal 'beginning-of-buffer nil))
3073 (unless (eq last-command 'kill-region)
3075 (setq last-command 'kill-region))
3077 ;; We need to kill in two steps, because the previous command
3078 ;; could have been a kill command, in which case the text
3079 ;; before point needs to be prepended to the current kill
3080 ;; ring entry and the text after point appended. Also, we
3081 ;; need to use save-excursion to avoid copying the same text
3082 ;; twice to the kill ring in read-only buffers.
3084 (kill-region (point) (progn (forward-visible-line 0) (point))))
3085 (kill-region (point) (progn (end-of-visible-line) (point))))
3088 (kill-region (point) (progn (end-of-visible-line) (point))))
3089 (kill-region (point)
3090 (progn (forward-visible-line (1+ arg))
3091 (unless (bobp) (backward-char))
3095 (kill-region (point) (progn (forward-visible-line 0) (point))))
3096 (kill-region (point)
3097 (progn (forward-visible-line arg) (point))))))
3099 (defun forward-visible-line (arg)
3100 "Move forward by ARG lines, ignoring currently invisible newlines only.
3101 If ARG is negative, move backward -ARG lines.
3102 If ARG is zero, move to the beginning of the current line."
3107 (or (zerop (forward-line 1))
3108 (signal 'end-of-buffer nil))
3109 ;; If the newline we just skipped is invisible,
3112 (get-char-property (1- (point)) 'invisible)))
3113 (if (if (eq buffer-invisibility-spec t)
3115 (or (memq prop buffer-invisibility-spec)
3116 (assq prop buffer-invisibility-spec)))
3117 (setq arg (1+ arg))))
3118 (setq arg (1- arg)))
3119 ;; If invisible text follows, and it is a number of complete lines,
3121 (let ((opoint (point)))
3122 (while (and (not (eobp))
3124 (get-char-property (point) 'invisible)))
3125 (if (eq buffer-invisibility-spec t)
3127 (or (memq prop buffer-invisibility-spec)
3128 (assq prop buffer-invisibility-spec)))))
3130 (if (get-text-property (point) 'invisible)
3131 (or (next-single-property-change (point) 'invisible)
3133 (next-overlay-change (point)))))
3135 (goto-char opoint))))
3137 (while (or first (<= arg 0))
3140 (or (zerop (forward-line -1))
3141 (signal 'beginning-of-buffer nil)))
3142 ;; If the newline we just moved to is invisible,
3146 (get-char-property (1- (point)) 'invisible)))
3147 (unless (if (eq buffer-invisibility-spec t)
3149 (or (memq prop buffer-invisibility-spec)
3150 (assq prop buffer-invisibility-spec)))
3151 (setq arg (1+ arg)))))
3153 ;; If invisible text follows, and it is a number of complete lines,
3155 (let ((opoint (point)))
3156 (while (and (not (bobp))
3158 (get-char-property (1- (point)) 'invisible)))
3159 (if (eq buffer-invisibility-spec t)
3161 (or (memq prop buffer-invisibility-spec)
3162 (assq prop buffer-invisibility-spec)))))
3164 (if (get-text-property (1- (point)) 'invisible)
3165 (or (previous-single-property-change (point) 'invisible)
3167 (previous-overlay-change (point)))))
3169 (goto-char opoint)))))
3170 ((beginning-of-buffer end-of-buffer)
3173 (defun end-of-visible-line ()
3174 "Move to end of current visible line."
3176 ;; If the following character is currently invisible,
3177 ;; skip all characters with that same `invisible' property value,
3178 ;; then find the next newline.
3179 (while (and (not (eobp))
3181 (skip-chars-forward "^\n")
3183 (get-char-property (point) 'invisible)))
3184 (if (eq buffer-invisibility-spec t)
3186 (or (memq prop buffer-invisibility-spec)
3187 (assq prop buffer-invisibility-spec))))))
3188 (skip-chars-forward "^\n")
3189 (if (get-text-property (point) 'invisible)
3190 (goto-char (next-single-property-change (point) 'invisible))
3191 (goto-char (next-overlay-change (point))))
3194 (defun insert-buffer (buffer)
3195 "Insert after point the contents of BUFFER.
3196 Puts mark after the inserted text.
3197 BUFFER may be a buffer or a buffer name.
3199 This function is meant for the user to run interactively.
3200 Don't call it from programs: use `insert-buffer-substring' instead!"
3204 (barf-if-buffer-read-only)
3205 (read-buffer "Insert buffer: "
3206 (if (eq (selected-window) (next-window (selected-window)))
3207 (other-buffer (current-buffer))
3208 (window-buffer (next-window (selected-window))))
3212 (insert-buffer-substring (get-buffer buffer))
3216 (defun append-to-buffer (buffer start end)
3217 "Append to specified buffer the text of the region.
3218 It is inserted into that buffer before its point.
3220 When calling from a program, give three arguments:
3221 BUFFER (or buffer name), START and END.
3222 START and END specify the portion of the current buffer to be copied."
3224 (list (read-buffer "Append to buffer: " (other-buffer (current-buffer) t))
3225 (region-beginning) (region-end)))
3226 (let ((oldbuf (current-buffer)))
3228 (let* ((append-to (get-buffer-create buffer))
3229 (windows (get-buffer-window-list append-to t t))
3231 (set-buffer append-to)
3232 (setq point (point))
3233 (barf-if-buffer-read-only)
3234 (insert-buffer-substring oldbuf start end)
3235 (dolist (window windows)
3236 (when (= (window-point window) point)
3237 (set-window-point window (point))))))))
3239 (defun prepend-to-buffer (buffer start end)
3240 "Prepend to specified buffer the text of the region.
3241 It is inserted into that buffer after its point.
3243 When calling from a program, give three arguments:
3244 BUFFER (or buffer name), START and END.
3245 START and END specify the portion of the current buffer to be copied."
3246 (interactive "BPrepend to buffer: \nr")
3247 (let ((oldbuf (current-buffer)))
3249 (set-buffer (get-buffer-create buffer))
3250 (barf-if-buffer-read-only)
3252 (insert-buffer-substring oldbuf start end)))))
3254 (defun copy-to-buffer (buffer start end)
3255 "Copy to specified buffer the text of the region.
3256 It is inserted into that buffer, replacing existing text there.
3258 When calling from a program, give three arguments:
3259 BUFFER (or buffer name), START and END.
3260 START and END specify the portion of the current buffer to be copied."
3261 (interactive "BCopy to buffer: \nr")
3262 (let ((oldbuf (current-buffer)))
3263 (with-current-buffer (get-buffer-create buffer)
3264 (barf-if-buffer-read-only)
3267 (insert-buffer-substring oldbuf start end)))))
3269 (put 'mark-inactive 'error-conditions '(mark-inactive error))
3270 (put 'mark-inactive 'error-message "The mark is not active now")
3272 (defvar activate-mark-hook nil
3273 "Hook run when the mark becomes active.
3274 It is also run at the end of a command, if the mark is active and
3275 it is possible that the region may have changed.")
3277 (defvar deactivate-mark-hook nil
3278 "Hook run when the mark becomes inactive.")
3280 (defun mark (&optional force)
3281 "Return this buffer's mark value as integer, or nil if never set.
3283 In Transient Mark mode, this function signals an error if
3284 the mark is not active. However, if `mark-even-if-inactive' is non-nil,
3285 or the argument FORCE is non-nil, it disregards whether the mark
3286 is active, and returns an integer or nil in the usual way.
3288 If you are using this in an editing command, you are most likely making
3289 a mistake; see the documentation of `set-mark'."
3290 (if (or force (not transient-mark-mode) mark-active mark-even-if-inactive)
3291 (marker-position (mark-marker))
3292 (signal 'mark-inactive nil)))
3294 ;; Many places set mark-active directly, and several of them failed to also
3295 ;; run deactivate-mark-hook. This shorthand should simplify.
3296 (defsubst deactivate-mark ()
3297 "Deactivate the mark by setting `mark-active' to nil.
3298 \(That makes a difference only in Transient Mark mode.)
3299 Also runs the hook `deactivate-mark-hook'."
3301 ((eq transient-mark-mode 'lambda)
3302 (setq transient-mark-mode nil))
3303 (transient-mark-mode
3304 (setq mark-active nil)
3305 (run-hooks 'deactivate-mark-hook))))
3307 (defun set-mark (pos)
3308 "Set this buffer's mark to POS. Don't use this function!
3309 That is to say, don't use this function unless you want
3310 the user to see that the mark has moved, and you want the previous
3311 mark position to be lost.
3313 Normally, when a new mark is set, the old one should go on the stack.
3314 This is why most applications should use `push-mark', not `set-mark'.
3316 Novice Emacs Lisp programmers often try to use the mark for the wrong
3317 purposes. The mark saves a location for the user's convenience.
3318 Most editing commands should not alter the mark.
3319 To remember a location for internal use in the Lisp program,
3320 store it in a Lisp variable. Example:
3322 (let ((beg (point))) (forward-line 1) (delete-region beg (point)))."
3326 (setq mark-active t)
3327 (run-hooks 'activate-mark-hook)
3328 (set-marker (mark-marker) pos (current-buffer)))
3329 ;; Normally we never clear mark-active except in Transient Mark mode.
3330 ;; But when we actually clear out the mark value too,
3331 ;; we must clear mark-active in any mode.
3332 (setq mark-active nil)
3333 (run-hooks 'deactivate-mark-hook)
3334 (set-marker (mark-marker) nil)))
3336 (defvar mark-ring nil
3337 "The list of former marks of the current buffer, most recent first.")
3338 (make-variable-buffer-local 'mark-ring)
3339 (put 'mark-ring 'permanent-local t)
3341 (defcustom mark-ring-max 16
3342 "*Maximum size of mark ring. Start discarding off end if gets this big."
3344 :group 'editing-basics)
3346 (defvar global-mark-ring nil
3347 "The list of saved global marks, most recent first.")
3349 (defcustom global-mark-ring-max 16
3350 "*Maximum size of global mark ring. \
3351 Start discarding off end if gets this big."
3353 :group 'editing-basics)
3355 (defun pop-to-mark-command ()
3356 "Jump to mark, and pop a new position for mark off the ring
3357 \(does not affect global mark ring\)."
3360 (error "No mark set in this buffer")
3361 (if (= (point) (mark t))
3362 (message "Mark popped"))
3363 (goto-char (mark t))
3366 (defun push-mark-command (arg &optional nomsg)
3367 "Set mark at where point is.
3368 If no prefix arg and mark is already set there, just activate it.
3369 Display `Mark set' unless the optional second arg NOMSG is non-nil."
3371 (let ((mark (marker-position (mark-marker))))
3372 (if (or arg (null mark) (/= mark (point)))
3373 (push-mark nil nomsg t)
3374 (setq mark-active t)
3375 (run-hooks 'activate-mark-hook)
3377 (message "Mark activated")))))
3379 (defcustom set-mark-command-repeat-pop nil
3380 "*Non-nil means repeating \\[set-mark-command] after popping mark pops it again.
3381 That means that C-u \\[set-mark-command] \\[set-mark-command]
3382 will pop the mark twice, and
3383 C-u \\[set-mark-command] \\[set-mark-command] \\[set-mark-command]
3384 will pop the mark three times.
3386 A value of nil means \\[set-mark-command]'s behavior does not change
3387 after C-u \\[set-mark-command]."
3389 :group 'editing-basics)
3391 (defun set-mark-command (arg)
3392 "Set the mark where point is, or jump to the mark.
3393 Setting the mark also alters the region, which is the text
3394 between point and mark; this is the closest equivalent in
3395 Emacs to what some editors call the \"selection\".
3397 With no prefix argument, set the mark at point, and push the
3398 old mark position on local mark ring. Also push the old mark on
3399 global mark ring, if the previous mark was set in another buffer.
3401 Immediately repeating this command activates `transient-mark-mode' temporarily.
3403 With prefix argument \(e.g., \\[universal-argument] \\[set-mark-command]\), \
3404 jump to the mark, and set the mark from
3405 position popped off the local mark ring \(this does not affect the global
3406 mark ring\). Use \\[pop-global-mark] to jump to a mark popped off the global
3407 mark ring \(see `pop-global-mark'\).
3409 If `set-mark-command-repeat-pop' is non-nil, repeating
3410 the \\[set-mark-command] command with no prefix argument pops the next position
3411 off the local (or global) mark ring and jumps there.
3413 With \\[universal-argument] \\[universal-argument] as prefix
3414 argument, unconditionally set mark where point is, even if
3415 `set-mark-command-repeat-pop' is non-nil.
3417 Novice Emacs Lisp programmers often try to use the mark for the wrong
3418 purposes. See the documentation of `set-mark' for more information."
3420 (if (eq transient-mark-mode 'lambda)
3421 (setq transient-mark-mode nil))
3423 ((and (consp arg) (> (prefix-numeric-value arg) 4))
3424 (push-mark-command nil))
3425 ((not (eq this-command 'set-mark-command))
3427 (pop-to-mark-command)
3428 (push-mark-command t)))
3429 ((and set-mark-command-repeat-pop
3430 (eq last-command 'pop-to-mark-command))
3431 (setq this-command 'pop-to-mark-command)
3432 (pop-to-mark-command))
3433 ((and set-mark-command-repeat-pop
3434 (eq last-command 'pop-global-mark)
3436 (setq this-command 'pop-global-mark)
3439 (setq this-command 'pop-to-mark-command)
3440 (pop-to-mark-command))
3441 ((and (eq last-command 'set-mark-command)
3442 mark-active (null transient-mark-mode))
3443 (setq transient-mark-mode 'lambda)
3444 (message "Transient-mark-mode temporarily enabled"))
3446 (push-mark-command nil))))
3448 (defun push-mark (&optional location nomsg activate)
3449 "Set mark at LOCATION (point, by default) and push old mark on mark ring.
3450 If the last global mark pushed was not in the current buffer,
3451 also push LOCATION on the global mark ring.
3452 Display `Mark set' unless the optional second arg NOMSG is non-nil.
3454 Novice Emacs Lisp programmers often try to use the mark for the wrong
3455 purposes. See the documentation of `set-mark' for more information.
3457 In Transient Mark mode, activate mark if optional third arg ACTIVATE non-nil."
3458 (unless (null (mark t))
3459 (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring))
3460 (when (> (length mark-ring) mark-ring-max)
3461 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil)
3462 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil)))
3463 (set-marker (mark-marker) (or location (point)) (current-buffer))
3464 ;; Now push the mark on the global mark ring.
3465 (if (and global-mark-ring
3466 (eq (marker-buffer (car global-mark-ring)) (current-buffer)))
3467 ;; The last global mark pushed was in this same buffer.
3468 ;; Don't push another one.
3470 (setq global-mark-ring (cons (copy-marker (mark-marker)) global-mark-ring))
3471 (when (> (length global-mark-ring) global-mark-ring-max)
3472 (move-marker (car (nthcdr global-mark-ring-max global-mark-ring)) nil)
3473 (setcdr (nthcdr (1- global-mark-ring-max) global-mark-ring) nil)))
3474 (or nomsg executing-kbd-macro (> (minibuffer-depth) 0)
3475 (message "Mark set"))
3476 (if (or activate (not transient-mark-mode))
3477 (set-mark (mark t)))
3481 "Pop off mark ring into the buffer's actual mark.
3482 Does not set point. Does nothing if mark ring is empty."
3484 (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker)))))
3485 (set-marker (mark-marker) (+ 0 (car mark-ring)) (current-buffer))
3486 (move-marker (car mark-ring) nil)
3487 (if (null (mark t)) (ding))
3488 (setq mark-ring (cdr mark-ring)))
3491 (defalias 'exchange-dot-and-mark 'exchange-point-and-mark)
3492 (defun exchange-point-and-mark (&optional arg)
3493 "Put the mark where point is now, and point where the mark is now.
3494 This command works even when the mark is not active,
3495 and it reactivates the mark.
3496 With prefix arg, `transient-mark-mode' is enabled temporarily."
3500 (if (null transient-mark-mode)
3501 (setq transient-mark-mode 'lambda))
3504 (let ((omark (mark t)))
3506 (error "No mark set in this buffer"))
3511 (define-minor-mode transient-mark-mode
3512 "Toggle Transient Mark mode.
3513 With arg, turn Transient Mark mode on if arg is positive, off otherwise.
3515 In Transient Mark mode, when the mark is active, the region is highlighted.
3516 Changing the buffer \"deactivates\" the mark.
3517 So do certain other operations that set the mark
3518 but whose main purpose is something else--for example,
3519 incremental search, \\[beginning-of-buffer], and \\[end-of-buffer].
3521 You can also deactivate the mark by typing \\[keyboard-quit] or
3522 \\[keyboard-escape-quit].
3524 Many commands change their behavior when Transient Mark mode is in effect
3525 and the mark is active, by acting on the region instead of their usual
3526 default part of the buffer's text. Examples of such commands include
3527 \\[comment-dwim], \\[flush-lines], \\[keep-lines], \
3528 \\[query-replace], \\[query-replace-regexp], \\[ispell], and \\[undo].
3529 Invoke \\[apropos-documentation] and type \"transient\" or
3530 \"mark.*active\" at the prompt, to see the documentation of
3531 commands which are sensitive to the Transient Mark mode."
3532 :global t :group 'editing-basics)
3534 (defvar widen-automatically t
3535 "Non-nil means it is ok for commands to call `widen' when they want to.
3536 Some commands will do this in order to go to positions outside
3537 the current accessible part of the buffer.
3539 If `widen-automatically' is nil, these commands will do something else
3540 as a fallback, and won't change the buffer bounds.")
3542 (defun pop-global-mark ()
3543 "Pop off global mark ring and jump to the top location."
3545 ;; Pop entries which refer to non-existent buffers.
3546 (while (and global-mark-ring (not (marker-buffer (car global-mark-ring))))
3547 (setq global-mark-ring (cdr global-mark-ring)))
3548 (or global-mark-ring
3549 (error "No global mark set"))
3550 (let* ((marker (car global-mark-ring))
3551 (buffer (marker-buffer marker))
3552 (position (marker-position marker)))
3553 (setq global-mark-ring (nconc (cdr global-mark-ring)
3554 (list (car global-mark-ring))))
3556 (or (and (>= position (point-min))
3557 (<= position (point-max)))
3558 (if widen-automatically
3560 (error "Global mark position is outside accessible part of buffer")))
3561 (goto-char position)
3562 (switch-to-buffer buffer)))
3564 (defcustom next-line-add-newlines nil
3565 "*If non-nil, `next-line' inserts newline to avoid `end of buffer' error."
3568 :group 'editing-basics)
3570 (defun next-line (&optional arg try-vscroll)
3571 "Move cursor vertically down ARG lines.
3572 Interactively, vscroll tall lines if `auto-window-vscroll' is enabled.
3573 If there is no character in the target line exactly under the current column,
3574 the cursor is positioned after the character in that line which spans this
3575 column, or at the end of the line if it is not long enough.
3576 If there is no line in the buffer after this one, behavior depends on the
3577 value of `next-line-add-newlines'. If non-nil, it inserts a newline character
3578 to create a line, and moves the cursor to that line. Otherwise it moves the
3579 cursor to the end of the buffer.
3581 The command \\[set-goal-column] can be used to create
3582 a semipermanent goal column for this command.
3583 Then instead of trying to move exactly vertically (or as close as possible),
3584 this command moves to the specified goal column (or as close as possible).
3585 The goal column is stored in the variable `goal-column', which is nil
3586 when there is no goal column.
3588 If you are thinking of using this in a Lisp program, consider
3589 using `forward-line' instead. It is usually easier to use
3590 and more reliable (no dependence on goal column, etc.)."
3591 (interactive "p\np")
3592 (or arg (setq arg 1))
3593 (if (and next-line-add-newlines (= arg 1))
3594 (if (save-excursion (end-of-line) (eobp))
3595 ;; When adding a newline, don't expand an abbrev.
3596 (let ((abbrev-mode nil))
3598 (insert (if use-hard-newlines hard-newline "\n")))
3599 (line-move arg nil nil try-vscroll))
3602 (line-move arg nil nil try-vscroll)
3603 ((beginning-of-buffer end-of-buffer) (ding)))
3604 (line-move arg nil nil try-vscroll)))
3607 (defun previous-line (&optional arg try-vscroll)
3608 "Move cursor vertically up ARG lines.
3609 Interactively, vscroll tall lines if `auto-window-vscroll' is enabled.
3610 If there is no character in the target line exactly over the current column,
3611 the cursor is positioned after the character in that line which spans this
3612 column, or at the end of the line if it is not long enough.
3614 The command \\[set-goal-column] can be used to create
3615 a semipermanent goal column for this command.
3616 Then instead of trying to move exactly vertically (or as close as possible),
3617 this command moves to the specified goal column (or as close as possible).
3618 The goal column is stored in the variable `goal-column', which is nil
3619 when there is no goal column.
3621 If you are thinking of using this in a Lisp program, consider using
3622 `forward-line' with a negative argument instead. It is usually easier
3623 to use and more reliable (no dependence on goal column, etc.)."
3624 (interactive "p\np")
3625 (or arg (setq arg 1))
3628 (line-move (- arg) nil nil try-vscroll)
3629 ((beginning-of-buffer end-of-buffer) (ding)))
3630 (line-move (- arg) nil nil try-vscroll))
3633 (defcustom track-eol nil
3634 "*Non-nil means vertical motion starting at end of line keeps to ends of lines.
3635 This means moving to the end of each line moved onto.
3636 The beginning of a blank line does not count as the end of a line."
3638 :group 'editing-basics)
3640 (defcustom goal-column nil
3641 "*Semipermanent goal column for vertical motion, as set by \\[set-goal-column], or nil."
3642 :type '(choice integer
3643 (const :tag "None" nil))
3644 :group 'editing-basics)
3645 (make-variable-buffer-local 'goal-column)
3647 (defvar temporary-goal-column 0
3648 "Current goal column for vertical motion.
3649 It is the column where point was
3650 at the start of current run of vertical motion commands.
3651 When the `track-eol' feature is doing its job, the value is `most-positive-fixnum'.")
3653 (defcustom line-move-ignore-invisible t
3654 "*Non-nil means \\[next-line] and \\[previous-line] ignore invisible lines.
3655 Outline mode sets this."
3657 :group 'editing-basics)
3659 ;; Returns non-nil if partial move was done.
3660 (defun line-move-partial (arg noerror to-end)
3662 ;; Move backward (up).
3663 ;; If already vscrolled, reduce vscroll
3664 (let ((vs (window-vscroll nil t)))
3665 (when (> vs (frame-char-height))
3666 (set-window-vscroll nil (- vs (frame-char-height)) t)))
3668 ;; Move forward (down).
3669 (let* ((lh (window-line-height -1))
3675 (>= rbot (frame-char-height))
3676 (<= ypos (- (frame-char-height))))
3678 (let ((wend (pos-visible-in-window-p t nil t)))
3679 (setq rbot (nth 3 wend)
3680 vpos (nth 5 wend))))
3682 ;; If last line of window is fully visible, move forward.
3683 ((or (null rbot) (= rbot 0))
3685 ;; If cursor is not in the bottom scroll margin, move forward.
3688 (or (nth 1 (window-line-height))
3689 (let ((ppos (posn-at-point)))
3690 (cdr (or (posn-actual-col-row ppos)
3691 (posn-col-row ppos))))))
3692 (min (- (window-text-height) scroll-margin 1) (1- vpos))))
3694 ;; When already vscrolled, we vscroll some more if we can,
3695 ;; or clear vscroll and move forward at end of tall image.
3696 ((> (setq vs (window-vscroll nil t)) 0)
3698 (set-window-vscroll nil (+ vs (min rbot (frame-char-height))) t)))
3699 ;; If cursor just entered the bottom scroll margin, move forward,
3700 ;; but also vscroll one line so redisplay wont recenter.
3702 (= py (min (- (window-text-height) scroll-margin 1)
3704 (set-window-vscroll nil (frame-char-height) t)
3705 (line-move-1 arg noerror to-end)
3707 ;; If there are lines above the last line, scroll-up one line.
3711 ;; Finally, start vscroll.
3713 (set-window-vscroll nil (frame-char-height) t)))))))
3716 ;; This is like line-move-1 except that it also performs
3717 ;; vertical scrolling of tall images if appropriate.
3718 ;; That is not really a clean thing to do, since it mixes
3719 ;; scrolling with cursor motion. But so far we don't have
3720 ;; a cleaner solution to the problem of making C-n do something
3721 ;; useful given a tall image.
3722 (defun line-move (arg &optional noerror to-end try-vscroll)
3723 (unless (and auto-window-vscroll try-vscroll
3724 ;; Only vscroll for single line moves
3726 ;; But don't vscroll in a keyboard macro.
3727 (not defining-kbd-macro)
3728 (not executing-kbd-macro)
3729 (line-move-partial arg noerror to-end))
3730 (set-window-vscroll nil 0 t)
3731 (line-move-1 arg noerror to-end)))
3733 ;; This is the guts of next-line and previous-line.
3734 ;; Arg says how many lines to move.
3735 ;; The value is t if we can move the specified number of lines.
3736 (defun line-move-1 (arg &optional noerror to-end)
3737 ;; Don't run any point-motion hooks, and disregard intangibility,
3738 ;; for intermediate positions.
3739 (let ((inhibit-point-motion-hooks t)
3744 (if (not (memq last-command '(next-line previous-line)))
3745 (setq temporary-goal-column
3746 (if (and track-eol (eolp)
3747 ;; Don't count beg of empty line as end of line
3748 ;; unless we just did explicit end-of-line.
3749 (or (not (bolp)) (eq last-command 'move-end-of-line)))
3750 most-positive-fixnum
3753 (if (not (or (integerp selective-display)
3754 line-move-ignore-invisible))
3755 ;; Use just newline characters.
3756 ;; Set ARG to 0 if we move as many lines as requested.
3758 (progn (if (> arg 1) (forward-line (1- arg)))
3759 ;; This way of moving forward ARG lines
3760 ;; verifies that we have a newline after the last one.
3761 ;; It doesn't get confused by intangible text.
3763 (if (zerop (forward-line 1))
3765 (and (zerop (forward-line arg))
3769 (signal (if (< arg 0)
3770 'beginning-of-buffer
3773 ;; Move by arg lines, but ignore invisible ones.
3775 (while (and (> arg 0) (not done))
3776 ;; If the following character is currently invisible,
3777 ;; skip all characters with that same `invisible' property value.
3778 (while (and (not (eobp)) (invisible-p (point)))
3779 (goto-char (next-char-property-change (point))))
3781 ;; We don't use `end-of-line', since we want to escape
3782 ;; from field boundaries ocurring exactly at point.
3783 (goto-char (constrain-to-field
3784 (let ((inhibit-field-text-motion t))
3785 (line-end-position))
3787 'inhibit-line-move-field-capture))
3788 ;; If there's no invisibility here, move over the newline.
3792 (signal 'end-of-buffer nil)
3794 ((and (> arg 1) ;; Use vertical-motion for last move
3795 (not (integerp selective-display))
3796 (not (invisible-p (point))))
3797 ;; We avoid vertical-motion when possible
3798 ;; because that has to fontify.
3800 ;; Otherwise move a more sophisticated way.
3801 ((zerop (vertical-motion 1))
3803 (signal 'end-of-buffer nil)
3806 (setq arg (1- arg))))
3807 ;; The logic of this is the same as the loop above,
3808 ;; it just goes in the other direction.
3809 (while (and (< arg 0) (not done))
3810 ;; For completely consistency with the forward-motion
3811 ;; case, we should call beginning-of-line here.
3812 ;; However, if point is inside a field and on a
3813 ;; continued line, the call to (vertical-motion -1)
3814 ;; below won't move us back far enough; then we return
3815 ;; to the same column in line-move-finish, and point
3816 ;; gets stuck -- cyd
3821 (signal 'beginning-of-buffer nil)
3823 ((and (< arg -1) ;; Use vertical-motion for last move
3824 (not (integerp selective-display))
3825 (not (invisible-p (1- (point)))))
3827 ((zerop (vertical-motion -1))
3829 (signal 'beginning-of-buffer nil)
3833 (while (and ;; Don't move over previous invis lines
3834 ;; if our target is the middle of this line.
3835 (or (zerop (or goal-column temporary-goal-column))
3837 (not (bobp)) (invisible-p (1- (point))))
3838 (goto-char (previous-char-property-change (point))))))))
3839 ;; This is the value the function returns.
3843 ;; If we did not move down as far as desired,
3844 ;; at least go to end of line.
3847 ;; If we did not move up as far as desired,
3848 ;; at least go to beginning of line.
3849 (beginning-of-line))
3851 (line-move-finish (or goal-column temporary-goal-column)
3852 opoint (> orig-arg 0)))))))
3854 (defun line-move-finish (column opoint forward)
3857 ;; Set REPEAT to t to repeat the whole thing.
3862 (line-beg (save-excursion (beginning-of-line) (point)))
3864 ;; Compute the end of the line
3865 ;; ignoring effectively invisible newlines.
3867 ;; Like end-of-line but ignores fields.
3868 (skip-chars-forward "^\n")
3869 (while (and (not (eobp)) (invisible-p (point)))
3870 (goto-char (next-char-property-change (point)))
3871 (skip-chars-forward "^\n"))
3874 ;; Move to the desired column.
3875 (line-move-to-column column)
3877 ;; Corner case: suppose we start out in a field boundary in
3878 ;; the middle of a continued line. When we get to
3879 ;; line-move-finish, point is at the start of a new *screen*
3880 ;; line but the same text line; then line-move-to-column would
3881 ;; move us backwards. Test using C-n with point on the "x" in
3882 ;; (insert "a" (propertize "x" 'field t) (make-string 89 ?y))
3889 ;; Process intangibility within a line.
3890 ;; With inhibit-point-motion-hooks bound to nil, a call to
3891 ;; goto-char moves point past intangible text.
3893 ;; However, inhibit-point-motion-hooks controls both the
3894 ;; intangibility and the point-entered/point-left hooks. The
3895 ;; following hack avoids calling the point-* hooks
3896 ;; unnecessarily. Note that we move *forward* past intangible
3897 ;; text when the initial and final points are the same.
3899 (let ((inhibit-point-motion-hooks nil))
3902 ;; If intangibility moves us to a different (later) place
3903 ;; in the same line, use that as the destination.
3904 (if (<= (point) line-end)
3906 ;; If that position is "too late",
3907 ;; try the previous allowable position.
3911 ;; If going forward, don't accept the previous
3912 ;; allowable position if it is before the target line.
3913 (< line-beg (point))
3914 ;; If going backward, don't accept the previous
3915 ;; allowable position if it is still after the target line.
3916 (<= (point) line-end))
3918 ;; As a last resort, use the end of the line.
3919 (setq new line-end))))
3921 ;; Now move to the updated destination, processing fields
3922 ;; as well as intangibility.
3924 (let ((inhibit-point-motion-hooks nil))
3926 ;; Ignore field boundaries if the initial and final
3927 ;; positions have the same `field' property, even if the
3928 ;; fields are non-contiguous. This seems to be "nicer"
3929 ;; behavior in many situations.
3930 (if (eq (get-char-property new 'field)
3931 (get-char-property opoint 'field))
3933 (constrain-to-field new opoint t t
3934 'inhibit-line-move-field-capture))))
3936 ;; If all this moved us to a different line,
3937 ;; retry everything within that new line.
3938 (when (or (< (point) line-beg) (> (point) line-end))
3939 ;; Repeat the intangibility and field processing.
3940 (setq repeat t))))))
3942 (defun line-move-to-column (col)
3943 "Try to find column COL, considering invisibility.
3944 This function works only in certain cases,
3945 because what we really need is for `move-to-column'
3946 and `current-column' to be able to ignore invisible text."
3949 (move-to-column col))
3951 (when (and line-move-ignore-invisible
3952 (not (bolp)) (invisible-p (1- (point))))
3953 (let ((normal-location (point))
3954 (normal-column (current-column)))
3955 ;; If the following character is currently invisible,
3956 ;; skip all characters with that same `invisible' property value.
3957 (while (and (not (eobp))
3958 (invisible-p (point)))
3959 (goto-char (next-char-property-change (point))))
3960 ;; Have we advanced to a larger column position?
3961 (if (> (current-column) normal-column)
3962 ;; We have made some progress towards the desired column.
3963 ;; See if we can make any further progress.
3964 (line-move-to-column (+ (current-column) (- col normal-column)))
3965 ;; Otherwise, go to the place we originally found
3966 ;; and move back over invisible text.
3967 ;; that will get us to the same place on the screen
3968 ;; but with a more reasonable buffer position.
3969 (goto-char normal-location)
3970 (let ((line-beg (save-excursion (beginning-of-line) (point))))
3971 (while (and (not (bolp)) (invisible-p (1- (point))))
3972 (goto-char (previous-char-property-change (point) line-beg))))))))
3974 (defun move-end-of-line (arg)
3975 "Move point to end of current line as displayed.
3976 \(If there's an image in the line, this disregards newlines
3977 which are part of the text that the image rests on.)
3979 With argument ARG not nil or 1, move forward ARG - 1 lines first.
3980 If point reaches the beginning or end of buffer, it stops there.
3981 To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
3983 (or arg (setq arg 1))
3988 (let ((goal-column 0))
3989 (and (line-move arg t)
3992 (while (and (not (bobp)) (invisible-p (1- (point))))
3993 (goto-char (previous-single-char-property-change
3994 (point) 'invisible)))
3998 (if (and (> (point) newpos)
3999 (eq (preceding-char) ?\n))
4001 (if (and (> (point) newpos) (not (eobp))
4002 (not (eq (following-char) ?\n)))
4003 ;; If we skipped something intangible
4004 ;; and now we're not really at eol,
4009 (defun move-beginning-of-line (arg)
4010 "Move point to beginning of current line as displayed.
4011 \(If there's an image in the line, this disregards newlines
4012 which are part of the text that the image rests on.)
4014 With argument ARG not nil or 1, move forward ARG - 1 lines first.
4015 If point reaches the beginning or end of buffer, it stops there.
4016 To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
4018 (or arg (setq arg 1))
4020 (let ((orig (point))
4021 first-vis first-vis-field-value)
4023 ;; Move by lines, if ARG is not 1 (the default).
4025 (line-move (1- arg) t))
4027 ;; Move to beginning-of-line, ignoring fields and invisibles.
4028 (skip-chars-backward "^\n")
4029 (while (and (not (bobp)) (invisible-p (1- (point))))
4030 (goto-char (previous-char-property-change (point)))
4031 (skip-chars-backward "^\n"))
4033 ;; Now find first visible char in the line
4034 (while (and (not (eobp)) (invisible-p (point)))
4035 (goto-char (next-char-property-change (point))))
4036 (setq first-vis (point))
4038 ;; See if fields would stop us from reaching FIRST-VIS.
4039 (setq first-vis-field-value
4040 (constrain-to-field first-vis orig (/= arg 1) t nil))
4042 (goto-char (if (/= first-vis-field-value first-vis)
4043 ;; If yes, obey them.
4044 first-vis-field-value
4045 ;; Otherwise, move to START with attention to fields.
4046 ;; (It is possible that fields never matter in this case.)
4047 (constrain-to-field (point) orig
4048 (/= arg 1) t nil)))))
4051 ;;; Many people have said they rarely use this feature, and often type
4052 ;;; it by accident. Maybe it shouldn't even be on a key.
4053 (put 'set-goal-column 'disabled t)
4055 (defun set-goal-column (arg)
4056 "Set the current horizontal position as a goal for \\[next-line] and \\[previous-line].
4057 Those commands will move to this position in the line moved to
4058 rather than trying to keep the same horizontal position.
4059 With a non-nil argument, clears out the goal column
4060 so that \\[next-line] and \\[previous-line] resume vertical motion.
4061 The goal column is stored in the variable `goal-column'."
4065 (setq goal-column nil)
4066 (message "No goal column"))
4067 (setq goal-column (current-column))
4068 ;; The older method below can be erroneous if `set-goal-column' is bound
4069 ;; to a sequence containing %
4070 ;;(message (substitute-command-keys
4071 ;;"Goal column %d (use \\[set-goal-column] with an arg to unset it)")
4075 (format "Goal column %d " goal-column)
4076 (substitute-command-keys
4077 "(use \\[set-goal-column] with an arg to unset it)")))
4083 (defun scroll-other-window-down (lines)
4084 "Scroll the \"other window\" down.
4085 For more details, see the documentation for `scroll-other-window'."
4087 (scroll-other-window
4088 ;; Just invert the argument's meaning.
4089 ;; We can do that without knowing which window it will be.
4090 (if (eq lines '-) nil
4092 (- (prefix-numeric-value lines))))))
4094 (defun beginning-of-buffer-other-window (arg)
4095 "Move point to the beginning of the buffer in the other window.
4096 Leave mark at previous position.
4097 With arg N, put point N/10 of the way from the true beginning."
4099 (let ((orig-window (selected-window))
4100 (window (other-window-for-scrolling)))
4101 ;; We use unwind-protect rather than save-window-excursion
4102 ;; because the latter would preserve the things we want to change.
4105 (select-window window)
4106 ;; Set point and mark in that window's buffer.
4108 (beginning-of-buffer arg))
4109 ;; Set point accordingly.
4111 (select-window orig-window))))
4113 (defun end-of-buffer-other-window (arg)
4114 "Move point to the end of the buffer in the other window.
4115 Leave mark at previous position.
4116 With arg N, put point N/10 of the way from the true end."
4118 ;; See beginning-of-buffer-other-window for comments.
4119 (let ((orig-window (selected-window))
4120 (window (other-window-for-scrolling)))
4123 (select-window window)
4125 (end-of-buffer arg))
4127 (select-window orig-window))))
4129 (defun transpose-chars (arg)
4130 "Interchange characters around point, moving forward one character.
4131 With prefix arg ARG, effect is to take character before point
4132 and drag it forward past ARG other characters (backward if ARG negative).
4133 If no argument and at end of line, the previous two chars are exchanged."
4135 (and (null arg) (eolp) (forward-char -1))
4136 (transpose-subr 'forward-char (prefix-numeric-value arg)))
4138 (defun transpose-words (arg)
4139 "Interchange words around point, leaving point at end of them.
4140 With prefix arg ARG, effect is to take word before or around point
4141 and drag it forward past ARG other words (backward if ARG negative).
4142 If ARG is zero, the words around or after point and around or after mark
4144 ;; FIXME: `foo a!nd bar' should transpose into `bar and foo'.
4146 (transpose-subr 'forward-word arg))
4148 (defun transpose-sexps (arg)
4149 "Like \\[transpose-words] but applies to sexps.
4150 Does not work on a sexp that point is in the middle of
4151 if it is a list or string."
4155 ;; Here we should try to simulate the behavior of
4156 ;; (cons (progn (forward-sexp x) (point))
4157 ;; (progn (forward-sexp (- x)) (point)))
4158 ;; Except that we don't want to rely on the second forward-sexp
4159 ;; putting us back to where we want to be, since forward-sexp-function
4160 ;; might do funny things like infix-precedence.
4162 (looking-at "\\sw\\|\\s_")
4164 (save-excursion (forward-char -1) (looking-at "\\sw\\|\\s_"))))
4165 ;; Jumping over a symbol. We might be inside it, mind you.
4166 (progn (funcall (if (> arg 0)
4167 'skip-syntax-backward 'skip-syntax-forward)
4169 (cons (save-excursion (forward-sexp arg) (point)) (point)))
4170 ;; Otherwise, we're between sexps. Take a step back before jumping
4171 ;; to make sure we'll obey the same precedence no matter which direction
4173 (funcall (if (> arg 0) 'skip-syntax-backward 'skip-syntax-forward) " .")
4174 (cons (save-excursion (forward-sexp arg) (point))
4175 (progn (while (or (forward-comment (if (> arg 0) 1 -1))
4176 (not (zerop (funcall (if (> arg 0)
4177 'skip-syntax-forward
4178 'skip-syntax-backward)
4183 (defun transpose-lines (arg)
4184 "Exchange current line and previous line, leaving point after both.
4185 With argument ARG, takes previous line and moves it past ARG lines.
4186 With argument 0, interchanges line point is in with line mark is in."
4188 (transpose-subr (function
4192 ;; Move forward over ARG lines,
4193 ;; but create newlines if necessary.
4194 (setq arg (forward-line arg))
4195 (if (/= (preceding-char) ?\n)
4196 (setq arg (1+ arg)))
4199 (forward-line arg))))
4202 (defun transpose-subr (mover arg &optional special)
4203 (let ((aux (if special mover
4205 (cons (progn (funcall mover x) (point))
4206 (progn (funcall mover (- x)) (point))))))
4211 (setq pos1 (funcall aux 1))
4213 (setq pos2 (funcall aux 1))
4214 (transpose-subr-1 pos1 pos2))
4215 (exchange-point-and-mark))
4217 (setq pos1 (funcall aux -1))
4218 (setq pos2 (funcall aux arg))
4219 (transpose-subr-1 pos1 pos2)
4220 (goto-char (car pos2)))
4222 (setq pos1 (funcall aux -1))
4223 (goto-char (car pos1))
4224 (setq pos2 (funcall aux arg))
4225 (transpose-subr-1 pos1 pos2)))))
4227 (defun transpose-subr-1 (pos1 pos2)
4228 (when (> (car pos1) (cdr pos1)) (setq pos1 (cons (cdr pos1) (car pos1))))
4229 (when (> (car pos2) (cdr pos2)) (setq pos2 (cons (cdr pos2) (car pos2))))
4230 (when (> (car pos1) (car pos2))
4232 (setq pos1 pos2 pos2 swap)))
4233 (if (> (cdr pos1) (car pos2)) (error "Don't have two things to transpose"))
4234 (atomic-change-group
4236 ;; FIXME: We first delete the two pieces of text, so markers that
4237 ;; used to point to after the text end up pointing to before it :-(
4238 (setq word2 (delete-and-extract-region (car pos2) (cdr pos2)))
4239 (goto-char (car pos2))
4240 (insert (delete-and-extract-region (car pos1) (cdr pos1)))
4241 (goto-char (car pos1))
4244 (defun backward-word (&optional arg)
4245 "Move backward until encountering the beginning of a word.
4246 With argument, do this that many times."
4248 (forward-word (- (or arg 1))))
4250 (defun mark-word (&optional arg allow-extend)
4251 "Set mark ARG words away from point.
4252 The place mark goes is the same place \\[forward-word] would
4253 move to with the same argument.
4254 Interactively, if this command is repeated
4255 or (in Transient Mark mode) if the mark is active,
4256 it marks the next ARG words after the ones already marked."
4257 (interactive "P\np")
4258 (cond ((and allow-extend
4259 (or (and (eq last-command this-command) (mark t))
4260 (and transient-mark-mode mark-active)))
4261 (setq arg (if arg (prefix-numeric-value arg)
4262 (if (< (mark) (point)) -1 1)))
4271 (forward-word (prefix-numeric-value arg))
4275 (defun kill-word (arg)
4276 "Kill characters forward until encountering the end of a word.
4277 With argument, do this that many times."
4279 (kill-region (point) (progn (forward-word arg) (point))))
4281 (defun backward-kill-word (arg)
4282 "Kill characters backward until encountering the beginning of a word.
4283 With argument, do this that many times."
4285 (kill-word (- arg)))
4287 (defun current-word (&optional strict really-word)
4288 "Return the symbol or word that point is on (or a nearby one) as a string.
4289 The return value includes no text properties.
4290 If optional arg STRICT is non-nil, return nil unless point is within
4291 or adjacent to a symbol or word. In all cases the value can be nil
4292 if there is no word nearby.
4293 The function, belying its name, normally finds a symbol.
4294 If optional arg REALLY-WORD is non-nil, it finds just a word."
4296 (let* ((oldpoint (point)) (start (point)) (end (point))
4297 (syntaxes (if really-word "w" "w_"))
4298 (not-syntaxes (concat "^" syntaxes)))
4299 (skip-syntax-backward syntaxes) (setq start (point))
4300 (goto-char oldpoint)
4301 (skip-syntax-forward syntaxes) (setq end (point))
4302 (when (and (eq start oldpoint) (eq end oldpoint)
4303 ;; Point is neither within nor adjacent to a word.
4305 ;; Look for preceding word in same line.
4306 (skip-syntax-backward not-syntaxes
4307 (save-excursion (beginning-of-line)
4310 ;; No preceding word in same line.
4311 ;; Look for following word in same line.
4313 (skip-syntax-forward not-syntaxes
4314 (save-excursion (end-of-line)
4316 (setq start (point))
4317 (skip-syntax-forward syntaxes)
4320 (skip-syntax-backward syntaxes)
4321 (setq start (point))))
4322 ;; If we found something nonempty, return it as a string.
4323 (unless (= start end)
4324 (buffer-substring-no-properties start end)))))
4326 (defcustom fill-prefix nil
4327 "*String for filling to insert at front of new line, or nil for none."
4328 :type '(choice (const :tag "None" nil)
4331 (make-variable-buffer-local 'fill-prefix)
4332 ;;;###autoload(put 'fill-prefix 'safe-local-variable 'string-or-null-p)
4334 (defcustom auto-fill-inhibit-regexp nil
4335 "*Regexp to match lines which should not be auto-filled."
4336 :type '(choice (const :tag "None" nil)
4340 ;; This function is used as the auto-fill-function of a buffer
4341 ;; when Auto-Fill mode is enabled.
4342 ;; It returns t if it really did any work.
4343 ;; (Actually some major modes use a different auto-fill function,
4344 ;; but this one is the default one.)
4345 (defun do-auto-fill ()
4346 (let (fc justify give-up
4347 (fill-prefix fill-prefix))
4348 (if (or (not (setq justify (current-justification)))
4349 (null (setq fc (current-fill-column)))
4350 (and (eq justify 'left)
4351 (<= (current-column) fc))
4352 (and auto-fill-inhibit-regexp
4353 (save-excursion (beginning-of-line)
4354 (looking-at auto-fill-inhibit-regexp))))
4355 nil ;; Auto-filling not required
4356 (if (memq justify '(full center right))
4357 (save-excursion (unjustify-current-line)))
4359 ;; Choose a fill-prefix automatically.
4360 (when (and adaptive-fill-mode
4361 (or (null fill-prefix) (string= fill-prefix "")))
4363 (fill-context-prefix
4364 (save-excursion (backward-paragraph 1) (point))
4365 (save-excursion (forward-paragraph 1) (point)))))
4366 (and prefix (not (equal prefix ""))
4367 ;; Use auto-indentation rather than a guessed empty prefix.
4368 (not (and fill-indent-according-to-mode
4369 (string-match "\\`[ \t]*\\'" prefix)))
4370 (setq fill-prefix prefix))))
4372 (while (and (not give-up) (> (current-column) fc))
4373 ;; Determine where to split the line.
4378 (setq after-prefix (point))
4380 (looking-at (regexp-quote fill-prefix))
4381 (setq after-prefix (match-end 0)))
4382 (move-to-column (1+ fc))
4383 (fill-move-to-break-point after-prefix)
4386 ;; See whether the place we found is any good.
4388 (goto-char fill-point)
4390 ;; There is no use breaking at end of line.
4391 (save-excursion (skip-chars-forward " ") (eolp))
4392 ;; It is futile to split at the end of the prefix
4393 ;; since we would just insert the prefix again.
4394 (and after-prefix (<= (point) after-prefix))
4395 ;; Don't split right after a comment starter
4396 ;; since we would just make another comment starter.
4397 (and comment-start-skip
4398 (let ((limit (point)))
4400 (and (re-search-forward comment-start-skip
4402 (eq (point) limit))))))
4403 ;; No good place to break => stop trying.
4405 ;; Ok, we have a useful place to break the line. Do it.
4406 (let ((prev-column (current-column)))
4407 ;; If point is at the fill-point, do not `save-excursion'.
4408 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
4409 ;; point will end up before it rather than after it.
4411 (skip-chars-backward " \t")
4412 (= (point) fill-point))
4413 (default-indent-new-line t)
4415 (goto-char fill-point)
4416 (default-indent-new-line t)))
4417 ;; Now do justification, if required
4418 (if (not (eq justify 'left))
4421 (justify-current-line justify nil t)))
4422 ;; If making the new line didn't reduce the hpos of
4423 ;; the end of the line, then give up now;
4424 ;; trying again will not help.
4425 (if (>= (current-column) prev-column)
4426 (setq give-up t))))))
4427 ;; Justify last line.
4428 (justify-current-line justify t t)
4431 (defvar comment-line-break-function 'comment-indent-new-line
4432 "*Mode-specific function which line breaks and continues a comment.
4433 This function is called during auto-filling when a comment syntax
4435 The function should take a single optional argument, which is a flag
4436 indicating whether it should use soft newlines.")
4438 (defun default-indent-new-line (&optional soft)
4439 "Break line at point and indent.
4440 If a comment syntax is defined, call `comment-indent-new-line'.
4442 The inserted newline is marked hard if variable `use-hard-newlines' is true,
4443 unless optional argument SOFT is non-nil."
4446 (funcall comment-line-break-function soft)
4447 ;; Insert the newline before removing empty space so that markers
4448 ;; get preserved better.
4449 (if soft (insert-and-inherit ?\n) (newline 1))
4450 (save-excursion (forward-char -1) (delete-horizontal-space))
4451 (delete-horizontal-space)
4453 (if (and fill-prefix (not adaptive-fill-mode))
4454 ;; Blindly trust a non-adaptive fill-prefix.
4456 (indent-to-left-margin)
4457 (insert-before-markers-and-inherit fill-prefix))
4460 ;; If there's an adaptive prefix, use it unless we're inside
4461 ;; a comment and the prefix is not a comment starter.
4463 (indent-to-left-margin)
4464 (insert-and-inherit fill-prefix))
4465 ;; If we're not inside a comment, just try to indent.
4466 (t (indent-according-to-mode))))))
4468 (defvar normal-auto-fill-function 'do-auto-fill
4469 "The function to use for `auto-fill-function' if Auto Fill mode is turned on.
4470 Some major modes set this.")
4472 (put 'auto-fill-function :minor-mode-function 'auto-fill-mode)
4473 ;; FIXME: turn into a proper minor mode.
4474 ;; Add a global minor mode version of it.
4475 (defun auto-fill-mode (&optional arg)
4476 "Toggle Auto Fill mode.
4477 With arg, turn Auto Fill mode on if and only if arg is positive.
4478 In Auto Fill mode, inserting a space at a column beyond `current-fill-column'
4479 automatically breaks the line at a previous space.
4481 The value of `normal-auto-fill-function' specifies the function to use
4482 for `auto-fill-function' when turning Auto Fill mode on."
4484 (prog1 (setq auto-fill-function
4486 (not auto-fill-function)
4487 (> (prefix-numeric-value arg) 0))
4488 normal-auto-fill-function
4490 (force-mode-line-update)))
4492 ;; This holds a document string used to document auto-fill-mode.
4493 (defun auto-fill-function ()
4494 "Automatically break line at a previous space, in insertion of text."
4497 (defun turn-on-auto-fill ()
4498 "Unconditionally turn on Auto Fill mode."
4501 (defun turn-off-auto-fill ()
4502 "Unconditionally turn off Auto Fill mode."
4503 (auto-fill-mode -1))
4505 (custom-add-option 'text-mode-hook 'turn-on-auto-fill)
4507 (defun set-fill-column (arg)
4508 "Set `fill-column' to specified argument.
4509 Use \\[universal-argument] followed by a number to specify a column.
4510 Just \\[universal-argument] as argument means to use the current column."
4513 (setq arg (current-column)))
4514 (if (not (integerp arg))
4515 ;; Disallow missing argument; it's probably a typo for C-x C-f.
4516 (error "set-fill-column requires an explicit argument")
4517 (message "Fill column set to %d (was %d)" arg fill-column)
4518 (setq fill-column arg)))
4520 (defun set-selective-display (arg)
4521 "Set `selective-display' to ARG; clear it if no arg.
4522 When the value of `selective-display' is a number > 0,
4523 lines whose indentation is >= that value are not displayed.
4524 The variable `selective-display' has a separate value for each buffer."
4526 (if (eq selective-display t)
4527 (error "selective-display already in use for marked lines"))
4530 (narrow-to-region (point-min) (point))
4531 (goto-char (window-start))
4532 (vertical-motion (window-height)))))
4533 (setq selective-display
4534 (and arg (prefix-numeric-value arg)))
4535 (recenter current-vpos))
4536 (set-window-start (selected-window) (window-start (selected-window)))
4537 (princ "selective-display set to " t)
4538 (prin1 selective-display t)
4541 (defvaralias 'indicate-unused-lines 'indicate-empty-lines)
4542 (defvaralias 'default-indicate-unused-lines 'default-indicate-empty-lines)
4544 (defun toggle-truncate-lines (&optional arg)
4545 "Toggle whether to fold or truncate long lines for the current buffer.
4546 With prefix argument ARG, truncate long lines if ARG is positive,
4547 otherwise don't truncate them. Note that in side-by-side
4548 windows, truncation is always enabled."
4550 (setq truncate-lines
4552 (not truncate-lines)
4553 (> (prefix-numeric-value arg) 0)))
4554 (force-mode-line-update)
4555 (unless truncate-lines
4556 (let ((buffer (current-buffer)))
4557 (walk-windows (lambda (window)
4558 (if (eq buffer (window-buffer window))
4559 (set-window-hscroll window 0)))
4561 (message "Truncate long lines %s"
4562 (if truncate-lines "enabled" "disabled")))
4564 (defvar overwrite-mode-textual " Ovwrt"
4565 "The string displayed in the mode line when in overwrite mode.")
4566 (defvar overwrite-mode-binary " Bin Ovwrt"
4567 "The string displayed in the mode line when in binary overwrite mode.")
4569 (defun overwrite-mode (arg)
4570 "Toggle overwrite mode.
4571 With prefix argument ARG, turn overwrite mode on if ARG is positive,
4572 otherwise turn it off. In overwrite mode, printing characters typed
4573 in replace existing text on a one-for-one basis, rather than pushing
4574 it to the right. At the end of a line, such characters extend the line.
4575 Before a tab, such characters insert until the tab is filled in.
4576 \\[quoted-insert] still inserts characters in overwrite mode; this
4577 is supposed to make it easier to insert characters when necessary."
4579 (setq overwrite-mode
4580 (if (if (null arg) (not overwrite-mode)
4581 (> (prefix-numeric-value arg) 0))
4582 'overwrite-mode-textual))
4583 (force-mode-line-update))
4585 (defun binary-overwrite-mode (arg)
4586 "Toggle binary overwrite mode.
4587 With prefix argument ARG, turn binary overwrite mode on if ARG is
4588 positive, otherwise turn it off. In binary overwrite mode, printing
4589 characters typed in replace existing text. Newlines are not treated
4590 specially, so typing at the end of a line joins the line to the next,
4591 with the typed character between them. Typing before a tab character
4592 simply replaces the tab with the character typed. \\[quoted-insert]
4593 replaces the text at the cursor, just as ordinary typing characters do.
4595 Note that binary overwrite mode is not its own minor mode; it is a
4596 specialization of overwrite mode, entered by setting the
4597 `overwrite-mode' variable to `overwrite-mode-binary'."
4599 (setq overwrite-mode
4601 (not (eq overwrite-mode 'overwrite-mode-binary))
4602 (> (prefix-numeric-value arg) 0))
4603 'overwrite-mode-binary))
4604 (force-mode-line-update))
4606 (define-minor-mode line-number-mode
4607 "Toggle Line Number mode.
4608 With arg, turn Line Number mode on if arg is positive, otherwise
4609 turn it off. When Line Number mode is enabled, the line number
4610 appears in the mode line.
4612 Line numbers do not appear for very large buffers and buffers
4613 with very long lines; see variables `line-number-display-limit'
4614 and `line-number-display-limit-width'."
4615 :init-value t :global t :group 'mode-line)
4617 (define-minor-mode column-number-mode
4618 "Toggle Column Number mode.
4619 With arg, turn Column Number mode on if arg is positive,
4620 otherwise turn it off. When Column Number mode is enabled, the
4621 column number appears in the mode line."
4622 :global t :group 'mode-line)
4624 (define-minor-mode size-indication-mode
4625 "Toggle Size Indication mode.
4626 With arg, turn Size Indication mode on if arg is positive,
4627 otherwise turn it off. When Size Indication mode is enabled, the
4628 size of the accessible part of the buffer appears in the mode line."
4629 :global t :group 'mode-line)
4631 (defgroup paren-blinking nil
4632 "Blinking matching of parens and expressions."
4633 :prefix "blink-matching-"
4634 :group 'paren-matching)
4636 (defcustom blink-matching-paren t
4637 "*Non-nil means show matching open-paren when close-paren is inserted."
4639 :group 'paren-blinking)
4641 (defcustom blink-matching-paren-on-screen t
4642 "*Non-nil means show matching open-paren when it is on screen.
4643 If nil, don't show it (but the open-paren can still be shown
4644 when it is off screen).
4646 This variable has no effect if `blink-matching-paren' is nil.
4647 \(In that case, the open-paren is never shown.)
4648 It is also ignored if `show-paren-mode' is enabled."
4650 :group 'paren-blinking)
4652 (defcustom blink-matching-paren-distance (* 25 1024)
4653 "*If non-nil, maximum distance to search backwards for matching open-paren.
4654 If nil, search stops at the beginning of the accessible portion of the buffer."
4655 :type '(choice (const nil) integer)
4656 :group 'paren-blinking)
4658 (defcustom blink-matching-delay 1
4659 "*Time in seconds to delay after showing a matching paren."
4661 :group 'paren-blinking)
4663 (defcustom blink-matching-paren-dont-ignore-comments nil
4664 "*If nil, `blink-matching-paren' ignores comments.
4665 More precisely, when looking for the matching parenthesis,
4666 it skips the contents of comments that end before point."
4668 :group 'paren-blinking)
4670 (defun blink-matching-open ()
4671 "Move cursor momentarily to the beginning of the sexp before point."
4673 (when (and (> (point) (point-min))
4674 blink-matching-paren
4675 ;; Verify an even number of quoting characters precede the close.
4676 (= 1 (logand 1 (- (point)
4679 (skip-syntax-backward "/\\")
4681 (let* ((oldpos (point))
4682 (message-log-max nil) ; Don't log messages about paren matching.
4683 (atdollar (eq (syntax-class (syntax-after (1- oldpos))) 8))
4688 (if blink-matching-paren-distance
4690 (max (minibuffer-prompt-end) ;(point-min) unless minibuf.
4691 (- (point) blink-matching-paren-distance))
4693 (let ((parse-sexp-ignore-comments
4694 (and parse-sexp-ignore-comments
4695 (not blink-matching-paren-dont-ignore-comments))))
4697 (scan-sexps oldpos -1)
4703 (eq (syntax-class (syntax-after blinkpos)) 8)))
4704 (let ((syntax (syntax-after blinkpos)))
4706 (eq (syntax-class syntax) 4)
4710 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00871.html
4711 ((not (or (and isdollar blinkpos)
4712 (and atdollar (not blinkpos)) ; see below
4713 (eq matching-paren (char-before oldpos))
4714 ;; The cdr might hold a new paren-class info rather than
4715 ;; a matching-char info, in which case the two CDRs
4717 (eq matching-paren (cdr (syntax-after (1- oldpos))))))
4718 (message "Mismatched parentheses"))
4720 (or blink-matching-paren-distance
4721 ;; Don't complain when `$' with no blinkpos, because it
4722 ;; could just be the first one typed in the buffer.
4724 (message "Unmatched parenthesis")))
4725 ((pos-visible-in-window-p blinkpos)
4726 ;; Matching open within window, temporarily move to blinkpos but only
4727 ;; if `blink-matching-paren-on-screen' is non-nil.
4728 (and blink-matching-paren-on-screen
4729 (not show-paren-mode)
4731 (goto-char blinkpos)
4732 (sit-for blink-matching-delay))))
4735 (goto-char blinkpos)
4736 (let ((open-paren-line-string
4737 ;; Show what precedes the open in its line, if anything.
4739 ((save-excursion (skip-chars-backward " \t") (not (bolp)))
4740 (buffer-substring (line-beginning-position)
4742 ;; Show what follows the open in its line, if anything.
4745 (skip-chars-forward " \t")
4747 (buffer-substring blinkpos
4748 (line-end-position)))
4749 ;; Otherwise show the previous nonblank line,
4751 ((save-excursion (skip-chars-backward "\n \t") (not (bobp)))
4753 (buffer-substring (progn
4754 (skip-chars-backward "\n \t")
4755 (line-beginning-position))
4756 (progn (end-of-line)
4757 (skip-chars-backward " \t")
4759 ;; Replace the newline and other whitespace with `...'.
4761 (buffer-substring blinkpos (1+ blinkpos))))
4762 ;; There is nothing to show except the char itself.
4763 (t (buffer-substring blinkpos (1+ blinkpos))))))
4764 (message "Matches %s"
4765 (substring-no-properties open-paren-line-string)))))))))
4767 ;; Turned off because it makes dbx bomb out.
4768 (setq blink-paren-function 'blink-matching-open)
4770 ;; This executes C-g typed while Emacs is waiting for a command.
4771 ;; Quitting out of a program does not go through here;
4772 ;; that happens in the QUIT macro at the C code level.
4773 (defun keyboard-quit ()
4774 "Signal a `quit' condition.
4775 During execution of Lisp code, this character causes a quit directly.
4776 At top-level, as an editor command, this simply beeps."
4779 (if (fboundp 'kmacro-keyboard-quit)
4780 (kmacro-keyboard-quit))
4781 (setq defining-kbd-macro nil)
4784 (defvar buffer-quit-function nil
4785 "Function to call to \"quit\" the current buffer, or nil if none.
4786 \\[keyboard-escape-quit] calls this function when its more local actions
4787 \(such as cancelling a prefix argument, minibuffer or region) do not apply.")
4789 (defun keyboard-escape-quit ()
4790 "Exit the current \"mode\" (in a generalized sense of the word).
4791 This command can exit an interactive command such as `query-replace',
4792 can clear out a prefix argument or a region,
4793 can get out of the minibuffer or other recursive edit,
4794 cancel the use of the current buffer (for special-purpose buffers),
4795 or go back to just one window (by deleting all but the selected window)."
4797 (cond ((eq last-command 'mode-exited) nil)
4798 ((> (minibuffer-depth) 0)
4799 (abort-recursive-edit))
4802 ((and transient-mark-mode mark-active)
4804 ((> (recursion-depth) 0)
4805 (exit-recursive-edit))
4806 (buffer-quit-function
4807 (funcall buffer-quit-function))
4808 ((not (one-window-p t))
4809 (delete-other-windows))
4810 ((string-match "^ \\*" (buffer-name (current-buffer)))
4813 (defun play-sound-file (file &optional volume device)
4814 "Play sound stored in FILE.
4815 VOLUME and DEVICE correspond to the keywords of the sound
4816 specification for `play-sound'."
4817 (interactive "fPlay sound file: ")
4818 (let ((sound (list :file file)))
4820 (plist-put sound :volume volume))
4822 (plist-put sound :device device))
4824 (play-sound sound)))
4827 (defcustom read-mail-command 'rmail
4828 "*Your preference for a mail reading package.
4829 This is used by some keybindings which support reading mail.
4830 See also `mail-user-agent' concerning sending mail."
4831 :type '(choice (function-item rmail)
4832 (function-item gnus)
4833 (function-item mh-rmail)
4834 (function :tag "Other"))
4838 (defcustom mail-user-agent 'sendmail-user-agent
4839 "*Your preference for a mail composition package.
4840 Various Emacs Lisp packages (e.g. Reporter) require you to compose an
4841 outgoing email message. This variable lets you specify which
4842 mail-sending package you prefer.
4844 Valid values include:
4846 `sendmail-user-agent' -- use the default Emacs Mail package.
4847 See Info node `(emacs)Sending Mail'.
4848 `mh-e-user-agent' -- use the Emacs interface to the MH mail system.
4849 See Info node `(mh-e)'.
4850 `message-user-agent' -- use the Gnus Message package.
4851 See Info node `(message)'.
4852 `gnus-user-agent' -- like `message-user-agent', but with Gnus
4853 paraphernalia, particularly the Gcc: header for
4856 Additional valid symbols may be available; check with the author of
4857 your package for details. The function should return non-nil if it
4860 See also `read-mail-command' concerning reading mail."
4861 :type '(radio (function-item :tag "Default Emacs mail"
4863 sendmail-user-agent)
4864 (function-item :tag "Emacs interface to MH"
4867 (function-item :tag "Gnus Message package"
4870 (function-item :tag "Gnus Message with full Gnus features"
4873 (function :tag "Other"))
4876 (define-mail-user-agent 'sendmail-user-agent
4877 'sendmail-user-agent-compose
4878 'mail-send-and-exit)
4880 (defun rfc822-goto-eoh ()
4881 ;; Go to header delimiter line in a mail message, following RFC822 rules
4882 (goto-char (point-min))
4883 (when (re-search-forward
4884 "^\\([:\n]\\|[^: \t\n]+[ \t\n]\\)" nil 'move)
4885 (goto-char (match-beginning 0))))
4887 (defun sendmail-user-agent-compose (&optional to subject other-headers continue
4888 switch-function yank-action
4891 (let ((special-display-buffer-names nil)
4892 (special-display-regexps nil)
4893 (same-window-buffer-names nil)
4894 (same-window-regexps nil))
4895 (funcall switch-function "*mail*")))
4896 (let ((cc (cdr (assoc-string "cc" other-headers t)))
4897 (in-reply-to (cdr (assoc-string "in-reply-to" other-headers t)))
4898 (body (cdr (assoc-string "body" other-headers t))))
4899 (or (mail continue to subject in-reply-to cc yank-action send-actions)
4901 (error "Message aborted"))
4904 (while other-headers
4905 (unless (member-ignore-case (car (car other-headers))
4906 '("in-reply-to" "cc" "body"))
4907 (insert (car (car other-headers)) ": "
4908 (cdr (car other-headers))
4909 (if use-hard-newlines hard-newline "\n")))
4910 (setq other-headers (cdr other-headers)))
4916 (defun compose-mail (&optional to subject other-headers continue
4917 switch-function yank-action send-actions)
4918 "Start composing a mail message to send.
4919 This uses the user's chosen mail composition package
4920 as selected with the variable `mail-user-agent'.
4921 The optional arguments TO and SUBJECT specify recipients
4922 and the initial Subject field, respectively.
4924 OTHER-HEADERS is an alist specifying additional
4925 header fields. Elements look like (HEADER . VALUE) where both
4926 HEADER and VALUE are strings.
4928 CONTINUE, if non-nil, says to continue editing a message already
4931 SWITCH-FUNCTION, if non-nil, is a function to use to
4932 switch to and display the buffer used for mail composition.
4934 YANK-ACTION, if non-nil, is an action to perform, if and when necessary,
4935 to insert the raw text of the message being replied to.
4936 It has the form (FUNCTION . ARGS). The user agent will apply
4937 FUNCTION to ARGS, to insert the raw text of the original message.
4938 \(The user agent will also run `mail-citation-hook', *after* the
4939 original text has been inserted in this way.)
4941 SEND-ACTIONS is a list of actions to call when the message is sent.
4942 Each action has the form (FUNCTION . ARGS)."
4944 (list nil nil nil current-prefix-arg))
4945 (let ((function (get mail-user-agent 'composefunc)))
4946 (funcall function to subject other-headers continue
4947 switch-function yank-action send-actions)))
4949 (defun compose-mail-other-window (&optional to subject other-headers continue
4950 yank-action send-actions)
4951 "Like \\[compose-mail], but edit the outgoing message in another window."
4953 (list nil nil nil current-prefix-arg))
4954 (compose-mail to subject other-headers continue
4955 'switch-to-buffer-other-window yank-action send-actions))
4958 (defun compose-mail-other-frame (&optional to subject other-headers continue
4959 yank-action send-actions)
4960 "Like \\[compose-mail], but edit the outgoing message in another frame."
4962 (list nil nil nil current-prefix-arg))
4963 (compose-mail to subject other-headers continue
4964 'switch-to-buffer-other-frame yank-action send-actions))
4966 (defvar set-variable-value-history nil
4967 "History of values entered with `set-variable'.")
4969 (defun set-variable (variable value &optional make-local)
4970 "Set VARIABLE to VALUE. VALUE is a Lisp object.
4971 VARIABLE should be a user option variable name, a Lisp variable
4972 meant to be customized by users. You should enter VALUE in Lisp syntax,
4973 so if you want VALUE to be a string, you must surround it with doublequotes.
4974 VALUE is used literally, not evaluated.
4976 If VARIABLE has a `variable-interactive' property, that is used as if
4977 it were the arg to `interactive' (which see) to interactively read VALUE.
4979 If VARIABLE has been defined with `defcustom', then the type information
4980 in the definition is used to check that VALUE is valid.
4982 With a prefix argument, set VARIABLE to VALUE buffer-locally."
4984 (let* ((default-var (variable-at-point))
4985 (var (if (user-variable-p default-var)
4986 (read-variable (format "Set variable (default %s): " default-var)
4988 (read-variable "Set variable: ")))
4989 (minibuffer-help-form '(describe-variable var))
4990 (prop (get var 'variable-interactive))
4991 (obsolete (car (get var 'byte-obsolete-variable)))
4992 (prompt (format "Set %s %s to value: " var
4993 (cond ((local-variable-p var)
4995 ((or current-prefix-arg
4996 (local-variable-if-set-p var))
5001 (message (concat "`%S' is obsolete; "
5002 (if (symbolp obsolete) "use `%S' instead" "%s"))
5006 ;; Use VAR's `variable-interactive' property
5007 ;; as an interactive spec for prompting.
5008 (call-interactively `(lambda (arg)
5012 (read-string prompt nil
5013 'set-variable-value-history
5014 (format "%S" (symbol-value var))))))))
5015 (list var val current-prefix-arg)))
5017 (and (custom-variable-p variable)
5018 (not (get variable 'custom-type))
5019 (custom-load-symbol variable))
5020 (let ((type (get variable 'custom-type)))
5022 ;; Match with custom type.
5024 (setq type (widget-convert type))
5025 (unless (widget-apply type :match value)
5026 (error "Value `%S' does not match type %S of %S"
5027 value (car type) variable))))
5030 (make-local-variable variable))
5032 (set variable value)
5034 ;; Force a thorough redisplay for the case that the variable
5035 ;; has an effect on the display, like `tab-width' has.
5036 (force-mode-line-update))
5038 ;; Define the major mode for lists of completions.
5040 (defvar completion-list-mode-map nil
5041 "Local map for completion list buffers.")
5042 (or completion-list-mode-map
5043 (let ((map (make-sparse-keymap)))
5044 (define-key map [mouse-2] 'mouse-choose-completion)
5045 (define-key map [follow-link] 'mouse-face)
5046 (define-key map [down-mouse-2] nil)
5047 (define-key map "\C-m" 'choose-completion)
5048 (define-key map "\e\e\e" 'delete-completion-window)
5049 (define-key map [left] 'previous-completion)
5050 (define-key map [right] 'next-completion)
5051 (setq completion-list-mode-map map)))
5053 ;; Completion mode is suitable only for specially formatted data.
5054 (put 'completion-list-mode 'mode-class 'special)
5056 (defvar completion-reference-buffer nil
5057 "Record the buffer that was current when the completion list was requested.
5058 This is a local variable in the completion list buffer.
5059 Initial value is nil to avoid some compiler warnings.")
5061 (defvar completion-no-auto-exit nil
5062 "Non-nil means `choose-completion-string' should never exit the minibuffer.
5063 This also applies to other functions such as `choose-completion'
5064 and `mouse-choose-completion'.")
5066 (defvar completion-base-size nil
5067 "Number of chars at beginning of minibuffer not involved in completion.
5068 This is a local variable in the completion list buffer
5069 but it talks about the buffer in `completion-reference-buffer'.
5070 If this is nil, it means to compare text to determine which part
5071 of the tail end of the buffer's text is involved in completion.")
5073 (defun delete-completion-window ()
5074 "Delete the completion list window.
5075 Go to the window from which completion was requested."
5077 (let ((buf completion-reference-buffer))
5078 (if (one-window-p t)
5079 (if (window-dedicated-p (selected-window))
5080 (delete-frame (selected-frame)))
5081 (delete-window (selected-window))
5082 (if (get-buffer-window buf)
5083 (select-window (get-buffer-window buf))))))
5085 (defun previous-completion (n)
5086 "Move to the previous item in the completion list."
5088 (next-completion (- n)))
5090 (defun next-completion (n)
5091 "Move to the next item in the completion list.
5092 With prefix argument N, move N items (negative N means move backward)."
5094 (let ((beg (point-min)) (end (point-max)))
5095 (while (and (> n 0) (not (eobp)))
5096 ;; If in a completion, move to the end of it.
5097 (when (get-text-property (point) 'mouse-face)
5098 (goto-char (next-single-property-change (point) 'mouse-face nil end)))
5099 ;; Move to start of next one.
5100 (unless (get-text-property (point) 'mouse-face)
5101 (goto-char (next-single-property-change (point) 'mouse-face nil end)))
5103 (while (and (< n 0) (not (bobp)))
5104 (let ((prop (get-text-property (1- (point)) 'mouse-face)))
5105 ;; If in a completion, move to the start of it.
5106 (when (and prop (eq prop (get-text-property (point) 'mouse-face)))
5107 (goto-char (previous-single-property-change
5108 (point) 'mouse-face nil beg)))
5109 ;; Move to end of the previous completion.
5110 (unless (or (bobp) (get-text-property (1- (point)) 'mouse-face))
5111 (goto-char (previous-single-property-change
5112 (point) 'mouse-face nil beg)))
5113 ;; Move to the start of that one.
5114 (goto-char (previous-single-property-change
5115 (point) 'mouse-face nil beg))
5118 (defun choose-completion ()
5119 "Choose the completion that point is in or next to."
5121 (let (beg end completion (buffer completion-reference-buffer)
5122 (base-size completion-base-size))
5123 (if (and (not (eobp)) (get-text-property (point) 'mouse-face))
5124 (setq end (point) beg (1+ (point))))
5125 (if (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face))
5126 (setq end (1- (point)) beg (point)))
5128 (error "No completion here"))
5129 (setq beg (previous-single-property-change beg 'mouse-face))
5130 (setq end (or (next-single-property-change end 'mouse-face) (point-max)))
5131 (setq completion (buffer-substring-no-properties beg end))
5132 (let ((owindow (selected-window)))
5133 (if (and (one-window-p t 'selected-frame)
5134 (window-dedicated-p (selected-window)))
5135 ;; This is a special buffer's frame
5136 (iconify-frame (selected-frame))
5137 (or (window-dedicated-p (selected-window))
5139 (select-window owindow))
5140 (choose-completion-string completion buffer base-size)))
5142 ;; Delete the longest partial match for STRING
5143 ;; that can be found before POINT.
5144 (defun choose-completion-delete-max-match (string)
5145 (let ((opoint (point))
5147 ;; Try moving back by the length of the string.
5148 (goto-char (max (- (point) (length string))
5149 (minibuffer-prompt-end)))
5150 ;; See how far back we were actually able to move. That is the
5151 ;; upper bound on how much we can match and delete.
5152 (setq len (- opoint (point)))
5153 (if completion-ignore-case
5154 (setq string (downcase string)))
5155 (while (and (> len 0)
5156 (let ((tail (buffer-substring (point) opoint)))
5157 (if completion-ignore-case
5158 (setq tail (downcase tail)))
5159 (not (string= tail (substring string 0 len)))))
5164 (defvar choose-completion-string-functions nil
5165 "Functions that may override the normal insertion of a completion choice.
5166 These functions are called in order with four arguments:
5167 CHOICE - the string to insert in the buffer,
5168 BUFFER - the buffer in which the choice should be inserted,
5169 MINI-P - non-nil if BUFFER is a minibuffer, and
5170 BASE-SIZE - the number of characters in BUFFER before
5171 the string being completed.
5173 If a function in the list returns non-nil, that function is supposed
5174 to have inserted the CHOICE in the BUFFER, and possibly exited
5175 the minibuffer; no further functions will be called.
5177 If all functions in the list return nil, that means to use
5178 the default method of inserting the completion in BUFFER.")
5180 (defun choose-completion-string (choice &optional buffer base-size)
5181 "Switch to BUFFER and insert the completion choice CHOICE.
5182 BASE-SIZE, if non-nil, says how many characters of BUFFER's text
5183 to keep. If it is nil, we call `choose-completion-delete-max-match'
5184 to decide what to delete."
5186 ;; If BUFFER is the minibuffer, exit the minibuffer
5187 ;; unless it is reading a file name and CHOICE is a directory,
5188 ;; or completion-no-auto-exit is non-nil.
5190 (let* ((buffer (or buffer completion-reference-buffer))
5191 (mini-p (minibufferp buffer)))
5192 ;; If BUFFER is a minibuffer, barf unless it's the currently
5193 ;; active minibuffer.
5195 (or (not (active-minibuffer-window))
5197 (window-buffer (active-minibuffer-window))))))
5198 (error "Minibuffer is not active for completion")
5199 ;; Set buffer so buffer-local choose-completion-string-functions works.
5201 (unless (run-hook-with-args-until-success
5202 'choose-completion-string-functions
5203 choice buffer mini-p base-size)
5204 ;; Insert the completion into the buffer where it was requested.
5206 (delete-region (+ base-size (if mini-p
5207 (minibuffer-prompt-end)
5210 (choose-completion-delete-max-match choice))
5212 (remove-text-properties (- (point) (length choice)) (point)
5214 ;; Update point in the window that BUFFER is showing in.
5215 (let ((window (get-buffer-window buffer t)))
5216 (set-window-point window (point)))
5217 ;; If completing for the minibuffer, exit it with this choice.
5218 (and (not completion-no-auto-exit)
5219 (equal buffer (window-buffer (minibuffer-window)))
5220 minibuffer-completion-table
5221 ;; If this is reading a file name, and the file name chosen
5222 ;; is a directory, don't exit the minibuffer.
5223 (if (and (eq minibuffer-completion-table 'read-file-name-internal)
5224 (file-directory-p (field-string (point-max))))
5225 (let ((mini (active-minibuffer-window)))
5226 (select-window mini)
5227 (when minibuffer-auto-raise
5228 (raise-frame (window-frame mini))))
5229 (exit-minibuffer)))))))
5231 (defun completion-list-mode ()
5232 "Major mode for buffers showing lists of possible completions.
5233 Type \\<completion-list-mode-map>\\[choose-completion] in the completion list\
5234 to select the completion near point.
5235 Use \\<completion-list-mode-map>\\[mouse-choose-completion] to select one\
5238 (kill-all-local-variables)
5239 (use-local-map completion-list-mode-map)
5240 (setq mode-name "Completion List")
5241 (setq major-mode 'completion-list-mode)
5242 (make-local-variable 'completion-base-size)
5243 (setq completion-base-size nil)
5244 (run-mode-hooks 'completion-list-mode-hook))
5246 (defun completion-list-mode-finish ()
5247 "Finish setup of the completions buffer.
5248 Called from `temp-buffer-show-hook'."
5249 (when (eq major-mode 'completion-list-mode)
5250 (toggle-read-only 1)))
5252 (add-hook 'temp-buffer-show-hook 'completion-list-mode-finish)
5254 (defvar completion-setup-hook nil
5255 "Normal hook run at the end of setting up a completion list buffer.
5256 When this hook is run, the current buffer is the one in which the
5257 command to display the completion list buffer was run.
5258 The completion list buffer is available as the value of `standard-output'.
5259 The common prefix substring for completion may be available as the
5260 value of `completion-common-substring'. See also `display-completion-list'.")
5263 ;; Variables and faces used in `completion-setup-function'.
5265 (defcustom completion-show-help t
5266 "Non-nil means show help message in *Completions* buffer."
5271 (defface completions-first-difference
5272 '((t (:inherit bold)))
5273 "Face put on the first uncommon character in completions in *Completions* buffer."
5276 (defface completions-common-part
5277 '((t (:inherit default)))
5278 "Face put on the common prefix substring in completions in *Completions* buffer.
5279 The idea of `completions-common-part' is that you can use it to
5280 make the common parts less visible than normal, so that the rest
5281 of the differing parts is, by contrast, slightly highlighted."
5284 ;; This is for packages that need to bind it to a non-default regexp
5285 ;; in order to make the first-differing character highlight work
5287 (defvar completion-root-regexp "^/"
5288 "Regexp to use in `completion-setup-function' to find the root directory.")
5290 (defvar completion-common-substring nil
5291 "Common prefix substring to use in `completion-setup-function' to put faces.
5292 The value is set by `display-completion-list' during running `completion-setup-hook'.
5294 To put faces `completions-first-difference' and `completions-common-part'
5295 in the `*Completions*' buffer, the common prefix substring in completions
5296 is needed as a hint. (The minibuffer is a special case. The content
5297 of the minibuffer before point is always the common substring.)")
5299 ;; This function goes in completion-setup-hook, so that it is called
5300 ;; after the text of the completion list buffer is written.
5301 (defun completion-setup-function ()
5302 (let* ((mainbuf (current-buffer))
5303 (mbuf-contents (minibuffer-completion-contents))
5304 common-string-length)
5305 ;; When reading a file name in the minibuffer,
5306 ;; set default-directory in the minibuffer
5307 ;; so it will get copied into the completion list buffer.
5308 (if minibuffer-completing-file-name
5309 (with-current-buffer mainbuf
5310 (setq default-directory
5311 (file-name-directory (expand-file-name mbuf-contents)))))
5312 (with-current-buffer standard-output
5313 (completion-list-mode)
5314 (set (make-local-variable 'completion-reference-buffer) mainbuf)
5315 (setq completion-base-size
5317 ((and (symbolp minibuffer-completion-table)
5318 (get minibuffer-completion-table 'completion-base-size-function))
5319 ;; To compute base size, a function can use the global value of
5320 ;; completion-common-substring or minibuffer-completion-contents.
5321 (with-current-buffer mainbuf
5322 (funcall (get minibuffer-completion-table
5323 'completion-base-size-function))))
5324 (minibuffer-completing-file-name
5325 ;; For file name completion, use the number of chars before
5326 ;; the start of the file name component at point.
5327 (with-current-buffer mainbuf
5329 (skip-chars-backward completion-root-regexp)
5330 (- (point) (minibuffer-prompt-end)))))
5331 (minibuffer-completing-symbol nil)
5332 ;; Otherwise, in minibuffer, the base size is 0.
5333 ((minibufferp mainbuf) 0)))
5334 (setq common-string-length
5336 (completion-common-substring
5337 (length completion-common-substring))
5338 (completion-base-size
5339 (- (length mbuf-contents) completion-base-size))))
5340 ;; Put faces on first uncommon characters and common parts.
5341 (when (and (integerp common-string-length) (>= common-string-length 0))
5342 (let ((element-start (point-min))
5345 (while (and (setq element-start
5346 (next-single-property-change
5347 element-start 'mouse-face))
5348 (< (setq element-common-end
5349 (+ element-start common-string-length))
5351 (when (get-char-property element-start 'mouse-face)
5352 (if (and (> common-string-length 0)
5353 (get-char-property (1- element-common-end) 'mouse-face))
5354 (put-text-property element-start element-common-end
5355 'font-lock-face 'completions-common-part))
5356 (if (get-char-property element-common-end 'mouse-face)
5357 (put-text-property element-common-end (1+ element-common-end)
5358 'font-lock-face 'completions-first-difference))))))
5359 ;; Maybe insert help string.
5360 (when completion-show-help
5361 (goto-char (point-min))
5362 (if (display-mouse-p)
5363 (insert (substitute-command-keys
5364 "Click \\[mouse-choose-completion] on a completion to select it.\n")))
5365 (insert (substitute-command-keys
5366 "In this buffer, type \\[choose-completion] to \
5367 select the completion near point.\n\n"))))))
5369 (add-hook 'completion-setup-hook 'completion-setup-function)
5371 (define-key minibuffer-local-completion-map [prior] 'switch-to-completions)
5372 (define-key minibuffer-local-completion-map "\M-v" 'switch-to-completions)
5374 (defun switch-to-completions ()
5375 "Select the completion list window."
5377 ;; Make sure we have a completions window.
5378 (or (get-buffer-window "*Completions*")
5379 (minibuffer-completion-help))
5380 (let ((window (get-buffer-window "*Completions*")))
5382 (select-window window)
5383 (goto-char (point-min))
5384 (search-forward "\n\n" nil t)
5387 ;;; Support keyboard commands to turn on various modifiers.
5389 ;; These functions -- which are not commands -- each add one modifier
5390 ;; to the following event.
5392 (defun event-apply-alt-modifier (ignore-prompt)
5393 "\\<function-key-map>Add the Alt modifier to the following event.
5394 For example, type \\[event-apply-alt-modifier] & to enter Alt-&."
5395 (vector (event-apply-modifier (read-event) 'alt 22 "A-")))
5396 (defun event-apply-super-modifier (ignore-prompt)
5397 "\\<function-key-map>Add the Super modifier to the following event.
5398 For example, type \\[event-apply-super-modifier] & to enter Super-&."
5399 (vector (event-apply-modifier (read-event) 'super 23 "s-")))
5400 (defun event-apply-hyper-modifier (ignore-prompt)
5401 "\\<function-key-map>Add the Hyper modifier to the following event.
5402 For example, type \\[event-apply-hyper-modifier] & to enter Hyper-&."
5403 (vector (event-apply-modifier (read-event) 'hyper 24 "H-")))
5404 (defun event-apply-shift-modifier (ignore-prompt)
5405 "\\<function-key-map>Add the Shift modifier to the following event.
5406 For example, type \\[event-apply-shift-modifier] & to enter Shift-&."
5407 (vector (event-apply-modifier (read-event) 'shift 25 "S-")))
5408 (defun event-apply-control-modifier (ignore-prompt)
5409 "\\<function-key-map>Add the Ctrl modifier to the following event.
5410 For example, type \\[event-apply-control-modifier] & to enter Ctrl-&."
5411 (vector (event-apply-modifier (read-event) 'control 26 "C-")))
5412 (defun event-apply-meta-modifier (ignore-prompt)
5413 "\\<function-key-map>Add the Meta modifier to the following event.
5414 For example, type \\[event-apply-meta-modifier] & to enter Meta-&."
5415 (vector (event-apply-modifier (read-event) 'meta 27 "M-")))
5417 (defun event-apply-modifier (event symbol lshiftby prefix)
5418 "Apply a modifier flag to event EVENT.
5419 SYMBOL is the name of this modifier, as a symbol.
5420 LSHIFTBY is the numeric value of this modifier, in keyboard events.
5421 PREFIX is the string that represents this modifier in an event type symbol."
5423 (cond ((eq symbol 'control)
5424 (if (and (<= (downcase event) ?z)
5425 (>= (downcase event) ?a))
5426 (- (downcase event) ?a -1)
5427 (if (and (<= (downcase event) ?Z)
5428 (>= (downcase event) ?A))
5429 (- (downcase event) ?A -1)
5430 (logior (lsh 1 lshiftby) event))))
5432 (if (and (<= (downcase event) ?z)
5433 (>= (downcase event) ?a))
5435 (logior (lsh 1 lshiftby) event)))
5437 (logior (lsh 1 lshiftby) event)))
5438 (if (memq symbol (event-modifiers event))
5440 (let ((event-type (if (symbolp event) event (car event))))
5441 (setq event-type (intern (concat prefix (symbol-name event-type))))
5444 (cons event-type (cdr event)))))))
5446 (define-key function-key-map [?\C-x ?@ ?h] 'event-apply-hyper-modifier)
5447 (define-key function-key-map [?\C-x ?@ ?s] 'event-apply-super-modifier)
5448 (define-key function-key-map [?\C-x ?@ ?m] 'event-apply-meta-modifier)
5449 (define-key function-key-map [?\C-x ?@ ?a] 'event-apply-alt-modifier)
5450 (define-key function-key-map [?\C-x ?@ ?S] 'event-apply-shift-modifier)
5451 (define-key function-key-map [?\C-x ?@ ?c] 'event-apply-control-modifier)
5453 ;;;; Keypad support.
5455 ;; Make the keypad keys act like ordinary typing keys. If people add
5456 ;; bindings for the function key symbols, then those bindings will
5457 ;; override these, so this shouldn't interfere with any existing
5460 ;; Also tell read-char how to handle these keys.
5462 (lambda (keypad-normal)
5463 (let ((keypad (nth 0 keypad-normal))
5464 (normal (nth 1 keypad-normal)))
5465 (put keypad 'ascii-character normal)
5466 (define-key function-key-map (vector keypad) (vector normal))))
5467 '((kp-0 ?0) (kp-1 ?1) (kp-2 ?2) (kp-3 ?3) (kp-4 ?4)
5468 (kp-5 ?5) (kp-6 ?6) (kp-7 ?7) (kp-8 ?8) (kp-9 ?9)
5481 ;;;; forking a twin copy of a buffer.
5484 (defvar clone-buffer-hook nil
5485 "Normal hook to run in the new buffer at the end of `clone-buffer'.")
5487 (defun clone-process (process &optional newname)
5488 "Create a twin copy of PROCESS.
5489 If NEWNAME is nil, it defaults to PROCESS' name;
5490 NEWNAME is modified by adding or incrementing <N> at the end as necessary.
5491 If PROCESS is associated with a buffer, the new process will be associated
5492 with the current buffer instead.
5493 Returns nil if PROCESS has already terminated."
5494 (setq newname (or newname (process-name process)))
5495 (if (string-match "<[0-9]+>\\'" newname)
5496 (setq newname (substring newname 0 (match-beginning 0))))
5497 (when (memq (process-status process) '(run stop open))
5498 (let* ((process-connection-type (process-tty-name process))
5500 (if (memq (process-status process) '(open))
5501 (let ((args (process-contact process t)))
5502 (setq args (plist-put args :name newname))
5503 (setq args (plist-put args :buffer
5504 (if (process-buffer process)
5506 (apply 'make-network-process args))
5507 (apply 'start-process newname
5508 (if (process-buffer process) (current-buffer))
5509 (process-command process)))))
5510 (set-process-query-on-exit-flag
5511 new-process (process-query-on-exit-flag process))
5512 (set-process-inherit-coding-system-flag
5513 new-process (process-inherit-coding-system-flag process))
5514 (set-process-filter new-process (process-filter process))
5515 (set-process-sentinel new-process (process-sentinel process))
5516 (set-process-plist new-process (copy-sequence (process-plist process)))
5519 ;; things to maybe add (currently partly covered by `funcall mode'):
5522 (defun clone-buffer (&optional newname display-flag)
5523 "Create and return a twin copy of the current buffer.
5524 Unlike an indirect buffer, the new buffer can be edited
5525 independently of the old one (if it is not read-only).
5526 NEWNAME is the name of the new buffer. It may be modified by
5527 adding or incrementing <N> at the end as necessary to create a
5528 unique buffer name. If nil, it defaults to the name of the
5529 current buffer, with the proper suffix. If DISPLAY-FLAG is
5530 non-nil, the new buffer is shown with `pop-to-buffer'. Trying to
5531 clone a file-visiting buffer, or a buffer whose major mode symbol
5532 has a non-nil `no-clone' property, results in an error.
5534 Interactively, DISPLAY-FLAG is t and NEWNAME is the name of the
5535 current buffer with appropriate suffix. However, if a prefix
5536 argument is given, then the command prompts for NEWNAME in the
5539 This runs the normal hook `clone-buffer-hook' in the new buffer
5540 after it has been set up properly in other respects."
5543 (if buffer-file-name
5544 (error "Cannot clone a file-visiting buffer"))
5545 (if (get major-mode 'no-clone)
5546 (error "Cannot clone a buffer in %s mode" mode-name))
5547 (list (if current-prefix-arg
5548 (read-buffer "Name of new cloned buffer: " (current-buffer)))
5550 (if buffer-file-name
5551 (error "Cannot clone a file-visiting buffer"))
5552 (if (get major-mode 'no-clone)
5553 (error "Cannot clone a buffer in %s mode" mode-name))
5554 (setq newname (or newname (buffer-name)))
5555 (if (string-match "<[0-9]+>\\'" newname)
5556 (setq newname (substring newname 0 (match-beginning 0))))
5557 (let ((buf (current-buffer))
5561 (mk (if mark-active (mark t)))
5562 (modified (buffer-modified-p))
5564 (lvars (buffer-local-variables))
5565 (process (get-buffer-process (current-buffer)))
5566 (new (generate-new-buffer (or newname (buffer-name)))))
5569 (with-current-buffer new
5570 (insert-buffer-substring buf)))
5571 (with-current-buffer new
5572 (narrow-to-region ptmin ptmax)
5574 (if mk (set-mark mk))
5575 (set-buffer-modified-p modified)
5577 ;; Clone the old buffer's process, if any.
5578 (when process (clone-process process))
5580 ;; Now set up the major mode.
5583 ;; Set up other local variables.
5585 (condition-case () ;in case var is read-only
5588 (set (make-local-variable (car v)) (cdr v)))
5592 ;; Run any hooks (typically set up by the major mode
5593 ;; for cloning to work properly).
5594 (run-hooks 'clone-buffer-hook))
5596 ;; Presumably the current buffer is shown in the selected frame, so
5597 ;; we want to display the clone elsewhere.
5598 (let ((same-window-regexps nil)
5599 (same-window-buffer-names))
5600 (pop-to-buffer new)))
5604 (defun clone-indirect-buffer (newname display-flag &optional norecord)
5605 "Create an indirect buffer that is a twin copy of the current buffer.
5607 Give the indirect buffer name NEWNAME. Interactively, read NEWNAME
5608 from the minibuffer when invoked with a prefix arg. If NEWNAME is nil
5609 or if not called with a prefix arg, NEWNAME defaults to the current
5610 buffer's name. The name is modified by adding a `<N>' suffix to it
5611 or by incrementing the N in an existing suffix.
5613 DISPLAY-FLAG non-nil means show the new buffer with `pop-to-buffer'.
5614 This is always done when called interactively.
5616 Optional third arg NORECORD non-nil means do not put this buffer at the
5617 front of the list of recently selected ones."
5620 (if (get major-mode 'no-clone-indirect)
5621 (error "Cannot indirectly clone a buffer in %s mode" mode-name))
5622 (list (if current-prefix-arg
5623 (read-buffer "Name of indirect buffer: " (current-buffer)))
5625 (if (get major-mode 'no-clone-indirect)
5626 (error "Cannot indirectly clone a buffer in %s mode" mode-name))
5627 (setq newname (or newname (buffer-name)))
5628 (if (string-match "<[0-9]+>\\'" newname)
5629 (setq newname (substring newname 0 (match-beginning 0))))
5630 (let* ((name (generate-new-buffer-name newname))
5631 (buffer (make-indirect-buffer (current-buffer) name t)))
5633 (pop-to-buffer buffer norecord))
5637 (defun clone-indirect-buffer-other-window (newname display-flag &optional norecord)
5638 "Like `clone-indirect-buffer' but display in another window."
5641 (if (get major-mode 'no-clone-indirect)
5642 (error "Cannot indirectly clone a buffer in %s mode" mode-name))
5643 (list (if current-prefix-arg
5644 (read-buffer "Name of indirect buffer: " (current-buffer)))
5646 (let ((pop-up-windows t))
5647 (clone-indirect-buffer newname display-flag norecord)))
5650 ;;; Handling of Backspace and Delete keys.
5652 (defcustom normal-erase-is-backspace 'maybe
5653 "Set the default behaviour of the Delete and Backspace keys.
5655 If set to t, Delete key deletes forward and Backspace key deletes
5658 If set to nil, both Delete and Backspace keys delete backward.
5660 If set to 'maybe (which is the default), Emacs automatically
5661 selects a behaviour. On window systems, the behaviour depends on
5662 the keyboard used. If the keyboard has both a Backspace key and
5663 a Delete key, and both are mapped to their usual meanings, the
5664 option's default value is set to t, so that Backspace can be used
5665 to delete backward, and Delete can be used to delete forward.
5667 If not running under a window system, customizing this option
5668 accomplishes a similar effect by mapping C-h, which is usually
5669 generated by the Backspace key, to DEL, and by mapping DEL to C-d
5670 via `keyboard-translate'. The former functionality of C-h is
5671 available on the F1 key. You should probably not use this
5672 setting if you don't have both Backspace, Delete and F1 keys.
5674 Setting this variable with setq doesn't take effect. Programmatically,
5675 call `normal-erase-is-backspace-mode' (which see) instead."
5676 :type '(choice (const :tag "Off" nil)
5677 (const :tag "Maybe" maybe)
5678 (other :tag "On" t))
5679 :group 'editing-basics
5681 :set (lambda (symbol value)
5682 ;; The fboundp is because of a problem with :set when
5683 ;; dumping Emacs. It doesn't really matter.
5684 (if (fboundp 'normal-erase-is-backspace-mode)
5685 (normal-erase-is-backspace-mode (or value 0))
5686 (set-default symbol value))))
5688 (defun normal-erase-is-backspace-setup-frame (&optional frame)
5689 "Set up `normal-erase-is-backspace-mode' on FRAME, if necessary."
5690 (unless frame (setq frame (selected-frame)))
5691 (with-selected-frame frame
5692 (unless (terminal-parameter nil 'normal-erase-is-backspace)
5693 (normal-erase-is-backspace-mode
5694 (if (if (eq normal-erase-is-backspace 'maybe)
5695 (and (not noninteractive)
5696 (or (memq system-type '(ms-dos windows-nt))
5697 (eq window-system 'mac)
5698 (and (memq window-system '(x))
5699 (fboundp 'x-backspace-delete-keys-p)
5700 (x-backspace-delete-keys-p))
5701 ;; If the terminal Emacs is running on has erase char
5702 ;; set to ^H, use the Backspace key for deleting
5703 ;; backward, and the Delete key for deleting forward.
5704 (and (null window-system)
5705 (eq tty-erase-char ?\^H))))
5706 normal-erase-is-backspace)
5709 (defun normal-erase-is-backspace-mode (&optional arg)
5710 "Toggle the Erase and Delete mode of the Backspace and Delete keys.
5712 With numeric arg, turn the mode on if and only if ARG is positive.
5714 On window systems, when this mode is on, Delete is mapped to C-d
5715 and Backspace is mapped to DEL; when this mode is off, both
5716 Delete and Backspace are mapped to DEL. (The remapping goes via
5717 `local-function-key-map', so binding Delete or Backspace in the
5718 global or local keymap will override that.)
5720 In addition, on window systems, the bindings of C-Delete, M-Delete,
5721 C-M-Delete, C-Backspace, M-Backspace, and C-M-Backspace are changed in
5722 the global keymap in accordance with the functionality of Delete and
5723 Backspace. For example, if Delete is remapped to C-d, which deletes
5724 forward, C-Delete is bound to `kill-word', but if Delete is remapped
5725 to DEL, which deletes backward, C-Delete is bound to
5726 `backward-kill-word'.
5728 If not running on a window system, a similar effect is accomplished by
5729 remapping C-h (normally produced by the Backspace key) and DEL via
5730 `keyboard-translate': if this mode is on, C-h is mapped to DEL and DEL
5731 to C-d; if it's off, the keys are not remapped.
5733 When not running on a window system, and this mode is turned on, the
5734 former functionality of C-h is available on the F1 key. You should
5735 probably not turn on this mode on a text-only terminal if you don't
5736 have both Backspace, Delete and F1 keys.
5738 See also `normal-erase-is-backspace'."
5740 (let ((enabled (or (and arg (> (prefix-numeric-value arg) 0))
5742 (not (eq 1 (terminal-parameter
5743 nil 'normal-erase-is-backspace)))))))
5744 (set-terminal-parameter nil 'normal-erase-is-backspace
5747 (cond ((or (memq window-system '(x w32 mac pc))
5748 (memq system-type '(ms-dos windows-nt)))
5750 `(([C-delete] [C-backspace])
5751 ([M-delete] [M-backspace])
5752 ([C-M-delete] [C-M-backspace])
5754 [C-delete] [C-backspace])))
5755 (old-state (lookup-key local-function-key-map [delete])))
5759 (define-key local-function-key-map [delete] [?\C-d])
5760 (define-key local-function-key-map [kp-delete] [?\C-d])
5761 (define-key local-function-key-map [backspace] [?\C-?]))
5762 (define-key local-function-key-map [delete] [?\C-?])
5763 (define-key local-function-key-map [kp-delete] [?\C-?])
5764 (define-key local-function-key-map [backspace] [?\C-?]))
5766 ;; Maybe swap bindings of C-delete and C-backspace, etc.
5767 (unless (equal old-state (lookup-key local-function-key-map [delete]))
5768 (dolist (binding bindings)
5769 (let ((map global-map))
5770 (when (keymapp (car binding))
5771 (setq map (car binding) binding (cdr binding)))
5772 (let* ((key1 (nth 0 binding))
5773 (key2 (nth 1 binding))
5774 (binding1 (lookup-key map key1))
5775 (binding2 (lookup-key map key2)))
5776 (define-key map key1 binding2)
5777 (define-key map key2 binding1)))))))
5781 (keyboard-translate ?\C-h ?\C-?)
5782 (keyboard-translate ?\C-? ?\C-d))
5783 (keyboard-translate ?\C-h ?\C-h)
5784 (keyboard-translate ?\C-? ?\C-?))))
5786 (run-hooks 'normal-erase-is-backspace-hook)
5788 (message "Delete key deletes %s"
5789 (if (terminal-parameter nil 'normal-erase-is-backspace)
5790 "forward" "backward")))))
5792 (defvar vis-mode-saved-buffer-invisibility-spec nil
5793 "Saved value of `buffer-invisibility-spec' when Visible mode is on.")
5795 (define-minor-mode visible-mode
5796 "Toggle Visible mode.
5797 With argument ARG turn Visible mode on if ARG is positive, otherwise
5800 Enabling Visible mode makes all invisible text temporarily visible.
5801 Disabling Visible mode turns off that effect. Visible mode
5802 works by saving the value of `buffer-invisibility-spec' and setting it to nil."
5804 :group 'editing-basics
5805 (when (local-variable-p 'vis-mode-saved-buffer-invisibility-spec)
5806 (setq buffer-invisibility-spec vis-mode-saved-buffer-invisibility-spec)
5807 (kill-local-variable 'vis-mode-saved-buffer-invisibility-spec))
5809 (set (make-local-variable 'vis-mode-saved-buffer-invisibility-spec)
5810 buffer-invisibility-spec)
5811 (setq buffer-invisibility-spec nil)))
5813 ;; Minibuffer prompt stuff.
5815 ;(defun minibuffer-prompt-modification (start end)
5816 ; (error "You cannot modify the prompt"))
5819 ;(defun minibuffer-prompt-insertion (start end)
5820 ; (let ((inhibit-modification-hooks t))
5821 ; (delete-region start end)
5822 ; ;; Discard undo information for the text insertion itself
5823 ; ;; and for the text deletion.above.
5824 ; (when (consp buffer-undo-list)
5825 ; (setq buffer-undo-list (cddr buffer-undo-list)))
5826 ; (message "You cannot modify the prompt")))
5829 ;(setq minibuffer-prompt-properties
5830 ; (list 'modification-hooks '(minibuffer-prompt-modification)
5831 ; 'insert-in-front-hooks '(minibuffer-prompt-insertion)))
5835 ;;;; Problematic external packages.
5837 ;; rms says this should be done by specifying symbols that define
5838 ;; versions together with bad values. This is therefore not as
5839 ;; flexible as it could be. See the thread:
5840 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00300.html
5841 (defconst bad-packages-alist
5842 ;; Not sure exactly which semantic versions have problems.
5843 ;; Definitely 2.0pre3, probably all 2.0pre's before this.
5844 '((semantic semantic-version "2\\.0pre[1-3]"
5845 "The version of `semantic' loaded does not work in Emacs 22.
5846 It can cause constant high CPU load.
5847 Upgrade to at least Semantic 2.0pre4 (distributed with CEDET 1.0pre4).")
5848 ;; CUA-mode does not work with GNU Emacs version 22.1 and newer.
5849 ;; Except for version 1.2, all of the 1.x and 2.x version of cua-mode
5850 ;; provided the `CUA-mode' feature. Since this is no longer true,
5851 ;; we can warn the user if the `CUA-mode' feature is ever provided.
5853 "CUA-mode is now part of the standard GNU Emacs distribution,
5854 so you can now enable CUA via the Options menu or by customizing `cua-mode'.
5856 You have loaded an older version of CUA-mode which does not work
5857 correctly with this version of Emacs. You should remove the old
5858 version and use the one distributed with Emacs."))
5859 "Alist of packages known to cause problems in this version of Emacs.
5860 Each element has the form (PACKAGE SYMBOL REGEXP STRING).
5861 PACKAGE is either a regular expression to match file names, or a
5862 symbol (a feature name); see the documentation of
5863 `after-load-alist', to which this variable adds functions.
5864 SYMBOL is either the name of a string variable, or `t'. Upon
5865 loading PACKAGE, if SYMBOL is t or matches REGEXP, display a
5866 warning using STRING as the message.")
5868 (defun bad-package-check (package)
5869 "Run a check using the element from `bad-packages-alist' matching PACKAGE."
5871 (let* ((list (assoc package bad-packages-alist))
5872 (symbol (nth 1 list)))
5876 (and (stringp (setq symbol (eval symbol)))
5877 (string-match (nth 2 list) symbol)))
5878 (display-warning :warning (nth 3 list))))
5881 (mapc (lambda (elem)
5882 (eval-after-load (car elem) `(bad-package-check ',(car elem))))
5888 ;; arch-tag: 24af67c0-2a49-44f6-b3b1-312d8b570dfd
5889 ;;; simple.el ends here