* Notify region-extract-function change in NEWS?
@ 2016-02-05 20:29 Kaushal Modi
2016-02-05 20:47 ` Kaushal Modi
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Kaushal Modi @ 2016-02-05 20:29 UTC (permalink / raw)
To: Juri Linkov, Emacs developers
[-- Attachment #1: Type: text/plain, Size: 740 bytes --]
Hi all,
I do not know if a change to the default value of region-extract-function
is supposed to be put in the NEWS; especially because it's a defvar, not a
defcustom.
But that change broke my config because I was tweaking the value of
region-extract-function.
Commit that changes the default value of region-extract-function:
http://git.savannah.gnu.org/cgit/emacs.git/diff/lisp/simple.el?h=emacs-25&id=31f6e939334180add7bc11240343615a2e6350f6
Here is the associated change I needed in my config:
https://github.com/kaushalmodi/.emacs.d/commit/ae38531ca5fb51d4b3303face4c5103ed4f70b3b
I need to update the region-extract-function because I want to add C-u
functionality to C-w/M-w. (Please advise if there's a better way to do
that.)
[-- Attachment #2: Type: text/html, Size: 1134 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Notify region-extract-function change in NEWS?
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-08 13:48 ` Stefan Monnier
2 siblings, 0 replies; 7+ messages in thread
From: Kaushal Modi @ 2016-02-05 20:47 UTC (permalink / raw)
To: Juri Linkov, Emacs developers
[-- Attachment #1: Type: text/plain, Size: 1043 bytes --]
You can probably ignore this.. at least on github, not many people are
tweaking this variable:
https://github.com/search?utf8=%E2%9C%93&q=extension%3Ael+%22setq+region+extract+function%22
:P
On Fri, Feb 5, 2016 at 3:29 PM Kaushal Modi <kaushal.modi@gmail.com> wrote:
> Hi all,
>
> I do not know if a change to the default value of region-extract-function
> is supposed to be put in the NEWS; especially because it's a defvar, not a
> defcustom.
>
> But that change broke my config because I was tweaking the value of
> region-extract-function.
>
> Commit that changes the default value of region-extract-function:
> http://git.savannah.gnu.org/cgit/emacs.git/diff/lisp/simple.el?h=emacs-25&id=31f6e939334180add7bc11240343615a2e6350f6
>
> Here is the associated change I needed in my config:
> https://github.com/kaushalmodi/.emacs.d/commit/ae38531ca5fb51d4b3303face4c5103ed4f70b3b
>
> I need to update the region-extract-function because I want to add C-u
> functionality to C-w/M-w. (Please advise if there's a better way to do
> that.)
>
[-- Attachment #2: Type: text/html, Size: 1818 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Notify region-extract-function change in NEWS?
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-08 13:48 ` Stefan Monnier
2 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2016-02-06 0:30 UTC (permalink / raw)
To: Kaushal Modi; +Cc: Emacs developers
> (Please advise if there's a better way to do that.)
A better way to do that is to override the default value of
region-extract-function using add-function.
You could find some examples of add-function usages in
http://git.savannah.gnu.org/cgit/emacs.git/commit/?h=emacs-25&id=31f6e939334180add7bc11240343615a2e6350f6
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Notify region-extract-function change in NEWS?
2016-02-06 0:30 ` Juri Linkov
@ 2016-02-06 4:08 ` Kaushal Modi
2016-02-06 4:49 ` Kaushal Modi
0 siblings, 1 reply; 7+ messages in thread
From: Kaushal Modi @ 2016-02-06 4:08 UTC (permalink / raw)
To: Juri Linkov; +Cc: Emacs developers
[-- Attachment #1: Type: text/plain, Size: 990 bytes --]
Thanks Juri.
On Fri, Feb 5, 2016 at 8:13 PM Juri Linkov <juri@linkov.net> wrote:
> A better way to do that is to override the default value of
> region-extract-function using add-function.
> You could find some examples of add-function usages in
>
> http://git.savannah.gnu.org/cgit/emacs.git/commit/?h=emacs-25&id=31f6e939334180add7bc11240343615a2e6350f6
I have reimplemented my earlier redefinition of region-extract-function
using add-function:
https://github.com/kaushalmodi/.emacs.d/blob/78ed92f384bac8ef2f3a4ec2faf61a21814475cd/setup-files/setup-editing.el#L744-L766
and it seems to work fine as before, but with lesser lines of code! :)
So just to be clear, using add-function makes the region-extract-function
tweaks a bit concise. But I would still need to update this if and when the
region-extract-function default value changes in future. For instance, here
I needed to have the "(not (eq delete 'bounds))" condition to match what
was recently added to that var.
Kaushal
[-- Attachment #2: Type: text/html, Size: 1642 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Notify region-extract-function change in NEWS?
2016-02-06 4:08 ` Kaushal Modi
@ 2016-02-06 4:49 ` Kaushal Modi
0 siblings, 0 replies; 7+ messages in thread
From: Kaushal Modi @ 2016-02-06 4:49 UTC (permalink / raw)
To: Juri Linkov; +Cc: Emacs developers
[-- 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 --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Notify region-extract-function change in NEWS?
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-08 13:48 ` Stefan Monnier
2016-02-08 15:58 ` John Wiegley
2 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2016-02-08 13:48 UTC (permalink / raw)
To: emacs-devel
> I need to update the region-extract-function because I want to add C-u
> functionality to C-w/M-w. (Please advise if there's a better way to do
> that.)
Don't use setq on *-function. Instead, use add-function or remove-function.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Notify region-extract-function change in NEWS?
2016-02-08 13:48 ` Stefan Monnier
@ 2016-02-08 15:58 ` John Wiegley
0 siblings, 0 replies; 7+ messages in thread
From: John Wiegley @ 2016-02-08 15:58 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
>>>>> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> I need to update the region-extract-function because I want to add C-u
>> functionality to C-w/M-w. (Please advise if there's a better way to do
>> that.)
> Don't use setq on *-function. Instead, use add-function or remove-function.
The subtle pun in your answer did not go unappreciated. :)
--
John Wiegley GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com 60E1 46C4 BD1A 7AC1 4BA2
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-02-08 15:58 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2016-02-08 13:48 ` Stefan Monnier
2016-02-08 15:58 ` John Wiegley
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).