20

The splash screen is useful in the beginning, but now I want something more useful: I want to have list of recently opened files presented when starting emacs if there is no predefined file to open. Even better, if it can be the helm-recentf window (I use helm package)

Tyler
  • 21,719
  • 1
  • 52
  • 92
biocyberman
  • 962
  • 7
  • 17
  • I see that you found a solution, but I just wanted to comment that you do not have to limit yourself to methods designed by Emacs team in their `startup.el.` You can nullify all that stuff and then have your own startup order. – lawlist Jul 28 '15 at 02:30

3 Answers3

21

There's also a package on MELPA for this now: dashboard: https://github.com/rakanalh/emacs-dashboard. The package allows you to have a splash screen as in the image below:

dashboard screenshot

Here's the use-package snippet from my config to set it up with a custom banner image and line of text, as well as a list of recent files and bookmarks:

(use-package dashboard
    :ensure t
    :diminish dashboard-mode
    :config
    (setq dashboard-banner-logo-title "your custom text")
    (setq dashboard-startup-banner "/path/to/image")
    (setq dashboard-items '((recents  . 10)
                            (bookmarks . 10)))
    (dashboard-setup-startup-hook))
tirocinium
  • 781
  • 5
  • 8
11

Manomagically :D, after posting the question I got the working solution by removing one single quote below in my .emacs

(setq initial-buffer-choice '(helm-recentf)) ;; Does not work

To this:

(setq initial-buffer-choice (helm-recentf)) ;; Works!!!
;; I still haven't tried doing with the built-in recentf only

Or this:

(setq initial-buffer-choice 'helm-recentf) ;; Works!!!

Update

It still doesn't work with the solution above actually. I got the file open but emacs switches to scratch buffer right afterward. I have to jump to the buffer of the file I want. So still need more help on this.

Update 2

After some wrestling with elisp, I got this one really works now:

(require 'recentf) ;; Provided for the whole picture
(require 'helm)
(require 'helm-config)

(defun startwithrecentf()
 (buffer-name (find-file (car (helm-recentf))))
  )
(setq initial-buffer-choice (startwithrecentf)) 

Update 3

The following is more compact. It also roughly handle the case emacs is called with additional arguments, i.e emacs somefile

(require 'recentf) ;; Provided for the whole picture
(require 'helm)
(require 'helm-config)
(if (< (length command-line-args) 2) 
(setq initial-buffer-choice (car (helm-recentf)))
)
sidharth arya
  • 235
  • 1
  • 7
biocyberman
  • 962
  • 7
  • 17
  • 2
    I believe your initial attempt should be `(setq initial-buffer-choice 'helm-recentf)`. The `initial-buffer-choice` can have a function as a value, which the quoted form without parantheses will give. – Meaningful Username Jul 28 '15 at 08:30
  • Obviously my elisp newbie skill. – biocyberman Jul 28 '15 at 09:00
  • We're here to learn :). With that form I get the `helm-recentf` buffer on start, so your update 2 solution shouldn't be needed. – Meaningful Username Jul 28 '15 at 09:19
  • @MeaningfulUsername I made **Update 3** :D it handles the case where you call emacs with a file name or something already. – biocyberman Jul 28 '15 at 10:06
  • And as you already noted, the quoted version does not switch to the buffer, so it seems your (car (helm-recentf)) is the correct solution. (I thought it should be a lambda expression instead of just a list, but that did not work...) – Meaningful Username Aug 10 '15 at 08:08
  • `(setq initial-buffer-choice 'recentf-open-files)` does the trick for me (using recentf rather than helm). From the docs for `initial-buffer-choice`: `If the value is a function, call it with no arguments and switch to the buffer that it returns.` – Amory Mar 23 '21 at 11:18
3

Here's a package that shows recentf-open-files when starting Emacs without a file to open: https://github.com/zonuexe/init-open-recentf.el

Configuration with use-package:

(recentf-mode 1)
(setq recentf-max-menu-items 25)

(use-package init-open-recentf
  :config
  (init-open-recentf))
njam
  • 131
  • 1