Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load file into buffer and switch to buffer on start up in Emacs

Tags:

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!")) 
like image 850
BebopSong Avatar asked Aug 16 '11 18:08

BebopSong


People also ask

How do I switch between buffers in Emacs?

To move between the buffers, type C-x b. Emacs shows you a default buffer name. Press Enter if that's the buffer you want, or type the first few characters of the correct buffer name and press Tab. Emacs fills in the rest of the name.

How do I use buffers in Emacs?

Most buffers are created by visiting files, or by Emacs commands that want to display some text, but you can also create a buffer explicitly by typing C-x b bufname <RET> . This makes a new, empty buffer that is not visiting any file, and selects it for editing. Such buffers are used for making notes to yourself.

Can only have one buffer open in Emacs at a time?

Each Emacs window displays one Emacs buffer at any time. A single buffer may appear in more than one window; if it does, any changes in its text are displayed in all the windows where it appears. But the windows showing the same buffer can show different parts of it, because each window has its own value of point.

Can you have more than one buffer in Emacs?

When Emacs has multiple windows, each window has a chosen buffer which is displayed there, but at any time only one of the windows is selected and its chosen buffer is the selected buffer. Each window's mode line displays the name of the buffer that the window is displaying (see section Multiple Windows).


1 Answers

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")) 
like image 174
zev Avatar answered Nov 01 '22 16:11

zev