emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A mess in kill-region?


From: Kaushal Modi
Subject: Re: A mess in kill-region?
Date: Mon, 19 Oct 2015 14:05:03 -0400

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 <address@hidden> wrote:
>
> On 2015-10-19, at 19:53, Marcin Borkowski <address@hidden> 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
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]