2

I have noticed a weird behaviour with use-package for multiple-cursors when trying to customize insertion of numbers.

I am able to insert numbers on multiple cursors using C-c n using this code

;; Multiple Cursors (use-package multiple-cursors :ensure t :bind(("C-S-c C-S-c" . mc/edit-lines) ("C-»" . mc/mark-next-like-this) ("C-«" . mc/mark-previous-like-this) ("C-c C-«" . mc/mark-all-like-this)) ) (setq mc/insert-numbers-default 1) (global-set-key (kbd "C-c n") 'mc/insert-numbers) 

but this alternative declaration of multiple-cursors does not produce the same effect, i.e., when pressing C-c n there is no keybinding associated and no numbers are inserted on the cursors.

;; Multiple Cursors (use-package multiple-cursors :ensure t :bind(("C-S-c C-S-c" . mc/edit-lines) ("C-»" . mc/mark-next-like-this) ("C-«" . mc/mark-previous-like-this) ("C-c C-«" . mc/mark-all-like-this)) :config (setq mc/insert-numbers-default 1) (global-set-key (kbd "C-c n") 'mc/insert-numbers) ) 

This is strange since the whole point of :config is to run code after the package is loaded, which is the intended purpose here. It works fine for other packages as far as I can tell. Any thoughts?

4
  • You said that there is a “weird behaviour” but not what was weird. Did you get an error message or something? Commented Sep 20, 2022 at 17:17
  • Sorry for the lack of clarity. What is weird is that the :config option does not seem to work in this particular case, although when the setq and keybinding commands are written after the use-package construct they work fine. Incidentally, these commands allow to insert sequence of numbers along the multiple cursors Commented Sep 20, 2022 at 17:36
  • “does not seem to work” is still a bit indefinite. Have you used C-h v to inspect the value of the mc/insert-numbers-default variable, for example? Note that packages are lazily loaded, so “after the package is loaded” could easily be after you first call a function defined in the package. Commented Sep 20, 2022 at 18:00
  • I've updated the question to try to shed some extra light. Ic. Is there any workaround/alternative way to invoke the package? Also, are you able to reproduce the same behaviour? Thanks. Commented Sep 20, 2022 at 18:14

1 Answer 1

3

If I understand your question, I think the problem is that loading multiple cursors is deferred, and so your :config code doesn't get loaded prior to the first time you use a mc command. The :bind argument exists to deal with this. Try the following:

(use-package multiple-cursors :ensure t :bind(("C-S-c C-S-c" . mc/edit-lines) ("C-»" . mc/mark-next-like-this) ("C-«" . mc/mark-previous-like-this) ("C-c C-«" . mc/mark-all-like-this) ("C-c n" . mc/insert-numbers)) :config (setq mc/insert-numbers-default 1) ) 
4
  • Thanks. With your solution I am indeed able to insert numbers. However, the setq command, which sets the default number at which the count starts from, is set to 0 (not 1). Commented Sep 21, 2022 at 7:46
  • * I meant to say the mc/insert-numbers-default variable - not the setq command Commented Sep 21, 2022 at 11:59
  • 1
    @Ajned switch :config to :init to force the setq command to be called earlier Commented Sep 21, 2022 at 12:53
  • Thanks @Tyler. It works like a charm but I cannot understand why. Being mc/insert-numbers-default a variable from multiple-cursors why do I need to set it before the package is loaded? O_O Thank you in advance for any explanation/pointers to documentation Commented Sep 21, 2022 at 18:14

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.