From de711094a6d898b66038c39127ceebd50d1c2a71 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bernardy Date: Sun, 4 Sep 2016 09:16:54 +0200 Subject: [PATCH] block selector --- boon-arguments.el | 31 +++++++++++++++++++++++++------ boon-colemak.el | 1 + boon-main.el | 2 +- boon-moves.el | 10 ++++++---- boon-utils.el | 17 ++++++----------- 5 files changed, 39 insertions(+), 22 deletions(-) diff --git a/boon-arguments.el b/boon-arguments.el index 03680e0..6b790cf 100644 --- a/boon-arguments.el +++ b/boon-arguments.el @@ -106,12 +106,31 @@ This item is either the symbol at point, or, if this fails, the sexp at point." (defun boon-select-blanks () (interactive) (lambda ()(boon-regs-from-bounds (cons - (save-excursion - (boon-jump-over-blanks-backward) - (point)) - (save-excursion - (boon-jump-over-blanks-forward) - (point)))))) + (save-excursion + (boon-jump-over-blanks-backward) + (point)) + (save-excursion + (boon-jump-over-blanks-forward) + (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) "Read a string using the region selection functionality. diff --git a/boon-colemak.el b/boon-colemak.el index f1882db..79c0f7f 100644 --- a/boon-colemak.el +++ b/boon-colemak.el @@ -15,6 +15,7 @@ (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 "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 "x" 'boon-select-outside-pairs) ;; eXpression diff --git a/boon-main.el b/boon-main.el index 7a7ef8e..3c077e9 100644 --- a/boon-main.el +++ b/boon-main.el @@ -215,7 +215,7 @@ Regions are given by REGS." (defun boon-newline-dwim () "Insert a new line do-what-i-mean style." (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) (boon-split-line))) diff --git a/boon-moves.el b/boon-moves.el index 35eec30..469b767 100644 --- a/boon-moves.el +++ b/boon-moves.el @@ -95,19 +95,21 @@ If possible, prompt the symbol at point." (boon-edge-of-expression nil)) (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") + (back-to-indentation) (dotimes (_number count) (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)) (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") + (back-to-indentation) (dotimes (_number count) (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)) (defun boon-smarter-backward (count) diff --git a/boon-utils.el b/boon-utils.el index 1a17dba..fab0be8 100644 --- a/boon-utils.el +++ b/boon-utils.el @@ -11,6 +11,7 @@ (defmacro boon-with-ordered-region (body) "Run the BODY, ensuring that the point is before the mark." + (declare (obsolete "Used only by obsolete code" "20160904")) `(if (< (point) (mark)) ,body (progn (exchange-point-and-mark) ,body (exchange-point-and-mark)))) @@ -28,9 +29,9 @@ (back-to-indentation) (current-column))) - (defun boon-line-prefix () "Return the text between beginning of line and point." + (declare (obsolete "use boon-col-relative-to-indent instead" "20160903")) (buffer-substring-no-properties (line-beginning-position) (point))) @@ -41,15 +42,10 @@ (line-end-position) (point))) -(defun boon-at-indent-or-more-p () - "Return non-nil if the point is at the current line indentation; or to the right." - (or (eolp) - (and (not (boon-at-indent-p)) - (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-col-relative-to-indent () + "Return the position of the cursor relative to indentation. +Can be negative." + (- (point) (save-excursion (back-to-indentation) (point)))) (defun boon-looking-at-comment (how-many) "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) (error "Nothing relevant at point; move to a symbol or select a region")))) - (defun boon-jump-over-blanks-forward () "Jump over blanks, forward." (interactive)