all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* A mess in kill-region?
@ 2015-10-19 17:53 Marcin Borkowski
  2015-10-19 17:58 ` Marcin Borkowski
  0 siblings, 1 reply; 4+ messages in thread
From: Marcin Borkowski @ 2015-10-19 17:53 UTC (permalink / raw)
  To: Emacs developers

Hi there,

I don't have the time now to study this deeper, but if this something
non-obvious, I can try to dig into it (maybe in a few days).

Here's the problem.  This is taken from `kill-region':

(if region
    (funcall region-extract-function 'delete)
  (filter-buffer-substring beg end 'delete))

But this is the definition of `region-extract-function':

(defvar region-extract-function
  (lambda (delete)
    (when (region-beginning)
      (if (eq delete 'delete-only)
          (delete-region (region-beginning) (region-end))
        (filter-buffer-substring (region-beginning) (region-end) delete))))
  "Function to get the region's content.
Called with one argument DELETE.
If DELETE is `delete-only', then only delete the region and the return value
is undefined.  If DELETE is nil, just return the content as a string.
If anything else, delete the region and return its content as a string.")

So I guess that the argument of 'delete in `kill-region' is misleading
at least and maybe buggy.

And btw: what exactly is the meaning of the third argument to
`kill-region'?  The "explanation" is the docstring looks like a joke to
me;-).

PS. GNU Emacs 25.0.50.1 (i686-pc-linux-gnu, GTK+ Version 3.10.8) of 2015-01-02

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: A mess in kill-region?
  2015-10-19 17:53 A mess in kill-region? Marcin Borkowski
@ 2015-10-19 17:58 ` Marcin Borkowski
  2015-10-19 18:05   ` Kaushal Modi
  2015-10-19 18:20   ` Michael Heerdegen
  0 siblings, 2 replies; 4+ messages in thread
From: Marcin Borkowski @ 2015-10-19 17:58 UTC (permalink / raw)
  To: Emacs developers


On 2015-10-19, at 19:53, Marcin Borkowski <mbork@mbork.pl> wrote:

> So I guess that the argument of 'delete in `kill-region' is misleading
> at least and maybe buggy.

OK, I looked a bit more, and I guess I get it, there's no bug here.

> And btw: what exactly is the meaning of the third argument to
> `kill-region'?  The "explanation" is the docstring looks like a joke to
> me;-).

Still, I don't get the point of the third argument.  After all, it ends
up calling `filter-buffer-substring' anyway.

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: A mess in kill-region?
  2015-10-19 17:58 ` Marcin Borkowski
@ 2015-10-19 18:05   ` Kaushal Modi
  2015-10-19 18:20   ` Michael Heerdegen
  1 sibling, 0 replies; 4+ messages in thread
From: Kaushal Modi @ 2015-10-19 18:05 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: Emacs developers

I was trying to understand this few months back.

-> http://emacs.stackexchange.com/q/14937/115

The conclusion was that that REGION argument for `kill-ring-save` is
ALWAYS non-nil when used interactively.

Someone correct this if that's an incorrect statement.

I configure region-extract-function this way in my config.. the
comments in there will help you understand the DELETE argument:

;;; C-u before M-w/C-w to trim white space
;; Update the `region-extract-function' variable defined in `simple.el'
(setq region-extract-function
      (lambda (delete)
        (when (region-beginning)
          ;; `delete' is set to `'delete-only' in `delete-backward-char' and
          ;;  `delete-forward-char' functions.
          (if (eq delete 'delete-only)
              (delete-region (region-beginning) (region-end))
            ;; `delete' is set to `'delete' in `kill-region' function
            ;; `delete' is set to `nil' in `copy-region-as-kill' and
            ;;  `deactivate-mark' functions.

            ;; When doing `C-u M-w`, `C-u C-w', kill the region
            ;; - with all trailing whitespace removed
            ;; - also replace 2 or more spaces with single spaces
            (if (eq 4 (prefix-numeric-value current-prefix-arg))
                (let ((sel (filter-buffer-substring (region-beginning)
(region-end) delete)))
                  (with-temp-buffer
                    (insert sel)
                    ;; Removing trailing whitespace from the whole temp buffer
                    (delete-trailing-whitespace)
                    (goto-char (point-min))
                    (while (re-search-forward "\\s-\\{2,\\}" nil :noerror)
                      (replace-match " "))
                    (buffer-string)))
              (filter-buffer-substring (region-beginning) (region-end)
delete))))))




--
Kaushal Modi


On Mon, Oct 19, 2015 at 1:58 PM, Marcin Borkowski <mbork@mbork.pl> wrote:
>
> On 2015-10-19, at 19:53, Marcin Borkowski <mbork@mbork.pl> wrote:
>
>> So I guess that the argument of 'delete in `kill-region' is misleading
>> at least and maybe buggy.
>
> OK, I looked a bit more, and I guess I get it, there's no bug here.
>
>> And btw: what exactly is the meaning of the third argument to
>> `kill-region'?  The "explanation" is the docstring looks like a joke to
>> me;-).
>
> Still, I don't get the point of the third argument.  After all, it ends
> up calling `filter-buffer-substring' anyway.
>
> Best,
>
> --
> Marcin Borkowski
> http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
> Faculty of Mathematics and Computer Science
> Adam Mickiewicz University
>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: A mess in kill-region?
  2015-10-19 17:58 ` Marcin Borkowski
  2015-10-19 18:05   ` Kaushal Modi
@ 2015-10-19 18:20   ` Michael Heerdegen
  1 sibling, 0 replies; 4+ messages in thread
From: Michael Heerdegen @ 2015-10-19 18:20 UTC (permalink / raw)
  To: emacs-devel

Marcin Borkowski <mbork@mbork.pl> writes:

> Still, I don't get the point of the third argument.  After all, it
> ends up calling `filter-buffer-substring' anyway.

I haven't checked if it ends up with that in every case.  However, a
variable can be changed or dynamically bound so that it might not end up
like that.  Or note this in rect.el:

(add-function :around region-extract-function
  #'rectangle--extract-region)

That it makes no difference in the default case doesn't mean it makes no
sense in general.


Regards,

Michael.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-10-19 18:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-19 17:53 A mess in kill-region? Marcin Borkowski
2015-10-19 17:58 ` Marcin Borkowski
2015-10-19 18:05   ` Kaushal Modi
2015-10-19 18:20   ` Michael Heerdegen

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.