Is it possible to load modes in interactive functions before the interactive prompt is executed?

54 Views Asked by At

This is a follow-up question to this original question.

I try to provide a custom interactive function, requiring the loading of another package, right after startup of Spacemacs. My problem is that the interactive call seems to be executed always at the beginning of the function call, preventing me from using not yet loaded mode variables within the interactive call.

Example: I would like to access (with completion) my org-agenda-files interactively, but org-agenda-files are defined only after org-mode has been loaded. So the idea at the moment looks like this:

;;;###autoload
(defun my/org-agenda-find-file(file-path)
  (require 'org)
  (interactive (list
                (completing-read "Choose agenda file: " org-agenda-files)))
  (find-file file-path)
  )

Unfortunately, calling this function interactively after startup results in:

list: Symbol’s value as variable is void: org-agenda-files,

as it does without the "require" statement.

I got inspired by this part of the manual, but did not find a similar example specifically for interactive functions.

Is it possible to achieve what I want here with interactive functions?

Thanks a lot for your contributions!

1

There are 1 best solutions below

0
On BEST ANSWER

You can add as many commands to interactive as long as they are inside a block that returns the arguments that have to be passed to the function. In your case, just wrap all into a progn block:

(defun my/org-agenda-find-file (file-path)
  (interactive
   (progn
     (require 'org)
     (list (completing-read "Choose agenda file: " org-agenda-files))))
  (find-file file-path))