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) (defun boon-select-with-spaces (regs)
"Return the regions REGS, including some surrounding spaces. "Return the regions REGS, including some surrounding spaces.
This function is meant to be called interactively." 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)))) (cons 'region (mapcar (lambda (reg) (boon-include-surround-spaces reg)) (mapcar 'boon-normalize-reg regs))))
(defun boon-select-content (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)) (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)))) (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) (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 (save-excursion
(let* ((beg (boon-reg-begin reg)) (let* ((mk (boon-reg-mark reg))
(end (boon-reg-end reg)) (pt (boon-reg-point reg))
(space-at-end (progn (fwd (> pt mk)))
(goto-char end) (boon-mk-reg mk
(looking-at "\\s-")))) (if fwd
(if space-at-end (progn
(boon-mk-reg beg (progn (goto-char pt)
(skip-syntax-forward "-") (skip-syntax-forward "-")
(point))) (point))
(boon-mk-reg (progn (goto-char beg) (progn
(skip-syntax-backward "-") (goto-char pt)
(point)) (skip-syntax-backward "-")
end))))) (point)))))))
(defun boon-reg-begin (reg) (defun boon-reg-begin (reg)
"The begining of region REG." "The begining of region REG."