【问题标题】:Setting default-directory in .emacs在 .emacs 中设置默认目录
【发布时间】:2012-12-07 03:20:58
【问题描述】:

我真的不知道该说什么。

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

当我启动 emacs 时,我的 .emacs 文件 似乎 可以正确读取 - 例如,当我访问 .notes 文件时,会评估挂钩等等。令我惊讶的是:未设置默认目录 - 同一加载文件中的命令。我可以手动评估它,也可以简单地执行(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)))

【问题讨论】:

    标签: emacs elisp dot-emacs


    【解决方案1】:

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

    【讨论】:

    • 有趣。所以(例如,因为我 刚刚 测试了它),*scratch* 缓冲区将在我 C-x C-f 时出现 default-directory 的预期值,但由于 emacs start页面在它自己的小世界中,我当前的启动目录是该文档所在的位置......
    • 我不知道起始页发生了什么,但是您为 default-directory 设置的值将在访问文件的任何缓冲区中被覆盖。 scratch 没有访问 q 文件,因此这是您的默认设置实际上会坚持的少数情况之一。
    • (setq inhibit-startup-message t) 禁用启动页面,瞧,您的default-directory 设置将起作用
    猜你喜欢
    • 1970-01-01
    • 2014-01-30
    • 1970-01-01
    • 2011-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-26
    • 2016-05-23
    相关资源
    最近更新 更多