help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to delete a line without putting them into yanking?


From: Ole Laursen
Subject: Re: how to delete a line without putting them into yanking?
Date: Thu, 09 Sep 2004 22:28:27 +0200
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

emacs Fan <emacsNT@gmail.com> writes:

[...]

> 3. write a lisp function to delete the path line, not kill it.

Here's one. Just put in your Emacs file and bind it to some key with
something alongs:

  (global-set-key (kbd "C-c d") 'delete-line)



;; for some reason Emacs lacks delete-line, implementing it with the
;; source from kill-line is, however, trivial
(defun delete-line (&optional arg)
  "Delete the rest of the current line; if no nonblanks there, delete
thru newline. With prefix argument, delete that many lines from point.
Negative arguments delete lines backward.

When calling from a program, nil means \"no arg\", a number counts as
a prefix arg.

To delete a whole line, when point is not at the beginning, type \
\\[beginning-of-line] \\[delete-line] \\[delete-line].

If `kill-whole-line' is non-nil, then this command deletes the whole line
including its terminating newline, when used at the beginning of a line
with no argument.  As a consequence, you can always delete a whole line
by typing \\[beginning-of-line] \\[delete-line]."
  (interactive "P")
  (delete-region (point)
               ;; It is better to move point to the other end of the
               ;; delete before deleting. That way, in a read-only
               ;; buffer, point moves across the text that is to be
               ;; delete. The choice has no effect on undo now that
               ;; undo records the value of point from before the
               ;; command was run.
               (progn
                 (if arg
                     (forward-visible-line (prefix-numeric-value arg))
                   (if (eobp)
                       (signal 'end-of-buffer nil))
                   (if (or (looking-at "[ \t]*$") (and kill-whole-line (bolp)))
                       (forward-visible-line 1)
                     (end-of-visible-line)))
                 (point))))


-- 
Ole Laursen
http://www.cs.aau.dk/~olau/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]