branch: externals/objed commit 29c1b3e1c601749d1e8e5cf2566c25962d5028c9 Author: Clemens Radermacher <clem...@posteo.net> Commit: Clemens Radermacher <clem...@posteo.net>
Make identifier movement easier --- README.asc | 13 +++---- objed-objects.el | 15 ++++++- objed.el | 58 ++++++++++++++++------------ test/tests/emacs-lisp-mode/expansion/block_1 | 2 +- test/tests/emacs-lisp-mode/state/npsfsb_pop | 2 +- test/tests/emacs-lisp-mode/state/rrrpop | 2 +- 6 files changed, 55 insertions(+), 37 deletions(-) diff --git a/README.asc b/README.asc index 83b0614..3403bb6 100644 --- a/README.asc +++ b/README.asc @@ -243,16 +243,15 @@ command mark all instances in current defun/buffer): [`objed-map`] |=== |Shortcut |Purpose - |kbd:[.] -|Switch to identifier object. +|Switch to identifier object or move to next. + +|kbd:[,] +|Switch to identifier object and move to previous. |kbd:[_] |Switch to symbol object. -|kbd:[l] -|Switch to line object. - |kbd:[c] |Prefix to switch to other objects, see `objed-object-map` for available objects and `objed-define-object` to add your own (https://with-emacs.com/posts/objed/writing-your-own-text-objects-for-objed/[blog]). |=== @@ -354,7 +353,7 @@ Misc commands: |kbd:[q] |Quit window if not the only one. -|kbd:[,] +|kbd:[l] |Pop to last state, which restores the last position and any object data. |kbd:[M-o] @@ -394,7 +393,7 @@ You can add your own prefix bindings using `objed-define-dispatch`. |Shortcut |Purpose |kbd:[*] -|Mark all instances of current object inside another object type. +|Mark more instances of current object inside defun/buffer. |kbd:[#] |Switch to another object using `avy`. diff --git a/objed-objects.el b/objed-objects.el index 02b3c06..54f89ab 100644 --- a/objed-objects.el +++ b/objed-objects.el @@ -403,8 +403,10 @@ OBJ is the object to use and defaults to `objed--current-obj'." (defun objed--basic-p () "Return non-nil if current object is a basic object. -From basic objects `objed' starts expanding to context objects." - (memq objed--object '(sexp line word char region buffer))) +From basic objects `objed' starts expanding to context objects. +Thus this should be objects which have their own movement +commands." + (memq objed--object '(sexp line identifier word char region buffer))) (defun objed--current (&optional obj) "Get the current range of interest. @@ -1074,6 +1076,13 @@ object." (objed--goto-char (objed--beg obj))))))) +(defun objed-goto-prev-identifier (arg) + (interactive "P") + (unless (eq objed--object 'identifier) + (objed--switch-to 'identifier)) + (objed--goto-previous arg)) + + (defun objed--make-object-overlay (&optional obj) "Create an overlay to mark current object. @@ -1996,6 +2005,7 @@ non-nil the indentation block can contain empty lines." :try-prev (objed-prev-identifier)) +;;;###autoload (defun objed-next-identifier () "Move to next identifier." (interactive) @@ -2013,6 +2023,7 @@ non-nil the indentation block can contain empty lines." (eq real-this-command #'objed-next-identifier)) (run-at-time 0 nil (apply-partially #'message "Last one!")))))))) +;;;###autoload (defun objed-prev-identifier () "Move to previous identifier." (interactive) diff --git a/objed.el b/objed.el index 1ba3369..72a41d3 100644 --- a/objed.el +++ b/objed.el @@ -513,16 +513,11 @@ update to given object." ;; initialize first (when (not objed--buffer) (objed--init name)) - (cond ((and (eq name current) - objed--marked-ovs - (not (region-active-p))) - (objed--mark-all-inside 'buffer)) - ((and (eq name current) - (not (region-active-p))) - (or (objed--mark-all-inside 'defun) - (objed--mark-all-inside 'buffer))) - (t (when (objed--switch-to name) - (goto-char (objed--beg)))))))))) + ;; goto next on repeat + (cond ((eq name current) + (objed--goto-next)) + (t (when (objed--switch-to name) + (goto-char (objed--beg)))))))))) (defun objed--switch-to-object-for-cmd (cmd) @@ -730,8 +725,21 @@ BEFORE and AFTER are forms to execute before/after calling the command." (define-key map "\"" (objed-define-op nil objed-electric)) + ;; direct object switches + (define-key map "." 'objed-identifier-object) + (define-key map "_" 'objed-symbol-object) + ;;(define-key map "%" 'objed-contents-object) + + + ;; prefix keys + (define-key map "x" 'objed-op-map) + (define-key map "c" 'objed-object-map) + ;; special commands - (define-key map "," 'objed-last) + (define-key map "*" 'objed-mark-more) + (define-key map "," 'objed-goto-prev-identifier) + (define-key map "l" 'objed-last) + ;; jump to objects with avy (define-key map "`" 'objed-ace) ;; swiper like object search @@ -751,23 +759,11 @@ BEFORE and AFTER are forms to execute before/after calling the command." nil objed-run-or-eval ignore)) (define-key map (kbd "<M-return>") 'objed-insert-new-object) - ;; TODO: ;; (define-key map "^" 'objed-raise-inner) - (define-key map "!" (objed-define-op nil objed-replace-op)) - ;; prefix keys - (define-key map "x" 'objed-op-map) - (define-key map "c" 'objed-object-map) - - ;; direct object switches - (define-key map "." 'objed-identifier-object) - (define-key map "_" 'objed-symbol-object) - (define-key map "l" 'objed-line-object) - ;;(define-key map "%" 'objed-contents-object) - map) "Keymap for commands when `objed' is active.") @@ -869,7 +865,7 @@ To define new objects see `objed-define-object'.") Use `objed-define-dispatch' to define a dispatch command.") -(objed-define-dispatch "*" objed--mark-all-inside) + (objed-define-dispatch "#" objed--ace-switch-object) (objed-define-dispatch "u" objed--backward-until) @@ -1972,6 +1968,18 @@ previous objects." (objed--toggle-mark nil 'append) (objed--goto-previous)))) + +(defun objed-mark-more () + "Mark more instances of current object. + +First try to mark more in current defun after that mark more in +current buffer." + (interactive) + (cond ((eq last-command this-command) + (objed--mark-all-inside 'buffer)) + (t + (objed--mark-all-inside 'defun)))) + (defun objed-last () "Resume to last state. @@ -3135,7 +3143,7 @@ whitespace they build a sequence." (define-key map (kbd "M-[") 'objed-beg-of-object-at-point) (define-key map (kbd "M-]") 'objed-end-of-object-at-point) (define-key map (kbd "C-,") 'objed-prev-identifier) - (define-key map (kbd "C-.") 'objed-next-identifier) + (define-key map (kbd "C-.") 'objed-identifier-object) map) "Keymap for /function`objed-mode'.") diff --git a/test/tests/emacs-lisp-mode/expansion/block_1 b/test/tests/emacs-lisp-mode/expansion/block_1 index 27f9eae..f090788 100644 --- a/test/tests/emacs-lisp-mode/expansion/block_1 +++ b/test/tests/emacs-lisp-mode/expansion/block_1 @@ -1,4 +1,4 @@ -l +C-a ;;;; (defun check () diff --git a/test/tests/emacs-lisp-mode/state/npsfsb_pop b/test/tests/emacs-lisp-mode/state/npsfsb_pop index 84d1c17..e61b6ec 100644 --- a/test/tests/emacs-lisp-mode/state/npsfsb_pop +++ b/test/tests/emacs-lisp-mode/state/npsfsb_pop @@ -1,4 +1,4 @@ -npsfsb,,,,,, +npsfsbllllll ;;;; Testing |line here diff --git a/test/tests/emacs-lisp-mode/state/rrrpop b/test/tests/emacs-lisp-mode/state/rrrpop index a836623..71610ff 100644 --- a/test/tests/emacs-lisp-mode/state/rrrpop +++ b/test/tests/emacs-lisp-mode/state/rrrpop @@ -1,4 +1,4 @@ -rrr, +rrrl ;;;; Testing line he|re