branch: externals/objed commit 8babcfc3a7c8834a842cb09615e2c232b4e02d17 Author: Clemens Radermacher <clem...@posteo.net> Commit: Clemens Radermacher <clem...@posteo.net>
Make obj state buffer local and keep it on movement Add subword for inner word object --- objed-objects.el | 30 ++++++++++++++++++++++-------- objed.el | 42 ++++++++++++++++++++++-------------------- 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/objed-objects.el b/objed-objects.el index 7b1c460..f0bedf5 100644 --- a/objed-objects.el +++ b/objed-objects.el @@ -27,6 +27,8 @@ ;; * Bytecomp +(require 'subword) + ;; info for byte-comp (declare-function avy--process "ext:avy") (declare-function avy--style-fn "ext:avy") @@ -343,7 +345,7 @@ Positions are stored in a list of the form: ((object-start object-end) (inner-start inner-end))") -(defvar objed--obj-state nil +(defvar-local objed--obj-state nil "The state used to get object positions. Either the symbol `whole' or `inner'.") @@ -1524,12 +1526,19 @@ comments." (bounds-of-thing-at-point 'symbol)) 'identifier) :get-obj - (if (and (bound-and-true-p subword-mode) - (eq this-command 'forward-word)) - (save-excursion - (forward-word -1) - (bounds-of-thing-at-point 'word)) - (bounds-of-thing-at-point 'word)) + (objed-make-object + :obounds (if (bound-and-true-p subword-mode) + (let ((find-word-boundary-function-table subword-empty-char-table)) + (bounds-of-thing-at-point 'word)) + (bounds-of-thing-at-point 'word)) + :ibounds (if (and (bound-and-true-p subword-mode) + (eq this-command 'forward-word)) + (save-excursion + (forward-word -1) + (bounds-of-thing-at-point 'word)) + (let ((find-word-boundary-function-table + subword-find-word-boundary-function-table)) + (bounds-of-thing-at-point 'word)))) :try-next (re-search-forward "\\<." nil t) :try-prev @@ -2128,7 +2137,12 @@ non-nil the indentation block can contain empty lines." :atp (or (looking-at "\\_<") (looking-back "\\_>" 1)) :get-obj - (bounds-of-thing-at-point 'symbol) + (let ((bounds (bounds-of-thing-at-point 'symbol))) + (when bounds + (objed-make-object + :obounds bounds + :ibounds (bounds-of-thing-at-point 'word)))) + :try-next (objed--next-identifier) :try-prev diff --git a/objed.el b/objed.el index 5c2f283..8510a87 100644 --- a/objed.el +++ b/objed.el @@ -124,6 +124,7 @@ (require 'cl-lib) (require 'nadvice) (require 'face-remap) +(require 'subword) (require 'objed-objects) @@ -580,7 +581,7 @@ BEFORE and AFTER are forms to execute before/after calling the command." (setq this-command ',cmd) (call-interactively ',cmd) ,after - (objed--switch-to ',obj) + (objed--switch-to ',obj objed--obj-state) (when (or prb pre) (cond ((and prb (= (point) (region-end))) @@ -615,6 +616,10 @@ selected one." (message "Indented defun."))) (call-interactively nc)))) +(defun objed--point-in-periphery () + "Return non-nil if point is in current lines periphery." + (<= (point) (save-excursion (back-to-indentation) (point)))) + (defvar objed-map (let ((map (make-sparse-keymap))) ;; block unused chars by default @@ -673,9 +678,16 @@ selected one." (define-key map "F" 'objed-move-object-forward) (define-key map "B" 'objed-move-object-backward) - (define-key map "p" (objed--call-and-switch previous-line line)) + (define-key map "p" (objed--call-and-switch + previous-line line + nil + (when (objed--point-in-periphery) + (back-to-indentation)))) (define-key map "n" (objed--call-and-switch - next-line line)) + next-line line + nil + (when (objed--point-in-periphery) + (back-to-indentation)))) (define-key map "P" 'objed-move-line-backward) (define-key map "N" 'objed-move-line-forward) @@ -718,7 +730,7 @@ selected one." (define-key map "o" 'objed-expand-context) (define-key map "i" 'objed-del-insert) - (define-key map "t" 'objed-shrink-context) + (define-key map "t" 'objed-toggle-state) (define-key map "j" 'objed-toggle-side) ;; marking/unmarking @@ -1862,26 +1874,16 @@ Default to sexp at point." (t (goto-char (objed--beg))))))) - -(defun objed-shrink-context () +(defun objed-toggle-state () "Shrink current object. Switches to inner object or object inside current one." (interactive) - (if (eq objed--object 'sexp) - (save-excursion - (objed-context-object)) - (if (objed--inner-p) - (save-excursion - (goto-char (objed--end)) - (objed--switch-to 'sexp)))) - (let ((sdiff (abs (- (point) (objed--beg)))) - (ediff (abs (- (point) (objed--end))))) - (objed--reverse) - (goto-char (cond ((> ediff sdiff) - (objed--beg)) - (t - (objed--end)))))) + (if (bound-and-true-p subword-mode) + (subword-mode -1) + (unless (objed--inner-p) + (subword-mode 1))) + (objed--toggle-state)) (defun objed-expand-context ()