emacs-async icon indicating copy to clipboard operation
emacs-async copied to clipboard

FR: An easy way to specify required modules

Open stsquad opened this issue 9 years ago • 7 comments

I've been experimenting with using this as a wrapper for some org-mode babel lisp. However I'm adding a bunch of boiler plate to require libraries for the child emacs. I notice you already jump some hoops to make "async" itself visible to the child. Would it be possible to add something like the inject-variables mechanism to make some libraries available to the child?

stsquad avatar Oct 27 '14 12:10 stsquad

This seems very important to me. I'm trying to use this library to make a package that uses emacsql and org, and it doesn't seem practical to manually initialize the package system in the START-FUNC. It's not even correct, because it's dependent on each user's config. Some users won't even use package.el.

How do I give the child Emacs process access to the same libraries that are loaded in the parent process? What is the correct way to do this?

alphapapa avatar May 07 '18 18:05 alphapapa

alphapapa [email protected] writes:

This seems very important to me. I'm trying to use this library to make a package that uses emacsql and org, and it doesn't seem practical to manually initialize the package system in the START-FUNC. It's not even correct, because it's dependent on each user's config. Some users won't even use package.el.

How do I give the child Emacs process access to the same libraries that are loaded in the parent process? What is the correct way to do this?

Install your libraries in ..emacs/site-lisp and use async-quiet-switch == "-q", like this all your libraries will be in load-path.

-- Thierry

thierryvolpiatto avatar May 08 '18 05:05 thierryvolpiatto

Thanks, Thierry. I'm not sure exactly what you mean, because that would still be dependent on the user's config. I was able to get it working by doing (setq load-path ,load-path) in the START-FUNC to pass the parent process's already-initialized load-path.

Maybe this should be documented in the readme, because now that I know about it, it seems like a straightforward solution. Or maybe there should even be an argument to async-start to do this automatically, because it seems like a commonly needed solution.

alphapapa avatar May 08 '18 13:05 alphapapa

So I ended up doing this which is good enough for me:

(defun my-add-first-elfeed-enclosure-to-transmission ()
  "Queue the first enclosure (if it is a torrent)."
  (interactive)
  (let ((enclosures (elfeed-entry-enclosures elfeed-show-entry)))
    (when (and enclosures
               (string-match-p
                "application/x-bittorrent"
                (nth 1 (-first-item enclosures))))
      (transmission-add (-first-item (-first-item enclosures))))))

(use-package elfeed
  :ensure t
  :bind (:map elfeed-show-mode-map
              ("C-c C-c" . my-add-first-elfeed-enclosure-to-transmission))
  :config (setq elfeed-enclosure-default-dir "~/torrent/"
                elfeed-log-level 'debug
                elfeed-use-curl 't))
                

Is this worth adding to a FAQ? I'm not sure how hidden this will be once you close the issue.

stsquad avatar May 08 '18 18:05 stsquad

@stsquad Did you post that on the wrong issue?

alphapapa avatar May 09 '18 17:05 alphapapa

@alphapapa I totally did, sorry - that was meant for https://github.com/skeeto/elfeed/issues/274

stsquad avatar May 09 '18 22:05 stsquad

The best way to do this with somewhat modern Emacs is to use lexical binding:

(let ((load--path load-path))
  (lambda ()
    (let ((load-path load--path))
      your code here
)))

This will use the parent load path for the child process. Similar construct can be used for any value which does not depend on the parent environment (like buffers).

Fuco1 avatar Mar 13 '23 12:03 Fuco1