summaryrefslogtreecommitdiff
path: root/evil-surround.el
diff options
context:
space:
mode:
authorHenrik Lissner <henrik@lissner.net>2015-06-04 15:03:18 -0400
committerHenrik Lissner <henrik@lissner.net>2015-06-04 15:03:18 -0400
commit6f290e02706bf781be240be5f79b3863dd908891 (patch)
treedb22a236aedcbce5b54d79cc0a7ba45f08e805ed /evil-surround.el
parent5e6bcb38e9b36506a8a0554f47cd00947e84ac0d (diff)
Implement block-wise surround
Diffstat (limited to 'evil-surround.el')
-rwxr-xr-xevil-surround.el21
1 files changed, 20 insertions, 1 deletions
diff --git a/evil-surround.el b/evil-surround.el
index faa7d96..3ded066 100755
--- a/evil-surround.el
+++ b/evil-surround.el
@@ -212,6 +212,22 @@ overlays OUTER and INNER, which are passed to `evil-surround-delete'."
(define-key evil-operator-shortcut-map "s" 'evil-surround-line)
(define-key evil-operator-shortcut-map "S" 'evil-surround-line))
+(defun evil-surround-block (beg end char)
+ "Split a block into regions per line and surround each of them individually."
+ (save-excursion
+ (goto-char beg)
+ (let ((lines (- (1+ (line-number-at-pos end)) (line-number-at-pos beg)))
+ (start-col (current-column))
+ (end-col (save-excursion (goto-char end) (current-column))))
+ (while (> lines 0)
+ (move-to-column start-col)
+ ;; skip lines that are empty at this column
+ (unless (/= start-col (current-column))
+ (evil-surround-region (point) (save-excursion (move-to-column end-col) (point))
+ 'inclusive char))
+ (setq lines (1- lines))
+ (next-line)))))
+
;; Dispatcher function in Operator-Pending state.
;; "cs" calls `evil-surround-change', "ds" calls `evil-surround-delete',
;; and "ys" calls `evil-surround-region'.
@@ -267,7 +283,10 @@ Becomes this:
(progn
(goto-char (overlay-start overlay))
- (cond ((eq type 'line)
+ (cond ((eq type 'block)
+ (evil-surround-block beg end char))
+
+ ((eq type 'line)
(insert open)
(indent-according-to-mode)
(newline-and-indent)