diff options
| author | Stefan Monnier | 2003-05-13 19:45:01 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2003-05-13 19:45:01 +0000 |
| commit | 1e96c0077df6f41d0559bc41ae0009ea51a8faff (patch) | |
| tree | 00fa3c827203f2a4a704d5528ace56152bfb8cba | |
| parent | dee9b44fb6e464707bb91e7571873f3f50cb7b94 (diff) | |
| download | emacs-1e96c0077df6f41d0559bc41ae0009ea51a8faff.tar.gz emacs-1e96c0077df6f41d0559bc41ae0009ea51a8faff.zip | |
(back-to-indentation): Simplify.
(undo-equiv-table, undo-in-region, undo-no-redo): New vars.
(undo): Use them to implement the no-redo form of undo.
(undo-only): New fun.
(shell-command): Don't require `shell' since shell-mode is autoloaded.
(insert-buffer): Simplify.
(completion-setup-function): Use minibufferp.
(event-apply-alt-modifier, event-apply-super-modifier)
(event-apply-hyper-modifier, event-apply-shift-modifier)
(event-apply-control-modifier, event-apply-meta-modifier):
Fix docstring to show the proper key sequence.
| -rw-r--r-- | lisp/simple.el | 96 |
1 files changed, 63 insertions, 33 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index f0c119e4a63..f83d096ed64 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -368,8 +368,7 @@ useful for editing binary files." | |||
| 368 | "Move point to the first non-whitespace character on this line." | 368 | "Move point to the first non-whitespace character on this line." |
| 369 | (interactive) | 369 | (interactive) |
| 370 | (beginning-of-line 1) | 370 | (beginning-of-line 1) |
| 371 | (let ((limit (line-end-position))) | 371 | (skip-syntax-forward " " (line-end-position)) |
| 372 | (skip-syntax-forward " " limit)) | ||
| 373 | ;; Move back over chars that have whitespace syntax but have the p flag. | 372 | ;; Move back over chars that have whitespace syntax but have the p flag. |
| 374 | (backward-prefix-chars)) | 373 | (backward-prefix-chars)) |
| 375 | 374 | ||
| @@ -938,13 +937,22 @@ Return 0 if current buffer is not a mini-buffer." | |||
| 938 | ;Put this on C-x u, so we can force that rather than C-_ into startup msg | 937 | ;Put this on C-x u, so we can force that rather than C-_ into startup msg |
| 939 | (defalias 'advertised-undo 'undo) | 938 | (defalias 'advertised-undo 'undo) |
| 940 | 939 | ||
| 940 | (defconst undo-equiv-table (make-hash-table :test 'eq :weakness t) | ||
| 941 | "Table mapping redo records to the corresponding undo one.") | ||
| 942 | |||
| 943 | (defvar undo-in-region nil | ||
| 944 | "Non-nil if `pending-undo-list' is not just a tail of `buffer-undo-list'.") | ||
| 945 | |||
| 946 | (defvar undo-no-redo nil | ||
| 947 | "If t, `undo' doesn't go through redo entries.") | ||
| 948 | |||
| 941 | (defun undo (&optional arg) | 949 | (defun undo (&optional arg) |
| 942 | "Undo some previous changes. | 950 | "Undo some previous changes. |
| 943 | Repeat this command to undo more changes. | 951 | Repeat this command to undo more changes. |
| 944 | A numeric argument serves as a repeat count. | 952 | A numeric argument serves as a repeat count. |
| 945 | 953 | ||
| 946 | In Transient Mark mode when the mark is active, only undo changes within | 954 | In Transient Mark mode when the mark is active, only undo changes within |
| 947 | the current region. Similarly, when not in Transient Mark mode, just C-u | 955 | the current region. Similarly, when not in Transient Mark mode, just \\[universal-argument] |
| 948 | as an argument limits undo to changes within the current region." | 956 | as an argument limits undo to changes within the current region." |
| 949 | (interactive "*P") | 957 | (interactive "*P") |
| 950 | ;; Make last-command indicate for the next command that this was an undo. | 958 | ;; Make last-command indicate for the next command that this was an undo. |
| @@ -956,20 +964,39 @@ as an argument limits undo to changes within the current region." | |||
| 956 | (setq this-command 'undo) | 964 | (setq this-command 'undo) |
| 957 | (let ((modified (buffer-modified-p)) | 965 | (let ((modified (buffer-modified-p)) |
| 958 | (recent-save (recent-auto-save-p))) | 966 | (recent-save (recent-auto-save-p))) |
| 959 | (or (eq (selected-window) (minibuffer-window)) | ||
| 960 | (message (if (and transient-mark-mode mark-active) | ||
| 961 | "Undo in region!" | ||
| 962 | "Undo!"))) | ||
| 963 | (unless (eq last-command 'undo) | 967 | (unless (eq last-command 'undo) |
| 964 | (if (if transient-mark-mode mark-active (and arg (not (numberp arg)))) | 968 | (setq undo-in-region |
| 969 | (if transient-mark-mode mark-active (and arg (not (numberp arg))))) | ||
| 970 | (if undo-in-region | ||
| 965 | (undo-start (region-beginning) (region-end)) | 971 | (undo-start (region-beginning) (region-end)) |
| 966 | (undo-start)) | 972 | (undo-start)) |
| 967 | ;; get rid of initial undo boundary | 973 | ;; get rid of initial undo boundary |
| 968 | (undo-more 1)) | 974 | (undo-more 1)) |
| 975 | ;; Check to see whether we're hitting a redo record, and if | ||
| 976 | ;; so, ask the user whether she wants to skip the redo/undo pair. | ||
| 977 | (let ((equiv (gethash pending-undo-list undo-equiv-table))) | ||
| 978 | (or (eq (selected-window) (minibuffer-window)) | ||
| 979 | (message (if undo-in-region | ||
| 980 | (if equiv "Redo in region!" "Undo in region!") | ||
| 981 | (if equiv "Redo!" "Undo!")))) | ||
| 982 | (when (and equiv undo-no-redo) | ||
| 983 | ;; The equiv entry might point to another redo record if we have done | ||
| 984 | ;; undo-redo-undo-redo-... so skip to the very last equiv. | ||
| 985 | (while (let ((next (gethash equiv undo-equiv-table))) | ||
| 986 | (if next (setq equiv next)))) | ||
| 987 | (setq pending-undo-list equiv))) | ||
| 969 | (undo-more | 988 | (undo-more |
| 970 | (if (or transient-mark-mode (numberp arg)) | 989 | (if (or transient-mark-mode (numberp arg)) |
| 971 | (prefix-numeric-value arg) | 990 | (prefix-numeric-value arg) |
| 972 | 1)) | 991 | 1)) |
| 992 | ;; Record the fact that the just-generated undo records come from an | ||
| 993 | ;; undo operation, so we can skip them later on. | ||
| 994 | ;; I don't know how to do that in the undo-in-region case. | ||
| 995 | (unless undo-in-region | ||
| 996 | (when (eval-when-compile (fboundp 'assert)) | ||
| 997 | (assert (or (null pending-undo-list) (car pending-undo-list))) | ||
| 998 | (assert (car buffer-undo-list))) | ||
| 999 | (puthash buffer-undo-list pending-undo-list undo-equiv-table)) | ||
| 973 | ;; Don't specify a position in the undo record for the undo command. | 1000 | ;; Don't specify a position in the undo record for the undo command. |
| 974 | ;; Instead, undoing this should move point to where the change is. | 1001 | ;; Instead, undoing this should move point to where the change is. |
| 975 | (let ((tail buffer-undo-list) | 1002 | (let ((tail buffer-undo-list) |
| @@ -977,9 +1004,9 @@ as an argument limits undo to changes within the current region." | |||
| 977 | (while (car tail) | 1004 | (while (car tail) |
| 978 | (when (integerp (car tail)) | 1005 | (when (integerp (car tail)) |
| 979 | (let ((pos (car tail))) | 1006 | (let ((pos (car tail))) |
| 980 | (if (null prev) | 1007 | (if prev |
| 981 | (setq buffer-undo-list (cdr tail)) | 1008 | (setcdr prev (cdr tail)) |
| 982 | (setcdr prev (cdr tail))) | 1009 | (setq buffer-undo-list (cdr tail))) |
| 983 | (setq tail (cdr tail)) | 1010 | (setq tail (cdr tail)) |
| 984 | (while (car tail) | 1011 | (while (car tail) |
| 985 | (if (eq pos (car tail)) | 1012 | (if (eq pos (car tail)) |
| @@ -994,6 +1021,15 @@ as an argument limits undo to changes within the current region." | |||
| 994 | (and modified (not (buffer-modified-p)) | 1021 | (and modified (not (buffer-modified-p)) |
| 995 | (delete-auto-save-file-if-necessary recent-save)))) | 1022 | (delete-auto-save-file-if-necessary recent-save)))) |
| 996 | 1023 | ||
| 1024 | (defun undo-only (&optional arg) | ||
| 1025 | "Undo some previous changes. | ||
| 1026 | Repeat this command to undo more changes. | ||
| 1027 | A numeric argument serves as a repeat count. | ||
| 1028 | Contrary to `undo', this will not redo a previous undo." | ||
| 1029 | (interactive "*p") | ||
| 1030 | (let ((undo-no-redo t)) (undo arg))) | ||
| 1031 | (define-key ctl-x-map "U" 'undo-only) | ||
| 1032 | |||
| 997 | (defvar pending-undo-list nil | 1033 | (defvar pending-undo-list nil |
| 998 | "Within a run of consecutive undo commands, list remaining to be undone.") | 1034 | "Within a run of consecutive undo commands, list remaining to be undone.") |
| 999 | 1035 | ||
| @@ -1307,8 +1343,7 @@ specifies the value of ERROR-BUFFER." | |||
| 1307 | (if (yes-or-no-p "A command is running. Kill it? ") | 1343 | (if (yes-or-no-p "A command is running. Kill it? ") |
| 1308 | (kill-process proc) | 1344 | (kill-process proc) |
| 1309 | (error "Shell command in progress"))) | 1345 | (error "Shell command in progress"))) |
| 1310 | (save-excursion | 1346 | (with-current-buffer buffer |
| 1311 | (set-buffer buffer) | ||
| 1312 | (setq buffer-read-only nil) | 1347 | (setq buffer-read-only nil) |
| 1313 | (erase-buffer) | 1348 | (erase-buffer) |
| 1314 | (display-buffer buffer) | 1349 | (display-buffer buffer) |
| @@ -1316,7 +1351,7 @@ specifies the value of ERROR-BUFFER." | |||
| 1316 | (setq proc (start-process "Shell" buffer shell-file-name | 1351 | (setq proc (start-process "Shell" buffer shell-file-name |
| 1317 | shell-command-switch command)) | 1352 | shell-command-switch command)) |
| 1318 | (setq mode-line-process '(":%s")) | 1353 | (setq mode-line-process '(":%s")) |
| 1319 | (require 'shell) (shell-mode) | 1354 | (shell-mode) |
| 1320 | (set-process-sentinel proc 'shell-command-sentinel) | 1355 | (set-process-sentinel proc 'shell-command-sentinel) |
| 1321 | )) | 1356 | )) |
| 1322 | (shell-command-on-region (point) (point) command | 1357 | (shell-command-on-region (point) (point) command |
| @@ -2276,7 +2311,7 @@ Puts mark after the inserted text. | |||
| 2276 | BUFFER may be a buffer or a buffer name. | 2311 | BUFFER may be a buffer or a buffer name. |
| 2277 | 2312 | ||
| 2278 | This function is meant for the user to run interactively. | 2313 | This function is meant for the user to run interactively. |
| 2279 | Don't call it from programs!" | 2314 | Don't call it from programs: use `insert-buffer-substring' instead!" |
| 2280 | (interactive | 2315 | (interactive |
| 2281 | (list | 2316 | (list |
| 2282 | (progn | 2317 | (progn |
| @@ -2286,16 +2321,10 @@ Don't call it from programs!" | |||
| 2286 | (other-buffer (current-buffer)) | 2321 | (other-buffer (current-buffer)) |
| 2287 | (window-buffer (next-window (selected-window)))) | 2322 | (window-buffer (next-window (selected-window)))) |
| 2288 | t)))) | 2323 | t)))) |
| 2289 | (or (bufferp buffer) | 2324 | (push-mark |
| 2290 | (setq buffer (get-buffer buffer))) | 2325 | (save-excursion |
| 2291 | (let (start end newmark) | 2326 | (insert-buffer-substring (get-buffer buffer)) |
| 2292 | (save-excursion | 2327 | (point))) |
| 2293 | (save-excursion | ||
| 2294 | (set-buffer buffer) | ||
| 2295 | (setq start (point-min) end (point-max))) | ||
| 2296 | (insert-buffer-substring buffer start end) | ||
| 2297 | (setq newmark (point))) | ||
| 2298 | (push-mark newmark)) | ||
| 2299 | nil) | 2328 | nil) |
| 2300 | 2329 | ||
| 2301 | (defun append-to-buffer (buffer start end) | 2330 | (defun append-to-buffer (buffer start end) |
| @@ -3040,6 +3069,8 @@ With argument 0, interchanges line point is in with line mark is in." | |||
| 3040 | (if (> (cdr pos1) (car pos2)) (error "Don't have two things to transpose")) | 3069 | (if (> (cdr pos1) (car pos2)) (error "Don't have two things to transpose")) |
| 3041 | (atomic-change-group | 3070 | (atomic-change-group |
| 3042 | (let (word2) | 3071 | (let (word2) |
| 3072 | ;; FIXME: We first delete the two pieces of text, so markers that | ||
| 3073 | ;; used to point to after the text end up pointing to before it :-( | ||
| 3043 | (setq word2 (delete-and-extract-region (car pos2) (cdr pos2))) | 3074 | (setq word2 (delete-and-extract-region (car pos2) (cdr pos2))) |
| 3044 | (goto-char (car pos2)) | 3075 | (goto-char (car pos2)) |
| 3045 | (insert (delete-and-extract-region (car pos1) (cdr pos1))) | 3076 | (insert (delete-and-extract-region (car pos1) (cdr pos1))) |
| @@ -4014,8 +4045,7 @@ The completion list buffer is available as the value of `standard-output'.") | |||
| 4014 | (- (point) (minibuffer-prompt-end)))) | 4045 | (- (point) (minibuffer-prompt-end)))) |
| 4015 | ;; Otherwise, in minibuffer, the whole input is being completed. | 4046 | ;; Otherwise, in minibuffer, the whole input is being completed. |
| 4016 | (save-match-data | 4047 | (save-match-data |
| 4017 | (if (string-match "\\` \\*Minibuf-[0-9]+\\*\\'" | 4048 | (if (minibufferp mainbuf) |
| 4018 | (buffer-name mainbuf)) | ||
| 4019 | (setq completion-base-size 0)))) | 4049 | (setq completion-base-size 0)))) |
| 4020 | (goto-char (point-min)) | 4050 | (goto-char (point-min)) |
| 4021 | (if (display-mouse-p) | 4051 | (if (display-mouse-p) |
| @@ -4055,27 +4085,27 @@ select the completion near point.\n\n"))))) | |||
| 4055 | ;; to the following event. | 4085 | ;; to the following event. |
| 4056 | 4086 | ||
| 4057 | (defun event-apply-alt-modifier (ignore-prompt) | 4087 | (defun event-apply-alt-modifier (ignore-prompt) |
| 4058 | "Add the Alt modifier to the following event. | 4088 | "\\<function-key-map>Add the Alt modifier to the following event. |
| 4059 | For example, type \\[event-apply-alt-modifier] & to enter Alt-&." | 4089 | For example, type \\[event-apply-alt-modifier] & to enter Alt-&." |
| 4060 | (vector (event-apply-modifier (read-event) 'alt 22 "A-"))) | 4090 | (vector (event-apply-modifier (read-event) 'alt 22 "A-"))) |
| 4061 | (defun event-apply-super-modifier (ignore-prompt) | 4091 | (defun event-apply-super-modifier (ignore-prompt) |
| 4062 | "Add the Super modifier to the following event. | 4092 | "\\<function-key-map>Add the Super modifier to the following event. |
| 4063 | For example, type \\[event-apply-super-modifier] & to enter Super-&." | 4093 | For example, type \\[event-apply-super-modifier] & to enter Super-&." |
| 4064 | (vector (event-apply-modifier (read-event) 'super 23 "s-"))) | 4094 | (vector (event-apply-modifier (read-event) 'super 23 "s-"))) |
| 4065 | (defun event-apply-hyper-modifier (ignore-prompt) | 4095 | (defun event-apply-hyper-modifier (ignore-prompt) |
| 4066 | "Add the Hyper modifier to the following event. | 4096 | "\\<function-key-map>Add the Hyper modifier to the following event. |
| 4067 | For example, type \\[event-apply-hyper-modifier] & to enter Hyper-&." | 4097 | For example, type \\[event-apply-hyper-modifier] & to enter Hyper-&." |
| 4068 | (vector (event-apply-modifier (read-event) 'hyper 24 "H-"))) | 4098 | (vector (event-apply-modifier (read-event) 'hyper 24 "H-"))) |
| 4069 | (defun event-apply-shift-modifier (ignore-prompt) | 4099 | (defun event-apply-shift-modifier (ignore-prompt) |
| 4070 | "Add the Shift modifier to the following event. | 4100 | "\\<function-key-map>Add the Shift modifier to the following event. |
| 4071 | For example, type \\[event-apply-shift-modifier] & to enter Shift-&." | 4101 | For example, type \\[event-apply-shift-modifier] & to enter Shift-&." |
| 4072 | (vector (event-apply-modifier (read-event) 'shift 25 "S-"))) | 4102 | (vector (event-apply-modifier (read-event) 'shift 25 "S-"))) |
| 4073 | (defun event-apply-control-modifier (ignore-prompt) | 4103 | (defun event-apply-control-modifier (ignore-prompt) |
| 4074 | "Add the Ctrl modifier to the following event. | 4104 | "\\<function-key-map>Add the Ctrl modifier to the following event. |
| 4075 | For example, type \\[event-apply-control-modifier] & to enter Ctrl-&." | 4105 | For example, type \\[event-apply-control-modifier] & to enter Ctrl-&." |
| 4076 | (vector (event-apply-modifier (read-event) 'control 26 "C-"))) | 4106 | (vector (event-apply-modifier (read-event) 'control 26 "C-"))) |
| 4077 | (defun event-apply-meta-modifier (ignore-prompt) | 4107 | (defun event-apply-meta-modifier (ignore-prompt) |
| 4078 | "Add the Meta modifier to the following event. | 4108 | "\\<function-key-map>Add the Meta modifier to the following event. |
| 4079 | For example, type \\[event-apply-meta-modifier] & to enter Meta-&." | 4109 | For example, type \\[event-apply-meta-modifier] & to enter Meta-&." |
| 4080 | (vector (event-apply-modifier (read-event) 'meta 27 "M-"))) | 4110 | (vector (event-apply-modifier (read-event) 'meta 27 "M-"))) |
| 4081 | 4111 | ||