1 ;; Basic editing commands for Emacs
2 ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
4 ;; This file is part of GNU Emacs.
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 1, or (at your option)
11 ;; GNU Emacs is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 (defun open-line (arg)
22 "Insert a newline and leave point before it. If there is a fill
23 prefix, inserts the fill prefix after the newline that it inserts.
24 With arg, inserts that many newlines."
26 (let ((flag (and (bolp) (not (bobp)))))
27 (if flag (forward-char -1))
31 (if fill-prefix (insert fill-prefix)))
33 (if flag (forward-char 1))))
36 "Split current line, moving portion beyond point vertically down."
38 (skip-chars-forward " \t")
39 (let ((col (current-column))
45 (defun quoted-insert (arg)
46 "Read next input character and insert it.
47 Useful for inserting control characters.
48 You may also type up to 3 octal digits, to insert a character with that code"
50 (let ((char (read-quoted-char)))
53 (setq arg (1- arg)))))
55 (defun delete-indentation (&optional arg)
56 "Join this line to previous and fix up whitespace at join.
57 With argument, join this line to following line."
60 (if arg (forward-line 1))
61 (if (eq (preceding-char) ?\n)
63 (delete-region (point) (1- (point)))
66 (defun fixup-whitespace ()
67 "Fixup white space between objects around point.
68 Leave one space or none, according to the context."
71 (delete-horizontal-space)
72 (if (or (looking-at "^\\|\\s)")
73 (save-excursion (forward-char -1)
74 (looking-at "$\\|\\s(\\|\\s'")))
78 (defun delete-horizontal-space ()
79 "Delete all spaces and tabs around point."
81 (skip-chars-backward " \t")
82 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
84 (defun just-one-space ()
85 "Delete all spaces and tabs around point, leaving one space."
87 (skip-chars-backward " \t")
88 (if (= (following-char) ? )
91 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
93 (defun delete-blank-lines ()
94 "On blank line, delete all surrounding blank lines, leaving just one.
95 On isolated blank line, delete that one.
96 On nonblank line, delete all blank lines that follow it."
98 (let (thisblank singleblank)
101 (setq thisblank (looking-at "[ \t]*$"))
104 (not (looking-at "[ \t]*\n[ \t]*$"))
106 (progn (forward-line -1)
107 (not (looking-at "[ \t]*$")))))))
111 (if singleblank (forward-line 1))
112 (delete-region (point)
113 (if (re-search-backward "[^ \t\n]" nil t)
114 (progn (forward-line 1) (point))
116 (if (not (and thisblank singleblank))
120 (delete-region (point)
121 (if (re-search-forward "[^ \t\n]" nil t)
122 (progn (beginning-of-line) (point))
125 (defun back-to-indentation ()
126 "Move point to the first non-whitespace character on this line."
128 (beginning-of-line 1)
129 (skip-chars-forward " \t"))
131 (defun newline-and-indent ()
132 "Insert a newline, then indent according to major mode.
133 Indentation is done using the current indent-line-function.
134 In programming language modes, this is the same as TAB.
135 In some text modes, where TAB inserts a tab, this indents to the
136 specified left-margin column."
138 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
140 (indent-according-to-mode))
142 (defun reindent-then-newline-and-indent ()
143 "Reindent current line, insert newline, then indent the new line.
144 Indentation of both lines is done according to the current major mode,
145 which means that the current value of indent-line-function is called.
146 In programming language modes, this is the same as TAB.
147 In some text modes, where TAB inserts a tab, this indents to the
148 specified left-margin column."
151 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
152 (indent-according-to-mode))
154 (indent-according-to-mode))
156 ;; Internal subroutine of delete-char
157 (defun kill-forward-chars (arg)
158 (if (listp arg) (setq arg (car arg)))
159 (if (eq arg '-) (setq arg -1))
160 (kill-region (point) (+ (point) arg)))
162 ;; Internal subroutine of backward-delete-char
163 (defun kill-backward-chars (arg)
164 (if (listp arg) (setq arg (car arg)))
165 (if (eq arg '-) (setq arg -1))
166 (kill-region (point) (- (point) arg)))
168 (defun backward-delete-char-untabify (arg &optional killp)
169 "Delete characters backward, changing tabs into spaces.
170 Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil.
171 Interactively, ARG is the prefix arg (default 1)
172 and KILLP is t if prefix arg is was specified."
173 (interactive "*p\nP")
176 (while (and (> count 0) (not (bobp)))
177 (if (= (preceding-char) ?\t)
178 (let ((col (current-column)))
180 (setq col (- col (current-column)))
184 (setq count (1- count)))))
185 (delete-backward-char arg killp)
186 ;; In overwrite mode, back over columns while clearing them out,
187 ;; unless at end of line.
188 (and overwrite-mode (not (eolp))
189 (save-excursion (insert-char ?\ arg))))
191 (defun zap-to-char (arg char)
192 "Kill up to and including ARG'th occurrence of CHAR.
193 Goes backward if ARG is negative; error if CHAR not found."
194 (interactive "p\ncZap to char: ")
195 (kill-region (point) (progn
196 (search-forward (char-to-string char) nil nil arg)
197 ; (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
200 (defun beginning-of-buffer (&optional arg)
201 "Move point to the beginning of the buffer; leave mark at previous position.
202 With arg N, put point N/10 of the way from the true beginning.
203 Don't use this in Lisp programs!
204 \(goto-char (point-min)) is faster and avoids clobbering the mark."
208 (if (> (buffer-size) 10000)
209 ;; Avoid overflow for large buffer sizes!
210 (* (prefix-numeric-value arg)
211 (/ (buffer-size) 10))
212 (/ (+ 10 (* (buffer-size) (prefix-numeric-value arg))) 10))
214 (if arg (forward-line 1)))
216 (defun end-of-buffer (&optional arg)
217 "Move point to the end of the buffer; leave mark at previous position.
218 With arg N, put point N/10 of the way from the true end.
219 Don't use this in Lisp programs!
220 \(goto-char (point-max)) is faster and avoids clobbering the mark."
224 (- (1+ (buffer-size))
225 (if (> (buffer-size) 10000)
226 ;; Avoid overflow for large buffer sizes!
227 (* (prefix-numeric-value arg)
228 (/ (buffer-size) 10))
229 (/ (* (buffer-size) (prefix-numeric-value arg)) 10)))
231 (if arg (forward-line 1)
232 ;; Scroll to put point near bottom--show nearly maximum amount of text,
233 ;; but leave room to add something.
236 (defun mark-whole-buffer ()
237 "Put point at beginning and mark at end of buffer."
240 (push-mark (point-max))
241 (goto-char (point-min)))
243 (defun count-lines-region (start end)
244 "Print number of lines and charcters in the region."
246 (message "Region has %d lines, %d characters"
247 (count-lines start end) (- end start)))
250 "Print the current line number (in the buffer) of point."
257 (1+ (count-lines 1 (point)))))))
259 (defun count-lines (start end)
260 "Return number of lines between START and END.
261 This is usually the number of newlines between them,
262 but will be one more if START is not equal to END
263 and the greater of them is not at the start of a line."
266 (narrow-to-region start end)
267 (goto-char (point-min))
268 (if (eq selective-display t)
270 (while (re-search-forward "[\n\C-m]" nil t 40)
271 (setq done (+ 40 done)))
272 (while (re-search-forward "[\n\C-m]" nil t 1)
273 (setq done (+ 1 done)))
275 (- (buffer-size) (forward-line (buffer-size)))))))
277 (defun what-cursor-position ()
278 "Print info on cursor position (on screen and within buffer)."
280 (let* ((char (following-char))
284 (total (buffer-size))
285 (percent (if (> total 50000)
286 ;; Avoid overflow from multiplying by 100!
287 (/ (+ (/ total 200) (1- pos)) (max (/ total 100) 1))
288 (/ (+ (/ total 2) (* 100 (1- pos))) (max total 1))))
289 (hscroll (if (= (window-hscroll) 0)
291 (format " Hscroll=%d" (window-hscroll))))
292 (col (current-column)))
294 (if (or (/= beg 1) (/= end (1+ total)))
295 (message "point=%d of %d(%d%%) <%d - %d> column %d %s"
296 pos total percent beg end col hscroll)
297 (message "point=%d of %d(%d%%) column %d %s"
298 pos total percent col hscroll))
299 (if (or (/= beg 1) (/= end (1+ total)))
300 (message "Char: %s (0%o) point=%d of %d(%d%%) <%d - %d> column %d %s"
301 (single-key-description char) char pos total percent beg end col hscroll)
302 (message "Char: %s (0%o) point=%d of %d(%d%%) column %d %s"
303 (single-key-description char) char pos total percent col hscroll)))))
305 (defun fundamental-mode ()
306 "Major mode not specialized for anything in particular.
307 Other major modes are defined by comparison with this one."
309 (kill-all-local-variables))
311 (put 'eval-expression 'disabled t)
313 ;; We define this, rather than making eval interactive,
314 ;; for the sake of completion of names like eval-region, eval-current-buffer.
315 (defun eval-expression (expression)
316 "Evaluate EXPRESSION and print value in minibuffer.
317 Value is also consed on to front of variable values 's value."
318 (interactive "xEval: ")
319 (setq values (cons (eval expression) values))
320 (prin1 (car values) t))
322 (defun edit-and-eval-command (prompt command)
323 "Prompting with PROMPT, let user edit COMMAND and eval result.
324 COMMAND is a Lisp expression. Let user edit that expression in
325 the minibuffer, then read and evaluate the result."
326 (let ((command (read-minibuffer prompt
327 (prin1-to-string command))))
328 ;; Add edited command to command history, unless redundant.
329 (or (equal command (car command-history))
330 (setq command-history (cons command command-history)))
333 ;; (defvar repeat-complex-command nil)
335 (defvar repeat-complex-command-map (copy-keymap minibuffer-local-map))
336 (define-key repeat-complex-command-map "\ep" 'previous-complex-command)
337 (define-key repeat-complex-command-map "\en" 'next-complex-command)
338 (defun repeat-complex-command (repeat-complex-command-arg)
339 "Edit and re-evaluate last complex command, or ARGth from last.
340 A complex command is one which used the minibuffer.
341 The command is placed in the minibuffer as a Lisp form for editing.
342 The result is executed, repeating the command as changed.
343 If the command has been changed or is not the most recent previous command
344 it is added to the front of the command history.
345 Whilst editing the command, the following commands are available:
346 \\{repeat-complex-command-map}"
348 (let ((elt (nth (1- repeat-complex-command-arg) command-history))
349 (repeat-complex-command-flag t)
353 (setq newcmd (read-from-minibuffer "Redo: "
354 (prin1-to-string elt)
355 repeat-complex-command-map
357 ;; If command to be redone does not match front of history,
358 ;; add it to the history.
359 (or (equal newcmd (car command-history))
360 (setq command-history (cons newcmd command-history)))
364 (defun next-complex-command (n)
365 "Inserts the next element of `command-history' into the minibuffer."
367 (let ((narg (min (max 1 (- repeat-complex-command-arg n))
368 (length command-history))))
369 (if (= repeat-complex-command-arg narg)
370 (error (if (= repeat-complex-command-arg 1)
371 "No following item in command history"
372 "No preceding item in command history"))
374 (setq repeat-complex-command-arg narg)
375 (insert (prin1-to-string (nth (1- repeat-complex-command-arg)
377 (goto-char (point-min)))))
379 (defun previous-complex-command (n)
380 "Inserts the previous element of `command-history' into the minibuffer."
382 (if repeat-complex-command-flag
383 (next-complex-command (- n))
384 (repeat-complex-command 1)))
386 (defun goto-line (arg)
387 "Goto line ARG, counting from line 1 at beginning of buffer."
388 (interactive "NGoto line: ")
392 (if (eq selective-display t)
393 (re-search-forward "[\n\C-m]" nil 'end (1- arg))
394 (forward-line (1- arg)))))
396 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
397 (fset 'advertised-undo 'undo)
399 (defun undo (&optional arg)
400 "Undo some previous changes.
401 Repeat this command to undo more changes.
402 A numeric argument serves as a repeat count."
404 (let ((modified (buffer-modified-p)))
406 (or (eq last-command 'undo)
409 (setq this-command 'undo)
410 (undo-more (or arg 1))
411 (and modified (not (buffer-modified-p))
412 (delete-auto-save-file-if-necessary))))
415 "Move pending-undo-list to front of undo records.
416 The next call to undo-more will undo the most recently made change."
417 (if (eq buffer-undo-list t)
418 (error "No undo information in this buffer"))
419 (setq pending-undo-list buffer-undo-list))
421 (defun undo-more (count)
422 "Undo back N undo-boundaries beyond what was already undone recently.
423 Call undo-start to get ready to undo recent changes,
424 then call undo-more one or more times to undo them."
425 (or pending-undo-list
426 (error "No further undo information"))
427 (setq pending-undo-list (primitive-undo count pending-undo-list)))
429 (defvar last-shell-command "")
430 (defvar last-shell-command-on-region "")
432 (defun shell-command (command &optional flag)
433 "Execute string COMMAND in inferior shell; display output, if any.
434 If COMMAND ends in ampersand, execute it asynchronously.
436 Optional second arg non-nil (prefix arg, if interactive)
437 means insert output in current buffer after point (leave mark after it).
438 This cannot be done asynchronously."
439 (interactive (list (read-string "Shell command: " last-shell-command)
442 (progn (barf-if-buffer-read-only)
444 ;; We do not use -f for csh; we will not support broken use of
445 ;; .cshrcs. Even the BSD csh manual says to use
446 ;; "if ($?prompt) exit" before things which are not useful
447 ;; non-interactively. Besides, if someone wants their other
448 ;; aliases for shell commands then they can still have them.
449 (call-process shell-file-name nil t nil
451 (exchange-point-and-mark))
452 ;; Preserve the match data in case called from a program.
453 (let ((data (match-data)))
455 (if (string-match "[ \t]*&[ \t]*$" command)
456 ;; Command ending with ampersand means asynchronous.
457 (let ((buffer (get-buffer-create "*shell-command*"))
458 (directory default-directory)
460 ;; Remove the ampersand.
461 (setq command (substring command 0 (match-beginning 0)))
462 ;; If will kill a process, query first.
463 (setq proc (get-buffer-process buffer))
465 (if (yes-or-no-p "A command is running. Kill it? ")
467 (error "Shell command in progress")))
471 (display-buffer buffer)
472 (setq default-directory directory)
473 (setq proc (start-process "Shell" buffer
474 shell-file-name "-c" command))
475 (setq mode-line-process '(": %s"))
476 (set-process-sentinel proc 'shell-command-sentinel)
477 (set-process-filter proc 'shell-command-filter)
479 (shell-command-on-region (point) (point) command nil))
480 (store-match-data data)))))
482 ;; We have a sentinel to prevent insertion of a termination message
483 ;; in the buffer itself.
484 (defun shell-command-sentinel (process signal)
485 (if (memq (process-status process) '(exit signal))
488 (car (cdr (cdr (process-command process))))
489 (substring signal 0 -1))
491 (set-buffer (process-buffer process))
492 (setq mode-line-process nil))
493 (delete-process process))))
495 (defun shell-command-filter (proc string)
496 ;; Do save-excursion by hand so that we can leave point numerically unchanged
497 ;; despite an insertion immediately after it.
498 (let* ((obuf (current-buffer))
499 (buffer (process-buffer proc))
501 (window (get-buffer-window buffer))
502 (pos (window-start window)))
506 (setq opoint (point))
507 (goto-char (point-max))
508 (insert-before-markers string))
509 ;; insert-before-markers moved this marker: set it back.
510 (set-window-start window pos)
511 ;; Finish our save-excursion.
515 (defun shell-command-on-region (start end command &optional flag interactive)
516 "Execute string COMMAND in inferior shell with region as input.
517 Normally display output (if any) in temp buffer `*Shell Command Output*';
518 Prefix arg means replace the region with it.
519 Noninteractive args are START, END, COMMAND, FLAG.
520 Noninteractively FLAG means insert output in place of text from START to END,
521 and put point at the end, but don't alter the mark.
523 If the output is one line, it is displayed in the echo area,
524 but it is nonetheless available in buffer `*Shell Command Output*'
525 even though that buffer is not automatically displayed. If there is no output
526 or output is inserted in the current buffer then `*Shell Command Output*' is
528 (interactive (list (min (point) (mark)) (max (point) (mark))
529 (read-string "Shell command on region: "
530 last-shell-command-on-region)
532 (prefix-numeric-value current-prefix-arg)))
534 ;; Replace specified region with output from command.
535 (let ((swap (and interactive (< (point) (mark)))))
536 ;; Don't muck with mark
537 ;; unless called interactively.
538 (and interactive (push-mark))
539 (call-process-region start end shell-file-name t t nil
541 (if (get-buffer "*Shell Command Output*")
542 (kill-buffer "*Shell Command Output*"))
543 (and interactive swap (exchange-point-and-mark)))
544 ;; No prefix argument: put the output in a temp buffer,
545 ;; replacing its entire contents.
546 (let ((buffer (get-buffer-create "*Shell Command Output*")))
547 (if (eq buffer (current-buffer))
548 ;; If the input is the same buffer as the output,
549 ;; delete everything but the specified region,
550 ;; then replace that region with the output.
551 (progn (delete-region end (point-max))
552 (delete-region (point-min) start)
553 (call-process-region (point-min) (point-max)
554 shell-file-name t t nil
556 ;; Clear the output buffer, then run the command with output there.
560 (call-process-region start end shell-file-name
563 ;; Report the amount of output.
564 (let ((lines (save-excursion
566 (if (= (buffer-size) 0)
568 (count-lines (point-min) (point-max))))))
570 (message "(Shell command completed with no output)")
571 (kill-buffer "*Shell Command Output*"))
576 (goto-char (point-min))
577 (buffer-substring (point)
578 (progn (end-of-line) (point))))))
580 (set-window-start (display-buffer buffer) 1)))))))
582 (defun universal-argument ()
583 "Begin a numeric argument for the following command.
584 Digits or minus sign following \\[universal-argument] make up the numeric argument.
585 \\[universal-argument] following the digits or minus sign ends the argument.
586 \\[universal-argument] without digits or minus sign provides 4 as argument.
587 Repeating \\[universal-argument] without digits or minus sign
588 multiplies the argument by 4 each time."
592 (describe-arg (list factor) 1)
593 (setq key (read-key-sequence nil))
594 (while (equal (key-binding key) 'universal-argument)
595 (setq factor (* 4 factor))
596 (describe-arg (list factor) 1)
597 (setq key (read-key-sequence nil)))
598 (prefix-arg-internal key factor nil)))
600 (defun prefix-arg-internal (key factor value)
602 (if (and (numberp value) (< value 0))
603 (setq sign -1 value (- value)))
605 (setq sign -1 value nil))
606 (describe-arg value sign)
607 (while (equal key "-")
608 (setq sign (- sign) factor nil)
609 (describe-arg value sign)
610 (setq key (read-key-sequence nil)))
611 (while (and (= (length key) 1)
612 (not (string< key "0"))
613 (not (string< "9" key)))
614 (setq value (+ (* (if (numberp value) value 0) 10)
617 (describe-arg value sign)
618 (setq key (read-key-sequence nil)))
620 (cond (factor (list factor))
621 ((numberp value) (* value sign))
623 ;; Calling universal-argument after digits
624 ;; terminates the argument but is ignored.
625 (if (eq (key-binding key) 'universal-argument)
627 (describe-arg value sign)
628 (setq key (read-key-sequence nil))))
629 (if (= (length key) 1)
630 ;; Make sure self-insert-command finds the proper character;
631 ;; unread the character and let the command loop process it.
632 (setq unread-command-char (string-to-char key))
633 ;; We can't push back a longer string, so we'll emulate the
634 ;; command loop ourselves.
635 (command-execute (key-binding key)))))
637 (defun describe-arg (value sign)
638 (cond ((numberp value)
639 (message "Arg: %d" (* value sign)))
641 (message "Arg: [%d]" (car value)))
643 (message "Arg: -"))))
645 (defun digit-argument (arg)
646 "Part of the numeric argument for the next command.
647 \\[universal-argument] following digits or minus sign ends the argument."
649 (prefix-arg-internal (char-to-string (logand last-command-char ?\177))
652 (defun negative-argument (arg)
653 "Begin a negative numeric argument for the next command.
654 \\[universal-argument] following digits or minus sign ends the argument."
656 (prefix-arg-internal "-" nil arg))
658 (defun forward-to-indentation (arg)
659 "Move forward ARG lines and position at first nonblank character."
662 (skip-chars-forward " \t"))
664 (defun backward-to-indentation (arg)
665 "Move backward ARG lines and position at first nonblank character."
667 (forward-line (- arg))
668 (skip-chars-forward " \t"))
670 (defun kill-line (&optional arg)
671 "Kill the rest of the current line; if no nonblanks there, kill thru newline.
672 With prefix argument, kill that many lines from point.
673 Negative arguments kill lines backward.
675 When calling from a program, nil means \"no arg\",
676 a number counts as a prefix arg."
681 (forward-line (prefix-numeric-value arg))
683 (signal 'end-of-buffer nil))
684 (if (looking-at "[ \t]*$")
691 (defvar kill-ring nil
692 "List of killed text sequences.")
694 (defconst kill-ring-max 30
695 "*Maximum length of kill ring before oldest elements are thrown away.")
697 (defvar kill-ring-yank-pointer nil
698 "The tail of the kill ring whose car is the last thing yanked.")
700 (defun kill-append (string before-p)
703 (concat string (car kill-ring))
704 (concat (car kill-ring) string))))
706 (defun kill-region (beg end)
707 "Kill between point and mark.
708 The text is deleted but saved in the kill ring.
709 The command \\[yank] can retrieve it from there.
710 \(If you want to kill and then yank immediately, use \\[copy-region-as-kill].)
712 This is the primitive for programs to kill text (as opposed to deleting it).
713 Supply two arguments, character numbers indicating the stretch of text
715 Any command that calls this function is a \"kill command\".
716 If the previous command was also a kill command,
717 the text killed this time appends to the text killed last time
718 to make one entry in the kill ring."
720 (if (and (not (eq buffer-undo-list t))
721 (not (eq last-command 'kill-region))
723 (not buffer-read-only))
724 ;; Don't let the undo list be truncated before we can even access it.
725 (let ((undo-high-threshold (+ (- (max beg end) (min beg end)) 100)))
726 (delete-region beg end)
727 ;; Take the same string recorded for undo
728 ;; and put it in the kill-ring.
729 (setq kill-ring (cons (car (car buffer-undo-list)) kill-ring))
730 (if (> (length kill-ring) kill-ring-max)
731 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
732 (setq this-command 'kill-region)
733 (setq kill-ring-yank-pointer kill-ring))
734 (copy-region-as-kill beg end)
735 (or buffer-read-only (delete-region beg end))))
737 (defvar interprogram-cut-function nil
738 "Function to call to make a killed region available to other programs.
740 Most window systems provide some sort of facility for cutting and
741 pasting text between the windows of different programs. On startup,
742 this variable is set to a function which emacs will call to make the
743 most recently killed text available to other programs.
745 The function takes one argument, TEXT, which is a string containing
746 the text which should be made available.")
748 (defun copy-region-as-kill (beg end)
749 "Save the region as if killed, but don't kill it.
750 If `x-select-kill' is non-nil, also save the text for X cut and paste."
752 (if (eq last-command 'kill-region)
753 (kill-append (buffer-substring beg end) (< end beg))
754 (setq kill-ring (cons (buffer-substring beg end) kill-ring))
755 (if (> (length kill-ring) kill-ring-max)
756 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)))
757 (if interprogram-cut-function
758 (funcall interprogram-cut-function (car kill-ring)))
759 (setq this-command 'kill-region
760 kill-ring-yank-pointer kill-ring)
763 (defun kill-ring-save (beg end)
764 "Save the region as if killed, but don't kill it."
766 (copy-region-as-kill beg end)
767 (message "%d characters copied to kill ring"
768 (- (max beg end) (min beg end))))
770 (defun append-next-kill ()
771 "Cause following command, if kill, to append to previous kill."
775 (setq this-command 'kill-region)
776 (message "If the next command is a kill, it will append"))
777 (setq last-command 'kill-region)))
779 (defun rotate-yank-pointer (arg)
780 "Rotate the yanking point in the kill ring."
782 (let ((length (length kill-ring)))
784 (error "Kill ring is empty")
785 (setq kill-ring-yank-pointer
786 (nthcdr (% (+ arg (- length (length kill-ring-yank-pointer)))
790 (defun yank-pop (arg)
791 "Replace just-yanked stretch of killed-text with a different stretch.
792 This command is allowed only immediately after a yank or a yank-pop.
793 At such a time, the region contains a stretch of reinserted
794 previously-killed text. yank-pop deletes that text and inserts in its
795 place a different stretch of killed text.
797 With no argument, the previous kill is inserted.
798 With argument n, the n'th previous kill is inserted.
799 If n is negative, this is a more recent kill.
801 The sequence of kills wraps around, so that after the oldest one
802 comes the newest one."
804 (if (not (eq last-command 'yank))
805 (error "Previous command was not a yank"))
806 (setq this-command 'yank)
807 (let ((before (< (point) (mark))))
808 (delete-region (point) (mark))
809 (rotate-yank-pointer arg)
811 (insert (car kill-ring-yank-pointer))
812 (if before (exchange-point-and-mark))))
814 (defun yank (&optional arg)
815 "Reinsert the last stretch of killed text.
816 More precisely, reinsert the stretch of killed text most recently
818 With just C-U as argument, same but put point in front (and mark at end).
819 With argument n, reinsert the nth most recently killed stretch of killed
821 See also the command \\[yank-pop]."
823 (rotate-yank-pointer (if (listp arg) 0
827 (insert (car kill-ring-yank-pointer))
829 (exchange-point-and-mark)))
831 (defun insert-buffer (buffer)
832 "Insert after point the contents of BUFFER.
833 Puts mark after the inserted text.
834 BUFFER may be a buffer or a buffer name."
835 (interactive (list (read-buffer "Insert buffer: " (other-buffer) t)))
837 (setq buffer (get-buffer buffer)))
838 (let (start end newmark)
842 (setq start (point-min) end (point-max)))
843 (insert-buffer-substring buffer start end)
844 (setq newmark (point)))
845 (push-mark newmark)))
847 (defun append-to-buffer (buffer start end)
848 "Append to specified buffer the text of the region.
849 It is inserted into that buffer before its point.
851 When calling from a program, give three arguments:
852 BUFFER (or buffer name), START and END.
853 START and END specify the portion of the current buffer to be copied."
854 (interactive "BAppend to buffer: \nr")
855 (let ((oldbuf (current-buffer)))
857 (set-buffer (get-buffer-create buffer))
858 (insert-buffer-substring oldbuf start end))))
860 (defun prepend-to-buffer (buffer start end)
861 "Prepend to specified buffer the text of the region.
862 It is inserted into that buffer after its point.
864 When calling from a program, give three arguments:
865 BUFFER (or buffer name), START and END.
866 START and END specify the portion of the current buffer to be copied."
867 (interactive "BPrepend to buffer: \nr")
868 (let ((oldbuf (current-buffer)))
870 (set-buffer (get-buffer-create buffer))
872 (insert-buffer-substring oldbuf start end)))))
874 (defun copy-to-buffer (buffer start end)
875 "Copy to specified buffer the text of the region.
876 It is inserted into that buffer, replacing existing text there.
878 When calling from a program, give three arguments:
879 BUFFER (or buffer name), START and END.
880 START and END specify the portion of the current buffer to be copied."
881 (interactive "BCopy to buffer: \nr")
882 (let ((oldbuf (current-buffer)))
884 (set-buffer (get-buffer-create buffer))
887 (insert-buffer-substring oldbuf start end)))))
890 "Return this buffer's mark value as integer, or nil if no mark.
891 If you are using this in an editing command, you are most likely making
892 a mistake; see the documentation of `set-mark'."
893 (marker-position (mark-marker)))
895 (defun set-mark (pos)
896 "Set this buffer's mark to POS. Don't use this function!
897 That is to say, don't use this function unless you want
898 the user to see that the mark has moved, and you want the previous
899 mark position to be lost.
901 Normally, when a new mark is set, the old one should go on the stack.
902 This is why most applications should use push-mark, not set-mark.
904 Novice emacs-lisp programmers often try to use the mark for the wrong
905 purposes. The mark saves a location for the user's convenience.
906 Most editing commands should not alter the mark.
907 To remember a location for internal use in the Lisp program,
908 store it in a Lisp variable. Example:
910 (let ((beg (point))) (forward-line 1) (delete-region beg (point)))."
912 (set-marker (mark-marker) pos (current-buffer)))
914 (defvar mark-ring nil
915 "The list of saved former marks of the current buffer,
917 (make-variable-buffer-local 'mark-ring)
919 (defconst mark-ring-max 16
920 "*Maximum size of mark ring. Start discarding off end if gets this big.")
922 (defun set-mark-command (arg)
923 "Set mark at where point is, or jump to mark.
924 With no prefix argument, set mark, and push previous mark on mark ring.
925 With argument, jump to mark, and pop into mark off the mark ring.
927 Novice emacs-lisp programmers often try to use the mark for the wrong
928 purposes. See the documentation of `set-mark' for more information."
933 (error "No mark set in this buffer")
937 (defun push-mark (&optional location nomsg)
938 "Set mark at LOCATION (point, by default) and push old mark on mark ring.
939 Displays \"Mark set\" unless the optional second arg NOMSG is non-nil.
941 Novice emacs-lisp programmers often try to use the mark for the wrong
942 purposes. See the documentation of `set-mark' for more information."
945 (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring))
946 (if (> (length mark-ring) mark-ring-max)
948 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil)
949 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil))))
950 (set-mark (or location (point)))
951 (or nomsg executing-macro (> (minibuffer-depth) 0)
952 (message "Mark set"))
956 "Pop off mark ring into the buffer's actual mark.
957 Does not set point. Does nothing if mark ring is empty."
960 (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker)))))
961 (set-mark (+ 0 (car mark-ring)))
962 (move-marker (car mark-ring) nil)
963 (if (null (mark)) (ding))
964 (setq mark-ring (cdr mark-ring)))))
966 (fset 'exchange-dot-and-mark 'exchange-point-and-mark)
967 (defun exchange-point-and-mark ()
968 "Put the mark where point is now, and point where the mark is now."
970 (let ((omark (mark)))
972 (error "No mark set in this buffer"))
977 (defun next-line (arg)
978 "Move cursor vertically down ARG lines.
979 If there is no character in the target line exactly under the current column,
980 the cursor is positioned after the character in that line which spans this
981 column, or at the end of the line if it is not long enough.
982 If there is no line in the buffer after this one,
983 a newline character is inserted to create a line
984 and the cursor moves to that line.
986 The command \\[set-goal-column] can be used to create
987 a semipermanent goal column to which this command always moves.
988 Then it does not try to move vertically. This goal column is stored
989 in `goal-column', which is nil when there is none.
991 If you are thinking of using this in a Lisp program, consider
992 using `forward-line' instead. It is usually easier to use
993 and more reliable (no dependence on goal column, etc.)."
996 (let ((opoint (point)))
998 (if (or (= opoint (point))
999 (not (eq (preceding-char) ?\n)))
1006 (defun previous-line (arg)
1007 "Move cursor vertically up ARG lines.
1008 If there is no character in the target line exactly over the current column,
1009 the cursor is positioned after the character in that line which spans this
1010 column, or at the end of the line if it is not long enough.
1012 The command \\[set-goal-column] can be used to create
1013 a semipermanent goal column to which this command always moves.
1014 Then it does not try to move vertically.
1016 If you are thinking of using this in a Lisp program, consider using
1017 `forward-line' with negative argument instead.. It is usually easier
1018 to use and more reliable (no dependence on goal column, etc.)."
1023 (defconst track-eol nil
1024 "*Non-nil means vertical motion starting at end of line keeps to ends of lines.
1025 This means moving to the end of each line moved onto.
1026 The beginning of a blank line does not count as the end of a line.")
1028 (make-variable-buffer-local
1029 (defvar goal-column nil
1030 "*Semipermanent goal column for vertical motion, as set by \\[set-goal-column], or nil."))
1032 (defvar temporary-goal-column 0
1033 "Current goal column for vertical motion.
1034 It is the column where point was
1035 at the start of current run of vertical motion commands.
1036 When the `track-eol' feature is doing its job, the value is 9999.")
1038 (defun line-move (arg)
1039 (if (not (or (eq last-command 'next-line)
1040 (eq last-command 'previous-line)))
1041 (setq temporary-goal-column
1042 (if (and track-eol (eolp)
1043 ;; Don't count beg of empty line as end of line
1044 ;; unless we just did explicit end-of-line.
1045 (or (not (bolp)) (eq last-command 'end-of-line)))
1048 (if (not (integerp selective-display))
1050 ;; Move by arg lines, but ignore invisible ones.
1055 (setq arg (1- arg)))
1057 (vertical-motion -1)
1059 (setq arg (1+ arg))))
1060 (move-to-column (or goal-column temporary-goal-column))
1064 (defun set-goal-column (arg)
1065 "Set the current horizontal position as a goal for \\[next-line] and \\[previous-line].
1066 Those commands will move to this position in the line moved to
1067 rather than trying to keep the same horizontal position.
1068 With a non-nil argument, clears out the goal column
1069 so that \\[next-line] and \\[previous-line] resume vertical motion."
1073 (setq goal-column nil)
1074 (message "No goal column"))
1075 (setq goal-column (current-column))
1076 (message (substitute-command-keys
1077 "Goal column %d (use \\[set-goal-column] with an arg to unset it)")
1081 (defun transpose-chars (arg)
1082 "Interchange characters around point, moving forward one character.
1083 With prefix arg ARG, effect is to take character before point
1084 and drag it forward past ARG other characters (backward if ARG negative).
1085 If no argument and at end of line, the previous two chars are exchanged."
1087 (and (null arg) (eolp) (forward-char -1))
1088 (transpose-subr 'forward-char (prefix-numeric-value arg)))
1090 (defun transpose-words (arg)
1091 "Interchange words around point, leaving point at end of them.
1092 With prefix arg ARG, effect is to take word before or around point
1093 and drag it forward past ARG other words (backward if ARG negative).
1094 If ARG is zero, the words around or after point and around or after mark
1097 (transpose-subr 'forward-word arg))
1099 (defun transpose-sexps (arg)
1100 "Like \\[transpose-words] but applies to sexps.
1101 Does not work on a sexp that point is in the middle of
1102 if it is a list or string."
1104 (transpose-subr 'forward-sexp arg))
1106 (defun transpose-lines (arg)
1107 "Exchange current line and previous line, leaving point after both.
1108 With argument ARG, takes previous line and moves it past ARG lines.
1109 With argument 0, interchanges line point is in with line mark is in."
1111 (transpose-subr (function
1115 ;; Move forward over a line,
1116 ;; but create a newline if none exists yet.
1121 (forward-line arg))))
1124 (defun transpose-subr (mover arg)
1125 (let (start1 end1 start2 end2)
1132 (setq start2 (point))
1137 (setq start1 (point))
1139 (exchange-point-and-mark)))
1142 (setq start1 (point))
1148 (setq start2 (point))
1151 (setq arg (1- arg)))
1154 (setq start2 (point))
1156 (setq start1 (point))
1162 (setq arg (1+ arg)))))
1164 (defun transpose-subr-1 ()
1165 (if (> (min end1 end2) (max start1 start2))
1166 (error "Don't have two things to transpose"))
1167 (let ((word1 (buffer-substring start1 end1))
1168 (word2 (buffer-substring start2 end2)))
1169 (delete-region start2 end2)
1172 (goto-char (if (< start1 start2) start1
1173 (+ start1 (- (length word1) (length word2)))))
1174 (delete-char (length word1))
1177 (defconst comment-column 32
1178 "*Column to indent right-margin comments to.
1179 Setting this variable automatically makes it local to the current buffer.")
1180 (make-variable-buffer-local 'comment-column)
1182 (defconst comment-start nil
1183 "*String to insert to start a new comment, or nil if no comment syntax defined.")
1185 (defconst comment-start-skip nil
1186 "*Regexp to match the start of a comment plus everything up to its body.
1187 If there are any \\(...\\) pairs, the comment delimiter text is held to begin
1188 at the place matched by the close of the first pair.")
1190 (defconst comment-end ""
1191 "*String to insert to end a new comment.
1192 Should be an empty string if comments are terminated by end-of-line.")
1194 (defconst comment-indent-hook
1195 '(lambda () comment-column)
1196 "Function to compute desired indentation for a comment.
1197 This function is called with no args with point at the beginning of
1198 the comment's starting delimiter.")
1200 (defun indent-for-comment ()
1201 "Indent this line's comment to comment column, or insert an empty comment."
1203 (beginning-of-line 1)
1204 (if (null comment-start)
1205 (error "No comment syntax defined")
1206 (let* ((eolpos (save-excursion (end-of-line) (point)))
1208 (if (re-search-forward comment-start-skip eolpos 'move)
1209 (progn (setq cpos (point-marker))
1210 ;; Find the start of the comment delimiter.
1211 ;; If there were paren-pairs in comment-start-skip,
1212 ;; position at the end of the first pair.
1214 (goto-char (match-end 1))
1215 ;; If comment-start-skip matched a string with internal
1216 ;; whitespace (not final whitespace) then the delimiter
1217 ;; start at the end of that whitespace.
1218 ;; Otherwise, it starts at the beginning of what was matched.
1219 (skip-chars-backward " \t" (match-beginning 0))
1220 (skip-chars-backward "^ \t" (match-beginning 0)))))
1221 (setq begpos (point))
1222 ;; Compute desired indent.
1223 (if (= (current-column)
1224 (setq indent (funcall comment-indent-hook)))
1226 ;; If that's different from current, change it.
1227 (skip-chars-backward " \t")
1228 (delete-region (point) begpos)
1230 ;; An existing comment?
1232 (progn (goto-char cpos)
1233 (set-marker cpos nil))
1235 (insert comment-start)
1237 (insert comment-end))))))
1239 (defun set-comment-column (arg)
1240 "Set the comment column based on point.
1241 With no arg, set the comment column to the current column.
1242 With just minus as arg, kill any comment on this line.
1243 With any other arg, set comment column to indentation of the previous comment
1244 and then align or create a comment on this line at that column."
1252 (re-search-backward comment-start-skip)
1254 (re-search-forward comment-start-skip)
1255 (goto-char (match-beginning 0))
1256 (setq comment-column (current-column))
1257 (message "Comment column set to %d" comment-column))
1258 (indent-for-comment))
1259 (setq comment-column (current-column))
1260 (message "Comment column set to %d" comment-column))))
1262 (defun kill-comment (arg)
1263 "Kill the comment on this line, if any.
1264 With argument, kill comments on that many lines starting with this one."
1265 ;; this function loses in a lot of situations. it incorrectly recognises
1266 ;; comment delimiters sometimes (ergo, inside a string), doesn't work
1267 ;; with multi-line comments, can kill extra whitespace if comment wasn't
1268 ;; through end-of-line, et cetera.
1270 (or comment-start-skip (error "No comment syntax defined"))
1271 (let ((count (prefix-numeric-value arg)) endc)
1277 (and (string< "" comment-end)
1280 (re-search-forward (regexp-quote comment-end) endc 'move)
1281 (skip-chars-forward " \t")
1284 (if (re-search-forward comment-start-skip endc t)
1286 (goto-char (match-beginning 0))
1287 (skip-chars-backward " \t")
1288 (kill-region (point) endc)
1289 ;; to catch comments a line beginnings
1290 (indent-according-to-mode))))
1291 (if arg (forward-line 1))
1292 (setq count (1- count)))))
1294 (defun comment-region (beg end &optional arg)
1295 "Comment the region; third arg numeric means use ARG comment characters.
1296 If ARG is negative, delete that many comment characters instead.
1297 Comments are terminated on each line, even for syntax in which newline does
1298 not end the comment. Blank lines do not get comments."
1299 ;; if someone wants it to only put a comment-start at the beginning and
1300 ;; comment-end at the end then typing it, C-x C-x, closing it, C-x C-x
1301 ;; is easy enough. No option is made here for other than commenting
1303 (interactive "r\np")
1304 (or comment-start (error "No comment syntax is defined"))
1305 (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
1308 (let ((cs comment-start) (ce comment-end))
1309 (cond ((not arg) (setq arg 1))
1311 (while (> (setq arg (1- arg)) 0)
1312 (setq cs (concat cs comment-start)
1313 ce (concat ce comment-end)))))
1314 (narrow-to-region beg end)
1319 (while (and (> 1 (setq count (1+ count)))
1320 (looking-at (regexp-quote cs)))
1321 (delete-char (length cs)))
1322 (if (string= "" ce) ()
1324 (while (> 1 (setq count (1+ count)))
1326 ;; this is questionable if comment-end ends in whitespace
1327 ;; that is pretty brain-damaged though
1328 (skip-chars-backward " \t")
1329 (backward-char (length ce))
1330 (if (looking-at (regexp-quote ce))
1331 (delete-char (length ce))))))
1332 (if (looking-at "[ \t]*$") ()
1334 (if (string= "" ce) ()
1337 (search-forward "\n" nil 'move)))))))
1339 (defun backward-word (arg)
1340 "Move backward until encountering the end of a word.
1341 With argument, do this that many times.
1342 In programs, it is faster to call forward-word with negative arg."
1344 (forward-word (- arg)))
1346 (defun mark-word (arg)
1347 "Set mark arg words away from point."
1354 (defun kill-word (arg)
1355 "Kill characters forward until encountering the end of a word.
1356 With argument, do this that many times."
1358 (kill-region (point) (progn (forward-word arg) (point))))
1360 (defun backward-kill-word (arg)
1361 "Kill characters backward until encountering the end of a word.
1362 With argument, do this that many times."
1364 (kill-word (- arg)))
1366 (defconst fill-prefix nil
1367 "*String for filling to insert at front of new line, or nil for none.
1368 Setting this variable automatically makes it local to the current buffer.")
1369 (make-variable-buffer-local 'fill-prefix)
1371 (defconst auto-fill-inhibit-regexp nil
1372 "*Regexp to match lines which should not be auto-filled.")
1374 (defun do-auto-fill ()
1376 (or (and auto-fill-inhibit-regexp
1377 (save-excursion (beginning-of-line)
1378 (looking-at auto-fill-inhibit-regexp)))
1379 (while (and (not give-up) (> (current-column) fill-column))
1381 (let ((opoint (point)))
1383 (move-to-column (1+ fill-column))
1384 (skip-chars-backward "^ \t\n")
1386 (re-search-forward "[ \t]" opoint t))
1387 (skip-chars-backward " \t")
1389 ;; If there is a space on the line before fill-point,
1390 ;; and nonspaces precede it, break the line there.
1392 (goto-char fill-point)
1394 ;; If point is at the fill-point, do not `save-excursion'.
1395 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
1396 ;; point will end up before it rather than after it.
1398 (skip-chars-backward " \t")
1399 (= (point) fill-point))
1400 (indent-new-comment-line)
1402 (goto-char fill-point)
1403 (indent-new-comment-line)))
1404 ;; No place to break => stop trying.
1405 (setq give-up t)))))))
1407 (defconst comment-multi-line nil
1408 "*Non-nil means \\[indent-new-comment-line] should continue same comment
1409 on new line, with no new terminator or starter.")
1411 (defun indent-new-comment-line ()
1412 "Break line at point and indent, continuing comment if presently within one.
1413 The body of the continued comment is indented under the previous comment line."
1415 (let (comcol comstart)
1416 (skip-chars-backward " \t")
1417 (delete-region (point)
1418 (progn (skip-chars-forward " \t")
1422 (if (and comment-start-skip
1423 (let ((opoint (point)))
1425 (re-search-forward comment-start-skip opoint t)))
1426 ;; The old line is a comment.
1427 ;; Set WIN to the pos of the comment-start.
1428 ;; But if the comment is empty, look at preceding lines
1429 ;; to find one that has a nonempty comment.
1430 (let ((win (match-beginning 0)))
1431 (while (and (eolp) (not (bobp))
1434 (setq opoint (point))
1436 (re-search-forward comment-start-skip opoint t)))
1437 (setq win (match-beginning 0)))
1438 ;; Indent this line like what we found.
1440 (setq comcol (current-column))
1441 (setq comstart (buffer-substring (point) (match-end 0))))))
1443 (let ((comment-column comcol)
1444 (comment-start comstart)
1445 (comment-end comment-end))
1446 (and comment-end (not (equal comment-end ""))
1447 (if (not comment-multi-line)
1450 (insert comment-end)
1452 (setq comment-column (+ comment-column (length comment-start))
1455 (setq comment-end ""))
1458 (indent-for-comment)
1460 ;; Make sure we delete the newline inserted above.
1464 (insert fill-prefix)
1465 (indent-according-to-mode)))))
1467 (defun auto-fill-mode (&optional arg)
1468 "Toggle auto-fill mode.
1469 With arg, turn auto-fill mode on if and only if arg is positive.
1470 In auto-fill mode, inserting a space at a column beyond fill-column
1471 automatically breaks the line at a previous space."
1473 (prog1 (setq auto-fill-function
1475 (not auto-fill-function)
1476 (> (prefix-numeric-value arg) 0))
1480 (set-buffer-modified-p (buffer-modified-p))))
1482 (defun turn-on-auto-fill ()
1483 "Unconditionally turn on Auto Fill mode."
1486 (defun set-fill-column (arg)
1487 "Set fill-column to current column, or to argument if given.
1488 fill-column's value is separate for each buffer."
1490 (setq fill-column (if (integerp arg) arg (current-column)))
1491 (message "fill-column set to %d" fill-column))
1493 (defun set-selective-display (arg)
1494 "Set selective-display to ARG; clear it if no arg.
1495 When selective-display is a number > 0,
1496 lines whose indentation is >= selective-display are not displayed.
1497 selective-display's value is separate for each buffer."
1499 (if (eq selective-display t)
1500 (error "selective-display already in use for marked lines"))
1501 (setq selective-display
1502 (and arg (prefix-numeric-value arg)))
1503 (set-window-start (selected-window) (window-start (selected-window)))
1504 (princ "selective-display set to " t)
1505 (prin1 selective-display t)
1508 (defun overwrite-mode (arg)
1509 "Toggle overwrite mode.
1510 With arg, turn overwrite mode on iff arg is positive.
1511 In overwrite mode, printing characters typed in replace existing text
1512 on a one-for-one basis, rather than pushing it to the right."
1514 (setq overwrite-mode
1515 (if (null arg) (not overwrite-mode)
1516 (> (prefix-numeric-value arg) 0)))
1517 (set-buffer-modified-p (buffer-modified-p))) ;No-op, but updates mode line.
1519 (defvar blink-matching-paren t
1520 "*Non-nil means show matching open-paren when close-paren is inserted.")
1522 (defconst blink-matching-paren-distance 4000
1523 "*If non-nil, is maximum distance to search for matching open-paren
1524 when close-paren is inserted.")
1526 (defun blink-matching-open ()
1527 "Move cursor momentarily to the beginning of the sexp before point."
1529 (and (> (point) (1+ (point-min)))
1530 (/= (char-syntax (char-after (- (point) 2))) ?\\ )
1531 blink-matching-paren
1532 (let* ((oldpos (point))
1537 (if blink-matching-paren-distance
1538 (narrow-to-region (max (point-min)
1539 (- (point) blink-matching-paren-distance))
1542 (setq blinkpos (scan-sexps oldpos -1))
1544 (and blinkpos (/= (char-syntax (char-after blinkpos))
1547 (/= (char-after (1- oldpos))
1548 (logand (lsh (aref (syntax-table)
1549 (char-after blinkpos))
1552 (if mismatch (setq blinkpos nil))
1555 (goto-char blinkpos)
1556 (if (pos-visible-in-window-p)
1558 (goto-char blinkpos)
1562 (skip-chars-backward " \t")
1564 (buffer-substring (progn (beginning-of-line) (point))
1566 (buffer-substring blinkpos
1569 (skip-chars-forward "\n \t")
1573 (message "Mismatched parentheses"))
1574 ((not blink-matching-paren-distance)
1575 (message "Unmatched parenthesis"))))))))
1577 ;Turned off because it makes dbx bomb out.
1578 (setq blink-paren-function 'blink-matching-open)
1580 ; this is just something for the luser to see in a keymap -- this is not
1581 ; how quitting works normally!
1582 (defun keyboard-quit ()
1583 "Signal a quit condition."
1587 (define-key global-map "\C-g" 'keyboard-quit)
1589 (defun set-variable (var val)
1590 "Set VARIABLE to VALUE. VALUE is a Lisp object.
1591 When using this interactively, supply a Lisp expression for VALUE.
1592 If you want VALUE to be a string, you must surround it with doublequotes."
1594 (let* ((var (read-variable "Set variable: "))
1595 (minibuffer-help-form
1600 (with-output-to-temp-buffer "*Help*"
1602 (princ "\nDocumentation:\n")
1603 (princ (substring (documentation-property var 'variable-documentation)
1606 (let ((print-length 20))
1607 (princ "\n\nCurrent value: ")
1608 (prin1 (symbol-value var))))
1611 (eval-minibuffer (format "Set %s to value: " var)))))
1614 ;These commands are defined in editfns.c
1615 ;but they are not assigned to keys there.
1616 (put 'narrow-to-region 'disabled t)
1617 (define-key ctl-x-map "n" 'narrow-to-region)
1618 (define-key ctl-x-map "w" 'widen)
1620 (define-key global-map "\C-j" 'newline-and-indent)
1621 (define-key global-map "\C-m" 'newline)
1622 (define-key global-map "\C-o" 'open-line)
1623 (define-key esc-map "\C-o" 'split-line)
1624 (define-key global-map "\C-q" 'quoted-insert)
1625 (define-key esc-map "^" 'delete-indentation)
1626 (define-key esc-map "\\" 'delete-horizontal-space)
1627 (define-key esc-map "m" 'back-to-indentation)
1628 (define-key ctl-x-map "\C-o" 'delete-blank-lines)
1629 (define-key esc-map " " 'just-one-space)
1630 (define-key esc-map "z" 'zap-to-char)
1631 (define-key esc-map "=" 'count-lines-region)
1632 (define-key ctl-x-map "=" 'what-cursor-position)
1633 (define-key esc-map "\e" 'eval-expression)
1634 (define-key ctl-x-map "\e" 'repeat-complex-command)
1635 (define-key ctl-x-map "u" 'advertised-undo)
1636 (define-key global-map "\C-_" 'undo)
1637 (define-key esc-map "!" 'shell-command)
1638 (define-key esc-map "|" 'shell-command-on-region)
1640 (define-key global-map "\C-u" 'universal-argument)
1643 (define-key esc-map (char-to-string i) 'digit-argument)
1645 (define-key esc-map "-" 'negative-argument)
1647 (define-key global-map "\C-k" 'kill-line)
1648 (define-key global-map "\C-w" 'kill-region)
1649 (define-key esc-map "w" 'kill-ring-save)
1650 (define-key esc-map "\C-w" 'append-next-kill)
1651 (define-key global-map "\C-y" 'yank)
1652 (define-key esc-map "y" 'yank-pop)
1654 (define-key ctl-x-map "a" 'append-to-buffer)
1656 (define-key global-map "\C-@" 'set-mark-command)
1657 (define-key ctl-x-map "\C-x" 'exchange-point-and-mark)
1659 (define-key global-map "\C-n" 'next-line)
1660 (define-key global-map "\C-p" 'previous-line)
1661 (define-key ctl-x-map "\C-n" 'set-goal-column)
1663 (define-key global-map [up] 'previous-line)
1664 (define-key global-map [down] 'next-line)
1665 (define-key global-map [left] 'backward-char)
1666 (define-key global-map [right] 'forward-char)
1668 (define-key global-map "\C-t" 'transpose-chars)
1669 (define-key esc-map "t" 'transpose-words)
1670 (define-key esc-map "\C-t" 'transpose-sexps)
1671 (define-key ctl-x-map "\C-t" 'transpose-lines)
1673 (define-key esc-map ";" 'indent-for-comment)
1674 (define-key esc-map "j" 'indent-new-comment-line)
1675 (define-key esc-map "\C-j" 'indent-new-comment-line)
1676 (define-key ctl-x-map ";" 'set-comment-column)
1677 (define-key ctl-x-map "f" 'set-fill-column)
1678 (define-key ctl-x-map "$" 'set-selective-display)
1680 (define-key esc-map "@" 'mark-word)
1681 (define-key esc-map "f" 'forward-word)
1682 (define-key esc-map "b" 'backward-word)
1683 (define-key esc-map "d" 'kill-word)
1684 (define-key esc-map "\177" 'backward-kill-word)
1686 (define-key esc-map "<" 'beginning-of-buffer)
1687 (define-key esc-map ">" 'end-of-buffer)
1688 (define-key ctl-x-map "h" 'mark-whole-buffer)
1689 (define-key esc-map "\\" 'delete-horizontal-space)
1691 (fset 'mode-specific-command-prefix (make-sparse-keymap))
1692 (defconst mode-specific-map (symbol-function 'mode-specific-command-prefix)
1693 "Keymap for characters following C-c.")
1694 (define-key global-map "\C-c" 'mode-specific-command-prefix)