From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kaushal Modi Newsgroups: gmane.emacs.devel Subject: Re: Notify region-extract-function change in NEWS? Date: Sat, 06 Feb 2016 04:49:19 +0000 Message-ID: References: <87r3gqso64.fsf@mail.linkov.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a113d7c9866e71a052b12b1ba X-Trace: ger.gmane.org 1454734188 4740 80.91.229.3 (6 Feb 2016 04:49:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 6 Feb 2016 04:49:48 +0000 (UTC) Cc: Emacs developers To: Juri Linkov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Feb 06 05:49:48 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aRuoc-0001oH-Ig for ged-emacs-devel@m.gmane.org; Sat, 06 Feb 2016 05:49:46 +0100 Original-Received: from localhost ([::1]:51603 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRuob-000479-SI for ged-emacs-devel@m.gmane.org; Fri, 05 Feb 2016 23:49:45 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRuoN-00046p-4v for emacs-devel@gnu.org; Fri, 05 Feb 2016 23:49:32 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRuoM-00065T-1O for emacs-devel@gnu.org; Fri, 05 Feb 2016 23:49:31 -0500 Original-Received: from mail-oi0-x22d.google.com ([2607:f8b0:4003:c06::22d]:35261) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRuoL-00065P-Qh for emacs-devel@gnu.org; Fri, 05 Feb 2016 23:49:29 -0500 Original-Received: by mail-oi0-x22d.google.com with SMTP id s2so53963648oie.2 for ; Fri, 05 Feb 2016 20:49:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-type; bh=PW5uLZzp5U+m1gTWgUhhFC+rU3b2qa5X720RnhWDh9g=; b=xr0SSlol9EQkzHrNOpr7ZwaEnQWYcjl485WdTg1JAxgqEKRg1CFNKWVWDKjQJYlgL3 Llf2+oPSC1j7H/LfQi3XAzlhp5v++SR85xQ8i6nwx74d/qf6BnmUlZowXT2A5GTFA1G5 giguojYroMUsz6YcOJd9/QS8N0G69+2bgrJqa6Y23HTvudYwPS8G8EI/PFQgB1s00Zkj KbD6tf1MFLLEUSlqZMRGJpCvoyUt+tOxZXKHsIGmU5itcyH0hGetUufQphasL5ml6apG yx9ABhC6+6YGcW+I/i75daZG0Y8Z/lG5HbkpURREMtw8hXVKq+wlogTMmVtR/NVk7xRc pdcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-type; bh=PW5uLZzp5U+m1gTWgUhhFC+rU3b2qa5X720RnhWDh9g=; b=K0sXXFayCwG+LGiBy9HnBMAPpooxflGJ24chia8pcNqLGZftFmThZ3imDeLTOWedgw OuGbAOhwrIFQ/Z6P7lGoPp3qgZyCuR6doH/vgAZu/4SCG7UwwOjZ1qlY1Rrxf3HnTBkI FxU/tG0qWOs68PE6FOaOoGu+QSAeq0ZomcDE08vw9qDIrxJ5INxtvaalInpAftapWizc PI9ateGtTMPK05prquw76z7rjfI9EjxHJayhIYuzOmXYfG8T+4xKB0aC+IwcRPsLCZc7 1bB4wr2pb+qTlnuhFsONYLuSxSkyKdIjLKl1m8HHi1HRnJM2LEuL5zOaVOROEhKO8eXP 9UKg== X-Gm-Message-State: AG10YOQdl7bosQ0A1zcorp1cU1ceIq8YLSE/SKjq1YLkxJjQmKcXkIrM25RyNZgUHFi9jP/OCuZvGnqOFbMkvg== X-Received: by 10.202.81.74 with SMTP id f71mr891978oib.23.1454734169267; Fri, 05 Feb 2016 20:49:29 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c06::22d X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:199398 Archived-At: --001a113d7c9866e71a052b12b1ba Content-Type: text/plain; charset=UTF-8 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. --001a113d7c9866e71a052b12b1ba Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I believe I was doing a bit wrong earlier; it's fixed = now (=C2=A0https://github.com/kaushalmodi/.emacs.d= /commit/822854333cd2cc05c2b4cfe642925f832cf40cfb=C2=A0).

=
=3D=3D=3D=3D=3D

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

=3D=3D=3D=3D= =3D

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

--001a113d7c9866e71a052b12b1ba--