4

I'd like to pass some extra information to my init.el via command line arguments. However, the variable command-line-args-left is always nil when Emacs is run interactively. (Though it is correctly populated when run with the --script option).

How can I get a list of command line arguments when Emacs is run normally?

3

Arguments are deleted after being processed at startup, you can either handle them like sds specified or if you'd like the list of args given after start up, save the contents of command-line-args at the start of your init.

(setq my-save-args command-line-args)

Though if you're planning on passing custom args, you'll need to handle them during startup.

You can probably also get them from the ps command.

(shell-command-to-string (format "ps -o args -p %s" (emacs-pid)))

should return the full command emacs was run with if you have ps.

  • 1
    I see now! Why they're deleted is a mystery. I can't use a handler like @sds said, for other reasons, but it appears that command-line-args does exists at startup time. – PythonNut Jan 17 '15 at 0:24
5

The command line options are processed in startup.el.

You need to add your handlers to command-line-functions to handle the additional options.

  • Doesn't that happen before loading the init file? Will he be able to add the handlers in time? – Malabarba Jan 16 '15 at 22:39
  • @Malabarba Yeah, I'm not clear on the sequence of events. But I tried it out and adding an arg handler in my init file works fine. – glucas Jan 17 '15 at 1:50
  • Ah, looks like the args are processed in two phases. This is useful: gnu.org/software/emacs/manual/html_node/elisp/… – glucas Jan 17 '15 at 1:57

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.