summaryrefslogtreecommitdiff
path: root/lisp/rect.el
diff options
context:
space:
mode:
authorJuri Linkov <juri@linkov.net>2015-11-14 01:28:03 +0200
committerJuri Linkov <juri@linkov.net>2015-11-14 01:28:03 +0200
commit31f6e939334180add7bc11240343615a2e6350f6 (patch)
tree376d0c9d5290a69187be11d71fffc692d31a53c0 /lisp/rect.el
parentf103a2771bc8691f00b331ec25aa5c0477c2089a (diff)
downloademacs-31f6e939334180add7bc11240343615a2e6350f6.tar.gz
Support rectangular regions for more commands
* lisp/simple.el (region-extract-function): Handle the arg value ‘bounds’. (region-insert-function): New function. (shell-command-on-region): Add arg ‘region-noncontiguous-p’. If non-nil, operate on multiple chunks. (region-noncontiguous-p): New function. * lisp/rect.el: Add function rectangle--insert-region around region-insert-function. (extract-rectangle-bounds): New function. (rectangle--extract-region): Handle the arg value ‘bounds’. (rectangle--insert-region): New function. * lisp/emulation/cua-rect.el: Add function cua--insert-rectangle around region-insert-function. (cua--extract-rectangle-bounds): New function. (cua--rectangle-region-extract): Handle the arg value ‘bounds’. * lisp/replace.el (query-replace, query-replace-regexp): Add arg ‘region-noncontiguous-p’. Use ‘use-region-p’. (query-replace-regexp-eval, map-query-replace-regexp) (replace-string, replace-regexp): Use ‘use-region-p’. (keep-lines, flush-lines, how-many): Use ‘use-region-p’. (perform-replace): Add arg ‘region-noncontiguous-p’. If non-nil, operate on multiple chunks. * src/casefiddle.c (Fdowncase_region): Add arg ‘region-noncontiguous-p’. If non-nil, operate on multiple chunks. (Bug#19829)
Diffstat (limited to 'lisp/rect.el')
-rw-r--r--lisp/rect.el32
1 files changed, 29 insertions, 3 deletions
diff --git a/lisp/rect.el b/lisp/rect.el
index acd3a48f2da..46ebbf259cf 100644
--- a/lisp/rect.el
+++ b/lisp/rect.el
@@ -257,6 +257,19 @@ Return it as a list of strings, one for each line of the rectangle."
(apply-on-rectangle 'extract-rectangle-line start end lines)
(nreverse (cdr lines))))
+(defun extract-rectangle-bounds (start end)
+ "Return the bounds of the rectangle with corners at START and END.
+Return it as a list of (START . END) positions, one for each line of
+the rectangle."
+ (let (bounds)
+ (apply-on-rectangle
+ (lambda (startcol endcol)
+ (move-to-column startcol)
+ (push (cons (prog1 (point) (move-to-column endcol)) (point))
+ bounds))
+ start end)
+ (nreverse bounds)))
+
(defvar killed-rectangle nil
"Rectangle for `yank-rectangle' to insert.")
@@ -563,6 +576,8 @@ with a prefix argument, prompt for START-AT and FORMAT."
#'rectangle--unhighlight-for-redisplay)
(add-function :around region-extract-function
#'rectangle--extract-region)
+(add-function :around region-insert-function
+ #'rectangle--insert-region)
(defvar rectangle-mark-mode-map
(let ((map (make-sparse-keymap)))
@@ -681,8 +696,12 @@ Ignores `line-move-visual'."
(defun rectangle--extract-region (orig &optional delete)
- (if (not rectangle-mark-mode)
- (funcall orig delete)
+ (cond
+ ((not rectangle-mark-mode)
+ (funcall orig delete))
+ ((eq delete 'bounds)
+ (extract-rectangle-bounds (region-beginning) (region-end)))
+ (t
(let* ((strs (funcall (if delete
#'delete-extract-rectangle
#'extract-rectangle)
@@ -696,7 +715,14 @@ Ignores `line-move-visual'."
(put-text-property 0 (length str) 'yank-handler
`(rectangle--insert-for-yank ,strs t)
str)
- str))))
+ str)))))
+
+(defun rectangle--insert-region (orig strings)
+ (cond
+ ((not rectangle-mark-mode)
+ (funcall orig strings))
+ (t
+ (funcall #'insert-rectangle strings))))
(defun rectangle--insert-for-yank (strs)
(push (point) buffer-undo-list)