Mercurial > emacs
comparison lisp/simple.el @ 1027:f0000f6f7942
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 21 Aug 1992 07:18:16 +0000 |
parents | 9e51bb887797 |
children | 8ab465f7a7ff |
comparison
equal
deleted
inserted
replaced
1026:cc96e2df9b71 | 1027:f0000f6f7942 |
---|---|
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | 20 |
21 ;;; Code: | 21 ;;; Code: |
22 | 22 |
23 (defun open-line (arg) | 23 (defun open-line (arg) |
24 "Insert a newline and leave point before it. If there is a fill | 24 "Insert a newline and leave point before it. |
25 prefix, inserts the fill prefix after the newline that it inserts. | 25 If there is a fill prefix, insert the fill prefix after the newline |
26 With arg, inserts that many newlines." | 26 that it inserts. With arg N, insert N newlines." |
27 (interactive "*p") | 27 (interactive "*p") |
28 (let ((flag (and (bolp) (not (bobp))))) | 28 (let ((flag (and (bolp) (not (bobp))))) |
29 (if flag (forward-char -1)) | 29 (if flag (forward-char -1)) |
30 (while (> arg 0) | 30 (while (> arg 0) |
31 (save-excursion | 31 (save-excursion |
44 (indent-to col 0) | 44 (indent-to col 0) |
45 (goto-char pos))) | 45 (goto-char pos))) |
46 | 46 |
47 (defun quoted-insert (arg) | 47 (defun quoted-insert (arg) |
48 "Read next input character and insert it. | 48 "Read next input character and insert it. |
49 Useful for inserting control characters. | 49 This is useful for inserting control characters. |
50 You may also type up to 3 octal digits, to insert a character with that code" | 50 You may also type up to 3 octal digits, to insert a character with that code" |
51 (interactive "*p") | 51 (interactive "*p") |
52 (let ((char (read-quoted-char))) | 52 (let ((char (read-quoted-char))) |
53 (while (> arg 0) | 53 (while (> arg 0) |
54 (insert char) | 54 (insert char) |
146 (beginning-of-line 1) | 146 (beginning-of-line 1) |
147 (skip-chars-forward " \t")) | 147 (skip-chars-forward " \t")) |
148 | 148 |
149 (defun newline-and-indent () | 149 (defun newline-and-indent () |
150 "Insert a newline, then indent according to major mode. | 150 "Insert a newline, then indent according to major mode. |
151 Indentation is done using the current indent-line-function. | 151 Indentation is done using the value of `indent-line-function'. |
152 In programming language modes, this is the same as TAB. | 152 In programming language modes, this is the same as TAB. |
153 In some text modes, where TAB inserts a tab, this indents to the | 153 In some text modes, where TAB inserts a tab, this command indents to the |
154 specified left-margin column." | 154 column specified by the variable `left-margin'." |
155 (interactive "*") | 155 (interactive "*") |
156 (delete-region (point) (progn (skip-chars-backward " \t") (point))) | 156 (delete-region (point) (progn (skip-chars-backward " \t") (point))) |
157 (newline) | 157 (newline) |
158 (indent-according-to-mode)) | 158 (indent-according-to-mode)) |
159 | 159 |
160 (defun reindent-then-newline-and-indent () | 160 (defun reindent-then-newline-and-indent () |
161 "Reindent current line, insert newline, then indent the new line. | 161 "Reindent current line, insert newline, then indent the new line. |
162 Indentation of both lines is done according to the current major mode, | 162 Indentation of both lines is done according to the current major mode, |
163 which means that the current value of indent-line-function is called. | 163 which means calling the current value of `indent-line-function'. |
164 In programming language modes, this is the same as TAB. | 164 In programming language modes, this is the same as TAB. |
165 In some text modes, where TAB inserts a tab, this indents to the | 165 In some text modes, where TAB inserts a tab, this indents to the |
166 specified left-margin column." | 166 column specified by the variable `left-margin'." |
167 (interactive "*") | 167 (interactive "*") |
168 (save-excursion | 168 (save-excursion |
169 (delete-region (point) (progn (skip-chars-backward " \t") (point))) | 169 (delete-region (point) (progn (skip-chars-backward " \t") (point))) |
170 (indent-according-to-mode)) | 170 (indent-according-to-mode)) |
171 (newline) | 171 (newline) |
216 (point)))) | 216 (point)))) |
217 | 217 |
218 (defun beginning-of-buffer (&optional arg) | 218 (defun beginning-of-buffer (&optional arg) |
219 "Move point to the beginning of the buffer; leave mark at previous position. | 219 "Move point to the beginning of the buffer; leave mark at previous position. |
220 With arg N, put point N/10 of the way from the true beginning. | 220 With arg N, put point N/10 of the way from the true beginning. |
221 Don't use this in Lisp programs! | 221 |
222 Don't use this command in Lisp programs! | |
222 \(goto-char (point-min)) is faster and avoids clobbering the mark." | 223 \(goto-char (point-min)) is faster and avoids clobbering the mark." |
223 (interactive "P") | 224 (interactive "P") |
224 (push-mark) | 225 (push-mark) |
225 (goto-char (if arg | 226 (goto-char (if arg |
226 (if (> (buffer-size) 10000) | 227 (if (> (buffer-size) 10000) |
232 (if arg (forward-line 1))) | 233 (if arg (forward-line 1))) |
233 | 234 |
234 (defun end-of-buffer (&optional arg) | 235 (defun end-of-buffer (&optional arg) |
235 "Move point to the end of the buffer; leave mark at previous position. | 236 "Move point to the end of the buffer; leave mark at previous position. |
236 With arg N, put point N/10 of the way from the true end. | 237 With arg N, put point N/10 of the way from the true end. |
237 Don't use this in Lisp programs! | 238 |
239 Don't use this command in Lisp programs! | |
238 \(goto-char (point-max)) is faster and avoids clobbering the mark." | 240 \(goto-char (point-max)) is faster and avoids clobbering the mark." |
239 (interactive "P") | 241 (interactive "P") |
240 (push-mark) | 242 (push-mark) |
241 (goto-char (if arg | 243 (goto-char (if arg |
242 (- (1+ (buffer-size)) | 244 (- (1+ (buffer-size)) |
285 (1+ (count-lines 1 (point))))))) | 287 (1+ (count-lines 1 (point))))))) |
286 | 288 |
287 (defun count-lines (start end) | 289 (defun count-lines (start end) |
288 "Return number of lines between START and END. | 290 "Return number of lines between START and END. |
289 This is usually the number of newlines between them, | 291 This is usually the number of newlines between them, |
290 but will be one more if START is not equal to END | 292 but can be one more if START is not equal to END |
291 and the greater of them is not at the start of a line." | 293 and the greater of them is not at the start of a line." |
292 (save-excursion | 294 (save-excursion |
293 (save-restriction | 295 (save-restriction |
294 (narrow-to-region start end) | 296 (narrow-to-region start end) |
295 (goto-char (point-min)) | 297 (goto-char (point-min)) |
491 (undo-more (or arg 1)) | 493 (undo-more (or arg 1)) |
492 (and modified (not (buffer-modified-p)) | 494 (and modified (not (buffer-modified-p)) |
493 (delete-auto-save-file-if-necessary)))) | 495 (delete-auto-save-file-if-necessary)))) |
494 | 496 |
495 (defun undo-start () | 497 (defun undo-start () |
496 "Move pending-undo-list to front of undo records. | 498 "Set `pending-undo-list' to the front of the undo list. |
497 The next call to undo-more will undo the most recently made change." | 499 The next call to `undo-more' will undo the most recently made change." |
498 (if (eq buffer-undo-list t) | 500 (if (eq buffer-undo-list t) |
499 (error "No undo information in this buffer")) | 501 (error "No undo information in this buffer")) |
500 (setq pending-undo-list buffer-undo-list)) | 502 (setq pending-undo-list buffer-undo-list)) |
501 | 503 |
502 (defun undo-more (count) | 504 (defun undo-more (count) |
503 "Undo back N undo-boundaries beyond what was already undone recently. | 505 "Undo back N undo-boundaries beyond what was already undone recently. |
504 Call undo-start to get ready to undo recent changes, | 506 Call `undo-start' to get ready to undo recent changes, |
505 then call undo-more one or more times to undo them." | 507 then call `undo-more' one or more times to undo them." |
506 (or pending-undo-list | 508 (or pending-undo-list |
507 (error "No further undo information")) | 509 (error "No further undo information")) |
508 (setq pending-undo-list (primitive-undo count pending-undo-list))) | 510 (setq pending-undo-list (primitive-undo count pending-undo-list))) |
509 | 511 |
510 (defvar last-shell-command "") | 512 (defvar last-shell-command "") |
937 (substring killed-text (- message-len))) | 939 (substring killed-text (- message-len))) |
938 (message "Saved text from \"%s\"" | 940 (message "Saved text from \"%s\"" |
939 (substring killed-text 0 message-len))))))))) | 941 (substring killed-text 0 message-len))))))))) |
940 | 942 |
941 (defun append-next-kill () | 943 (defun append-next-kill () |
942 "Cause following command, if kill, to append to previous kill." | 944 "Cause following command, if it kills, to append to previous kill." |
943 (interactive) | 945 (interactive) |
944 (if (interactive-p) | 946 (if (interactive-p) |
945 (progn | 947 (progn |
946 (setq this-command 'kill-region) | 948 (setq this-command 'kill-region) |
947 (message "If the next command is a kill, it will append")) | 949 (message "If the next command is a kill, it will append")) |
948 (setq last-command 'kill-region))) | 950 (setq last-command 'kill-region))) |
949 | 951 |
950 (defun yank-pop (arg) | 952 (defun yank-pop (arg) |
951 "Replace just-yanked stretch of killed-text with a different stretch. | 953 "Replace just-yanked stretch of killed text with a different stretch. |
952 This command is allowed only immediately after a yank or a yank-pop. | 954 This command is allowed only immediately after a `yank' or a `yank-pop'. |
953 At such a time, the region contains a stretch of reinserted | 955 At such a time, the region contains a stretch of reinserted |
954 previously-killed text. yank-pop deletes that text and inserts in its | 956 previously-killed text. `yank-pop' deletes that text and inserts in its |
955 place a different stretch of killed text. | 957 place a different stretch of killed text. |
956 | 958 |
957 With no argument, the previous kill is inserted. | 959 With no argument, the previous kill is inserted. |
958 With argument n, the n'th previous kill is inserted. | 960 With argument N, insert the Nth previous kill. |
959 If n is negative, this is a more recent kill. | 961 If N is negative, this is a more recent kill. |
960 | 962 |
961 The sequence of kills wraps around, so that after the oldest one | 963 The sequence of kills wraps around, so that after the oldest one |
962 comes the newest one." | 964 comes the newest one." |
963 (interactive "*p") | 965 (interactive "*p") |
964 (if (not (eq last-command 'yank)) | 966 (if (not (eq last-command 'yank)) |
971 (if before (exchange-point-and-mark)))) | 973 (if before (exchange-point-and-mark)))) |
972 | 974 |
973 (defun yank (&optional arg) | 975 (defun yank (&optional arg) |
974 "Reinsert the last stretch of killed text. | 976 "Reinsert the last stretch of killed text. |
975 More precisely, reinsert the stretch of killed text most recently | 977 More precisely, reinsert the stretch of killed text most recently |
976 killed OR yanked. | 978 killed OR yanked. Put point at end, and set mark at beginning. |
977 With just C-U as argument, same but put point in front (and mark at end). | 979 With just C-u as argument, same but put point at beginning (and mark at end). |
978 With argument n, reinsert the nth most recently killed stretch of killed | 980 With argument N, reinsert the Nth most recently killed stretch of killed |
979 text. | 981 text. |
980 See also the command \\[yank-pop]." | 982 See also the command \\[yank-pop]." |
981 (interactive "*P") | 983 (interactive "*P") |
982 (push-mark (point)) | 984 (push-mark (point)) |
983 (insert (current-kill (cond | 985 (insert (current-kill (cond |
1066 mark position to be lost. | 1068 mark position to be lost. |
1067 | 1069 |
1068 Normally, when a new mark is set, the old one should go on the stack. | 1070 Normally, when a new mark is set, the old one should go on the stack. |
1069 This is why most applications should use push-mark, not set-mark. | 1071 This is why most applications should use push-mark, not set-mark. |
1070 | 1072 |
1071 Novice emacs-lisp programmers often try to use the mark for the wrong | 1073 Novice Emacs Lisp programmers often try to use the mark for the wrong |
1072 purposes. The mark saves a location for the user's convenience. | 1074 purposes. The mark saves a location for the user's convenience. |
1073 Most editing commands should not alter the mark. | 1075 Most editing commands should not alter the mark. |
1074 To remember a location for internal use in the Lisp program, | 1076 To remember a location for internal use in the Lisp program, |
1075 store it in a Lisp variable. Example: | 1077 store it in a Lisp variable. Example: |
1076 | 1078 |
1089 (defun set-mark-command (arg) | 1091 (defun set-mark-command (arg) |
1090 "Set mark at where point is, or jump to mark. | 1092 "Set mark at where point is, or jump to mark. |
1091 With no prefix argument, set mark, and push previous mark on mark ring. | 1093 With no prefix argument, set mark, and push previous mark on mark ring. |
1092 With argument, jump to mark, and pop into mark off the mark ring. | 1094 With argument, jump to mark, and pop into mark off the mark ring. |
1093 | 1095 |
1094 Novice emacs-lisp programmers often try to use the mark for the wrong | 1096 Novice Emacs Lisp programmers often try to use the mark for the wrong |
1095 purposes. See the documentation of `set-mark' for more information." | 1097 purposes. See the documentation of `set-mark' for more information." |
1096 (interactive "P") | 1098 (interactive "P") |
1097 (if (null arg) | 1099 (if (null arg) |
1098 (push-mark) | 1100 (push-mark) |
1099 (if (null (mark)) | 1101 (if (null (mark)) |
1103 | 1105 |
1104 (defun push-mark (&optional location nomsg) | 1106 (defun push-mark (&optional location nomsg) |
1105 "Set mark at LOCATION (point, by default) and push old mark on mark ring. | 1107 "Set mark at LOCATION (point, by default) and push old mark on mark ring. |
1106 Displays \"Mark set\" unless the optional second arg NOMSG is non-nil. | 1108 Displays \"Mark set\" unless the optional second arg NOMSG is non-nil. |
1107 | 1109 |
1108 Novice emacs-lisp programmers often try to use the mark for the wrong | 1110 Novice Emacs Lisp programmers often try to use the mark for the wrong |
1109 purposes. See the documentation of `set-mark' for more information." | 1111 purposes. See the documentation of `set-mark' for more information." |
1110 (if (null (mark)) | 1112 (if (null (mark)) |
1111 nil | 1113 nil |
1112 (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring)) | 1114 (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring)) |
1113 (if (> (length mark-ring) mark-ring-max) | 1115 (if (> (length mark-ring) mark-ring-max) |
1504 (search-forward "\n" nil 'move))))))) | 1506 (search-forward "\n" nil 'move))))))) |
1505 | 1507 |
1506 (defun backward-word (arg) | 1508 (defun backward-word (arg) |
1507 "Move backward until encountering the end of a word. | 1509 "Move backward until encountering the end of a word. |
1508 With argument, do this that many times. | 1510 With argument, do this that many times. |
1509 In programs, it is faster to call forward-word with negative arg." | 1511 In programs, it is faster to call `forward-word' with negative arg." |
1510 (interactive "p") | 1512 (interactive "p") |
1511 (forward-word (- arg))) | 1513 (forward-word (- arg))) |
1512 | 1514 |
1513 (defun mark-word (arg) | 1515 (defun mark-word (arg) |
1514 "Set mark arg words away from point." | 1516 "Set mark arg words away from point." |
1657 (defun turn-on-auto-fill () | 1659 (defun turn-on-auto-fill () |
1658 "Unconditionally turn on Auto Fill mode." | 1660 "Unconditionally turn on Auto Fill mode." |
1659 (auto-fill-mode 1)) | 1661 (auto-fill-mode 1)) |
1660 | 1662 |
1661 (defun set-fill-column (arg) | 1663 (defun set-fill-column (arg) |
1662 "Set fill-column to current column, or to argument if given. | 1664 "Set `fill-column' to current column, or to argument if given. |
1663 fill-column's value is separate for each buffer." | 1665 The variable `fill-column' has a separate value for each buffer." |
1664 (interactive "P") | 1666 (interactive "P") |
1665 (setq fill-column (if (integerp arg) arg (current-column))) | 1667 (setq fill-column (if (integerp arg) arg (current-column))) |
1666 (message "fill-column set to %d" fill-column)) | 1668 (message "fill-column set to %d" fill-column)) |
1667 | 1669 |
1668 (defun set-selective-display (arg) | 1670 (defun set-selective-display (arg) |
1669 "Set selective-display to ARG; clear it if no arg. | 1671 "Set `selective-display' to ARG; clear it if no arg. |
1670 When selective-display is a number > 0, | 1672 When the value of `selective-display' is a number > 0, |
1671 lines whose indentation is >= selective-display are not displayed. | 1673 lines whose indentation is >= that value are not displayed. |
1672 selective-display's value is separate for each buffer." | 1674 The variable `selective-display' has a separate value for each buffer." |
1673 (interactive "P") | 1675 (interactive "P") |
1674 (if (eq selective-display t) | 1676 (if (eq selective-display t) |
1675 (error "selective-display already in use for marked lines")) | 1677 (error "selective-display already in use for marked lines")) |
1676 (let ((current-vpos | 1678 (let ((current-vpos |
1677 (save-restriction | 1679 (save-restriction |