Mercurial > emacs
comparison lisp/simple.el @ 2568:15014ba142a7
All fsets changed to defaliases.
(kill-forward-chars, kill-backward-chars): Deleted. These were
internal subroutines used by delete-char and delete-backward-char
before those functions were moved into the C kernel. Now nothing uses
them.
(kill-line): Added kill-whole-line variable. Defaults to nil; a
non-nil value causes a kill-line at the beginning of a line to kill
the newline as well as the line. I find it very convenient. Emulates
Unipress' &kill-lines-magic variable.
(next-line): Added next-line-add-newlines variable. If nil, next-line will not
insert newlines when invoked at the end of a buffer. This obviates three LCD
packages.
(left-arrow, right-arrow): New functions. These do backward-char and
forward-char first. If line truncation is on, they then scroll left or
right as necessary to make sure point is visible.
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Fri, 23 Apr 1993 06:50:37 +0000 |
parents | 11ca45403cf5 |
children | b28675709d41 |
comparison
equal
deleted
inserted
replaced
2567:2cd6cb337d7c | 2568:15014ba142a7 |
---|---|
198 (save-excursion | 198 (save-excursion |
199 (delete-region (point) (progn (skip-chars-backward " \t") (point))) | 199 (delete-region (point) (progn (skip-chars-backward " \t") (point))) |
200 (indent-according-to-mode)) | 200 (indent-according-to-mode)) |
201 (newline) | 201 (newline) |
202 (indent-according-to-mode)) | 202 (indent-according-to-mode)) |
203 | |
204 ;; Internal subroutine of delete-char | |
205 (defun kill-forward-chars (arg) | |
206 (if (listp arg) (setq arg (car arg))) | |
207 (if (eq arg '-) (setq arg -1)) | |
208 (kill-region (point) (+ (point) arg))) | |
209 | |
210 ;; Internal subroutine of backward-delete-char | |
211 (defun kill-backward-chars (arg) | |
212 (if (listp arg) (setq arg (car arg))) | |
213 (if (eq arg '-) (setq arg -1)) | |
214 (kill-region (point) (- (point) arg))) | |
215 | 203 |
216 (defun backward-delete-char-untabify (arg &optional killp) | 204 (defun backward-delete-char-untabify (arg &optional killp) |
217 "Delete characters backward, changing tabs into spaces. | 205 "Delete characters backward, changing tabs into spaces. |
218 Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil. | 206 Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil. |
219 Interactively, ARG is the prefix arg (default 1) | 207 Interactively, ARG is the prefix arg (default 1) |
578 (if (eq selective-display t) | 566 (if (eq selective-display t) |
579 (re-search-forward "[\n\C-m]" nil 'end (1- arg)) | 567 (re-search-forward "[\n\C-m]" nil 'end (1- arg)) |
580 (forward-line (1- arg))))) | 568 (forward-line (1- arg))))) |
581 | 569 |
582 ;Put this on C-x u, so we can force that rather than C-_ into startup msg | 570 ;Put this on C-x u, so we can force that rather than C-_ into startup msg |
583 (fset 'advertised-undo 'undo) | 571 (defalias 'advertised-undo 'undo) |
584 | 572 |
585 (defun undo (&optional arg) | 573 (defun undo (&optional arg) |
586 "Undo some previous changes. | 574 "Undo some previous changes. |
587 Repeat this command to undo more changes. | 575 Repeat this command to undo more changes. |
588 A numeric argument serves as a repeat count." | 576 A numeric argument serves as a repeat count." |
847 "Move backward ARG lines and position at first nonblank character." | 835 "Move backward ARG lines and position at first nonblank character." |
848 (interactive "p") | 836 (interactive "p") |
849 (forward-line (- arg)) | 837 (forward-line (- arg)) |
850 (skip-chars-forward " \t")) | 838 (skip-chars-forward " \t")) |
851 | 839 |
840 (defvar kill-whole-line nil | |
841 "*If non-nil, kill-line kills the whole line (including the newline) | |
842 if point is positioned at the beginning of a line.") | |
843 | |
852 (defun kill-line (&optional arg) | 844 (defun kill-line (&optional arg) |
853 "Kill the rest of the current line; if no nonblanks there, kill thru newline. | 845 "Kill the rest of the current line; if the line is blank, or if point is at |
846 the beginning of the line and kill-whole-line is non-nil, kill thru newline. | |
854 With prefix argument, kill that many lines from point. | 847 With prefix argument, kill that many lines from point. |
855 Negative arguments kill lines backward. | 848 Negative arguments kill lines backward. |
856 | 849 |
857 When calling from a program, nil means \"no arg\", | 850 When calling from a program, nil means \"no arg\", |
858 a number counts as a prefix arg." | 851 a number counts as a prefix arg." |
863 (save-excursion | 856 (save-excursion |
864 (if arg | 857 (if arg |
865 (forward-line (prefix-numeric-value arg)) | 858 (forward-line (prefix-numeric-value arg)) |
866 (if (eobp) | 859 (if (eobp) |
867 (signal 'end-of-buffer nil)) | 860 (signal 'end-of-buffer nil)) |
868 (if (looking-at "[ \t]*$") | 861 (if (or (looking-at "[ \t]*$") (and kill-whole-line (bolp))) |
869 (forward-line 1) | 862 (forward-line 1) |
870 (end-of-line))) | 863 (end-of-line))) |
871 (point)))) | 864 (point)))) |
872 | 865 |
873 ;;;; Window system cut and paste hooks. | 866 ;;;; Window system cut and paste hooks. |
1259 (set-mark (+ 0 (car mark-ring))) | 1252 (set-mark (+ 0 (car mark-ring))) |
1260 (move-marker (car mark-ring) nil) | 1253 (move-marker (car mark-ring) nil) |
1261 (if (null (mark)) (ding)) | 1254 (if (null (mark)) (ding)) |
1262 (setq mark-ring (cdr mark-ring))))) | 1255 (setq mark-ring (cdr mark-ring))))) |
1263 | 1256 |
1264 (fset 'exchange-dot-and-mark 'exchange-point-and-mark) | 1257 (defalias 'exchange-dot-and-mark 'exchange-point-and-mark) |
1265 (defun exchange-point-and-mark () | 1258 (defun exchange-point-and-mark () |
1266 "Put the mark where point is now, and point where the mark is now. | 1259 "Put the mark where point is now, and point where the mark is now. |
1267 This command works even when the mark is not active, | 1260 This command works even when the mark is not active, |
1268 and it reactivates the mark." | 1261 and it reactivates the mark." |
1269 (interactive nil) | 1262 (interactive nil) |
1272 (error "No mark set in this buffer")) | 1265 (error "No mark set in this buffer")) |
1273 (set-mark (point)) | 1266 (set-mark (point)) |
1274 (goto-char omark) | 1267 (goto-char omark) |
1275 nil)) | 1268 nil)) |
1276 | 1269 |
1270 (defvar next-line-add-newlines t | |
1271 "*If non-nil, next-line will insert a newline into the buffer | |
1272 when invoked with no newline character between the point and the end | |
1273 of the buffer.") | |
1274 | |
1277 (defun next-line (arg) | 1275 (defun next-line (arg) |
1278 "Move cursor vertically down ARG lines. | 1276 "Move cursor vertically down ARG lines. |
1279 If there is no character in the target line exactly under the current column, | 1277 If there is no character in the target line exactly under the current column, |
1280 the cursor is positioned after the character in that line which spans this | 1278 the cursor is positioned after the character in that line which spans this |
1281 column, or at the end of the line if it is not long enough. | 1279 column, or at the end of the line if it is not long enough. |
1282 If there is no line in the buffer after this one, | 1280 If there is no line in the buffer after this one, behavior depends on the |
1283 a newline character is inserted to create a line | 1281 value of next-line-add-newlines. If non-nil, a newline character is inserted |
1284 and the cursor moves to that line. | 1282 to create a line and the cursor moves to that line, otherwise the cursor is |
1283 moved to the end of the buffer (if already at the end of the buffer, an error | |
1284 is signaled). | |
1285 | 1285 |
1286 The command \\[set-goal-column] can be used to create | 1286 The command \\[set-goal-column] can be used to create |
1287 a semipermanent goal column to which this command always moves. | 1287 a semipermanent goal column to which this command always moves. |
1288 Then it does not try to move vertically. This goal column is stored | 1288 Then it does not try to move vertically. This goal column is stored |
1289 in `goal-column', which is nil when there is none. | 1289 in `goal-column', which is nil when there is none. |
1290 | 1290 |
1291 If you are thinking of using this in a Lisp program, consider | 1291 If you are thinking of using this in a Lisp program, consider |
1292 using `forward-line' instead. It is usually easier to use | 1292 using `forward-line' instead. It is usually easier to use |
1293 and more reliable (no dependence on goal column, etc.)." | 1293 and more reliable (no dependence on goal column, etc.)." |
1294 (interactive "p") | 1294 (interactive "p") |
1295 (if (= arg 1) | 1295 (let ((opoint (point))) |
1296 (let ((opoint (point))) | 1296 (if next-line-add-newlines |
1297 (forward-line 1) | 1297 (if (/= arg 1) |
1298 (if (or (= opoint (point)) | 1298 (line-move arg) |
1299 (not (eq (preceding-char) ?\n))) | 1299 (forward-line 1) |
1300 (insert ?\n) | 1300 (if (or (= opoint (point)) (not (eq (preceding-char) ?\n))) |
1301 (goto-char opoint) | 1301 (insert ?\n) |
1302 (line-move arg))) | 1302 (goto-char opoint) |
1303 (line-move arg)) | 1303 (line-move arg))) |
1304 (if (eobp) | |
1305 (signal 'end-of-buffer nil)) | |
1306 (line-move arg) | |
1307 (if (= opoint (point)) | |
1308 (end-of-line)))) | |
1304 nil) | 1309 nil) |
1305 | 1310 |
1306 (defun previous-line (arg) | 1311 (defun previous-line (arg) |
1307 "Move cursor vertically up ARG lines. | 1312 "Move cursor vertically up ARG lines. |
1308 If there is no character in the target line exactly over the current column, | 1313 If there is no character in the target line exactly over the current column, |
1379 (setq goal-column (current-column)) | 1384 (setq goal-column (current-column)) |
1380 (message (substitute-command-keys | 1385 (message (substitute-command-keys |
1381 "Goal column %d (use \\[set-goal-column] with an arg to unset it)") | 1386 "Goal column %d (use \\[set-goal-column] with an arg to unset it)") |
1382 goal-column)) | 1387 goal-column)) |
1383 nil) | 1388 nil) |
1389 | |
1390 (defun right-arrow (arg) | |
1391 "Move right one character on the screen (with prefix ARG, that many chars). | |
1392 Scroll right if needed to keep point horizontally onscreen." | |
1393 (interactive "P") | |
1394 (forward-char arg) | |
1395 (if truncate-lines | |
1396 (let ((x (current-column)) (w (- (window-width) 2))) | |
1397 (set-window-hscroll (selected-window) (- x (% x w)) )))) | |
1398 | |
1399 (defun left-arrow (arg) | |
1400 "Move left one character on the screen (with prefix ARG, that many chars). | |
1401 Scroll left if needed to keep point horizontally onscreen." | |
1402 (interactive "P") | |
1403 (backward-char arg) | |
1404 (if truncate-lines | |
1405 (let ((x (current-column)) (w (- (window-width) 2))) | |
1406 (set-window-hscroll (selected-window) (- x (% x w)) )))) | |
1384 | 1407 |
1385 (defun transpose-chars (arg) | 1408 (defun transpose-chars (arg) |
1386 "Interchange characters around point, moving forward one character. | 1409 "Interchange characters around point, moving forward one character. |
1387 With prefix arg ARG, effect is to take character before point | 1410 With prefix arg ARG, effect is to take character before point |
1388 and drag it forward past ARG other characters (backward if ARG negative). | 1411 and drag it forward past ARG other characters (backward if ARG negative). |