如何在Emacs启动时将文件加载到缓冲区并切换到缓冲区 [英] How to load file into buffer and switch to buffer on start up in Emacs

查看:157
本文介绍了如何在Emacs启动时将文件加载到缓冲区并切换到缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TODO文件,我加载emacs使用90%的时间。当我加载emacs,但它默认是加载临时缓冲区。我希望它最初加载TODO文件。我对Emacs很新,并尝试使用.emacs文件进行搜索,但迄今没有任何工作。



以下是我的尝试:



1:使用find-file获取文件并切换到缓冲区将其加载到屏幕上

 (切换到缓冲区(find-filec:/ Users / Seb / Documents /Emacs/TODO_List.org))

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

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

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

 (desktop-save-mode 1)

这些都没有工作。



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

 code>(custom-set-variables 
;; custom-set-variables是通过Custom添加的。
;;如果你手动编辑,你可以把它弄乱,所以要小心。
;;你的init文件应该只包含一个这样的实例
;;如果有不止一个,它们将不能正常工作
;'(inhibit-startup-buffer-menu t)
'(inhibit-startup-screen t)
'(初始缓冲区选择t))
(自定义设置面
;;自定义设置面
;;如果你手动编辑它,你可以把它弄乱,所以要小心
;;你的init文件应该只包含一个这样的实例
;;如果有不止一个,他们将无法正常工作


;;将当前目录设置为Emacs Documents dir
(cdC:/ Users / Seb / Documents / Emacs)

;;在启动时打开TODO列表
(pop-to-buffer(find-filec:/Users/Seb/Documents/Emacs/TODO_List.org))

;;在启动时关闭烦人的工具栏 - 重新启动
;;只需键入M-x工具栏模式
(工具栏模式-1)

;;当光标靠近
时移动鼠标(鼠标避免模式'cat-and-mouse)

;;这样可以在关机时保存当前桌面。
(desktop-save-mode 1)

;; XML漂亮打印
(defun xml-pretty-print(begin end)
区域中的漂亮格式XML标记您需要具有nxml-mode
http://www.emacswiki.org / cgi-bin / wiki / NxmlMode安装到
这个函数插入linebreaks分隔的标签有
只有空格之间它们之间,然后缩进标记
通过使用nxml的缩进规则
(interactiver)
(save-excursion
(nxml-mode)
(goto-char begin)
(while(search-forward- regexp\> [\\t] * \<nil t)
(backward-char)(插入\\\
))
(缩进区域开始结束)
(消息啊,好多了!))


解决方案

在您的启动文件中,您有以下一行:

 '(initial-buffer-choice t)) 

作为custom-set-variables命令的一部分。 initial-buffer-choice的文档字符串是:


启动Emacs后显示的缓冲区。如果值为零,
inhibit-startup-screen'为nil,则显示启动屏幕。如果
值是字符串,请使用
find-file'访问指定的文件或目录。如果t,打开' scratch '缓冲区。


所以,你指定的值't')导致启动后显示 * scratch * 缓冲区。将此行更改为以下内容,您的问题应解决:

 '(初始缓冲区选择c:/ Users / Seb / Documents / Emacs / TODO_List.org))


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

解决方案

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

这篇关于如何在Emacs启动时将文件加载到缓冲区并切换到缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆