[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Flexible Killing
From: |
Stefan Monnier |
Subject: |
Re: Flexible Killing |
Date: |
Thu, 11 Jan 2007 00:36:15 -0500 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.91 (gnu/linux) |
> 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)))))))
Whenever you use `setq', make sure you really need it
=>
(defun flexikill ()
(interactive)
(let ((m (mark 1)))
(if (not m)
(kill-line)
(let ((p (point)))
(if (= p m)
(kill-line)
(kill-region (region-beginning)
(region-end)))))))
no need to let-bind if you only use the value once:
=>
(defun flexikill ()
(interactive)
(let ((m (mark 1)))
(if (not m)
(kill-line)
(if (= (point) m)
(kill-line)
(kill-region (region-beginning)
(region-end))))))
merge tests to avoid duplicated identical calls
=>
(defun flexikill ()
(interactive)
(let ((m (mark 1)))
(if (or (not m) (= (point) m))
(kill-line)
(kill-region (region-beginning)
(region-end)))))
rather than 1, use a less-arbitrary value
=>
(defun flexikill ()
(interactive)
(let ((m (mark 'force)))
(if (or (not m) (= (point) m))
(kill-line)
(kill-region (region-beginning)
(region-end)))))
and if you ever use mark-even-if-inactive, then you will prefer
(defun flexikill ()
(interactive)
(if (or (not mark-active) (eq (point) (mark 'force)))
(kill-line)
(kill-region (region-beginning)
(region-end))))
-- Stefan