1

I have package that has no relation to evil-mode, but doesn't work well when the command is repeated.

While the repeat command can be disabled, I don't want to add a dependency on evil mode just to do this.

I also want to avoid the load-order of my package and evil causing my package not to detect evil mode.

While this works, it's not elegant, is there a better way to handle this?

(if (fboundp 'evil-declare-not-repeat)
  (progn
    (evil-declare-not-repeat 'my-foo-cmd)
    (evil-declare-not-repeat 'my-bar-cmd)
    (evil-declare-not-repeat 'my-baz-cmd))
  (with-eval-after-load 'evil
    (evil-declare-not-repeat 'my-foo-cmd)
    (evil-declare-not-repeat 'my-bar-cmd)
    (evil-declare-not-repeat 'my-baz-cmd)))

ideasman42
  • 8,786
  • 1
  • 32
  • 114
  • 1
    I don't understand your question. I suspect there are several ways to make a command not repeat, without using evil-mode at all. – Tyler Jan 10 '20 at 01:17
  • This sets up information in evil-mode to tell it not to repeat the command. That is - not to register it as a command that supports the repeat action. Am quite sure this is needed. – ideasman42 Jan 10 '20 at 01:28
  • 1
    Your code will only run after evil is loaded, so I take it you are actually using the evil package? Not sure why eval-after-load isn't enough here, without wrapping it in an if statement. – Tyler Jan 10 '20 at 12:06
  • I can't ensure how people use my package, evil may or may not be loaded, it may also not be installed. I would like to write evil logic in an elegant way that doesn't duplicate logic twice. – ideasman42 Jan 10 '20 at 12:48
  • 1
    with-eval-after-load runs the body code immediately if the feature is already loaded, and immediately after the feature is loaded if it isn't already. If the feature is never loaded, body is never run. so your (if (fboundp 'evil-declare-not-repeat) ...) isn't necessary - it doesn't add anything that isn't already covered by with-eval-after-load. – Tyler Jan 10 '20 at 13:52

1 Answers1

1

This can be done using with-eval-after-load which runs after the package has been loaded, or immediately if it's already loaded.


Submitting own answer, although there may be better alternatives.

(declare-function evil-declare-not-repeat "ext:evil-common")
(with-eval-after-load 'evil
  (evil-declare-not-repeat 'my-foo-cmd)
  (evil-declare-not-repeat 'my-bar-cmd)
  (evil-declare-not-repeat 'my-baz-cmd))
ideasman42
  • 8,786
  • 1
  • 32
  • 114
  • Shouldn't with-eval-after-load have a FILE parameter? Can you explain how this works? – RichieHH Feb 12 '20 at 20:40
  • Now, you mention "featurep" here but don't use it. From the "and" I expected you to use it here. I suspect it would be clearer to people to drop the mention of "featurep" and just mention you ONLY load the feature if evil is loaded or at a later date when it's loaded, which is indeed the facility which "with-eval-after-load" provides. – RichieHH Feb 13 '20 at 08:06
  • 1
    When writing this I didn't understand eval-after-load would run immediately, updated answer. – ideasman42 Feb 13 '20 at 10:05