Discussion:
get name of script file with emacs --script?
(too old to reply)
d***@gmail.com
2017-03-04 19:50:17 UTC
Permalink
If you're writing an elisp script using the "#!/usr/bin/emacs --script" hashbang, is there a way to get the name of the script that's running? I'm looking for an analog of perl's $0 variable.
Gene
2017-03-06 01:36:25 UTC
Permalink
Post by d***@gmail.com
If you're writing an elisp script using the "#!/usr/bin/emacs --script" hashbang, is there a way to get the name of the script that's running? I'm looking for an analog of perl's $0 variable.
(progn ; eval this in the *scratch* buffer
(eww "https://www.gnu.org/software/emacs/manual/html_node/elisp/Command_002dLine-Arguments.html")
(switch-to-buffer "*eww*")
(occur "command-line-args")
)
d***@gmail.com
2017-03-06 03:24:53 UTC
Permalink
Post by Gene
Post by d***@gmail.com
If you're writing an elisp script using the "#!/usr/bin/emacs --script" hashbang, is there a way to get the name of the script that's running? I'm looking for an analog of perl's $0 variable.
(eww "https://www.gnu.org/software/emacs/manual/html_node/elisp/Command_002dLine-Arguments.html")
Ah, thanks. Yes, this does it:

#!/usr/bin/emacs --script
(setq script-file-name (nth 2 command-line-args))
d***@gmail.com
2017-03-16 01:45:55 UTC
Permalink
Post by d***@gmail.com
Post by Gene
Post by d***@gmail.com
If you're writing an elisp script using the "#!/usr/bin/emacs --script" hashbang, is there a way to get the name of the script that's running? I'm looking for an analog of perl's $0 variable.
(eww "https://www.gnu.org/software/emacs/manual/html_node/elisp/Command_002dLine-Arguments.html")
#!/usr/bin/emacs --script
(setq script-file-name (nth 2 command-line-args))
Hm... actually that does literally what I asked, but it isn't quite what I want. That's a good way to get code behavior that differs when run from the command line or when executed inside of emacs, but if you'd like the code to know it's file name when run in either context, it's not so useful.

So, I guess really, I'm looking for something like an analog of perl's FindBin.

Or to put it another way: do defuns know what file they were defined inside of?
N. Jackson
2017-03-16 16:40:06 UTC
Permalink
Post by d***@gmail.com
Or to put it another way: do defuns know what file they were
defined inside of?
Not answering your question directly, but nonetheless helpful I
hope, `describe-function' is able to identify the file containing
a defun, so maybe have a look at how it does this?

N.

Loading...