InsideDarkWeb.com

use-package: autoload function outside the main package file

I am trying to install simplenote2 to read my org files on my phone.
The official setup method is:

(require 'simplenote2)
(setq simplenote2-email "[email protected]")
(setq simplenote2-password "yourpassword")
(simplenote2-setup)

and the app starts with

M-x simplenote2-list

In practice credentials are not necessary in clear and (require...) can be omitted because simplenote2-setup is autoloaded.

I would like to use a use-package declaration, therefore I am using:

(use-package simplenote2
  :config
  (setq simplenote2-email "[email protected]")
  (setq simplenote2-password "yourpassword")
  (setq simplenote2-notes-mode (quote org-mode))
  (simplenote2-setup))

(The extra line is for org-mode integration).

When I start the library with M-x simplenote2-list, I get an error due to a void variable simplenote2-notes-info-version.
This variable is defined through a defvar in simplenote2.el. So, it seems that the use-package declaration is not requiring simplenote2.el.

The likely cause is that the autoloaded function simplenote2-list is defined in the separate file simplenote2-list.el. Therefore simplenote2-list requires only simplenote2-list.el, but not simplenote2.el.

If this is the cause, how can I instruct use-package to require also simplenote2.el the first time M-x simplenote2-list is run?
Or alternatively: before running M-x simplenote2-list, how can I run the autoloaded (simplenote2-setup), which automatically requires simplenote2.el?

Note that I have the global option use-package-always-defer set true.

Emacs Asked on November 15, 2021

1 Answers

One Answer

You cannot easily run simplenote2-setup when lazy loading the package.

However, there are several options, to make lazy loading happening:


1. use of :after and defining a use-package declaration for simplenote2-list i.e.:

(use-package simplenote2-list
  :after (simplenote2))

2. require simplenote2 from simplenote2-list use-package declaration

(use-package simplenote2-list
  :config (require 'simplenote2))

3. you could define a keybinding for simplenote2-list from simplenote2 use-package declaration:

(use-package simplenote2
  :bind ("C-c s" . simplenote2-list)
  :config
  ...)

This works for the same reason like the next option.


4. a somewhat hacky one, declaring simplenote2-list as command of simplenote2. This works because simplenote2-list is required by simplenote2.

(use-package simplenote2
  :commands (simplenote2-list)
  :config
  ...)

5. if simplenotes2 is able to be started with hooks or mode-interpreters, you could emulate the simplenote2-setup with keywords :mode or :hook. Please read the use-package manual.

Answered by jue on November 15, 2021

Add your own answers!

Related Questions

How to wrap lines at window edge

2  Asked on September 2, 2021 by lambda-pumpkin

 

C-h v gives ” Symbol’s value as variable is void: default

0  Asked on September 2, 2021 by brian-postow

     

Fixed length buffer for shell

1  Asked on September 2, 2021

 

Adding Spacemacs documented layers fails

1  Asked on September 2, 2021 by samusz

   

Easily accessing org files

1  Asked on September 2, 2021 by fraxture

 

View multiple emails at the same time with mu4e

1  Asked on September 2, 2021 by tyler

 

How can I set default paths for INCLUDE blocks under each heading in orgmode?

0  Asked on September 2, 2021 by scientific_explorer

 

In-line latex fragment position in org-mode

0  Asked on September 2, 2021 by a-blizzard

   

Filter list by regexps

2  Asked on September 2, 2021 by lorem-ipsum

       

Get a table of org-mode file from elisp to be passed to R

1  Asked on September 2, 2021 by omar113

 

Styling lists in org-export (html)

1  Asked on March 5, 2021 by user2699

   

Is there a way to show/open a file from a URI/URL

3  Asked on February 27, 2021 by carsten

   

Ask a Question

Get help from others!

© 2021 InsideDarkWeb.com. All rights reserved.