I don't quite understand your last comment, but try the following in your init file:
(setq inhibit-splash-screen t)
(setq command-line-functions (list #'handle-files))
(defun handle-files ()
(let* ((files (cons argi command-line-args-left))
(lastfile (car (last files)))
(files (butlast files)))
(while files
(find-file-noselect (car files))
(setq files (cdr files)))
(if lastfile
(find-file lastfile))
(setq command-line-args-left nil)
t))
The assumption is that all the options are already processed and you just have a list of files at the end of your command line. Each function in the list command-line-functions
is called with no args (do C-h i g (elisp)command-line-arguments
to read the relevant section of the Elisp manual in emacs or see the online Elisp manual for details). There is only one function in this case and it consumes all of the left-over arguments: it does a find-file-noselect
on all of them except the last one, on which it does a find-file
.
Doing emacs -Q -l /path/to/init/file.el a b c d
does what you want (I think).
EDIT: per the OP's comment, I fixed up the code so that it works with 0, 1 and 2 file arguments. By induction, it has to work for any number of arguments :-)
emacs file1 file2
and want to avoid the windows splitting by default at startup? IMO, it's better to open Emacs thenfind-file
as you don't have any startup latency. – Firmin Martin Nov 2 '20 at 1:49C-x C-e
every file. Latency has never been a noticeable issue. – young_souvlaki Nov 2 '20 at 2:14emacs --eval '(find-file-noselect "a")' --eval '(find-file-noselect "b")' c
? This opensa
andb
but does not select them and then opensc
. – NickD Nov 2 '20 at 2:25init
so that I can continue to open files normally, now with the desired behavior. It's not that important to me to choose which file gets the single window. – young_souvlaki Nov 2 '20 at 17:12