0

I am trying to override some of the default keymaps of emacs evil mode. What I have done is this:

(evil-define-key 'visual 'global
  "<" (lambda ()
    (evil-shift-left)
    (evil-visual-restore))
  ">" (lambda ()
    (evil-shift-right)
    (evil-visual-restore)))

And I got this error message: Wrong type argument: commandp, (lambda nil (evil-shift-left) (evil-visual-restore)) when I press >, when the expected behavior was shifting the selected text right and restore visual mode.

Since I am only 2 days into trying to learn emacs, I am pretty confused what I have done wrong here.

Drew
  • 29,895
  • 7
  • 74
  • 104
  • 3
    Why? Because it is not a command. ||| Solution: Add `(interactive)` right after `(lambda ()`. ||| Your first step should be to learn some **basic** ELisp knowledge, otherwise you'll waste your time. In the words of *Confucius*: "*To think without learning is perilous.*" – shynur Aug 03 '23 at 12:19
  • 2
    See . (This is an excellent book to get started with ELisp.) – shynur Aug 03 '23 at 12:30

1 Answers1

1

Thank the great advice by @shynur, and I really do agree now that learning the basic of elisp is crucial before starting to hack emacs. Still, I figured out how to solve my problem and it is not quite as simple as adding interactive. My solution goes like this:

(evil-define-key 'visual 'global
  (kbd "<") (lambda ()
        (interactive)
        (call-interactively 'evil-shift-left)
        (evil-normal-state)
        (evil-visual-restore))
  (kbd ">") (lambda ()
        (interactive)
        (call-interactively 'evil-shift-right)
        (evil-normal-state)
        (evil-visual-restore)))

Referred also to https://superuser.com/questions/684540/evil-mode-evil-shift-left-loses-selection