branch: externals/objed commit 2a25ff215d212c20244c5bd8f1b9c8ba06c94e01 Author: Clemens Radermacher <clem...@posteo.net> Commit: Clemens Radermacher <clem...@posteo.net>
Make toggle smarter for sexp objects --- objed-objects.el | 15 +-------------- objed.el | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/objed-objects.el b/objed-objects.el index 7add776..6648e11 100644 --- a/objed-objects.el +++ b/objed-objects.el @@ -1773,20 +1773,7 @@ comments." (when (/= pos (point)) (cons pos (point))))))))) - - (when bounds - (objed-make-object - :obounds bounds - :ibounds (when bounds - (goto-char (car bounds)) - ;; include leading punctuation - (skip-syntax-forward ".'") - (let ((beg (point))) - (goto-char (cdr bounds)) - (with-syntax-table text-mode-syntax-table - (skip-syntax-backward ".")) - (skip-syntax-backward " .'") - (cons beg (point))))))) + bounds) :try-next (or (ignore-errors (forward-sexp 1) diff --git a/objed.el b/objed.el index 2e9fca1..739f934 100644 --- a/objed.el +++ b/objed.el @@ -1801,13 +1801,28 @@ to an object containing the current one." (or (objed--switch-to 'defun 'inner) (objed--switch-to 'line 'inner)))))) + +(defun objed--sexp-fallback (&optional pos) + "Return fallback object for sexp at POS." + (let ((pos (or pos (point)))) + (goto-char pos) + (or (objed--at-p '(bracket string tag)) + (and (or (not (= 0 (skip-syntax-forward "'"))) + (not (= 0 (skip-syntax-backward "'")))) + (objed--at-p '(bracket string))) + (if (equal (bounds-of-thing-at-point 'symbol) + (objed--bounds)) + 'word + 'identifier)))) + (defun objed--toggle-state () "Toggle state of object. Shrinks to inner objects on repeat if possible." (when (eq objed--object 'sexp) - (save-excursion - (objed-context-object))) + (let ((fallback (objed--sexp-fallback))) + (when fallback + (objed--switch-to fallback)))) (objed--reverse)) (defun objed-backward-until-context ()