28

I have a TODO file that I load emacs up to use 90% of the time. When I load emacs though it defaults to loading the scratch buffer. I would like it to load the TODO file initially. I'm very new to Emacs and have tried searching round for ways to do this using the .emacs file but nothing has worked so far.

Here are my attempts:

1: Use find-file to get the file and switch-to-buffer to load it to the screen

(switch-to-buffer (find-file "c:/Users/Seb/Documents/Emacs/TODO_List.org"))

2: Use pop-to-buffer to load the file instead

(pop-to-buffer (find-file "c:/Users/Seb/Documents/Emacs/TODO_List.org"))

3: Save the desktop so it loads the next time

(desktop-save-mode 1)

None of these are working.

Here is my full .emacs file, as you can see it's barely used!

(custom-set-variables
 ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
; '(inhibit-startup-buffer-menu t)
'(inhibit-startup-screen t)
'(initial-buffer-choice t))
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 )

;; Set the current directory to the Emacs Documents dir
(cd "C:/Users/Seb/Documents/Emacs")

;; Open TODO list on start up
(pop-to-buffer (find-file "c:/Users/Seb/Documents/Emacs/TODO_List.org"))

;; Turn off the annoying tool bar at startup - to turn back on 
;; just type M-x tool-bar-mode
(tool-bar-mode -1)

;; Move the mouse when cursor is near
(mouse-avoidance-mode 'cat-and-mouse)

;; This enables saving the current desktop on shutdown.
(desktop-save-mode 1)

;; XML Pretty Print
(defun xml-pretty-print (begin end)
  "Pretty format XML markup in region. You need to have nxml-mode
http://www.emacswiki.org/cgi-bin/wiki/NxmlMode installed to do
this.  The function inserts linebreaks to separate tags that have
nothing but whitespace between them.  It then indents the markup
by using nxml's indentation rules."
  (interactive "r")
  (save-excursion
      (nxml-mode)
      (goto-char begin)
      (while (search-forward-regexp "\>[ \\t]*\<" nil t) 
        (backward-char) (insert "\n"))
      (indent-region begin end))
    (message "Ah, much better!"))
1
  • [+1] Very nice question which hasn't received the attention it deserves. Cheers
    – rath
    Feb 7, 2014 at 4:45

1 Answer 1

29

In your startup file, you have this line:

'(initial-buffer-choice t))

as part of your "custom-set-variables" command. The documentation string for "initial-buffer-choice" is:

Buffer to show after starting Emacs. If the value is nil and inhibit-startup-screen' is nil, show the startup screen. If the value is string, visit the specified file or directory using find-file'. If t, open the `scratch' buffer.

So, the value that you've specified ('t') is causing the *scratch* buffer to be displayed after startup. Change this line to the following and your issue should be resolved:

'(initial-buffer-choice "c:/Users/Seb/Documents/Emacs/TODO_List.org"))
3
  • 2
    Thank you Zev. That worked a treat. I've taken a look at the documentation now and realise there are a few of the initial commands that I didn't know about. For anyone interested the documentation can be found here: link
    – BebopSong
    Aug 16, 2011 at 19:25
  • 4
    How to start Emacs up and let it open two windows each of which open a different file?
    – qazwsx
    Mar 17, 2012 at 17:13
  • Thanks for the doc! @BebopSong
    – cyc115
    Aug 14, 2017 at 14:51

Your Answer

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

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