diff options
| author | Henrik Lissner <henrik@lissner.net> | 2015-11-18 00:42:13 -0500 |
|---|---|---|
| committer | Henrik Lissner <henrik@lissner.net> | 2015-11-18 00:42:13 -0500 |
| commit | 641498131afea83dc612b73569ba61055a648ec8 (patch) | |
| tree | 81bdccc4268b01995ce3fafc2bc7ab8162e88902 /evil-surround.el | |
| parent | f44d52431568066ce99bbf50af17aab10fa425d6 (diff) | |
Refactor evil-surround-block
Diffstat (limited to 'evil-surround.el')
| -rwxr-xr-x | evil-surround.el | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/evil-surround.el b/evil-surround.el index 4a8aaf5..63df8f6 100755 --- a/evil-surround.el +++ b/evil-surround.el @@ -217,21 +217,19 @@ 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-column-at (pos) + (save-excursion (goto-char pos) (current-column))) + (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))))) + "Split a block into regions per line and surround them individually. Skips +lines where the columns don't line up." + (let* ((beg-col (evil-surround-column-at beg)) + (end-col (evil-surround-column-at end))) + (evil-apply-on-block + (lambda (ibeg iend) + (unless (< (evil-surround-column-at ibeg) (min beg-col end-col)) + (evil-surround-region ibeg iend t char))) + beg end nil))) ;; Dispatcher function in Operator-Pending state. ;; "cs" calls `evil-surround-change', "ds" calls `evil-surround-delete', |
