all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: Re: Flexible Killing
Date: Thu, 11 Jan 2007 00:36:15 -0500	[thread overview]
Message-ID: <jwvps9mgmi4.fsf-monnier+gnu.emacs.help@gnu.org> (raw)
In-Reply-To: 1168478133.448778.302780@77g2000hsv.googlegroups.com

> 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

      reply	other threads:[~2007-01-11  5:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-10 19:00 Flexible Killing haws
2007-01-11  1:15 ` Rupert
2007-01-11  5:36   ` Stefan Monnier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvps9mgmi4.fsf-monnier+gnu.emacs.help@gnu.org \
    --to=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.