(jka-compr-handler): Save match data.
[emacs.git] / lisp / simple.el
blobc0365c24c3b8a07b49917d6fb032031df1d85ed7
1 ;;; simple.el --- basic editing commands for Emacs
3 ;; Copyright (C) 1985, 1986, 1987, 1993, 1994 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; any later version.
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 ;;; Commentary:
23 ;; A grab-bag of basic Emacs commands not specifically related to some
24 ;; major mode or to file-handling.
26 ;;; Code:
28 (defun open-line (arg)
29 "Insert a newline and leave point before it.
30 If there is a fill prefix, insert the fill prefix on the new line
31 if the line would have been empty.
32 With arg N, insert N newlines."
33 (interactive "*p")
34 (let* ((do-fill-prefix (and fill-prefix (bolp)))
35 (flag (and (null do-fill-prefix) (bolp) (not (bobp)))))
36 ;; If this is a simple case, and we are at the beginning of a line,
37 ;; actually insert the newline *before* the preceding newline
38 ;; instead of after. That makes better display behavior.
39 (if flag
40 (progn
41 ;; If undo is enabled, don't let this hack be visible:
42 ;; record the real value of point as the place to move back to
43 ;; if we undo this insert.
44 (if (not (eq buffer-undo-list t))
45 (setq buffer-undo-list (cons (point) buffer-undo-list)))
46 (forward-char -1)))
47 (save-excursion
48 (while (> arg 0)
49 (if do-fill-prefix (insert fill-prefix))
50 (insert ?\n)
51 (setq arg (1- arg))))
52 (end-of-line)
53 (if flag (forward-char 1))))
55 (defun split-line ()
56 "Split current line, moving portion beyond point vertically down."
57 (interactive "*")
58 (skip-chars-forward " \t")
59 (let ((col (current-column))
60 (pos (point)))
61 (insert ?\n)
62 (indent-to col 0)
63 (goto-char pos)))
65 (defun quoted-insert (arg)
66 "Read next input character and insert it.
67 This is useful for inserting control characters.
68 You may also type up to 3 octal digits, to insert a character with that code.
70 In overwrite mode, this function inserts the character anyway, and
71 does not handle octal digits specially. This means that if you use
72 overwrite as your normal editing mode, you can use this function to
73 insert characters when necessary.
75 In binary overwrite mode, this function does overwrite, and octal
76 digits are interpreted as a character code. This is supposed to make
77 this function useful in editing binary files."
78 (interactive "*p")
79 (let ((char (if (or (not overwrite-mode)
80 (eq overwrite-mode 'overwrite-mode-binary))
81 (read-quoted-char)
82 (read-char))))
83 (if (eq overwrite-mode 'overwrite-mode-binary)
84 (delete-char arg))
85 ;; Turn a meta-character into a character with the 0200 bit set.
86 (if (/= (logand last-input-char (lsh 1 23)) 0)
87 (setq char (logior char 128)))
88 (insert-char char arg)))
90 (defun delete-indentation (&optional arg)
91 "Join this line to previous and fix up whitespace at join.
92 If there is a fill prefix, delete it from the beginning of this line.
93 With argument, join this line to following line."
94 (interactive "*P")
95 (beginning-of-line)
96 (if arg (forward-line 1))
97 (if (eq (preceding-char) ?\n)
98 (progn
99 (delete-region (point) (1- (point)))
100 ;; If the second line started with the fill prefix,
101 ;; delete the prefix.
102 (if (and fill-prefix
103 (<= (+ (point) (length fill-prefix)) (point-max))
104 (string= fill-prefix
105 (buffer-substring (point)
106 (+ (point) (length fill-prefix)))))
107 (delete-region (point) (+ (point) (length fill-prefix))))
108 (fixup-whitespace))))
110 (defun fixup-whitespace ()
111 "Fixup white space between objects around point.
112 Leave one space or none, according to the context."
113 (interactive "*")
114 (save-excursion
115 (delete-horizontal-space)
116 (if (or (looking-at "^\\|\\s)")
117 (save-excursion (forward-char -1)
118 (looking-at "$\\|\\s(\\|\\s'")))
120 (insert ?\ ))))
122 (defun delete-horizontal-space ()
123 "Delete all spaces and tabs around point."
124 (interactive "*")
125 (skip-chars-backward " \t")
126 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
128 (defun just-one-space ()
129 "Delete all spaces and tabs around point, leaving one space."
130 (interactive "*")
131 (skip-chars-backward " \t")
132 (if (= (following-char) ? )
133 (forward-char 1)
134 (insert ? ))
135 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
137 (defun delete-blank-lines ()
138 "On blank line, delete all surrounding blank lines, leaving just one.
139 On isolated blank line, delete that one.
140 On nonblank line, delete all blank lines that follow it."
141 (interactive "*")
142 (let (thisblank singleblank)
143 (save-excursion
144 (beginning-of-line)
145 (setq thisblank (looking-at "[ \t]*$"))
146 ;; Set singleblank if there is just one blank line here.
147 (setq singleblank
148 (and thisblank
149 (not (looking-at "[ \t]*\n[ \t]*$"))
150 (or (bobp)
151 (progn (forward-line -1)
152 (not (looking-at "[ \t]*$")))))))
153 ;; Delete preceding blank lines, and this one too if it's the only one.
154 (if thisblank
155 (progn
156 (beginning-of-line)
157 (if singleblank (forward-line 1))
158 (delete-region (point)
159 (if (re-search-backward "[^ \t\n]" nil t)
160 (progn (forward-line 1) (point))
161 (point-min)))))
162 ;; Delete following blank lines, unless the current line is blank
163 ;; and there are no following blank lines.
164 (if (not (and thisblank singleblank))
165 (save-excursion
166 (end-of-line)
167 (forward-line 1)
168 (delete-region (point)
169 (if (re-search-forward "[^ \t\n]" nil t)
170 (progn (beginning-of-line) (point))
171 (point-max)))))
172 ;; Handle the special case where point is followed by newline and eob.
173 ;; Delete the line, leaving point at eob.
174 (if (looking-at "^[ \t]*\n\\'")
175 (delete-region (point) (point-max)))))
177 (defun back-to-indentation ()
178 "Move point to the first non-whitespace character on this line."
179 (interactive)
180 (beginning-of-line 1)
181 (skip-chars-forward " \t"))
183 (defun newline-and-indent ()
184 "Insert a newline, then indent according to major mode.
185 Indentation is done using the value of `indent-line-function'.
186 In programming language modes, this is the same as TAB.
187 In some text modes, where TAB inserts a tab, this command indents to the
188 column specified by the variable `left-margin'."
189 (interactive "*")
190 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
191 (newline)
192 (indent-according-to-mode))
194 (defun reindent-then-newline-and-indent ()
195 "Reindent current line, insert newline, then indent the new line.
196 Indentation of both lines is done according to the current major mode,
197 which means calling the current value of `indent-line-function'.
198 In programming language modes, this is the same as TAB.
199 In some text modes, where TAB inserts a tab, this indents to the
200 column specified by the variable `left-margin'."
201 (interactive "*")
202 (save-excursion
203 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
204 (indent-according-to-mode))
205 (newline)
206 (indent-according-to-mode))
208 ;; Internal subroutine of delete-char
209 (defun kill-forward-chars (arg)
210 (if (listp arg) (setq arg (car arg)))
211 (if (eq arg '-) (setq arg -1))
212 (kill-region (point) (+ (point) arg)))
214 ;; Internal subroutine of backward-delete-char
215 (defun kill-backward-chars (arg)
216 (if (listp arg) (setq arg (car arg)))
217 (if (eq arg '-) (setq arg -1))
218 (kill-region (point) (- (point) arg)))
220 (defun backward-delete-char-untabify (arg &optional killp)
221 "Delete characters backward, changing tabs into spaces.
222 Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil.
223 Interactively, ARG is the prefix arg (default 1)
224 and KILLP is t if prefix arg is was specified."
225 (interactive "*p\nP")
226 (let ((count arg))
227 (save-excursion
228 (while (and (> count 0) (not (bobp)))
229 (if (= (preceding-char) ?\t)
230 (let ((col (current-column)))
231 (forward-char -1)
232 (setq col (- col (current-column)))
233 (insert-char ?\ col)
234 (delete-char 1)))
235 (forward-char -1)
236 (setq count (1- count)))))
237 (delete-backward-char arg killp)
238 ;; In overwrite mode, back over columns while clearing them out,
239 ;; unless at end of line.
240 (and overwrite-mode (not (eolp))
241 (save-excursion (insert-char ?\ arg))))
243 (defun zap-to-char (arg char)
244 "Kill up to and including ARG'th occurrence of CHAR.
245 Goes backward if ARG is negative; error if CHAR not found."
246 (interactive "p\ncZap to char: ")
247 (kill-region (point) (progn
248 (search-forward (char-to-string char) nil nil arg)
249 ; (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
250 (point))))
252 (defun beginning-of-buffer (&optional arg)
253 "Move point to the beginning of the buffer; leave mark at previous position.
254 With arg N, put point N/10 of the way from the true beginning.
256 Don't use this command in Lisp programs!
257 \(goto-char (point-min)) is faster and avoids clobbering the mark."
258 (interactive "P")
259 (push-mark)
260 (goto-char (if arg
261 (if (> (buffer-size) 10000)
262 ;; Avoid overflow for large buffer sizes!
263 (* (prefix-numeric-value arg)
264 (/ (buffer-size) 10))
265 (/ (+ 10 (* (buffer-size) (prefix-numeric-value arg))) 10))
266 (point-min)))
267 (if arg (forward-line 1)))
269 (defun end-of-buffer (&optional arg)
270 "Move point to the end of the buffer; leave mark at previous position.
271 With arg N, put point N/10 of the way from the true end.
273 Don't use this command in Lisp programs!
274 \(goto-char (point-max)) is faster and avoids clobbering the mark."
275 (interactive "P")
276 (push-mark)
277 (goto-char (if arg
278 (- (1+ (buffer-size))
279 (if (> (buffer-size) 10000)
280 ;; Avoid overflow for large buffer sizes!
281 (* (prefix-numeric-value arg)
282 (/ (buffer-size) 10))
283 (/ (* (buffer-size) (prefix-numeric-value arg)) 10)))
284 (point-max)))
285 ;; If we went to a place in the middle of the buffer,
286 ;; adjust it to the beginning of a line.
287 (if arg (forward-line 1)
288 ;; If the end of the buffer is not already on the screen,
289 ;; then scroll specially to put it near, but not at, the bottom.
290 (if (let ((old-point (point)))
291 (save-excursion
292 (goto-char (window-start))
293 (vertical-motion (window-height))
294 (< (point) old-point)))
295 (recenter -3))))
297 (defun mark-whole-buffer ()
298 "Put point at beginning and mark at end of buffer.
299 You probably should not use this function in Lisp programs;
300 it is usually a mistake for a Lisp function to use any subroutine
301 that uses or sets the mark."
302 (interactive)
303 (push-mark (point))
304 (push-mark (point-max) nil t)
305 (goto-char (point-min)))
307 (defun count-lines-region (start end)
308 "Print number of lines and characters in the region."
309 (interactive "r")
310 (message "Region has %d lines, %d characters"
311 (count-lines start end) (- end start)))
313 (defun what-line ()
314 "Print the current line number (in the buffer) of point."
315 (interactive)
316 (save-restriction
317 (widen)
318 (save-excursion
319 (beginning-of-line)
320 (message "Line %d"
321 (1+ (count-lines 1 (point)))))))
323 (defun count-lines (start end)
324 "Return number of lines between START and END.
325 This is usually the number of newlines between them,
326 but can be one more if START is not equal to END
327 and the greater of them is not at the start of a line."
328 (save-match-data
329 (save-excursion
330 (save-restriction
331 (narrow-to-region start end)
332 (goto-char (point-min))
333 (if (eq selective-display t)
334 (let ((done 0))
335 (while (re-search-forward "[\n\C-m]" nil t 40)
336 (setq done (+ 40 done)))
337 (while (re-search-forward "[\n\C-m]" nil t 1)
338 (setq done (+ 1 done)))
339 (goto-char (point-max))
340 (if (and (/= start end)
341 (not (bolp)))
342 (1+ done)
343 done))
344 (- (buffer-size) (forward-line (buffer-size))))))))
346 (defun what-cursor-position ()
347 "Print info on cursor position (on screen and within buffer)."
348 (interactive)
349 (let* ((char (following-char))
350 (beg (point-min))
351 (end (point-max))
352 (pos (point))
353 (total (buffer-size))
354 (percent (if (> total 50000)
355 ;; Avoid overflow from multiplying by 100!
356 (/ (+ (/ total 200) (1- pos)) (max (/ total 100) 1))
357 (/ (+ (/ total 2) (* 100 (1- pos))) (max total 1))))
358 (hscroll (if (= (window-hscroll) 0)
360 (format " Hscroll=%d" (window-hscroll))))
361 (col (current-column)))
362 (if (= pos end)
363 (if (or (/= beg 1) (/= end (1+ total)))
364 (message "point=%d of %d(%d%%) <%d - %d> column %d %s"
365 pos total percent beg end col hscroll)
366 (message "point=%d of %d(%d%%) column %d %s"
367 pos total percent col hscroll))
368 (if (or (/= beg 1) (/= end (1+ total)))
369 (message "Char: %s (0%o) point=%d of %d(%d%%) <%d - %d> column %d %s"
370 (single-key-description char) char pos total percent beg end col hscroll)
371 (message "Char: %s (0%o) point=%d of %d(%d%%) column %d %s"
372 (single-key-description char) char pos total percent col hscroll)))))
374 (defun fundamental-mode ()
375 "Major mode not specialized for anything in particular.
376 Other major modes are defined by comparison with this one."
377 (interactive)
378 (kill-all-local-variables))
380 (defvar read-expression-map (cons 'keymap minibuffer-local-map)
381 "Minibuffer keymap used for reading Lisp expressions.")
382 (define-key read-expression-map "\M-\t" 'lisp-complete-symbol)
384 (put 'eval-expression 'disabled t)
386 (defvar read-expression-history nil)
388 ;; We define this, rather than making `eval' interactive,
389 ;; for the sake of completion of names like eval-region, eval-current-buffer.
390 (defun eval-expression (expression)
391 "Evaluate EXPRESSION and print value in minibuffer.
392 Value is also consed on to front of the variable `values'."
393 (interactive
394 (list (read-from-minibuffer "Eval: "
395 nil read-expression-map t
396 'read-expression-history)))
397 (setq values (cons (eval expression) values))
398 (prin1 (car values) t))
400 (defun edit-and-eval-command (prompt command)
401 "Prompting with PROMPT, let user edit COMMAND and eval result.
402 COMMAND is a Lisp expression. Let user edit that expression in
403 the minibuffer, then read and evaluate the result."
404 (let ((command (read-from-minibuffer prompt
405 (prin1-to-string command)
406 read-expression-map t
407 '(command-history . 1))))
408 (eval command)))
410 (defun repeat-complex-command (arg)
411 "Edit and re-evaluate last complex command, or ARGth from last.
412 A complex command is one which used the minibuffer.
413 The command is placed in the minibuffer as a Lisp form for editing.
414 The result is executed, repeating the command as changed.
415 If the command has been changed or is not the most recent previous command
416 it is added to the front of the command history.
417 You can use the minibuffer history commands \\<minibuffer-local-map>\\[next-history-element] and \\[previous-history-element]
418 to get different commands to edit and resubmit."
419 (interactive "p")
420 (let ((elt (nth (1- arg) command-history))
421 (minibuffer-history-position arg)
422 (minibuffer-history-sexp-flag t)
423 newcmd)
424 (if elt
425 (progn
426 (setq newcmd
427 (read-from-minibuffer
428 "Redo: " (prin1-to-string elt) read-expression-map t
429 (cons 'command-history arg)))
431 ;; If command was added to command-history as a string,
432 ;; get rid of that. We want only evallable expressions there.
433 (if (stringp (car command-history))
434 (setq command-history (cdr command-history)))
436 ;; If command to be redone does not match front of history,
437 ;; add it to the history.
438 (or (equal newcmd (car command-history))
439 (setq command-history (cons newcmd command-history)))
440 (eval newcmd))
441 (ding))))
443 (defvar minibuffer-history nil
444 "Default minibuffer history list.
445 This is used for all minibuffer input
446 except when an alternate history list is specified.")
447 (defvar minibuffer-history-sexp-flag nil
448 "Nonzero when doing history operations on `command-history'.
449 More generally, indicates that the history list being acted on
450 contains expressions rather than strings.")
451 (setq minibuffer-history-variable 'minibuffer-history)
452 (setq minibuffer-history-position nil)
453 (defvar minibuffer-history-search-history nil)
455 (mapcar
456 (lambda (key-and-command)
457 (mapcar
458 (lambda (keymap-and-completionp)
459 ;; Arg is (KEYMAP-SYMBOL . COMPLETION-MAP-P).
460 ;; If the cdr of KEY-AND-COMMAND (the command) is a cons,
461 ;; its car is used if COMPLETION-MAP-P is nil, its cdr if it is t.
462 (define-key (symbol-value (car keymap-and-completionp))
463 (car key-and-command)
464 (let ((command (cdr key-and-command)))
465 (if (consp command)
466 ;; (and ... nil) => ... turns back on the completion-oriented
467 ;; history commands which rms turned off since they seem to
468 ;; do things he doesn't like.
469 (if (and (cdr keymap-and-completionp) nil) ;XXX turned off
470 (progn (error "EMACS BUG!") (cdr command))
471 (car command))
472 command))))
473 '((minibuffer-local-map . nil)
474 (minibuffer-local-ns-map . nil)
475 (minibuffer-local-completion-map . t)
476 (minibuffer-local-must-match-map . t)
477 (read-expression-map . nil))))
478 '(("\en" . (next-history-element . next-complete-history-element))
479 ([next] . (next-history-element . next-complete-history-element))
480 ("\ep" . (previous-history-element . previous-complete-history-element))
481 ([prior] . (previous-history-element . previous-complete-history-element))
482 ("\er" . previous-matching-history-element)
483 ("\es" . next-matching-history-element)))
485 (defun previous-matching-history-element (regexp n)
486 "Find the previous history element that matches REGEXP.
487 \(Previous history elements refer to earlier actions.)
488 With prefix argument N, search for Nth previous match.
489 If N is negative, find the next or Nth next match."
490 (interactive
491 (let* ((enable-recursive-minibuffers t)
492 (minibuffer-history-sexp-flag nil)
493 (regexp (read-from-minibuffer "Previous element matching (regexp): "
495 minibuffer-local-map
497 'minibuffer-history-search-history)))
498 ;; Use the last regexp specified, by default, if input is empty.
499 (list (if (string= regexp "")
500 (setcar minibuffer-history-search-history
501 (nth 1 minibuffer-history-search-history))
502 regexp)
503 (prefix-numeric-value current-prefix-arg))))
504 (let ((history (symbol-value minibuffer-history-variable))
505 prevpos
506 (pos minibuffer-history-position))
507 (while (/= n 0)
508 (setq prevpos pos)
509 (setq pos (min (max 1 (+ pos (if (< n 0) -1 1))) (length history)))
510 (if (= pos prevpos)
511 (error (if (= pos 1)
512 "No later matching history item"
513 "No earlier matching history item")))
514 (if (string-match regexp
515 (if minibuffer-history-sexp-flag
516 (prin1-to-string (nth (1- pos) history))
517 (nth (1- pos) history)))
518 (setq n (+ n (if (< n 0) 1 -1)))))
519 (setq minibuffer-history-position pos)
520 (erase-buffer)
521 (let ((elt (nth (1- pos) history)))
522 (insert (if minibuffer-history-sexp-flag
523 (prin1-to-string elt)
524 elt)))
525 (goto-char (point-min)))
526 (if (or (eq (car (car command-history)) 'previous-matching-history-element)
527 (eq (car (car command-history)) 'next-matching-history-element))
528 (setq command-history (cdr command-history))))
530 (defun next-matching-history-element (regexp n)
531 "Find the next history element that matches REGEXP.
532 \(The next history element refers to a more recent action.)
533 With prefix argument N, search for Nth next match.
534 If N is negative, find the previous or Nth previous match."
535 (interactive
536 (let* ((enable-recursive-minibuffers t)
537 (minibuffer-history-sexp-flag nil)
538 (regexp (read-from-minibuffer "Next element matching (regexp): "
540 minibuffer-local-map
542 'minibuffer-history-search-history)))
543 ;; Use the last regexp specified, by default, if input is empty.
544 (list (if (string= regexp "")
545 (setcar minibuffer-history-search-history
546 (nth 1 minibuffer-history-search-history))
547 regexp)
548 (prefix-numeric-value current-prefix-arg))))
549 (previous-matching-history-element regexp (- n)))
551 (defun next-history-element (n)
552 "Insert the next element of the minibuffer history into the minibuffer."
553 (interactive "p")
554 (let ((narg (min (max 1 (- minibuffer-history-position n))
555 (length (symbol-value minibuffer-history-variable)))))
556 (if (= minibuffer-history-position narg)
557 (error (if (= minibuffer-history-position 1)
558 "End of history; no next item"
559 "Beginning of history; no preceding item"))
560 (erase-buffer)
561 (setq minibuffer-history-position narg)
562 (let ((elt (nth (1- minibuffer-history-position)
563 (symbol-value minibuffer-history-variable))))
564 (insert
565 (if minibuffer-history-sexp-flag
566 (prin1-to-string elt)
567 elt)))
568 (goto-char (point-min)))))
570 (defun previous-history-element (n)
571 "Inserts the previous element of the minibuffer history into the minibuffer."
572 (interactive "p")
573 (next-history-element (- n)))
575 (defun next-complete-history-element (n)
576 "Get next element of history which is a completion of minibuffer contents."
577 (interactive "p")
578 (let ((point-at-start (point)))
579 (next-matching-history-element
580 (concat "^" (regexp-quote (buffer-substring (point-min) (point)))) n)
581 ;; next-matching-history-element always puts us at (point-min).
582 ;; Move to the position we were at before changing the buffer contents.
583 ;; This is still sensical, because the text before point has not changed.
584 (goto-char point-at-start)))
586 (defun previous-complete-history-element (n)
588 Get previous element of history which is a completion of minibuffer contents."
589 (interactive "p")
590 (next-complete-history-element (- n)))
592 (defun goto-line (arg)
593 "Goto line ARG, counting from line 1 at beginning of buffer."
594 (interactive "NGoto line: ")
595 (save-restriction
596 (widen)
597 (goto-char 1)
598 (if (eq selective-display t)
599 (re-search-forward "[\n\C-m]" nil 'end (1- arg))
600 (forward-line (1- arg)))))
602 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
603 (define-function 'advertised-undo 'undo)
605 (defun undo (&optional arg)
606 "Undo some previous changes.
607 Repeat this command to undo more changes.
608 A numeric argument serves as a repeat count."
609 (interactive "*p")
610 ;; If we don't get all the way thru, make last-command indicate that
611 ;; for the following command.
612 (setq this-command t)
613 (let ((modified (buffer-modified-p))
614 (recent-save (recent-auto-save-p)))
615 (or (eq (selected-window) (minibuffer-window))
616 (message "Undo!"))
617 (or (eq last-command 'undo)
618 (progn (undo-start)
619 (undo-more 1)))
620 (undo-more (or arg 1))
621 ;; Don't specify a position in the undo record for the undo command.
622 ;; Instead, undoing this should move point to where the change is.
623 (let ((tail buffer-undo-list)
624 done)
625 (while (and tail (not done) (not (null (car tail))))
626 (if (integerp (car tail))
627 (progn
628 (setq done t)
629 (setq buffer-undo-list (delq (car tail) buffer-undo-list))))
630 (setq tail (cdr tail))))
631 (and modified (not (buffer-modified-p))
632 (delete-auto-save-file-if-necessary recent-save)))
633 ;; If we do get all the way thru, make this-command indicate that.
634 (setq this-command 'undo))
636 (defvar pending-undo-list nil
637 "Within a run of consecutive undo commands, list remaining to be undone.")
639 (defun undo-start ()
640 "Set `pending-undo-list' to the front of the undo list.
641 The next call to `undo-more' will undo the most recently made change."
642 (if (eq buffer-undo-list t)
643 (error "No undo information in this buffer"))
644 (setq pending-undo-list buffer-undo-list))
646 (defun undo-more (count)
647 "Undo back N undo-boundaries beyond what was already undone recently.
648 Call `undo-start' to get ready to undo recent changes,
649 then call `undo-more' one or more times to undo them."
650 (or pending-undo-list
651 (error "No further undo information"))
652 (setq pending-undo-list (primitive-undo count pending-undo-list)))
654 (defvar shell-command-history nil
655 "History list for some commands that read shell commands.")
657 (defun shell-command (command &optional flag)
658 "Execute string COMMAND in inferior shell; display output, if any.
659 If COMMAND ends in ampersand, execute it asynchronously.
661 Optional second arg non-nil (prefix arg, if interactive)
662 means insert output in current buffer after point (leave mark after it).
663 This cannot be done asynchronously."
664 (interactive (list (read-from-minibuffer "Shell command: "
665 nil nil nil 'shell-command-history)
666 current-prefix-arg))
667 (if flag
668 (progn (barf-if-buffer-read-only)
669 (push-mark)
670 ;; We do not use -f for csh; we will not support broken use of
671 ;; .cshrcs. Even the BSD csh manual says to use
672 ;; "if ($?prompt) exit" before things which are not useful
673 ;; non-interactively. Besides, if someone wants their other
674 ;; aliases for shell commands then they can still have them.
675 (call-process shell-file-name nil t nil
676 "-c" command)
677 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
678 ;; It is cleaner to avoid activation, even though the command
679 ;; loop would deactivate the mark because we inserted text.
680 (goto-char (prog1 (mark t)
681 (set-marker (mark-marker) (point)
682 (current-buffer)))))
683 ;; Preserve the match data in case called from a program.
684 (let ((data (match-data)))
685 (unwind-protect
686 (if (string-match "[ \t]*&[ \t]*$" command)
687 ;; Command ending with ampersand means asynchronous.
688 (let ((buffer (get-buffer-create "*shell-command*"))
689 (directory default-directory)
690 proc)
691 ;; Remove the ampersand.
692 (setq command (substring command 0 (match-beginning 0)))
693 ;; If will kill a process, query first.
694 (setq proc (get-buffer-process buffer))
695 (if proc
696 (if (yes-or-no-p "A command is running. Kill it? ")
697 (kill-process proc)
698 (error "Shell command in progress")))
699 (save-excursion
700 (set-buffer buffer)
701 (erase-buffer)
702 (display-buffer buffer)
703 (setq default-directory directory)
704 (setq proc (start-process "Shell" buffer
705 shell-file-name "-c" command))
706 (setq mode-line-process '(": %s"))
707 (set-process-sentinel proc 'shell-command-sentinel)
708 (set-process-filter proc 'shell-command-filter)
710 (shell-command-on-region (point) (point) command nil))
711 (store-match-data data)))))
713 ;; We have a sentinel to prevent insertion of a termination message
714 ;; in the buffer itself.
715 (defun shell-command-sentinel (process signal)
716 (if (memq (process-status process) '(exit signal))
717 (progn
718 (message "%s: %s."
719 (car (cdr (cdr (process-command process))))
720 (substring signal 0 -1))
721 (save-excursion
722 (set-buffer (process-buffer process))
723 (setq mode-line-process nil))
724 (delete-process process))))
726 (defun shell-command-filter (proc string)
727 ;; Do save-excursion by hand so that we can leave point numerically unchanged
728 ;; despite an insertion immediately after it.
729 (let* ((obuf (current-buffer))
730 (buffer (process-buffer proc))
731 opoint
732 (window (get-buffer-window buffer))
733 (pos (window-start window)))
734 (unwind-protect
735 (progn
736 (set-buffer buffer)
737 (setq opoint (point))
738 (goto-char (point-max))
739 (insert-before-markers string))
740 ;; insert-before-markers moved this marker: set it back.
741 (set-window-start window pos)
742 ;; Finish our save-excursion.
743 (goto-char opoint)
744 (set-buffer obuf))))
746 (defun shell-command-on-region (start end command &optional flag interactive)
747 "Execute string COMMAND in inferior shell with region as input.
748 Normally display output (if any) in temp buffer `*Shell Command Output*';
749 Prefix arg means replace the region with it.
750 Noninteractive args are START, END, COMMAND, FLAG.
751 Noninteractively FLAG means insert output in place of text from START to END,
752 and put point at the end, but don't alter the mark.
754 If the output is one line, it is displayed in the echo area,
755 but it is nonetheless available in buffer `*Shell Command Output*'
756 even though that buffer is not automatically displayed. If there is no output
757 or output is inserted in the current buffer then `*Shell Command Output*' is
758 deleted."
759 (interactive (list (region-beginning) (region-end)
760 (read-from-minibuffer "Shell command on region: "
761 nil nil nil 'shell-command-history)
762 current-prefix-arg
763 (prefix-numeric-value current-prefix-arg)))
764 (if flag
765 ;; Replace specified region with output from command.
766 (let ((swap (and interactive (< (point) (mark)))))
767 ;; Don't muck with mark
768 ;; unless called interactively.
769 (and interactive (push-mark))
770 (call-process-region start end shell-file-name t t nil
771 "-c" command)
772 (if (get-buffer "*Shell Command Output*")
773 (kill-buffer "*Shell Command Output*"))
774 (and interactive swap (exchange-point-and-mark)))
775 ;; No prefix argument: put the output in a temp buffer,
776 ;; replacing its entire contents.
777 (let ((buffer (get-buffer-create "*Shell Command Output*"))
778 (success nil))
779 (unwind-protect
780 (if (eq buffer (current-buffer))
781 ;; If the input is the same buffer as the output,
782 ;; delete everything but the specified region,
783 ;; then replace that region with the output.
784 (progn (delete-region end (point-max))
785 (delete-region (point-min) start)
786 (call-process-region (point-min) (point-max)
787 shell-file-name t t nil
788 "-c" command)
789 (setq success t))
790 ;; Clear the output buffer, then run the command with output there.
791 (save-excursion
792 (set-buffer buffer)
793 (erase-buffer))
794 (call-process-region start end shell-file-name
795 nil buffer nil
796 "-c" command)
797 (setq success t))
798 ;; Report the amount of output.
799 (let ((lines (save-excursion
800 (set-buffer buffer)
801 (if (= (buffer-size) 0)
803 (count-lines (point-min) (point-max))))))
804 (cond ((= lines 0)
805 (if success
806 (message "(Shell command completed with no output)"))
807 (kill-buffer buffer))
808 ((and success (= lines 1))
809 (message "%s"
810 (save-excursion
811 (set-buffer buffer)
812 (goto-char (point-min))
813 (buffer-substring (point)
814 (progn (end-of-line) (point)))))
815 (kill-buffer buffer))
817 (set-window-start (display-buffer buffer) 1))))))))
819 (defun universal-argument ()
820 "Begin a numeric argument for the following command.
821 Digits or minus sign following \\[universal-argument] make up the numeric argument.
822 \\[universal-argument] following the digits or minus sign ends the argument.
823 \\[universal-argument] without digits or minus sign provides 4 as argument.
824 Repeating \\[universal-argument] without digits or minus sign
825 multiplies the argument by 4 each time."
826 (interactive nil)
827 (let ((factor 4)
828 key)
829 ;; (describe-arg (list factor) 1)
830 (setq key (read-key-sequence nil t))
831 (while (equal (key-binding key) 'universal-argument)
832 (setq factor (* 4 factor))
833 ;; (describe-arg (list factor) 1)
834 (setq key (read-key-sequence nil t)))
835 (prefix-arg-internal key factor nil)))
837 (defun prefix-arg-internal (key factor value)
838 (let ((sign 1))
839 (if (and (numberp value) (< value 0))
840 (setq sign -1 value (- value)))
841 (if (eq value '-)
842 (setq sign -1 value nil))
843 ;; (describe-arg value sign)
844 (while (equal key "-")
845 (setq sign (- sign) factor nil)
846 ;; (describe-arg value sign)
847 (setq key (read-key-sequence nil t)))
848 (while (and (stringp key)
849 (= (length key) 1)
850 (not (string< key "0"))
851 (not (string< "9" key)))
852 (setq value (+ (* (if (numberp value) value 0) 10)
853 (- (aref key 0) ?0))
854 factor nil)
855 ;; (describe-arg value sign)
856 (setq key (read-key-sequence nil t)))
857 (setq prefix-arg
858 (cond (factor (list factor))
859 ((numberp value) (* value sign))
860 ((= sign -1) '-)))
861 ;; Calling universal-argument after digits
862 ;; terminates the argument but is ignored.
863 (if (eq (key-binding key) 'universal-argument)
864 (progn
865 (describe-arg value sign)
866 (setq key (read-key-sequence nil t))))
867 (setq unread-command-events (listify-key-sequence key))))
869 (defun describe-arg (value sign)
870 (cond ((numberp value)
871 (message "Arg: %d" (* value sign)))
872 ((consp value)
873 (message "Arg: [%d]" (car value)))
874 ((< sign 0)
875 (message "Arg: -"))))
877 (defun digit-argument (arg)
878 "Part of the numeric argument for the next command.
879 \\[universal-argument] following digits or minus sign ends the argument."
880 (interactive "P")
881 (prefix-arg-internal (char-to-string (logand last-command-char ?\177))
882 nil arg))
884 (defun negative-argument (arg)
885 "Begin a negative numeric argument for the next command.
886 \\[universal-argument] following digits or minus sign ends the argument."
887 (interactive "P")
888 (prefix-arg-internal "-" nil arg))
890 (defun forward-to-indentation (arg)
891 "Move forward ARG lines and position at first nonblank character."
892 (interactive "p")
893 (forward-line arg)
894 (skip-chars-forward " \t"))
896 (defun backward-to-indentation (arg)
897 "Move backward ARG lines and position at first nonblank character."
898 (interactive "p")
899 (forward-line (- arg))
900 (skip-chars-forward " \t"))
902 (defvar kill-whole-line nil
903 "*If non-nil, `kill-line' with no arg at beg of line kills the whole line.")
905 (defun kill-line (&optional arg)
906 "Kill the rest of the current line; if no nonblanks there, kill thru newline.
907 With prefix argument, kill that many lines from point.
908 Negative arguments kill lines backward.
910 When calling from a program, nil means \"no arg\",
911 a number counts as a prefix arg.
913 If `kill-whole-line' is non-nil, then kill the whole line
914 when given no argument at the beginning of a line."
915 (interactive "P")
916 (kill-region (point)
917 ;; Don't shift point before doing the delete; that way,
918 ;; undo will record the right position of point.
919 (save-excursion
920 (if arg
921 (forward-line (prefix-numeric-value arg))
922 (if (eobp)
923 (signal 'end-of-buffer nil))
924 (if (or (looking-at "[ \t]*$") (and kill-whole-line (bolp)))
925 (forward-line 1)
926 (end-of-line)))
927 (point))))
929 ;;;; Window system cut and paste hooks.
931 (defvar interprogram-cut-function nil
932 "Function to call to make a killed region available to other programs.
934 Most window systems provide some sort of facility for cutting and
935 pasting text between the windows of different programs.
936 This variable holds a function that Emacs calls whenever text
937 is put in the kill ring, to make the new kill available to other
938 programs.
940 The function takes one or two arguments.
941 The first argument, TEXT, is a string containing
942 the text which should be made available.
943 The second, PUSH, if non-nil means this is a \"new\" kill;
944 nil means appending to an \"old\" kill.")
946 (defvar interprogram-paste-function nil
947 "Function to call to get text cut from other programs.
949 Most window systems provide some sort of facility for cutting and
950 pasting text between the windows of different programs.
951 This variable holds a function that Emacs calls to obtain
952 text that other programs have provided for pasting.
954 The function should be called with no arguments. If the function
955 returns nil, then no other program has provided such text, and the top
956 of the Emacs kill ring should be used. If the function returns a
957 string, that string should be put in the kill ring as the latest kill.
959 Note that the function should return a string only if a program other
960 than Emacs has provided a string for pasting; if Emacs provided the
961 most recent string, the function should return nil. If it is
962 difficult to tell whether Emacs or some other program provided the
963 current string, it is probably good enough to return nil if the string
964 is equal (according to `string=') to the last text Emacs provided.")
968 ;;;; The kill ring data structure.
970 (defvar kill-ring nil
971 "List of killed text sequences.
972 Since the kill ring is supposed to interact nicely with cut-and-paste
973 facilities offered by window systems, use of this variable should
974 interact nicely with `interprogram-cut-function' and
975 `interprogram-paste-function'. The functions `kill-new',
976 `kill-append', and `current-kill' are supposed to implement this
977 interaction; you may want to use them instead of manipulating the kill
978 ring directly.")
980 (defconst kill-ring-max 30
981 "*Maximum length of kill ring before oldest elements are thrown away.")
983 (defvar kill-ring-yank-pointer nil
984 "The tail of the kill ring whose car is the last thing yanked.")
986 (defun kill-new (string)
987 "Make STRING the latest kill in the kill ring.
988 Set the kill-ring-yank pointer to point to it.
989 If `interprogram-cut-function' is non-nil, apply it to STRING."
990 (setq kill-ring (cons string kill-ring))
991 (if (> (length kill-ring) kill-ring-max)
992 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
993 (setq kill-ring-yank-pointer kill-ring)
994 (if interprogram-cut-function
995 (funcall interprogram-cut-function string t)))
997 (defun kill-append (string before-p)
998 "Append STRING to the end of the latest kill in the kill ring.
999 If BEFORE-P is non-nil, prepend STRING to the kill.
1000 If `interprogram-cut-function' is set, pass the resulting kill to
1001 it."
1002 (setcar kill-ring
1003 (if before-p
1004 (concat string (car kill-ring))
1005 (concat (car kill-ring) string)))
1006 (if interprogram-cut-function
1007 (funcall interprogram-cut-function (car kill-ring))))
1009 (defun current-kill (n &optional do-not-move)
1010 "Rotate the yanking point by N places, and then return that kill.
1011 If N is zero, `interprogram-paste-function' is set, and calling it
1012 returns a string, then that string is added to the front of the
1013 kill ring and returned as the latest kill.
1014 If optional arg DO-NOT-MOVE is non-nil, then don't actually move the
1015 yanking point; just return the Nth kill forward."
1016 (let ((interprogram-paste (and (= n 0)
1017 interprogram-paste-function
1018 (funcall interprogram-paste-function))))
1019 (if interprogram-paste
1020 (progn
1021 ;; Disable the interprogram cut function when we add the new
1022 ;; text to the kill ring, so Emacs doesn't try to own the
1023 ;; selection, with identical text.
1024 (let ((interprogram-cut-function nil))
1025 (kill-new interprogram-paste))
1026 interprogram-paste)
1027 (or kill-ring (error "Kill ring is empty"))
1028 (let ((ARGth-kill-element
1029 (nthcdr (mod (- n (length kill-ring-yank-pointer))
1030 (length kill-ring))
1031 kill-ring)))
1032 (or do-not-move
1033 (setq kill-ring-yank-pointer ARGth-kill-element))
1034 (car ARGth-kill-element)))))
1038 ;;;; Commands for manipulating the kill ring.
1040 (defun kill-region (beg end)
1041 "Kill between point and mark.
1042 The text is deleted but saved in the kill ring.
1043 The command \\[yank] can retrieve it from there.
1044 \(If you want to kill and then yank immediately, use \\[copy-region-as-kill].)
1045 If the buffer is read-only, Emacs will beep and refrain from deleting
1046 the text, but put the text in the kill ring anyway. This means that
1047 you can use the killing commands to copy text from a read-only buffer.
1049 This is the primitive for programs to kill text (as opposed to deleting it).
1050 Supply two arguments, character numbers indicating the stretch of text
1051 to be killed.
1052 Any command that calls this function is a \"kill command\".
1053 If the previous command was also a kill command,
1054 the text killed this time appends to the text killed last time
1055 to make one entry in the kill ring."
1056 (interactive "r")
1057 (cond
1059 ;; If the buffer is read-only, we should beep, in case the person
1060 ;; just isn't aware of this. However, there's no harm in putting
1061 ;; the region's text in the kill ring, anyway.
1062 ((and buffer-read-only (not inhibit-read-only))
1063 (copy-region-as-kill beg end)
1064 ;; This should always barf, and give us the correct error.
1065 (barf-if-buffer-read-only))
1067 ;; In certain cases, we can arrange for the undo list and the kill
1068 ;; ring to share the same string object. This code does that.
1069 ((not (or (eq buffer-undo-list t)
1070 (eq last-command 'kill-region)
1071 (equal beg end)))
1072 ;; Don't let the undo list be truncated before we can even access it.
1073 (let ((undo-strong-limit (+ (- (max beg end) (min beg end)) 100))
1074 (old-list buffer-undo-list)
1075 tail)
1076 (delete-region beg end)
1077 ;; Search back in buffer-undo-list for this string,
1078 ;; in case a change hook made property changes.
1079 (setq tail buffer-undo-list)
1080 (while (not (stringp (car (car tail))))
1081 (setq tail (cdr tail)))
1082 ;; Take the same string recorded for undo
1083 ;; and put it in the kill-ring.
1084 (kill-new (car (car tail)))
1085 (setq this-command 'kill-region)))
1088 (copy-region-as-kill beg end)
1089 (delete-region beg end))))
1091 (defun copy-region-as-kill (beg end)
1092 "Save the region as if killed, but don't kill it.
1093 If `interprogram-cut-function' is non-nil, also save the text for a window
1094 system cut and paste."
1095 (interactive "r")
1096 (if (eq last-command 'kill-region)
1097 (kill-append (buffer-substring beg end) (< end beg))
1098 (kill-new (buffer-substring beg end)))
1099 (setq this-command 'kill-region)
1100 nil)
1102 (defun kill-ring-save (beg end)
1103 "Save the region as if killed, but don't kill it.
1104 This command is similar to `copy-region-as-kill', except that it gives
1105 visual feedback indicating the extent of the region being copied.
1106 If `interprogram-cut-function' is non-nil, also save the text for a window
1107 system cut and paste."
1108 (interactive "r")
1109 (copy-region-as-kill beg end)
1110 (if (interactive-p)
1111 (let ((other-end (if (= (point) beg) end beg))
1112 (opoint (point))
1113 ;; Inhibit quitting so we can make a quit here
1114 ;; look like a C-g typed as a command.
1115 (inhibit-quit t))
1116 (if (pos-visible-in-window-p other-end (selected-window))
1117 (progn
1118 ;; Swap point and mark.
1119 (set-marker (mark-marker) (point) (current-buffer))
1120 (goto-char other-end)
1121 (sit-for 1)
1122 ;; Swap back.
1123 (set-marker (mark-marker) other-end (current-buffer))
1124 (goto-char opoint)
1125 ;; If user quit, deactivate the mark
1126 ;; as C-g would as a command.
1127 (and quit-flag mark-active
1128 (deactivate-mark)))
1129 (let* ((killed-text (current-kill 0))
1130 (message-len (min (length killed-text) 40)))
1131 (if (= (point) beg)
1132 ;; Don't say "killed"; that is misleading.
1133 (message "Saved text until \"%s\""
1134 (substring killed-text (- message-len)))
1135 (message "Saved text from \"%s\""
1136 (substring killed-text 0 message-len))))))))
1138 (defun append-next-kill ()
1139 "Cause following command, if it kills, to append to previous kill."
1140 (interactive)
1141 (if (interactive-p)
1142 (progn
1143 (setq this-command 'kill-region)
1144 (message "If the next command is a kill, it will append"))
1145 (setq last-command 'kill-region)))
1147 (defun yank-pop (arg)
1148 "Replace just-yanked stretch of killed text with a different stretch.
1149 This command is allowed only immediately after a `yank' or a `yank-pop'.
1150 At such a time, the region contains a stretch of reinserted
1151 previously-killed text. `yank-pop' deletes that text and inserts in its
1152 place a different stretch of killed text.
1154 With no argument, the previous kill is inserted.
1155 With argument N, insert the Nth previous kill.
1156 If N is negative, this is a more recent kill.
1158 The sequence of kills wraps around, so that after the oldest one
1159 comes the newest one."
1160 (interactive "*p")
1161 (if (not (eq last-command 'yank))
1162 (error "Previous command was not a yank"))
1163 (setq this-command 'yank)
1164 (let ((before (< (point) (mark t))))
1165 (delete-region (point) (mark t))
1166 (set-marker (mark-marker) (point) (current-buffer))
1167 (insert (current-kill arg))
1168 (if before
1169 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1170 ;; It is cleaner to avoid activation, even though the command
1171 ;; loop would deactivate the mark because we inserted text.
1172 (goto-char (prog1 (mark t)
1173 (set-marker (mark-marker) (point) (current-buffer))))))
1174 nil)
1176 (defun yank (&optional arg)
1177 "Reinsert the last stretch of killed text.
1178 More precisely, reinsert the stretch of killed text most recently
1179 killed OR yanked. Put point at end, and set mark at beginning.
1180 With just C-u as argument, same but put point at beginning (and mark at end).
1181 With argument N, reinsert the Nth most recently killed stretch of killed
1182 text.
1183 See also the command \\[yank-pop]."
1184 (interactive "*P")
1185 ;; If we don't get all the way thru, make last-command indicate that
1186 ;; for the following command.
1187 (setq this-command t)
1188 (push-mark (point))
1189 (insert (current-kill (cond
1190 ((listp arg) 0)
1191 ((eq arg '-) -1)
1192 (t (1- arg)))))
1193 (if (consp arg)
1194 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1195 ;; It is cleaner to avoid activation, even though the command
1196 ;; loop would deactivate the mark because we inserted text.
1197 (goto-char (prog1 (mark t)
1198 (set-marker (mark-marker) (point) (current-buffer)))))
1199 ;; If we do get all the way thru, make this-command indicate that.
1200 (setq this-command 'yank)
1201 nil)
1203 (defun rotate-yank-pointer (arg)
1204 "Rotate the yanking point in the kill ring.
1205 With argument, rotate that many kills forward (or backward, if negative)."
1206 (interactive "p")
1207 (current-kill arg))
1210 (defun insert-buffer (buffer)
1211 "Insert after point the contents of BUFFER.
1212 Puts mark after the inserted text.
1213 BUFFER may be a buffer or a buffer name."
1214 (interactive (list (progn (barf-if-buffer-read-only)
1215 (read-buffer "Insert buffer: " (other-buffer) t))))
1216 (or (bufferp buffer)
1217 (setq buffer (get-buffer buffer)))
1218 (let (start end newmark)
1219 (save-excursion
1220 (save-excursion
1221 (set-buffer buffer)
1222 (setq start (point-min) end (point-max)))
1223 (insert-buffer-substring buffer start end)
1224 (setq newmark (point)))
1225 (push-mark newmark))
1226 nil)
1228 (defun append-to-buffer (buffer start end)
1229 "Append to specified buffer the text of the region.
1230 It is inserted into that buffer before its point.
1232 When calling from a program, give three arguments:
1233 BUFFER (or buffer name), START and END.
1234 START and END specify the portion of the current buffer to be copied."
1235 (interactive
1236 (list (read-buffer "Append to buffer: " (other-buffer nil t))
1237 (region-beginning) (region-end)))
1238 (let ((oldbuf (current-buffer)))
1239 (save-excursion
1240 (set-buffer (get-buffer-create buffer))
1241 (insert-buffer-substring oldbuf start end))))
1243 (defun prepend-to-buffer (buffer start end)
1244 "Prepend to specified buffer the text of the region.
1245 It is inserted into that buffer after its point.
1247 When calling from a program, give three arguments:
1248 BUFFER (or buffer name), START and END.
1249 START and END specify the portion of the current buffer to be copied."
1250 (interactive "BPrepend to buffer: \nr")
1251 (let ((oldbuf (current-buffer)))
1252 (save-excursion
1253 (set-buffer (get-buffer-create buffer))
1254 (save-excursion
1255 (insert-buffer-substring oldbuf start end)))))
1257 (defun copy-to-buffer (buffer start end)
1258 "Copy to specified buffer the text of the region.
1259 It is inserted into that buffer, replacing existing text there.
1261 When calling from a program, give three arguments:
1262 BUFFER (or buffer name), START and END.
1263 START and END specify the portion of the current buffer to be copied."
1264 (interactive "BCopy to buffer: \nr")
1265 (let ((oldbuf (current-buffer)))
1266 (save-excursion
1267 (set-buffer (get-buffer-create buffer))
1268 (erase-buffer)
1269 (save-excursion
1270 (insert-buffer-substring oldbuf start end)))))
1272 (defvar mark-even-if-inactive nil
1273 "*Non-nil means you can use the mark even when inactive.
1274 This option makes a difference in Transient Mark mode.
1275 When the option is non-nil, deactivation of the mark
1276 turns off region highlighting, but commands that use the mark
1277 behave as if the mark were still active.")
1279 (put 'mark-inactive 'error-conditions '(mark-inactive error))
1280 (put 'mark-inactive 'error-message "The mark is not active now")
1282 (defun mark (&optional force)
1283 "Return this buffer's mark value as integer; error if mark inactive.
1284 If optional argument FORCE is non-nil, access the mark value
1285 even if the mark is not currently active, and return nil
1286 if there is no mark at all.
1288 If you are using this in an editing command, you are most likely making
1289 a mistake; see the documentation of `set-mark'."
1290 (if (or force mark-active mark-even-if-inactive)
1291 (marker-position (mark-marker))
1292 (signal 'mark-inactive nil)))
1294 ;; Many places set mark-active directly, and several of them failed to also
1295 ;; run deactivate-mark-hook. This shorthand should simplify.
1296 (defsubst deactivate-mark ()
1297 "Deactivate the mark by setting `mark-active' to nil.
1298 \(That makes a difference only in Transient Mark mode.)
1299 Also runs the hook `deactivate-mark-hook'."
1300 (setq mark-active nil)
1301 (run-hooks 'deactivate-mark-hook))
1303 (defun set-mark (pos)
1304 "Set this buffer's mark to POS. Don't use this function!
1305 That is to say, don't use this function unless you want
1306 the user to see that the mark has moved, and you want the previous
1307 mark position to be lost.
1309 Normally, when a new mark is set, the old one should go on the stack.
1310 This is why most applications should use push-mark, not set-mark.
1312 Novice Emacs Lisp programmers often try to use the mark for the wrong
1313 purposes. The mark saves a location for the user's convenience.
1314 Most editing commands should not alter the mark.
1315 To remember a location for internal use in the Lisp program,
1316 store it in a Lisp variable. Example:
1318 (let ((beg (point))) (forward-line 1) (delete-region beg (point)))."
1320 (if pos
1321 (progn
1322 (setq mark-active t)
1323 (run-hooks 'activate-mark-hook)
1324 (set-marker (mark-marker) pos (current-buffer)))
1325 (deactivate-mark)
1326 (set-marker (mark-marker) pos (current-buffer))))
1328 (defvar mark-ring nil
1329 "The list of saved former marks of the current buffer,
1330 most recent first.")
1331 (make-variable-buffer-local 'mark-ring)
1333 (defconst mark-ring-max 16
1334 "*Maximum size of mark ring. Start discarding off end if gets this big.")
1336 (defvar global-mark-ring nil
1337 "The list of saved global marks, most recent first.")
1339 (defconst global-mark-ring-max 16
1340 "*Maximum size of global mark ring. \
1341 Start discarding off end if gets this big.")
1343 (defun set-mark-command (arg)
1344 "Set mark at where point is, or jump to mark.
1345 With no prefix argument, set mark, push old mark position on local mark
1346 ring, and push mark on global mark ring.
1347 With argument, jump to mark, and pop a new position for mark off the ring
1348 \(does not affect global mark ring\).
1350 Novice Emacs Lisp programmers often try to use the mark for the wrong
1351 purposes. See the documentation of `set-mark' for more information."
1352 (interactive "P")
1353 (if (null arg)
1354 (progn
1355 (push-mark nil nil t))
1356 (if (null (mark t))
1357 (error "No mark set in this buffer")
1358 (goto-char (mark t))
1359 (pop-mark))))
1361 (defun push-mark (&optional location nomsg activate)
1362 "Set mark at LOCATION (point, by default) and push old mark on mark ring.
1363 If the last global mark pushed was not in the current buffer,
1364 also push LOCATION on the global mark ring.
1365 Display `Mark set' unless the optional second arg NOMSG is non-nil.
1366 In Transient Mark mode, activate mark if optional third arg ACTIVATE non-nil.
1368 Novice Emacs Lisp programmers often try to use the mark for the wrong
1369 purposes. See the documentation of `set-mark' for more information.
1371 In Transient Mark mode, this does not activate the mark."
1372 (if (null (mark t))
1374 (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring))
1375 (if (> (length mark-ring) mark-ring-max)
1376 (progn
1377 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil)
1378 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil))))
1379 (set-marker (mark-marker) (or location (point)) (current-buffer))
1380 ;; Now push the mark on the global mark ring.
1381 (if (and global-mark-ring
1382 (eq (marker-buffer (car global-mark-ring)) (current-buffer)))
1383 ;; The last global mark pushed was in this same buffer.
1384 ;; Don't push another one.
1386 (setq global-mark-ring (cons (copy-marker (mark-marker)) global-mark-ring))
1387 (if (> (length global-mark-ring) global-mark-ring-max)
1388 (progn
1389 (move-marker (car (nthcdr global-mark-ring-max global-mark-ring))
1390 nil)
1391 (setcdr (nthcdr (1- global-mark-ring-max) global-mark-ring) nil))))
1392 (or nomsg executing-macro (> (minibuffer-depth) 0)
1393 (message "Mark set"))
1394 (if (or activate (not transient-mark-mode))
1395 (set-mark (mark t)))
1396 nil)
1398 (defun pop-mark ()
1399 "Pop off mark ring into the buffer's actual mark.
1400 Does not set point. Does nothing if mark ring is empty."
1401 (if mark-ring
1402 (progn
1403 (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker)))))
1404 (set-marker (mark-marker) (+ 0 (car mark-ring)) (current-buffer))
1405 (deactivate-mark)
1406 (move-marker (car mark-ring) nil)
1407 (if (null (mark t)) (ding))
1408 (setq mark-ring (cdr mark-ring)))))
1410 (define-function 'exchange-dot-and-mark 'exchange-point-and-mark)
1411 (defun exchange-point-and-mark ()
1412 "Put the mark where point is now, and point where the mark is now.
1413 This command works even when the mark is not active,
1414 and it reactivates the mark."
1415 (interactive nil)
1416 (let ((omark (mark t)))
1417 (if (null omark)
1418 (error "No mark set in this buffer"))
1419 (set-mark (point))
1420 (goto-char omark)
1421 nil))
1423 (defun transient-mark-mode (arg)
1424 "Toggle Transient Mark mode.
1425 With arg, turn Transient Mark mode on if arg is positive, off otherwise.
1427 In Transient Mark mode, when the mark is active, the region is highlighted.
1428 Changing the buffer \"deactivates\" the mark.
1429 So do certain other operations that set the mark
1430 but whose main purpose is something else--for example,
1431 incremental search, \\[beginning-of-buffer], and \\[end-of-buffer]."
1432 (interactive "P")
1433 (setq transient-mark-mode
1434 (if (null arg)
1435 (not transient-mark-mode)
1436 (> (prefix-numeric-value arg) 0))))
1438 (defun pop-global-mark ()
1439 "Pop off global mark ring and jump to the top location."
1440 (interactive)
1441 (or global-mark-ring
1442 (error "No global mark set"))
1443 (let* ((marker (car global-mark-ring))
1444 (buffer (marker-buffer marker))
1445 (position (marker-position marker)))
1446 (setq global-mark-ring (cdr global-mark-ring))
1447 (set-buffer buffer)
1448 (or (and (>= position (point-min))
1449 (<= position (point-max)))
1450 (widen))
1451 (goto-char position)
1452 (switch-to-buffer buffer)))
1453 (define-key ctl-x-map "\C-@" 'pop-global-mark)
1454 (define-key ctl-x-map [?\C-\ ] 'pop-global-mark)
1457 (defvar next-line-add-newlines t
1458 "*If non-nil, `next-line' inserts newline to avoid `end of buffer' error.")
1460 (defun next-line (arg)
1461 "Move cursor vertically down ARG lines.
1462 If there is no character in the target line exactly under the current column,
1463 the cursor is positioned after the character in that line which spans this
1464 column, or at the end of the line if it is not long enough.
1465 If there is no line in the buffer after this one, behavior depends on the
1466 value of next-line-add-newlines. If non-nil, a newline character is inserted
1467 to create a line and the cursor moves to that line, otherwise the cursor is
1468 moved to the end of the buffer (if already at the end of the buffer, an error
1469 is signaled).
1471 The command \\[set-goal-column] can be used to create
1472 a semipermanent goal column to which this command always moves.
1473 Then it does not try to move vertically. This goal column is stored
1474 in `goal-column', which is nil when there is none.
1476 If you are thinking of using this in a Lisp program, consider
1477 using `forward-line' instead. It is usually easier to use
1478 and more reliable (no dependence on goal column, etc.)."
1479 (interactive "p")
1480 (if (and next-line-add-newlines (= arg 1))
1481 (let ((opoint (point)))
1482 (forward-line 1)
1483 (if (or (= opoint (point)) (not (eq (preceding-char) ?\n)))
1484 (insert ?\n)
1485 (goto-char opoint)
1486 (line-move arg)))
1487 (line-move arg))
1488 nil)
1490 (defun previous-line (arg)
1491 "Move cursor vertically up ARG lines.
1492 If there is no character in the target line exactly over the current column,
1493 the cursor is positioned after the character in that line which spans this
1494 column, or at the end of the line if it is not long enough.
1496 The command \\[set-goal-column] can be used to create
1497 a semipermanent goal column to which this command always moves.
1498 Then it does not try to move vertically.
1500 If you are thinking of using this in a Lisp program, consider using
1501 `forward-line' with a negative argument instead. It is usually easier
1502 to use and more reliable (no dependence on goal column, etc.)."
1503 (interactive "p")
1504 (line-move (- arg))
1505 nil)
1507 (defconst track-eol nil
1508 "*Non-nil means vertical motion starting at end of line keeps to ends of lines.
1509 This means moving to the end of each line moved onto.
1510 The beginning of a blank line does not count as the end of a line.")
1512 (defvar goal-column nil
1513 "*Semipermanent goal column for vertical motion, as set by \\[set-goal-column], or nil.")
1514 (make-variable-buffer-local 'goal-column)
1516 (defvar temporary-goal-column 0
1517 "Current goal column for vertical motion.
1518 It is the column where point was
1519 at the start of current run of vertical motion commands.
1520 When the `track-eol' feature is doing its job, the value is 9999.")
1522 (defun line-move (arg)
1523 (let ((signal
1524 (catch 'exit
1525 (if (not (or (eq last-command 'next-line)
1526 (eq last-command 'previous-line)))
1527 (setq temporary-goal-column
1528 (if (and track-eol (eolp)
1529 ;; Don't count beg of empty line as end of line
1530 ;; unless we just did explicit end-of-line.
1531 (or (not (bolp)) (eq last-command 'end-of-line)))
1532 9999
1533 (current-column))))
1534 (if (not (integerp selective-display))
1535 (or (and (zerop (forward-line arg))
1536 (bolp))
1537 (throw 'exit (if (bobp)
1538 'beginning-of-buffer
1539 'end-of-buffer)))
1540 ;; Move by arg lines, but ignore invisible ones.
1541 (while (> arg 0)
1542 (end-of-line)
1543 (and (zerop (vertical-motion 1))
1544 (throw 'exit 'end-of-buffer))
1545 (setq arg (1- arg)))
1546 (while (< arg 0)
1547 (beginning-of-line)
1548 (and (zerop (vertical-motion -1))
1549 (throw 'exit 'beginning-of-buffer))
1550 (setq arg (1+ arg))))
1551 (move-to-column (or goal-column temporary-goal-column))
1552 nil)))
1553 (cond
1554 ((eq signal 'beginning-of-buffer)
1555 (message "Beginning of buffer")
1556 (ding))
1557 ((eq signal 'end-of-buffer)
1558 (message "End of buffer")
1559 (ding)))))
1561 ;;; Many people have said they rarely use this feature, and often type
1562 ;;; it by accident. Maybe it shouldn't even be on a key.
1563 (put 'set-goal-column 'disabled t)
1565 (defun set-goal-column (arg)
1566 "Set the current horizontal position as a goal for \\[next-line] and \\[previous-line].
1567 Those commands will move to this position in the line moved to
1568 rather than trying to keep the same horizontal position.
1569 With a non-nil argument, clears out the goal column
1570 so that \\[next-line] and \\[previous-line] resume vertical motion.
1571 The goal column is stored in the variable `goal-column'."
1572 (interactive "P")
1573 (if arg
1574 (progn
1575 (setq goal-column nil)
1576 (message "No goal column"))
1577 (setq goal-column (current-column))
1578 (message (substitute-command-keys
1579 "Goal column %d (use \\[set-goal-column] with an arg to unset it)")
1580 goal-column))
1581 nil)
1583 ;;; Partial support for horizontal autoscrolling. Someday, this feature
1584 ;;; will be built into the C level and all the (hscroll-point-visible) calls
1585 ;;; will go away.
1587 (defvar hscroll-step 0
1588 "*The number of columns to try scrolling a window by when point moves out.
1589 If that fails to bring point back on frame, point is centered instead.
1590 If this is zero, point is always centered after it moves off frame.")
1592 (defun hscroll-point-visible ()
1593 "Scrolls the selected window horizontally to make point visible."
1594 (save-excursion
1595 (set-buffer (window-buffer))
1596 (if (not (or truncate-lines
1597 (> (window-hscroll) 0)
1598 (and truncate-partial-width-windows
1599 (< (window-width) (frame-width)))))
1600 ;; Point is always visible when lines are wrapped.
1602 ;; If point is on the invisible part of the line before window-start,
1603 ;; then hscrolling can't bring it back, so reset window-start first.
1604 (and (< (point) (window-start))
1605 (let ((ws-bol (save-excursion
1606 (goto-char (window-start))
1607 (beginning-of-line)
1608 (point))))
1609 (and (>= (point) ws-bol)
1610 (set-window-start nil ws-bol))))
1611 (let* ((here (hscroll-window-column))
1612 (left (min (window-hscroll) 1))
1613 (right (1- (window-width))))
1614 ;; Allow for the truncation glyph, if we're not exactly at eol.
1615 (if (not (and (= here right)
1616 (= (following-char) ?\n)))
1617 (setq right (1- right)))
1618 (cond
1619 ;; If too far away, just recenter. But don't show too much
1620 ;; white space off the end of the line.
1621 ((or (< here (- left hscroll-step))
1622 (> here (+ right hscroll-step)))
1623 (let ((eol (save-excursion (end-of-line) (hscroll-window-column))))
1624 (scroll-left (min (- here (/ (window-width) 2))
1625 (- eol (window-width) -5)))))
1626 ;; Within range. Scroll by one step (or maybe not at all).
1627 ((< here left)
1628 (scroll-right hscroll-step))
1629 ((> here right)
1630 (scroll-left hscroll-step)))))))
1632 ;; This function returns the window's idea of the display column of point,
1633 ;; assuming that the window is already known to be truncated rather than
1634 ;; wrapped, and that we've already handled the case where point is on the
1635 ;; part of the line before window-start. We ignore window-width; if point
1636 ;; is beyond the right margin, we want to know how far. The return value
1637 ;; includes the effects of window-hscroll, window-start, and the prompt
1638 ;; string in the minibuffer. It may be negative due to hscroll.
1639 (defun hscroll-window-column ()
1640 (let* ((hscroll (window-hscroll))
1641 (startpos (save-excursion
1642 (beginning-of-line)
1643 (if (= (point) (save-excursion
1644 (goto-char (window-start))
1645 (beginning-of-line)
1646 (point)))
1647 (goto-char (window-start)))
1648 (point)))
1649 (hpos (+ (if (and (eq (selected-window) (minibuffer-window))
1650 (= 1 (window-start))
1651 (= startpos (point-min)))
1652 (minibuffer-prompt-width)
1654 (min 0 (- 1 hscroll))))
1655 val)
1656 (car (cdr (compute-motion startpos (cons hpos 0)
1657 (point) (cons 0 1)
1658 1000000 (cons hscroll 0) nil)))))
1661 ;; rms: (1) The definitions of arrow keys should not simply restate
1662 ;; what keys they are. The arrow keys should run the ordinary commands.
1663 ;; (2) The arrow keys are just one of many common ways of moving point
1664 ;; within a line. Real horizontal autoscrolling would be a good feature,
1665 ;; but supporting it only for arrow keys is too incomplete to be desirable.
1667 ;;;;; Make arrow keys do the right thing for improved terminal support
1668 ;;;;; When we implement true horizontal autoscrolling, right-arrow and
1669 ;;;;; left-arrow can lose the (if truncate-lines ...) clause and become
1670 ;;;;; aliases. These functions are bound to the corresponding keyboard
1671 ;;;;; events in loaddefs.el.
1673 ;;(defun right-arrow (arg)
1674 ;; "Move right one character on the screen (with prefix ARG, that many chars).
1675 ;;Scroll right if needed to keep point horizontally onscreen."
1676 ;; (interactive "P")
1677 ;; (forward-char arg)
1678 ;; (hscroll-point-visible))
1680 ;;(defun left-arrow (arg)
1681 ;; "Move left one character on the screen (with prefix ARG, that many chars).
1682 ;;Scroll left if needed to keep point horizontally onscreen."
1683 ;; (interactive "P")
1684 ;; (backward-char arg)
1685 ;; (hscroll-point-visible))
1687 (defun transpose-chars (arg)
1688 "Interchange characters around point, moving forward one character.
1689 With prefix arg ARG, effect is to take character before point
1690 and drag it forward past ARG other characters (backward if ARG negative).
1691 If no argument and at end of line, the previous two chars are exchanged."
1692 (interactive "*P")
1693 (and (null arg) (eolp) (forward-char -1))
1694 (transpose-subr 'forward-char (prefix-numeric-value arg)))
1696 (defun transpose-words (arg)
1697 "Interchange words around point, leaving point at end of them.
1698 With prefix arg ARG, effect is to take word before or around point
1699 and drag it forward past ARG other words (backward if ARG negative).
1700 If ARG is zero, the words around or after point and around or after mark
1701 are interchanged."
1702 (interactive "*p")
1703 (transpose-subr 'forward-word arg))
1705 (defun transpose-sexps (arg)
1706 "Like \\[transpose-words] but applies to sexps.
1707 Does not work on a sexp that point is in the middle of
1708 if it is a list or string."
1709 (interactive "*p")
1710 (transpose-subr 'forward-sexp arg))
1712 (defun transpose-lines (arg)
1713 "Exchange current line and previous line, leaving point after both.
1714 With argument ARG, takes previous line and moves it past ARG lines.
1715 With argument 0, interchanges line point is in with line mark is in."
1716 (interactive "*p")
1717 (transpose-subr (function
1718 (lambda (arg)
1719 (if (= arg 1)
1720 (progn
1721 ;; Move forward over a line,
1722 ;; but create a newline if none exists yet.
1723 (end-of-line)
1724 (if (eobp)
1725 (newline)
1726 (forward-char 1)))
1727 (forward-line arg))))
1728 arg))
1730 (defun transpose-subr (mover arg)
1731 (let (start1 end1 start2 end2)
1732 (if (= arg 0)
1733 (progn
1734 (save-excursion
1735 (funcall mover 1)
1736 (setq end2 (point))
1737 (funcall mover -1)
1738 (setq start2 (point))
1739 (goto-char (mark))
1740 (funcall mover 1)
1741 (setq end1 (point))
1742 (funcall mover -1)
1743 (setq start1 (point))
1744 (transpose-subr-1))
1745 (exchange-point-and-mark)))
1746 (while (> arg 0)
1747 (funcall mover -1)
1748 (setq start1 (point))
1749 (funcall mover 1)
1750 (setq end1 (point))
1751 (funcall mover 1)
1752 (setq end2 (point))
1753 (funcall mover -1)
1754 (setq start2 (point))
1755 (transpose-subr-1)
1756 (goto-char end2)
1757 (setq arg (1- arg)))
1758 (while (< arg 0)
1759 (funcall mover -1)
1760 (setq start2 (point))
1761 (funcall mover -1)
1762 (setq start1 (point))
1763 (funcall mover 1)
1764 (setq end1 (point))
1765 (funcall mover 1)
1766 (setq end2 (point))
1767 (transpose-subr-1)
1768 (setq arg (1+ arg)))))
1770 (defun transpose-subr-1 ()
1771 (if (> (min end1 end2) (max start1 start2))
1772 (error "Don't have two things to transpose"))
1773 (let ((word1 (buffer-substring start1 end1))
1774 (word2 (buffer-substring start2 end2)))
1775 (delete-region start2 end2)
1776 (goto-char start2)
1777 (insert word1)
1778 (goto-char (if (< start1 start2) start1
1779 (+ start1 (- (length word1) (length word2)))))
1780 (delete-char (length word1))
1781 (insert word2)))
1783 (defconst comment-column 32
1784 "*Column to indent right-margin comments to.
1785 Setting this variable automatically makes it local to the current buffer.
1786 Each mode establishes a different default value for this variable; you
1787 can set the value for a particular mode using that mode's hook.")
1788 (make-variable-buffer-local 'comment-column)
1790 (defconst comment-start nil
1791 "*String to insert to start a new comment, or nil if no comment syntax defined.")
1793 (defconst comment-start-skip nil
1794 "*Regexp to match the start of a comment plus everything up to its body.
1795 If there are any \\(...\\) pairs, the comment delimiter text is held to begin
1796 at the place matched by the close of the first pair.")
1798 (defconst comment-end ""
1799 "*String to insert to end a new comment.
1800 Should be an empty string if comments are terminated by end-of-line.")
1802 (defconst comment-indent-hook nil
1803 "Obsolete variable for function to compute desired indentation for a comment.
1804 This function is called with no args with point at the beginning of
1805 the comment's starting delimiter.")
1807 (defconst comment-indent-function
1808 '(lambda () comment-column)
1809 "Function to compute desired indentation for a comment.
1810 This function is called with no args with point at the beginning of
1811 the comment's starting delimiter.")
1813 (defun indent-for-comment ()
1814 "Indent this line's comment to comment column, or insert an empty comment."
1815 (interactive "*")
1816 (beginning-of-line 1)
1817 (if (null comment-start)
1818 (error "No comment syntax defined")
1819 (let* ((eolpos (save-excursion (end-of-line) (point)))
1820 cpos indent begpos)
1821 (if (re-search-forward comment-start-skip eolpos 'move)
1822 (progn (setq cpos (point-marker))
1823 ;; Find the start of the comment delimiter.
1824 ;; If there were paren-pairs in comment-start-skip,
1825 ;; position at the end of the first pair.
1826 (if (match-end 1)
1827 (goto-char (match-end 1))
1828 ;; If comment-start-skip matched a string with
1829 ;; internal whitespace (not final whitespace) then
1830 ;; the delimiter start at the end of that
1831 ;; whitespace. Otherwise, it starts at the
1832 ;; beginning of what was matched.
1833 (skip-syntax-backward " " (match-beginning 0))
1834 (skip-syntax-backward "^ " (match-beginning 0)))))
1835 (setq begpos (point))
1836 ;; Compute desired indent.
1837 (if (= (current-column)
1838 (setq indent (if comment-indent-hook
1839 (funcall comment-indent-hook)
1840 (funcall comment-indent-function))))
1841 (goto-char begpos)
1842 ;; If that's different from current, change it.
1843 (skip-chars-backward " \t")
1844 (delete-region (point) begpos)
1845 (indent-to indent))
1846 ;; An existing comment?
1847 (if cpos
1848 (progn (goto-char cpos)
1849 (set-marker cpos nil))
1850 ;; No, insert one.
1851 (insert comment-start)
1852 (save-excursion
1853 (insert comment-end))))))
1855 (defun set-comment-column (arg)
1856 "Set the comment column based on point.
1857 With no arg, set the comment column to the current column.
1858 With just minus as arg, kill any comment on this line.
1859 With any other arg, set comment column to indentation of the previous comment
1860 and then align or create a comment on this line at that column."
1861 (interactive "P")
1862 (if (eq arg '-)
1863 (kill-comment nil)
1864 (if arg
1865 (progn
1866 (save-excursion
1867 (beginning-of-line)
1868 (re-search-backward comment-start-skip)
1869 (beginning-of-line)
1870 (re-search-forward comment-start-skip)
1871 (goto-char (match-beginning 0))
1872 (setq comment-column (current-column))
1873 (message "Comment column set to %d" comment-column))
1874 (indent-for-comment))
1875 (setq comment-column (current-column))
1876 (message "Comment column set to %d" comment-column))))
1878 (defun kill-comment (arg)
1879 "Kill the comment on this line, if any.
1880 With argument, kill comments on that many lines starting with this one."
1881 ;; this function loses in a lot of situations. it incorrectly recognises
1882 ;; comment delimiters sometimes (ergo, inside a string), doesn't work
1883 ;; with multi-line comments, can kill extra whitespace if comment wasn't
1884 ;; through end-of-line, et cetera.
1885 (interactive "P")
1886 (or comment-start-skip (error "No comment syntax defined"))
1887 (let ((count (prefix-numeric-value arg)) endc)
1888 (while (> count 0)
1889 (save-excursion
1890 (end-of-line)
1891 (setq endc (point))
1892 (beginning-of-line)
1893 (and (string< "" comment-end)
1894 (setq endc
1895 (progn
1896 (re-search-forward (regexp-quote comment-end) endc 'move)
1897 (skip-chars-forward " \t")
1898 (point))))
1899 (beginning-of-line)
1900 (if (re-search-forward comment-start-skip endc t)
1901 (progn
1902 (goto-char (match-beginning 0))
1903 (skip-chars-backward " \t")
1904 (kill-region (point) endc)
1905 ;; to catch comments a line beginnings
1906 (indent-according-to-mode))))
1907 (if arg (forward-line 1))
1908 (setq count (1- count)))))
1910 (defun comment-region (beg end &optional arg)
1911 "Comment or uncomment each line in the region.
1912 With just C-u prefix arg, uncomment each line in region.
1913 Numeric prefix arg ARG means use ARG comment characters.
1914 If ARG is negative, delete that many comment characters instead.
1915 Comments are terminated on each line, even for syntax in which newline does
1916 not end the comment. Blank lines do not get comments."
1917 ;; if someone wants it to only put a comment-start at the beginning and
1918 ;; comment-end at the end then typing it, C-x C-x, closing it, C-x C-x
1919 ;; is easy enough. No option is made here for other than commenting
1920 ;; every line.
1921 (interactive "r\nP")
1922 (or comment-start (error "No comment syntax is defined"))
1923 (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
1924 (save-excursion
1925 (save-restriction
1926 (let ((cs comment-start) (ce comment-end)
1927 numarg)
1928 (if (consp arg) (setq numarg t)
1929 (setq numarg (prefix-numeric-value arg))
1930 ;; For positive arg > 1, replicate the comment delims now,
1931 ;; then insert the replicated strings just once.
1932 (while (> numarg 1)
1933 (setq cs (concat cs comment-start)
1934 ce (concat ce comment-end))
1935 (setq numarg (1- numarg))))
1936 ;; Loop over all lines from BEG to END.
1937 (narrow-to-region beg end)
1938 (goto-char beg)
1939 (while (not (eobp))
1940 (if (or (eq numarg t) (< numarg 0))
1941 (progn
1942 ;; Delete comment start from beginning of line.
1943 (if (eq numarg t)
1944 (while (looking-at (regexp-quote cs))
1945 (delete-char (length cs)))
1946 (let ((count numarg))
1947 (while (and (> 1 (setq count (1+ count)))
1948 (looking-at (regexp-quote cs)))
1949 (delete-char (length cs)))))
1950 ;; Delete comment end from end of line.
1951 (if (string= "" ce)
1953 (if (eq numarg t)
1954 (progn
1955 (end-of-line)
1956 ;; This is questionable if comment-end ends in
1957 ;; whitespace. That is pretty brain-damaged,
1958 ;; though.
1959 (skip-chars-backward " \t")
1960 (if (and (>= (- (point) (point-min)) (length ce))
1961 (save-excursion
1962 (backward-char (length ce))
1963 (looking-at (regexp-quote ce))))
1964 (delete-char (- (length ce)))))
1965 (let ((count numarg))
1966 (while (> 1 (setq count (1+ count)))
1967 (end-of-line)
1968 ;; this is questionable if comment-end ends in whitespace
1969 ;; that is pretty brain-damaged though
1970 (skip-chars-backward " \t")
1971 (save-excursion
1972 (backward-char (length ce))
1973 (if (looking-at (regexp-quote ce))
1974 (delete-char (length ce))))))))
1975 (forward-line 1))
1976 ;; Insert at beginning and at end.
1977 (if (looking-at "[ \t]*$") ()
1978 (insert cs)
1979 (if (string= "" ce) ()
1980 (end-of-line)
1981 (insert ce)))
1982 (search-forward "\n" nil 'move)))))))
1984 (defun backward-word (arg)
1985 "Move backward until encountering the end of a word.
1986 With argument, do this that many times.
1987 In programs, it is faster to call `forward-word' with negative arg."
1988 (interactive "p")
1989 (forward-word (- arg)))
1991 (defun mark-word (arg)
1992 "Set mark arg words away from point."
1993 (interactive "p")
1994 (push-mark
1995 (save-excursion
1996 (forward-word arg)
1997 (point))
1998 nil t))
2000 (defun kill-word (arg)
2001 "Kill characters forward until encountering the end of a word.
2002 With argument, do this that many times."
2003 (interactive "p")
2004 (kill-region (point) (save-excursion (forward-word arg) (point))))
2006 (defun backward-kill-word (arg)
2007 "Kill characters backward until encountering the end of a word.
2008 With argument, do this that many times."
2009 (interactive "p")
2010 (kill-word (- arg)))
2012 (defun current-word (&optional strict)
2013 "Return the word point is on (or a nearby word) as a string.
2014 If optional arg STRICT is non-nil, return nil unless point is within
2015 or adjacent to a word."
2016 (save-excursion
2017 (let ((oldpoint (point)) (start (point)) (end (point)))
2018 (skip-syntax-backward "w_") (setq start (point))
2019 (goto-char oldpoint)
2020 (skip-syntax-forward "w_") (setq end (point))
2021 (if (and (eq start oldpoint) (eq end oldpoint))
2022 ;; Point is neither within nor adjacent to a word.
2023 (and (not strict)
2024 (progn
2025 ;; Look for preceding word in same line.
2026 (skip-syntax-backward "^w_"
2027 (save-excursion (beginning-of-line)
2028 (point)))
2029 (if (bolp)
2030 ;; No preceding word in same line.
2031 ;; Look for following word in same line.
2032 (progn
2033 (skip-syntax-forward "^w_"
2034 (save-excursion (end-of-line)
2035 (point)))
2036 (setq start (point))
2037 (skip-syntax-forward "w_")
2038 (setq end (point)))
2039 (setq end (point))
2040 (skip-syntax-backward "w_")
2041 (setq start (point)))
2042 (buffer-substring start end)))
2043 (buffer-substring start end)))))
2045 (defconst fill-prefix nil
2046 "*String for filling to insert at front of new line, or nil for none.
2047 Setting this variable automatically makes it local to the current buffer.")
2048 (make-variable-buffer-local 'fill-prefix)
2050 (defconst auto-fill-inhibit-regexp nil
2051 "*Regexp to match lines which should not be auto-filled.")
2053 (defun do-auto-fill ()
2054 (let (give-up)
2055 (or (and auto-fill-inhibit-regexp
2056 (save-excursion (beginning-of-line)
2057 (looking-at auto-fill-inhibit-regexp)))
2058 (while (and (not give-up) (> (current-column) fill-column))
2059 ;; Determine where to split the line.
2060 (let ((fill-point
2061 (let ((opoint (point))
2062 bounce
2063 (first t))
2064 (save-excursion
2065 (move-to-column (1+ fill-column))
2066 ;; Move back to a word boundary.
2067 (while (or first
2068 ;; If this is after period and a single space,
2069 ;; move back once more--we don't want to break
2070 ;; the line there and make it look like a
2071 ;; sentence end.
2072 (and (not (bobp))
2073 (not bounce)
2074 sentence-end-double-space
2075 (save-excursion (forward-char -1)
2076 (and (looking-at "\\. ")
2077 (not (looking-at "\\. "))))))
2078 (setq first nil)
2079 (skip-chars-backward "^ \t\n")
2080 ;; If we find nowhere on the line to break it,
2081 ;; break after one word. Set bounce to t
2082 ;; so we will not keep going in this while loop.
2083 (if (bolp)
2084 (progn
2085 (re-search-forward "[ \t]" opoint t)
2086 (setq bounce t)))
2087 (skip-chars-backward " \t"))
2088 ;; Let fill-point be set to the place where we end up.
2089 (point)))))
2090 ;; If that place is not the beginning of the line,
2091 ;; break the line there.
2092 (if (save-excursion
2093 (goto-char fill-point)
2094 (not (bolp)))
2095 (let ((prev-column (current-column)))
2096 ;; If point is at the fill-point, do not `save-excursion'.
2097 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
2098 ;; point will end up before it rather than after it.
2099 (if (save-excursion
2100 (skip-chars-backward " \t")
2101 (= (point) fill-point))
2102 (indent-new-comment-line)
2103 (save-excursion
2104 (goto-char fill-point)
2105 (indent-new-comment-line)))
2106 ;; If making the new line didn't reduce the hpos of
2107 ;; the end of the line, then give up now;
2108 ;; trying again will not help.
2109 (if (>= (current-column) prev-column)
2110 (setq give-up t)))
2111 ;; No place to break => stop trying.
2112 (setq give-up t)))))))
2114 (defconst comment-multi-line nil
2115 "*Non-nil means \\[indent-new-comment-line] should continue same comment
2116 on new line, with no new terminator or starter.
2117 This is obsolete because you might as well use \\[newline-and-indent].")
2119 (defun indent-new-comment-line ()
2120 "Break line at point and indent, continuing comment if presently within one.
2121 The body of the continued comment is indented under the previous comment line.
2123 This command is intended for styles where you write a comment per line,
2124 starting a new comment (and terminating it if necessary) on each line.
2125 If you want to continue one comment across several lines, use \\[newline-and-indent]."
2126 (interactive "*")
2127 (let (comcol comstart)
2128 (skip-chars-backward " \t")
2129 (delete-region (point)
2130 (progn (skip-chars-forward " \t")
2131 (point)))
2132 (insert ?\n)
2133 (if (not comment-multi-line)
2134 (save-excursion
2135 (if (and comment-start-skip
2136 (let ((opoint (point)))
2137 (forward-line -1)
2138 (re-search-forward comment-start-skip opoint t)))
2139 ;; The old line is a comment.
2140 ;; Set WIN to the pos of the comment-start.
2141 ;; But if the comment is empty, look at preceding lines
2142 ;; to find one that has a nonempty comment.
2143 (let ((win (match-beginning 0)))
2144 (while (and (eolp) (not (bobp))
2145 (let (opoint)
2146 (beginning-of-line)
2147 (setq opoint (point))
2148 (forward-line -1)
2149 (re-search-forward comment-start-skip opoint t)))
2150 (setq win (match-beginning 0)))
2151 ;; Indent this line like what we found.
2152 (goto-char win)
2153 (setq comcol (current-column))
2154 (setq comstart (buffer-substring (point) (match-end 0)))))))
2155 (if comcol
2156 (let ((comment-column comcol)
2157 (comment-start comstart)
2158 (comment-end comment-end))
2159 (and comment-end (not (equal comment-end ""))
2160 ; (if (not comment-multi-line)
2161 (progn
2162 (forward-char -1)
2163 (insert comment-end)
2164 (forward-char 1))
2165 ; (setq comment-column (+ comment-column (length comment-start))
2166 ; comment-start "")
2169 (if (not (eolp))
2170 (setq comment-end ""))
2171 (insert ?\n)
2172 (forward-char -1)
2173 (indent-for-comment)
2174 (save-excursion
2175 ;; Make sure we delete the newline inserted above.
2176 (end-of-line)
2177 (delete-char 1)))
2178 (if fill-prefix
2179 (insert fill-prefix)
2180 (indent-according-to-mode)))))
2182 (defun auto-fill-mode (&optional arg)
2183 "Toggle auto-fill mode.
2184 With arg, turn auto-fill mode on if and only if arg is positive.
2185 In auto-fill mode, inserting a space at a column beyond fill-column
2186 automatically breaks the line at a previous space."
2187 (interactive "P")
2188 (prog1 (setq auto-fill-function
2189 (if (if (null arg)
2190 (not auto-fill-function)
2191 (> (prefix-numeric-value arg) 0))
2192 'do-auto-fill
2193 nil))
2194 ;; update mode-line
2195 (set-buffer-modified-p (buffer-modified-p))))
2197 (defun turn-on-auto-fill ()
2198 "Unconditionally turn on Auto Fill mode."
2199 (auto-fill-mode 1))
2201 (defun set-fill-column (arg)
2202 "Set `fill-column' to current column, or to argument if given.
2203 The variable `fill-column' has a separate value for each buffer."
2204 (interactive "P")
2205 (setq fill-column (if (integerp arg) arg (current-column)))
2206 (message "fill-column set to %d" fill-column))
2208 (defun set-selective-display (arg)
2209 "Set `selective-display' to ARG; clear it if no arg.
2210 When the value of `selective-display' is a number > 0,
2211 lines whose indentation is >= that value are not displayed.
2212 The variable `selective-display' has a separate value for each buffer."
2213 (interactive "P")
2214 (if (eq selective-display t)
2215 (error "selective-display already in use for marked lines"))
2216 (let ((current-vpos
2217 (save-restriction
2218 (narrow-to-region (point-min) (point))
2219 (goto-char (window-start))
2220 (vertical-motion (window-height)))))
2221 (setq selective-display
2222 (and arg (prefix-numeric-value arg)))
2223 (recenter current-vpos))
2224 (set-window-start (selected-window) (window-start (selected-window)))
2225 (princ "selective-display set to " t)
2226 (prin1 selective-display t)
2227 (princ "." t))
2229 (defconst overwrite-mode-textual " Ovwrt"
2230 "The string displayed in the mode line when in overwrite mode.")
2231 (defconst overwrite-mode-binary " Bin Ovwrt"
2232 "The string displayed in the mode line when in binary overwrite mode.")
2234 (defun overwrite-mode (arg)
2235 "Toggle overwrite mode.
2236 With arg, turn overwrite mode on iff arg is positive.
2237 In overwrite mode, printing characters typed in replace existing text
2238 on a one-for-one basis, rather than pushing it to the right. At the
2239 end of a line, such characters extend the line. Before a tab,
2240 such characters insert until the tab is filled in.
2241 \\[quoted-insert] still inserts characters in overwrite mode; this
2242 is supposed to make it easier to insert characters when necessary."
2243 (interactive "P")
2244 (setq overwrite-mode
2245 (if (if (null arg) (not overwrite-mode)
2246 (> (prefix-numeric-value arg) 0))
2247 'overwrite-mode-textual))
2248 (force-mode-line-update))
2250 (defun binary-overwrite-mode (arg)
2251 "Toggle binary overwrite mode.
2252 With arg, turn binary overwrite mode on iff arg is positive.
2253 In binary overwrite mode, printing characters typed in replace
2254 existing text. Newlines are not treated specially, so typing at the
2255 end of a line joins the line to the next, with the typed character
2256 between them. Typing before a tab character simply replaces the tab
2257 with the character typed.
2258 \\[quoted-insert] replaces the text at the cursor, just as ordinary
2259 typing characters do.
2261 Note that binary overwrite mode is not its own minor mode; it is a
2262 specialization of overwrite-mode, entered by setting the
2263 `overwrite-mode' variable to `overwrite-mode-binary'."
2264 (interactive "P")
2265 (setq overwrite-mode
2266 (if (if (null arg)
2267 (not (eq overwrite-mode 'overwrite-mode-binary))
2268 (> (prefix-numeric-value arg) 0))
2269 'overwrite-mode-binary))
2270 (force-mode-line-update))
2272 (defvar line-number-mode nil
2273 "*Non-nil means display line number in mode line.")
2275 (defun line-number-mode (arg)
2276 "Toggle Line Number mode.
2277 With arg, turn Line Number mode on iff arg is positive.
2278 When Line Number mode is enabled, the line number appears
2279 in the mode line."
2280 (interactive "P")
2281 (setq line-number-mode
2282 (if (null arg) (not line-number-mode)
2283 (> (prefix-numeric-value arg) 0)))
2284 (force-mode-line-update))
2286 (defvar blink-matching-paren t
2287 "*Non-nil means show matching open-paren when close-paren is inserted.")
2289 (defconst blink-matching-paren-distance 12000
2290 "*If non-nil, is maximum distance to search for matching open-paren.")
2292 (defun blink-matching-open ()
2293 "Move cursor momentarily to the beginning of the sexp before point."
2294 (interactive)
2295 (and (> (point) (1+ (point-min)))
2296 (not (memq (char-syntax (char-after (- (point) 2))) '(?/ ?\\ )))
2297 blink-matching-paren
2298 (let* ((oldpos (point))
2299 (blinkpos)
2300 (mismatch))
2301 (save-excursion
2302 (save-restriction
2303 (if blink-matching-paren-distance
2304 (narrow-to-region (max (point-min)
2305 (- (point) blink-matching-paren-distance))
2306 oldpos))
2307 (condition-case ()
2308 (setq blinkpos (scan-sexps oldpos -1))
2309 (error nil)))
2310 (and blinkpos (/= (char-syntax (char-after blinkpos))
2311 ?\$)
2312 (setq mismatch
2313 (/= (char-after (1- oldpos))
2314 (logand (lsh (aref (syntax-table)
2315 (char-after blinkpos))
2317 255))))
2318 (if mismatch (setq blinkpos nil))
2319 (if blinkpos
2320 (progn
2321 (goto-char blinkpos)
2322 (if (pos-visible-in-window-p)
2323 (sit-for 1)
2324 (goto-char blinkpos)
2325 (message
2326 "Matches %s"
2327 ;; Show what precedes the open in its line, if anything.
2328 (if (save-excursion
2329 (skip-chars-backward " \t")
2330 (not (bolp)))
2331 (buffer-substring (progn (beginning-of-line) (point))
2332 (1+ blinkpos))
2333 ;; Show what follows the open in its line, if anything.
2334 (if (save-excursion
2335 (forward-char 1)
2336 (skip-chars-forward " \t")
2337 (not (eolp)))
2338 (buffer-substring blinkpos
2339 (progn (end-of-line) (point)))
2340 ;; Otherwise show the previous nonblank line.
2341 (concat
2342 (buffer-substring (progn
2343 (backward-char 1)
2344 (skip-chars-backward "\n \t")
2345 (beginning-of-line)
2346 (point))
2347 (progn (end-of-line)
2348 (skip-chars-backward " \t")
2349 (point)))
2350 ;; Replace the newline and other whitespace with `...'.
2351 "..."
2352 (buffer-substring blinkpos (1+ blinkpos))))))))
2353 (cond (mismatch
2354 (message "Mismatched parentheses"))
2355 ((not blink-matching-paren-distance)
2356 (message "Unmatched parenthesis"))))))))
2358 ;Turned off because it makes dbx bomb out.
2359 (setq blink-paren-function 'blink-matching-open)
2361 ;; This executes C-g typed while Emacs is waiting for a command.
2362 ;; Quitting out of a program does not go through here;
2363 ;; that happens in the QUIT macro at the C code level.
2364 (defun keyboard-quit ()
2365 "Signal a quit condition.
2366 During execution of Lisp code, this character causes a quit directly.
2367 At top-level, as an editor command, this simply beeps."
2368 (interactive)
2369 (deactivate-mark)
2370 (signal 'quit nil))
2372 (define-key global-map "\C-g" 'keyboard-quit)
2374 (defun set-variable (var val)
2375 "Set VARIABLE to VALUE. VALUE is a Lisp object.
2376 When using this interactively, supply a Lisp expression for VALUE.
2377 If you want VALUE to be a string, you must surround it with doublequotes.
2379 If VARIABLE has a `variable-interactive' property, that is used as if
2380 it were the arg to `interactive' (which see) to interactively read the value."
2381 (interactive
2382 (let* ((var (read-variable "Set variable: "))
2383 (minibuffer-help-form
2384 '(funcall myhelp))
2385 (myhelp
2386 (function
2387 (lambda ()
2388 (with-output-to-temp-buffer "*Help*"
2389 (prin1 var)
2390 (princ "\nDocumentation:\n")
2391 (princ (substring (documentation-property var 'variable-documentation)
2393 (if (boundp var)
2394 (let ((print-length 20))
2395 (princ "\n\nCurrent value: ")
2396 (prin1 (symbol-value var))))
2397 nil)))))
2398 (list var
2399 (let ((prop (get var 'variable-interactive)))
2400 (if prop
2401 ;; Use VAR's `variable-interactive' property
2402 ;; as an interactive spec for prompting.
2403 (call-interactively (list 'lambda '(arg)
2404 (list 'interactive prop)
2405 'arg))
2406 (eval-minibuffer (format "Set %s to value: " var)))))))
2407 (set var val))
2409 ;; Define the major mode for lists of completions.
2411 (defvar completion-list-mode-map nil)
2412 (or completion-list-mode-map
2413 (let ((map (make-sparse-keymap)))
2414 (define-key map [mouse-2] 'mouse-choose-completion)
2415 (define-key map "\C-m" 'choose-completion)
2416 (define-key map [return] 'choose-completion)
2417 (setq completion-list-mode-map map)))
2419 ;; Completion mode is suitable only for specially formatted data.
2420 (put 'completion-list-mode 'mode-class 'special)
2422 ;; Record the buffer that was current when the completion list was requested.
2423 (defvar completion-reference-buffer)
2425 (defun choose-completion ()
2426 "Choose the completion that point is in or next to."
2427 (interactive)
2428 (let (beg end)
2429 (skip-chars-forward "^ \t\n")
2430 (setq end (point))
2431 (skip-chars-backward "^ \t\n")
2432 (setq beg (point))
2433 (choose-completion-string (buffer-substring beg end))))
2435 ;; Delete the longest partial match for STRING
2436 ;; that can be found before POINT.
2437 (defun choose-completion-delete-max-match (string)
2438 (let ((opoint (point))
2439 (len (min (length string)
2440 (- (point) (point-min)))))
2441 (goto-char (- (point) (length string)))
2442 (while (and (> len 0)
2443 (let ((tail (buffer-substring (point)
2444 (+ (point) len))))
2445 (not (string= tail (substring string 0 len)))))
2446 (setq len (1- len))
2447 (forward-char 1))
2448 (delete-char len)))
2450 (defun choose-completion-string (choice &optional buffer)
2451 (let ((buffer (or buffer completion-reference-buffer)))
2452 (set-buffer buffer)
2453 (choose-completion-delete-max-match choice)
2454 (insert choice)
2455 ;; Update point in the window that BUFFER is showing in.
2456 (let ((window (get-buffer-window buffer t)))
2457 (set-window-point window (point)))
2458 (and (equal buffer (window-buffer (minibuffer-window)))
2459 (minibuffer-complete-and-exit))))
2461 (defun completion-list-mode ()
2462 "Major mode for buffers showing lists of possible completions.
2463 Type \\<completion-list-mode-map>\\[choose-completion] in the completion list\
2464 to select the completion near point.
2465 Use \\<completion-list-mode-map>\\[mouse-choose-completion] to select one\
2466 with the mouse."
2467 (interactive)
2468 (kill-all-local-variables)
2469 (use-local-map completion-list-mode-map)
2470 (setq mode-name "Completion List")
2471 (setq major-mode 'completion-list-mode)
2472 (run-hooks 'completion-list-mode-hook))
2474 (defun completion-setup-function ()
2475 (save-excursion
2476 (let ((mainbuf (current-buffer)))
2477 (set-buffer standard-output)
2478 (completion-list-mode)
2479 (make-local-variable 'completion-reference-buffer)
2480 (setq completion-reference-buffer mainbuf)
2481 (goto-char (point-min))
2482 (if window-system
2483 (insert (substitute-command-keys
2484 "Click \\[mouse-choose-completion] on a completion to select it.\n")))
2485 (insert (substitute-command-keys
2486 "In this buffer, type \\[choose-completion] to \
2487 select the completion near point.\n\n"))
2488 (forward-line 1)
2489 (if window-system
2490 (while (re-search-forward "[^ \t\n]+" nil t)
2491 (put-text-property (match-beginning 0) (match-end 0)
2492 'mouse-face 'highlight))))))
2494 (add-hook 'completion-setup-hook 'completion-setup-function)
2496 ;;;; Keypad support.
2498 ;;; Make the keypad keys act like ordinary typing keys. If people add
2499 ;;; bindings for the function key symbols, then those bindings will
2500 ;;; override these, so this shouldn't interfere with any existing
2501 ;;; bindings.
2503 ;; Also tell read-char how to handle these keys.
2504 (mapcar
2505 (lambda (keypad-normal)
2506 (let ((keypad (nth 0 keypad-normal))
2507 (normal (nth 1 keypad-normal)))
2508 (put keypad 'ascii-character normal)
2509 (define-key function-key-map (vector keypad) (vector normal))))
2510 '((kp-0 ?0) (kp-1 ?1) (kp-2 ?2) (kp-3 ?3) (kp-4 ?4)
2511 (kp-5 ?5) (kp-6 ?6) (kp-7 ?7) (kp-8 ?8) (kp-9 ?9)
2512 (kp-space ?\ )
2513 (kp-tab ?\t)
2514 (kp-enter ?\r)
2515 (kp-multiply ?*)
2516 (kp-add ?+)
2517 (kp-separator ?,)
2518 (kp-subtract ?-)
2519 (kp-decimal ?.)
2520 (kp-divide ?/)
2521 (kp-equal ?=)))
2523 ;;; simple.el ends here