help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I need packages and custom with --script


From: Felix Dietrich
Subject: Re: I need packages and custom with --script
Date: Wed, 28 Sep 2022 13:06:18 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux)

Hi Jean,

Jean Louis <bugs@gnu.support> writes:

> I have on server Emacs 27 running, and I notice that I cannot load
> packages with `require' even if installed, if I use --script […]

> [How do I load packages when using the “--script” argument?]  Do I
> need to load 'package like this? I have tried, but it still does not
> recognize other packages, so I can't load them with (require
> 'my-package)
>
> #!/home/data1/protected/bin/emacs --script
> (require 'package)
> (require 'custom)

If you have manually installed some Emacs Lisp files that you would now
like to ‘require’ in your script, you need to add their directory to the
‘load-path’ using, for example, “(add-to-list 'load-path
"/path/to/directory")” before you can ‘require’ them.

For packages, if you want to use its automation of the above process
plus whatever else it does, I believe the needed incantation is
something like the following:

#+begin_src emacs-lisp
  (require 'package)
  ;; Maybe set ‘package-load-list’ here.
  (package-initialize)
#+end_src

After this you should be able to ‘require’ the packages you need.

> [How can I load “~/.emacs.d/init.el”] if I use --script […]

Within a script, you should be able to load any Emacs Lisp file, for
example the Emacs init file:

#+begin_src emacs-lisp
  (load-file "~/.emacs.d/init.el")
#+end_src

Emacs also handles a “--load” argument, but the file passed via this
argument is evaluated after “--script”:

#+NAME: /tmp/my-load-file.el
#+begin_src emacs-lisp
  (princ "Hello from --load file")
  (terpri)
#+end_src

#+NAME: /tmp/my-script-file.el
#+begin_src emacs-lisp
  (princ "Hello from --script file")
  (terpri)
#+end_src

#+begin_src sh :dir /tmp :results output
  emacs --load   my-load-file.el   --script my-script-file.el
  # Note that the order of the arguments does not matter:
  emacs --script my-script-file.el --load   my-load-file.el
#+end_src

#+RESULTS:
: Hello from script file
: Hello from load file
: Hello from script file
: Hello from load file

> And what do I need to load so that […]  custom variables [are] read
> while running under --script ?

For variables set with the Emacsʼs customisation system, you can,
presumably, just load the file in which custom.el inserts the settings.
Maybe you need to ‘require’ ‘custom’ first so that Emacs recognises the
“custom-” functions used there, like you do in your example above.  Just
try it out.

-- 
Felix Dietrich



reply via email to

[Prev in Thread] Current Thread [Next in Thread]