# HG changeset patch # User Luc Teirlinck # Date 1054250969 0 # Node ID dfd8b52708ae3693ce6346f03cfce17f8a423aea # Parent 650061f9f9028d0de1feb9d561b3c2c3dc319f61 (kill-whole-line): Make it interact correctly with the kill ring. diff -r 650061f9f902 -r dfd8b52708ae lisp/simple.el --- a/lisp/simple.el Thu May 29 22:46:07 2003 +0000 +++ b/lisp/simple.el Thu May 29 23:29:29 2003 +0000 @@ -2210,23 +2210,41 @@ (defun kill-whole-line (&optional arg) "Kill current line. -With prefix arg, kill that many lines from point. -If arg is negative, kill backwards. +With prefix arg, kill that many lines starting from the current line. +If arg is negative, kill backward. Also kill the preceding newline. +\(This is meant to make C-x z work well with negative arguments.\) If arg is zero, kill current line but exclude the trailing newline." (interactive "P") (setq arg (prefix-numeric-value arg)) + (if (and (> arg 0) (eobp) (save-excursion (forward-visible-line 0) (eobp))) + (signal 'end-of-buffer nil)) + (if (and (< arg 0) (bobp) (save-excursion (end-of-visible-line) (bobp))) + (signal 'beginning-of-buffer nil)) + (unless (eq last-command 'kill-region) + (kill-new "") + (setq last-command 'kill-region)) (cond ((zerop arg) - (kill-region (point) (progn (forward-visible-line 0) (point))) + ;; We need to kill in two steps, because the previous command + ;; could have been a kill command, in which case the text + ;; before point needs to be prepended to the current kill + ;; ring entry and the text after point appended. Also, we + ;; need to use save-excursion to avoid copying the same text + ;; twice to the kill ring in read-only buffers. + (save-excursion + (kill-region (point) (progn (forward-visible-line 0) (point)))) (kill-region (point) (progn (end-of-visible-line) (point)))) ((< arg 0) - (kill-line 1) - (kill-line (1+ arg)) - (unless (bobp) (forward-visible-line -1))) + (save-excursion + (kill-region (point) (progn (end-of-visible-line) (point)))) + (kill-region (point) + (progn (forward-visible-line (1+ arg)) + (unless (bobp) (backward-char)) + (point)))) (t - (kill-line 0) - (if (eobp) - (signal 'end-of-buffer nil) - (kill-line arg))))) + (save-excursion + (kill-region (point) (progn (forward-visible-line 0) (point)))) + (kill-region (point) + (progn (forward-visible-line arg) (point)))))) (defun forward-visible-line (arg) "Move forward by ARG lines, ignoring currently invisible newlines only.