Как загрузить файл в буфер и переключиться в буфер при запуске в Emacs - PullRequest
20 голосов
/ 16 августа 2011

У меня есть файл TODO, который я загружаю в emacs, чтобы использовать его 90% времени. Когда я загружаю emacs, он по умолчанию загружает рабочий буфер Я хотел бы, чтобы это загрузить файл TODO первоначально. Я очень новичок в Emacs и попробовал поискать способы сделать это, используя файл .emacs, но пока ничего не получалось.

Вот мои попытки:

1: Используйте find-file для получения файла и переключения в буфер для загрузки его на экран

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

1 Ответ

24 голосов
/ 16 августа 2011

В вашем файле запуска у вас есть эта строка:

'(initial-buffer-choice t))

как часть вашей команды "custom-set-variable".Строка документации для "initial-buffer-choice":

Буфер для отображения после запуска Emacs.Если значение равно nil и inhibit-startup-screen' is nil, show the startup screen. If the value is string, visit the specified file or directory using find-file '.Если t, откройте буфер ` scratch '.

Итак, указанное вами значение (' t ') вызывает отображение буфера *scratch* послезапускать.Измените эту строку на следующую, и ваша проблема должна быть решена:

'(initial-buffer-choice "c:/Users/Seb/Documents/Emacs/TODO_List.org"))
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...