all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kaushal Modi <kaushal.modi@gmail.com>
To: Juri Linkov <juri@linkov.net>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: Notify region-extract-function change in NEWS?
Date: Sat, 06 Feb 2016 04:49:19 +0000	[thread overview]
Message-ID: <CAFyQvY3x+o=oGNAGUjcki58kXFcOAY42xqHoN2JmVXWyrTu8yQ@mail.gmail.com> (raw)
In-Reply-To: <CAFyQvY00Ni0Unv_aGEOQtTH=GBqTK=2XFF=u6yH4dV86qWg0Eg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1364 bytes --]

I believe I was doing a bit wrong earlier; it's fixed now (
https://github.com/kaushalmodi/.emacs.d/commit/822854333cd2cc05c2b4cfe642925f832cf40cfb
 ).

=====

(defun modi/region-extract-function--C-u-kill (orig delete)
  "When a region is selected,
and if \\[universal-argument] is used,
and DELETE is \\='delete (when doing \\[kill-region]), or
    DELETE is nil (when doing \\[kill-ring-save]),
kill the region with all trailing whitespace removed and also replace 2
or more spaces with single spaces.
Else, execute ORIG function."
  (if (and (region-beginning)
           (eq 4 (prefix-numeric-value current-prefix-arg)) ; when using
C-u, and
           (or (eq delete 'delete) ; when cutting (C-w), or
               (eq delete nil))) ; when copying (M-w)
      (let ((sel (filter-buffer-substring (region-beginning) (region-end)
delete)))
        (with-temp-buffer
          (insert sel)
          (delete-trailing-whitespace)
          (goto-char (point-min))
          (while (re-search-forward "\\s-\\{2,\\}" nil :noerror)
            (replace-match " "))
          (buffer-string)))
    (funcall orig delete)))
(add-function :around region-extract-function
#'modi/region-extract-function--C-u-kill)

=====

So now it is probably more immune to future changes to the default value of
region-extract-function. Thanks for the tip to look into add-function.

[-- Attachment #2: Type: text/html, Size: 1931 bytes --]

  reply	other threads:[~2016-02-06  4:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-05 20:29 Notify region-extract-function change in NEWS? Kaushal Modi
2016-02-05 20:47 ` Kaushal Modi
2016-02-06  0:30 ` Juri Linkov
2016-02-06  4:08   ` Kaushal Modi
2016-02-06  4:49     ` Kaushal Modi [this message]
2016-02-08 13:48 ` Stefan Monnier
2016-02-08 15:58   ` John Wiegley

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='CAFyQvY3x+o=oGNAGUjcki58kXFcOAY42xqHoN2JmVXWyrTu8yQ@mail.gmail.com' \
    --to=kaushal.modi@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=juri@linkov.net \
    /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.