在Emacs启动时如何将文件加载到缓冲区并切换到缓冲区

27

我有一个TODO文件,我会90%的时间使用emacs来处理它。但是每次打开emacs时,它默认加载scratch缓冲区。我希望它最初加载TODO文件。我对Emacs非常陌生,并尝试在.emacs文件中搜索如何做到这一点,但迄今为止没有成功。

以下是我的尝试:

1:使用find-file获取该文件并使用switch-to-buffer将其加载到屏幕上

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

2:使用pop-to-buffer加载文件


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

3: 保存桌面,以便下次加载

(desktop-save-mode 1)

这些都不起作用。

这是我的完整.emacs文件,你可以看到它几乎没有被使用过!

(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!"))

非常好的问题,它没有得到应有的关注。干杯 - rath
1个回答

28
在您的启动文件中,有这样一行代码:
'(initial-buffer-choice t))

作为您的“custom-set-variables”命令的一部分,“initial-buffer-choice”的文档字符串如下:
启动Emacs后显示的缓冲区。如果值为nil且“inhibit-startup-screen”为nil,则显示启动屏幕。如果该值为字符串,则使用“find-file”访问指定的文件或目录。如果是t,则打开“scratch”缓冲区。
因此,您指定的值('t')导致在启动后显示“*scratch*”缓冲区。将此行更改为以下内容,您的问题应该得到解决:
'(initial-buffer-choice "c:/Users/Seb/Documents/Emacs/TODO_List.org"))

2
谢谢你,Zev。这太有效了。我现在已经查看了文档,并意识到有一些我不知道的初始命令。对于任何感兴趣的人,文档可以在这里找到:[链接](http://www.gnu.org/s/emacs/manual/html_node/elisp/Startup-Summary.html) - BebopSong
4
如何启动Emacs并让它打开两个窗口,每个窗口都打开不同的文件? - qazwsx
感谢提供文档!@BebopSong - cyc115

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接