improve selection with spaces

This commit is contained in:
Jean-Philippe Bernardy 2015-12-30 21:37:28 +01:00
parent 9604996c14
commit 3363f17f0e
2 changed files with 16 additions and 14 deletions

View file

@ -111,7 +111,7 @@ This function is meant to be called interactively."
(defun boon-select-with-spaces (regs)
"Return the regions REGS, including some surrounding spaces.
This function is meant to be called interactively."
(interactive (list (boon-spec-region "select contents")))
(interactive (list (boon-spec-region "select with spaces")))
(cons 'region (mapcar (lambda (reg) (boon-include-surround-spaces reg)) (mapcar 'boon-normalize-reg regs))))
(defun boon-select-content (regs)

View file

@ -31,21 +31,23 @@ The size of the borders is HOW-MUCH."
(list (boon-mk-reg (boon-reg-end reg) (- (boon-reg-end reg) how-much))
(boon-mk-reg (boon-reg-begin reg) (+ (boon-reg-begin reg) how-much))))
;; TODO: also include surrounding blank lines if the other boundary is at bol/eol.
(defun boon-include-surround-spaces (reg)
"Extend REG to include spaces after its 'boon-reg-point' (or before, if the region is backwards)."
(save-excursion
(let* ((beg (boon-reg-begin reg))
(end (boon-reg-end reg))
(space-at-end (progn
(goto-char end)
(looking-at "\\s-"))))
(if space-at-end
(boon-mk-reg beg (progn
(let* ((mk (boon-reg-mark reg))
(pt (boon-reg-point reg))
(fwd (> pt mk)))
(boon-mk-reg mk
(if fwd
(progn
(goto-char pt)
(skip-syntax-forward "-")
(point)))
(boon-mk-reg (progn (goto-char beg)
(skip-syntax-backward "-")
(point))
end)))))
(progn
(goto-char pt)
(skip-syntax-backward "-")
(point)))))))
(defun boon-reg-begin (reg)
"The begining of region REG."