diff options
| author | Luc Teirlinck | 2003-05-29 23:29:29 +0000 |
|---|---|---|
| committer | Luc Teirlinck | 2003-05-29 23:29:29 +0000 |
| commit | 6c770e384d322b3677d98a13e4c36f4a606b08e8 (patch) | |
| tree | f5ccb11662181a60ca034da8d44f473b5fe1c2cd /lisp | |
| parent | 4b8779767273ef149d1f8219d76828516640ff3f (diff) | |
| download | emacs-6c770e384d322b3677d98a13e4c36f4a606b08e8.tar.gz emacs-6c770e384d322b3677d98a13e4c36f4a606b08e8.zip | |
(kill-whole-line): Make it interact correctly with the kill ring.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/simple.el | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index 3dcbb73f114..6a382d8c550 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -2210,23 +2210,41 @@ even beep.)" | |||
| 2210 | 2210 | ||
| 2211 | (defun kill-whole-line (&optional arg) | 2211 | (defun kill-whole-line (&optional arg) |
| 2212 | "Kill current line. | 2212 | "Kill current line. |
| 2213 | With prefix arg, kill that many lines from point. | 2213 | With prefix arg, kill that many lines starting from the current line. |
| 2214 | If arg is negative, kill backwards. | 2214 | If arg is negative, kill backward. Also kill the preceding newline. |
| 2215 | \(This is meant to make C-x z work well with negative arguments.\) | ||
| 2215 | If arg is zero, kill current line but exclude the trailing newline." | 2216 | If arg is zero, kill current line but exclude the trailing newline." |
| 2216 | (interactive "P") | 2217 | (interactive "P") |
| 2217 | (setq arg (prefix-numeric-value arg)) | 2218 | (setq arg (prefix-numeric-value arg)) |
| 2219 | (if (and (> arg 0) (eobp) (save-excursion (forward-visible-line 0) (eobp))) | ||
| 2220 | (signal 'end-of-buffer nil)) | ||
| 2221 | (if (and (< arg 0) (bobp) (save-excursion (end-of-visible-line) (bobp))) | ||
| 2222 | (signal 'beginning-of-buffer nil)) | ||
| 2223 | (unless (eq last-command 'kill-region) | ||
| 2224 | (kill-new "") | ||
| 2225 | (setq last-command 'kill-region)) | ||
| 2218 | (cond ((zerop arg) | 2226 | (cond ((zerop arg) |
| 2219 | (kill-region (point) (progn (forward-visible-line 0) (point))) | 2227 | ;; We need to kill in two steps, because the previous command |
| 2228 | ;; could have been a kill command, in which case the text | ||
| 2229 | ;; before point needs to be prepended to the current kill | ||
| 2230 | ;; ring entry and the text after point appended. Also, we | ||
| 2231 | ;; need to use save-excursion to avoid copying the same text | ||
| 2232 | ;; twice to the kill ring in read-only buffers. | ||
| 2233 | (save-excursion | ||
| 2234 | (kill-region (point) (progn (forward-visible-line 0) (point)))) | ||
| 2220 | (kill-region (point) (progn (end-of-visible-line) (point)))) | 2235 | (kill-region (point) (progn (end-of-visible-line) (point)))) |
| 2221 | ((< arg 0) | 2236 | ((< arg 0) |
| 2222 | (kill-line 1) | 2237 | (save-excursion |
| 2223 | (kill-line (1+ arg)) | 2238 | (kill-region (point) (progn (end-of-visible-line) (point)))) |
| 2224 | (unless (bobp) (forward-visible-line -1))) | 2239 | (kill-region (point) |
| 2240 | (progn (forward-visible-line (1+ arg)) | ||
| 2241 | (unless (bobp) (backward-char)) | ||
| 2242 | (point)))) | ||
| 2225 | (t | 2243 | (t |
| 2226 | (kill-line 0) | 2244 | (save-excursion |
| 2227 | (if (eobp) | 2245 | (kill-region (point) (progn (forward-visible-line 0) (point)))) |
| 2228 | (signal 'end-of-buffer nil) | 2246 | (kill-region (point) |
| 2229 | (kill-line arg))))) | 2247 | (progn (forward-visible-line arg) (point)))))) |
| 2230 | 2248 | ||
| 2231 | (defun forward-visible-line (arg) | 2249 | (defun forward-visible-line (arg) |
| 2232 | "Move forward by ARG lines, ignoring currently invisible newlines only. | 2250 | "Move forward by ARG lines, ignoring currently invisible newlines only. |