TransWikia.com

Force one window when opening multiple files

Emacs Asked on February 7, 2021

Any time I open multiple files I’d like emacs to only show me one buffer. I do not want any split windows. This would save me a keystroke every time.

I learned I could do away with the buffer list from this post with (setq-default inhibit-startup-buffer-menu t). But, now another buffer just replaces what would have been the buffer list. Any way to force only one window when opening multiple files?

One Answer

I don't quite understand your last comment, but try the following in your init file:

(setq command-line-functions (list #'handle-files))

(defun handle-files ()
  (let ((lfile (car (last command-line-args-left)))
    (files (butlast command-line-args-left)))
    (while files
      (find-file-noselect (car files))
      (setq files (cdr files)))
    (find-file lfile)
    (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 (see the 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).

Answered by NickD on February 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP