Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Determine if emacs or emacsclient was run with filename(s) as commandline argument.

13 views
Skip to first unread message

Constantin Kulikov

unread,
May 10, 2013, 4:40:41 PM5/10/13
to help-gnu-emacs
Is there a way to know if emacs was run with filename argument?
Example:
emacsclinet -c "/some/path/some_file"
It'l create new emacs frame and open 'some_file'. Can I somehow determine
or detect opening files from commandline?
I tried setting up `before-make-frame-hook', `after-make-frame-functions'
and `find-file-hook' and I discovered that find-file-hook is last hook that
executed so I can't differentiate 'command line file opening' from regular
user action.
Why I need it:
I wrote some elisp code that saves window configuration on frame
destruction and restores it on new frame creation. emacsclient -c is set as
my $EDITOR. I need some way to detect case when some program calls the
$EDITOR with file name as argument because in that case I don't need to
restore window configuration.

Bernardo

unread,
May 12, 2013, 3:26:32 AM5/12/13
to Constantin Kulikov, help-gnu-emacs
> Is there a way to know if emacs was run with filename argument?

command-line-args?

,----
| command-line-args is a variable defined in `C source code'.
| Its value is ("~/EmacsTrunk/src/emacs")
|
| Documentation:
| Args passed by shell to Emacs, as a list of strings.
| Many arguments are deleted from the list as they are processed.
`----



Constantin Kulikov

unread,
May 12, 2013, 3:41:25 AM5/12/13
to help-gnu-emacs
Looks like it's always `("emacs")' for emacsclient -c file, or it's
processed and set to that value before any of hooks that I can set.
I discovered that before-make-frame-hook and after-make-frame-functions is
triggered before the find-file-hook, but command-line-args is `("emacs")'
in each of this hooks.

Constantin Kulikov

unread,
May 12, 2013, 6:56:14 AM5/12/13
to help-gnu-emacs
found server-visit-hook, will try use it
0 new messages