One possible approach is to exploit the hooks command-line-functions
, which are called with variable argi
dynamically bound to any unrecognised command-line options. The following are some of the many possible options; you can of course implement any logic you like.
The calls to ignore
(always returning nil
) indicate that our custom hooks have not "processed" the corresponding command-line argument. That is, we only want to effect a state change in the presence of unrecognised command-line arguments, not handle them manually.
Option 1
Assume all unrecognised options are files worthy of inhibiting the startup screen for. This option probably corresponds the most to what the default startup procedure is like.
(defun my-inhibit-startup-screen-always ()
"Startup screen inhibitor for `command-line-functions`.
Inhibits startup screen on the first unrecognised option."
(ignore (setq inhibit-startup-screen t)))
(add-hook 'command-line-functions #'my-inhibit-startup-screen-always)
Option 2
Only inhibit startup screen when existing files are passed as arguments.
(defun my-inhibit-startup-screen-file ()
"Startup screen inhibitor for `command-line-functions`.
Inhibits startup screen on the first unrecognised option which
names an existing file."
(ignore
(setq inhibit-startup-screen
(file-exists-p
(expand-file-name argi command-line-default-directory)))))
(add-hook 'command-line-functions #'my-inhibit-startup-screen-file)
Option 3
Only inhibit startup screen when an unrecognised option has a file extension.
(defun my-inhibit-startup-screen-ext ()
"Startup screen inhibitor for `command-line-functions`.
Inhibits startup screen on the first unrecognised option which
has a file name extension."
(ignore (setq inhibit-startup-screen (file-name-extension argi))))
(add-hook 'command-line-functions #'my-inhibit-startup-screen-ext)
startup.el
is that the code is baked into the Emacs executable. It may be possible to catch a function in the startup process and redefine it, but it may also not be possible. This is why I build my own Emacs and have my ownstartup.el
so that I can control exactly how and when things happen when starting Emacs. It would be easier to just close the Welcome window after callingemacs foo.txt
with theafter-init-hook
or theemacs-startup-hook
, or putting thedelete-other-windows
at the tail end of the.emacs
file. – lawlist May 18 '17 at 03:35$ emacs -nw foo.txt
behaves. – Brian Fitzpatrick May 18 '17 at 04:55