all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* I need packages and custom with --script
@ 2022-09-28  6:57 Jean Louis
  2022-09-28 11:06 ` Felix Dietrich
  0 siblings, 1 reply; 3+ messages in thread
From: Jean Louis @ 2022-09-28  6:57 UTC (permalink / raw)
  To: Help GNU Emacs

I have on server Emacs 27 running, and I notice that I cannot load
packages with `require' even if installed, if I use --script and I see
that I cannot load packages and cannot get ~/.emacs.d/init.el
automatically loaded so that I can get customized variables from
inside.

I need help on that. 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)

And what do I need to load so that ~/.emacs.d/init.el is read and
custom variables read while running under --script ?

#!/home/data1/protected/bin/emacs --script
(require 'package)
(require 'custom)


Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: I need packages and custom with --script
  2022-09-28  6:57 I need packages and custom with --script Jean Louis
@ 2022-09-28 11:06 ` Felix Dietrich
  2022-09-29  3:05   ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 3+ messages in thread
From: Felix Dietrich @ 2022-09-28 11:06 UTC (permalink / raw)
  To: Jean Louis; +Cc: Help GNU Emacs

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: I need packages and custom with --script
  2022-09-28 11:06 ` Felix Dietrich
@ 2022-09-29  3:05   ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2022-09-29  3:05 UTC (permalink / raw)
  To: help-gnu-emacs

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

Nitpick: `package-initialize` sets up package.el so it's ready to do
pretty much anything, including install/uninstall etc...

So, nowadays (since Emacs-27) you should use `package-activate-all`
instead, which focuses on activating the installed packages without
paying attention to things like the list of existing packages in the
package archives etc...

IOW, it's faster (especially if you're using `package-quickstart`).


        Stefan




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-29  3:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-28  6:57 I need packages and custom with --script Jean Louis
2022-09-28 11:06 ` Felix Dietrich
2022-09-29  3:05   ` Stefan Monnier via Users list for the GNU Emacs text editor

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.