5

Like a lot of people I think I activated inhibit-startup-screen because it’s ugly and tedious to always have your emacs horizontally split when you open a file with half taken by an useless startup screen… But I notice I find it better/more beautifull/helpfull/useful than just an unique void scratch buffer when I open Emacs without opening a file…

So is there a way so that this startup screen shows up only when there’s nothing else to show up? as when the scratch buffer is displayed at startup? instead of it? and not to show up if I open a file or run a command like gnus or erc?

galex-713
  • 245
  • 2
  • 8

2 Answers2

2

Ok, so no custom setting allow that behavior, so here a function to put in the after-init-hook as proposed by Xaldew.

(defun maybe-splash-screen ()
  "Open display-splash-screen instead of *scratch* buffer."
  (when (and (string= "*scratch*" (buffer-name)) (not (buffer-file-name)))
    (display-splash-screen)))
(add-hook 'after-init-hook 'maybe-splash-screen)
galex-713
  • 245
  • 2
  • 8
1

I did a bit of research on this and this snippet seems to work:

(defun my-after-init-hook ()
  "Test."
  (print command-line-args)
  (when (= 1 (length command-line-args))
    (setq initial-buffer-choice #'gnus)))
(add-hook 'after-init-hook 'my-after-init-hook)

I'm not too fond of the conditional in there since that might easily break when you add different command-line arguments, but I'm afraid I couldn't find any other checks that are valid when running the after-init-hook.

If you want a different initial buffer, simply change #'gnus in the above snippet.

I also found some other similar questions which may be of interest:

Customize startup screen text

How can I override initial-buffer-choice if I specify a filename at command line?

Programming of Initial-buffer-choice

Xaldew
  • 1,181
  • 9
  • 20
  • No I meant I want the default startup screen, the one inhibited by `inhibit-startup-screen`, not like « I want gnus if no file opened », but « I want the default startup sceer if no-file-opened-OR-gnus/erc-ran » – galex-713 Mar 20 '16 at 13:59
  • Ok, the function `display-splash-screen` does what I want. And temporary I can still test `(equal "*scratch*" (buffer-name))`… But two questions: first, why to use `after-init-hook` and not just put the code in the `.emacs.d` (is there any difference?)? and second, is there a “real” way to test if a buffer is the scratch buffer, other than if its name is `*scratch*` (for example that wouldn’t work if I open a file like `/home/galex-713/*scratch*`, and something cleaner than use `(and (equal "*scratch*" (buffer-name)) (not (buffer-file-name)))`)? – galex-713 Mar 20 '16 at 14:08
  • 1
    The main difference with using `after-init-hook` instead of setting it directly in `.emacs` has to do with the [Emacs startup order](https://www.gnu.org/software/emacs/manual/html_node/elisp/Startup-Summary.html). Basically, `after-init-hook` happens quite a few steps after loading your `.emacs` file, and at that time you can take advantage of Emacs having parsed and set various runtime options. – Xaldew Mar 20 '16 at 14:33
  • 1
    Regarding the `*scratch*`: you can still use a test such as `(string= "*scratch*" (buffer-name))`. When emacs starts, `*scratch*` is 'always' created and opening a new file named `*scratch*` will pass that buffer through `uniquify-buffer-file-name`, giving it a new, proper, and unique buffer name. – Xaldew Mar 20 '16 at 14:45
  • 2
    I think you should consider filing an enhancement request for this: `M-x report-emacs-bug`. You should be able, for example, to use a function like `display-startup-screen` as the value of `initial-buffer-choice`, to show the startup screen only when you do not provide a file/dir argument to `emacs`. Right now, if you use `initial-buffer-choice` to specify a buffer (and possibly other behavior, but ending with a buffer value), that buffer is just added to the list of files etc. provided on the command line. There should be a way to not use that buffer if there are such files. – Drew Mar 20 '16 at 15:55