Skip to content

Commit

Permalink
Re-do the cond for region-extract-function tweak
Browse files Browse the repository at this point in the history
- Now the focus is on implementing the tweak when the desired conditions
  are met (i.e. when `kill-region` or `kill-ring-save` is called).
- Earlier the reverse condition was checked.
- This change seems more robust and probably more immune to future
  changes in the default value of `region-extract-function`.
  • Loading branch information
kaushalmodi committed Feb 6, 2016
1 parent 78ed92f commit 8228543
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions setup-files/setup-editing.el
@@ -1,4 +1,4 @@
;; Time-stamp: <2016-02-05 23:05:56 kmodi>
;; Time-stamp: <2016-02-05 23:42:34 kmodi>

;; Functions related to editing text in the buffer
;; Contents:
Expand Down Expand Up @@ -743,20 +743,19 @@ Try the repeated popping up to 10 times."
;;; Tweaking `region-extract-function'
(defun modi/region-extract-function--C-u-kill (orig delete)
"When a region is selected,
and DELETE is not \\='bounds,
and DELETE is not \\='delete-only,
and if \\[universal-argument] is used when killing the region (for example,
when doing \\[kill-ring-save] or \\[kill-region]), kill the region with all
trailing whitespace removed and also replace 2 or more spaces with single spaces.
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)
(not (eq delete 'bounds))
(not (eq delete 'delete-only))
(eq 4 (prefix-numeric-value current-prefix-arg)))
(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)
;; Removing trailing whitespace from the whole temp buffer
(delete-trailing-whitespace)
(goto-char (point-min))
(while (re-search-forward "\\s-\\{2,\\}" nil :noerror)
Expand Down

0 comments on commit 8228543

Please sign in to comment.