emacs-evil / evil

The extensible vi layer for Emacs.
GNU General Public License v3.0
3.35k stars 283 forks source link

Help overriding only certain postfixs to "m" #1874

Closed leath-dub closed 6 months ago

leath-dub commented 6 months ago

Issue type

Question

Environment

Emacs version: 29.3 Operating System: Ubuntu 22.04

Graphical/Terminal: Graphical

Is there a way I can maintain marks behaviour for all keys but some exceptions like "f" for example, i.e I would like to bind "mf" to something while also maintaining normal marks behaviour for all other keys.

I have been able to get the work with rebinding 'motion and disabling "m" in normal mode, however can't for the life of me get it to work without disabling in normal mode

tomdl89 commented 6 months ago

I think advice is the best thing here, as evil-set-marker doesn't use a keymap for the marker input, but rather just uses read-char so you can't selectively "rebind" in the usual way. Something like this would work:

(defun marker-overrides (fn &rest args)
  (pcase (car args)
    (?f (message "called f!"))
    ;; etc...
    (_ (apply fn args))))

(advice-add 'evil-set-marker :around #'marker-overrides)
leath-dub commented 6 months ago

I think advice is the best thing here, as evil-set-marker doesn't use a keymap for the marker input, but rather just uses read-char so you can't selectively "rebind" in the usual way. Something like this would work:

(defun marker-overrides (fn &rest args)
  (pcase (car args)
    (?f (message "called f!"))
    ;; etc...
    (_ (apply fn args))))

(advice-add 'evil-set-marker :around #'marker-overrides)

thank you so much ! I am only new to emacs.You can just wrap any function and add your own behavior, that's awesome!