Skip to content

Commit

Permalink
Add convenient way to mark target and use region actions on it
Browse files Browse the repository at this point in the history
This adds a mark action that is repeatable and tweaks the cycling so
that if the region is active, cycling starts with the region actions
rather than with a target of the same type.
  • Loading branch information
oantolin committed Aug 15, 2021
1 parent 36cd01c commit b20de98
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions embark.el
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,10 @@ the key :always are executed always."
(raise-sexp embark--beginning-of-target)
(kill-sexp embark--beginning-of-target)
(mark-sexp embark--beginning-of-target)
(mark embark--mark-target)
(kill-region embark--mark-target)
(kill-ring-save embark--mark-target)
(indent-region embark--mark-target)
(indent-rigidly embark--mark-target)
(whitespace-cleanup-region embark--mark-target)
(apply-macro-to-region-lines embark--mark-target)
(indent-rigidly embark--mark-target))
(indent-region embark--mark-target))
"Alist associating commands with pre-action hooks.
The hooks are run right before an action is embarked upon. See
`embark-setup-action-hooks' for information about the hook
Expand Down Expand Up @@ -451,7 +448,7 @@ arguments and more details."

(defcustom embark-repeat-actions
'(embark-next-symbol embark-previous-symbol backward-up-list
backward-list forward-list forward-sexp backward-sexp)
backward-list forward-list forward-sexp backward-sexp mark)
"List of repeatable actions."
:type '(repeat function))

Expand Down Expand Up @@ -1720,16 +1717,23 @@ target."
(if embark-quit-after-action (not arg) arg))
(when-let (new-targets (and (memq action embark-repeat-actions)
(embark--targets)))
;; Terminate repeated prompter on default action, when
;; repeating. Jump to the same target type.
;; Terminate repeated prompter on default action,
;; when repeating. Jump to the region type if the
;; region is active after the action, or else to the
;; current type again.
(setq default-done #'embark-done
targets (embark--rotate
new-targets
(or (cl-position-if
(lambda (x) (eq (plist-get x :type)
(plist-get (car targets) :type)))
new-targets)
0))))))))
targets
(embark--rotate
new-targets
(or (cl-position-if
(let ((desired-type
(if (use-region-p)
'region
(plist-get (car targets) :type))))
(lambda (x)
(eq (plist-get x :type) desired-type)))
new-targets)
0))))))))
(mapc #'funcall indicators))))

(defun embark-highlight-indicator ()
Expand Down Expand Up @@ -3047,7 +3051,8 @@ and leaves the point to the left of it."
("S" embark-collect-snapshot)
("L" embark-collect-live)
("B" embark-become)
("C-s" embark-isearch))
("C-s" embark-isearch)
("SPC" mark))

(autoload 'org-table-convert-region "org-table")

Expand Down Expand Up @@ -3132,13 +3137,12 @@ and leaves the point to the left of it."
("RET" pp-eval-expression)
("e" pp-eval-expression)
("m" pp-macroexpand-expression)
("TAB" indent-pp-sexp)
("TAB" indent-region)
("r" raise-sexp)
("k" kill-sexp)
("k" kill-region)

This comment has been minimized.

Copy link
@minad

minad Aug 15, 2021

Contributor

Is this here only for backward compatibility?

This comment has been minimized.

Copy link
@oantolin

oantolin Aug 15, 2021

Author Owner

Yes. Maybe it's better to remove it?

This comment has been minimized.

Copy link
@minad

minad Aug 15, 2021

Contributor

No idea, it is a policy thing. I very much like the generalization we have now. But it may make sense to keep these convenience bindings. Besides why does this exist as a separate command even since you can easily replicate it by marking+kill-region - just for convenience!

("u" backward-up-list)
("n" forward-list)
("p" backward-list)
("SPC" mark-sexp))
("p" backward-list))

(embark-define-keymap embark-defun-map
"Keymap for Embark defun actions."
Expand All @@ -3149,8 +3153,7 @@ and leaves the point to the left of it."
("l" elint-defun)
("D" edebug-defun)
("o" checkdoc-defun)
("n" narrow-to-defun)
("SPC" mark-defun))
("n" narrow-to-defun))

This comment has been minimized.

Copy link
@minad

minad Aug 15, 2021

Contributor

narrow-to-defun also seems unnecessary given the general mark command. I am not sureif it makes sense to keep this or not to avoid the redundancy with SPC n?

This comment has been minimized.

Copy link
@oantolin

oantolin Aug 15, 2021

Author Owner

Yes, it can go too.

This comment has been minimized.

Copy link
@minad

minad Aug 15, 2021

Contributor

Or keep it. Does not hurt much. See my comment above.


(embark-define-keymap embark-symbol-map
"Keymap for Embark symbol actions."
Expand Down

0 comments on commit b20de98

Please sign in to comment.