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

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

Re: Flexible Killing


From: Rupert
Subject: Re: Flexible Killing
Date: 10 Jan 2007 17:15:33 -0800
User-agent: G2/1.0

haws wrote:
> Hello!
>
> I'm a emacs beginner and would like to write a function that performs
> this:
> If there is a region selected, then it would kill-region, otherwise it
> would kill-line.
> Can anyone tell me how? I bet it's 2 lines of code!
>
> Thank you very much,
>
> Hugo

Well, I'm a bit of a beginner too, but came up with this:

(defun flexikill ()
  (interactive)
  (let ((m nil))
    (if (not (setq m (mark 1)))
        (kill-line)
      (let ((p (point)))
        (if (= p m)
            (kill-line)
          (kill-region (region-beginning)
                       (region-end)))))))

The problem is that we can't use (interactive 'r') as if there is no
region, an (uncatchable) error message is printed, rather than us being
able to do something. Thus we need to check that a mark exists in the
buffer and that it's not equal to point (otherwise kill-region wouldn't
make much sense).

Rupert



reply via email to

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