0

I would like to write a function that attaches files using org-attach. Unfortunately, org-attach only seems designed to launch a "menu", and not to be used programmatically. Since it does not accept arguments, I can't just do:

(defun attempt1 () 
  (interactive)
  (org-attach "testfile.txt"))

I looked through the org-attach.el source and found a org-attach-attach function, which allows me to do:

(defun attempt2 () 
  (interactive)
  (org-attach-attach "testfile.txt"))

This works but only after I have called org-attach at least once interactively.

How can I feed a file name to org-attach inside a function? Alternatively, how can I make sure that org-attach-attach is available at startup in a "fresh" emacs session, without manually calling org-attach first?

1
  • 1
    Looks like a clear question. Hopefully someone will have a helpful answer for you.
    – Drew
    Mar 26 at 3:34
0

Unsurprisingly, my answer can be found in the elisp manual under "Autoload":

The autoload facility lets you register the existence of a function or macro, but put off loading the file that defines it. The first call to the function automatically loads the proper library, in order to install the real definition and other associated code, then runs the real definition as if it had been loaded all along.

An easy fix is to simply add a require call before my function:

(require org-attach)

(defun attempt2 () 
  (interactive)
  (org-attach-attach "testfile.txt"))

This makes the org-attach-attach function available on startup, without having to call org-attach manually first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.