2012-12-19 81 views
1

我真的不知道该说什么。在.emacs中设置默认目录

我一直在努力定制我的emacs,我注意到它实际上并没有在启动时加载我的.emacs。根据(http://www.gnu.org/software/emacs/manual/html_node/emacs/Find-Init.html#Find-Init),emacs首先在HOME目录(~/)中查找初始化文件。 。

当我启动Emacs,我.emacs文件似乎被正确读取 - 当我访问一个.notes文件,例如,钩进行评估和某某。我惊讶的是:default-directory没有被设置 - 一个命令在同一个加载文件中。我可以手动评估它或简单地执行(load "~/.emacs"),它会正常工作。

我想这个问题可以总结:如果load命令手动执行时按预期工作,为什么它不自动启动?

全部(除注释的功能).emacs文件:

; http://stackoverflow.com/a/13946304/1443496 
(defvar auto-minor-mode-alist() 
    "Alist of filename patterns vs correpsonding minor mode functions, 
    see `auto-mode-alist'. All elements of this alist are checked, 
    meaning you can enable multiple minor modes for the same regexp.") 

(defun enable-minor-mode-based-on-extension() 
    "check file name against auto-minor-mode-alist to enable minor modes 
the checking happens for all pairs in auto-minor-mode-alist" 
    (when buffer-file-name 
    (let ((name buffer-file-name) 
      (remote-id (file-remote-p buffer-file-name)) 
      (alist auto-minor-mode-alist)) 
     ;; Remove backup-suffixes from file name. 
     (setq name (file-name-sans-versions name)) 
     ;; Remove remote file name identification. 
     (when (and (stringp remote-id) 
       (string-match-p (regexp-quote remote-id) name)) 
     (setq name (substring name (match-end 0)))) 
     (while (and alist (caar alist) (cdar alist)) 
     (if (string-match (caar alist) name) 
      (funcall (cdar alist) 1)) 
     (setq alist (cdr alist)))))) 

(add-hook 'find-file-hook 'enable-minor-mode-based-on-extension) 


;; the wrapping up of the two loads make sure 
;; auctex is loaded only when editing tex files. 
(eval-after-load "tex-mode" 
    '(progn 
    (load "auctex.el" nil nil t) 
    (load "preview-latex.el" nil nil t) 
    ) 
) 

; Sets my default directory to my dropbox (platform-dependent) 
(setq default-directory 
     (concat 
     (if (eq system-type 'windows-nt) 
     "t:" "~") 
     "/Dropbox/Public/School/TeX/")) 


; Set up the .notes extension 
(setq auto-mode-alist 
     (cons '("\\.notes\\'" . text-mode) 
     auto-mode-alist)) 
(setq auto-minor-mode-alist 
     (cons '("\\.notes\\'" . auto-fill-mode) 
      auto-minor-mode-alist)) 


;; AUCTeX replaces latex-mode-hook with LaTeX-mode-hook 
(add-hook 'LaTeX-mode-hook 
     (lambda() 
     (setq TeX-auto-save t) 
     (setq TeX-parse-self t) 
     ;; (setq-default TeX-master nil) 
     (reftex-mode t) 
     (TeX-fold-mode t))) 

回答

5

默认目录是本地缓存。你的.emacs加载得很好;为您打开的每个新缓冲区设置(重新)default-directory的值。当您重新加载.emacs时,它会更改您所在缓冲区的default-directory的值。

+0

有趣。因此(例如,因为我*只是*测试了它),例如,当'Cx Cf'时,'* scratch *'缓冲区将具有预期的'default-directory'值,但是由于emacs *起始页*是在它自己的小世界中,我在启动时的当前目录是文档所在的地方... –

+0

我不知道启动页面正在发生什么,但是您为default-directory设置的值将被覆盖正在访问文件的缓冲区。 * scratch *没有访问q文件,所以它是少数情况下你的默认实际上会坚持的一种。 – Tyler

+0

'(setq inhibit-startup-message t)'禁用启动页面,并且你的'default-directory'设置将起作用 – fiacobelli