4

I would like to be able to implement the following logic.

(if (developer-opened-file-with-emacs)
    (do nothing, get on with working as fast as possible)
    (load fancy splash screen that may take a while))

What would be a good way to detect this case so that I may use this to choose what kind of startup behavior to use?

Another way to say this is: Will emacs show *scratch* buffer once it's started.


Examples of opening emacs with a file include:

emacs somefile.txt

Or using elisp:

emacs --eval '(progn (find-file "test.txt"))'

Note that checking argv isn't a good option since elisp may be used in a command line argument to open files.

5
  • How did the developer open a file with Emacs; e.g., double-clicking on a file (with an extension associated with Emacs) from Finder.app on OSX and Emacs was built --with-ns?
    – lawlist
    Feb 13, 2018 at 0:02
  • Generally I don't think it should matter? To avoid ambiguity, I added examples using argument or elisp. (not sure of other ways)
    – ideasman42
    Feb 13, 2018 at 0:07
  • 2
    Hm, maybe your predicate is (cl-remove-if-not #'buffer-file-name (buffer-list)). But maybe there is some history mechanism interfering which opens the last file buffers automagically...
    – Tobias
    Feb 13, 2018 at 1:27
  • 1
    Checking buffer-file-name works as long as this isn't in the body of the init file (worth adding as an answer?)
    – ideasman42
    Feb 14, 2018 at 3:56
  • @ideasman42 yes, it worth an answer
    – Hettomei
    Nov 17, 2020 at 7:46

1 Answer 1

2

As pointed out in the comment by @ideasman42, you can use buffer-file-name (both variable and function):

(defun tim/run-after-emacs-is-loaded ()
  (if (not buffer-file-name)
    (tim/load-session)))


(add-hook 'window-setup-hook #'tim/run-after-emacs-is-loaded)
1
  • thanks for this. I'm looking to replace the splash screen with showing the contents of my ~ directory. Do you have any advice why (find-file "~") in the hook doesn't do anything?
    – Nicolas78
    Jul 22, 2021 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.