block selector

This commit is contained in:
Jean-Philippe Bernardy 2016-09-04 09:16:54 +02:00
parent 0e9c4b7ef1
commit de711094a6
5 changed files with 39 additions and 22 deletions

View file

@ -106,12 +106,31 @@ This item is either the symbol at point, or, if this fails, the sexp at point."
(defun boon-select-blanks () (defun boon-select-blanks ()
(interactive) (interactive)
(lambda ()(boon-regs-from-bounds (cons (lambda ()(boon-regs-from-bounds (cons
(save-excursion (save-excursion
(boon-jump-over-blanks-backward) (boon-jump-over-blanks-backward)
(point)) (point))
(save-excursion (save-excursion
(boon-jump-over-blanks-forward) (boon-jump-over-blanks-forward)
(point)))))) (point))))))
(defun boon-select-block ()
(interactive)
(lambda ()
(boon-regs-from-bounds
(save-excursion
(back-to-indentation)
(setq temporary-goal-column (current-column))
(cons
(save-excursion
(while (and (not (bolp)) (<= (boon-col-relative-to-indent) 0))
(previous-logical-line))
(next-logical-line)
(beginning-of-line)
(point))
(save-excursion
(while (and (not (bolp)) (<= (boon-col-relative-to-indent) 0))
(next-logical-line))
(beginning-of-line)
(point)))))))
(defun boon-spec-string-lazy (prompt) (defun boon-spec-string-lazy (prompt)
"Read a string using the region selection functionality. "Read a string using the region selection functionality.

View file

@ -15,6 +15,7 @@
(define-key boon-select-map "s" 'boon-select-wim) ;; symbol (define-key boon-select-map "s" 'boon-select-wim) ;; symbol
(define-key boon-select-map "t" 'boon-select-with-spaces) (define-key boon-select-map "t" 'boon-select-with-spaces)
(define-key boon-select-map "d" 'boon-select-document) (define-key boon-select-map "d" 'boon-select-document)
(define-key boon-select-map "b" 'boon-select-block)
(define-key boon-select-map "C" 'boon-select-comment) (define-key boon-select-map "C" 'boon-select-comment)
(define-key boon-select-map "x" 'boon-select-outside-pairs) ;; eXpression (define-key boon-select-map "x" 'boon-select-outside-pairs) ;; eXpression

View file

@ -215,7 +215,7 @@ Regions are given by REGS."
(defun boon-newline-dwim () (defun boon-newline-dwim ()
"Insert a new line do-what-i-mean style." "Insert a new line do-what-i-mean style."
(interactive) (interactive)
(if (and (not (eolp)) (string-blank-p (boon-line-prefix))) (if (and (not (eolp)) (< (boon-col-relative-to-indent) 0))
(call-interactively 'boon-open-line) (call-interactively 'boon-open-line)
(boon-split-line))) (boon-split-line)))

View file

@ -95,19 +95,21 @@ If possible, prompt the symbol at point."
(boon-edge-of-expression nil)) (boon-edge-of-expression nil))
(defun boon-smarter-upward (count) (defun boon-smarter-upward (count)
"Move upward, to a line with the same level of indentation, or less, COUNT times." "Move upward, to a line with the same level of indentation or less, COUNT times."
(interactive "p") (interactive "p")
(back-to-indentation)
(dotimes (_number count) (dotimes (_number count)
(previous-logical-line) (previous-logical-line)
(while (boon-at-indent-or-more-p) (previous-logical-line))) (while (< (boon-col-relative-to-indent) 0) (previous-logical-line)))
(back-to-indentation)) (back-to-indentation))
(defun boon-smarter-downward (count) (defun boon-smarter-downward (count)
"Move downward, to a line with the same level of indentation, or less COUNT times." "Move downward, to a line with the same level of indentation or less, COUNT times."
(interactive "p") (interactive "p")
(back-to-indentation)
(dotimes (_number count) (dotimes (_number count)
(next-logical-line) (next-logical-line)
(while (boon-at-indent-or-more-p) (next-logical-line))) (while (< (boon-col-relative-to-indent) 0) (next-logical-line)))
(back-to-indentation)) (back-to-indentation))
(defun boon-smarter-backward (count) (defun boon-smarter-backward (count)

View file

@ -11,6 +11,7 @@
(defmacro boon-with-ordered-region (body) (defmacro boon-with-ordered-region (body)
"Run the BODY, ensuring that the point is before the mark." "Run the BODY, ensuring that the point is before the mark."
(declare (obsolete "Used only by obsolete code" "20160904"))
`(if (< (point) (mark)) `(if (< (point) (mark))
,body ,body
(progn (exchange-point-and-mark) ,body (exchange-point-and-mark)))) (progn (exchange-point-and-mark) ,body (exchange-point-and-mark))))
@ -28,9 +29,9 @@
(back-to-indentation) (back-to-indentation)
(current-column))) (current-column)))
(defun boon-line-prefix () (defun boon-line-prefix ()
"Return the text between beginning of line and point." "Return the text between beginning of line and point."
(declare (obsolete "use boon-col-relative-to-indent instead" "20160903"))
(buffer-substring-no-properties (buffer-substring-no-properties
(line-beginning-position) (line-beginning-position)
(point))) (point)))
@ -41,15 +42,10 @@
(line-end-position) (line-end-position)
(point))) (point)))
(defun boon-at-indent-or-more-p () (defun boon-col-relative-to-indent ()
"Return non-nil if the point is at the current line indentation; or to the right." "Return the position of the cursor relative to indentation.
(or (eolp) Can be negative."
(and (not (boon-at-indent-p)) (- (point) (save-excursion (back-to-indentation) (point))))
(string-blank-p (boon-line-prefix)))))
(defun boon-at-indent-p ()
"Return non-nil if the point is at the current line indentation."
(eq (save-excursion (back-to-indentation) (point)) (point)))
(defun boon-looking-at-comment (how-many) (defun boon-looking-at-comment (how-many)
"Is the current point looking at HOW-MANY comments? (negative for backwards)?" "Is the current point looking at HOW-MANY comments? (negative for backwards)?"
@ -77,7 +73,6 @@ If no such text exists, throw an error."
(or (thing-at-point 'symbol) (or (thing-at-point 'symbol)
(error "Nothing relevant at point; move to a symbol or select a region")))) (error "Nothing relevant at point; move to a symbol or select a region"))))
(defun boon-jump-over-blanks-forward () (defun boon-jump-over-blanks-forward ()
"Jump over blanks, forward." "Jump over blanks, forward."
(interactive) (interactive)