如何在Emacs中设置默认工作目录 - 故障排除

 mobiledu2502898347 发布于 2023-02-04 14:44

我知道这已被多次发布,但解决方案对我不起作用.我已经尝试过这篇文章中的以下解决方案(更改Emacs中的默认文件夹):

解决方案1:添加(cd "C:/Users/Name/Desktop").emacs文件中

解决方案2:添加(setq default-directory "C:/Documents and Settings/USER NAME/Desktop/" ).emacs文件中

解决方案3:右键单击emacs快捷方式,点击属性并将字段中的开头更改为所需目录.

只有解决方案3正在运行.不幸的是,我需要使用解决方案1或2.

我相信,我的.emacs文件是正确的,因为我的主题被正确的加载/卸载时我添加/删除(load-theme 'light-blue t).emacs文件.

这是我最近的.emacs文件:

(message "Default Dir: %S" default-directory)
(setq-default default-directory "C:/Users/Lucas/")
(message "Default Dir: %S" default-directory)
(setq-default indent-tabs-mode nil)
(add-hook 'ruby-mode-hook
      (lambda ()
        (define-key ruby-mode-map "\C-c#" 'comment-or-uncomment-region)
        )
 )  
(defadvice comment-or-uncomment-region (before slick-comment activate compile)
  "When called interactively with no active region, comment a single line instead."
  (interactive
   (if mark-active (list (region-beginning) (region-end))
     (list (line-beginning-position)
       (line-beginning-position 2)))))
(load-theme 'light-blue t)
;setq default-directory "~/")
(setq-default default-directory "C:/Users/Lucas/")

(defun xp-read-file-name (prompt &optional dir default-filename mustmatch initial predicate)
(setq last-nonmenu-event nil)
  (funcall (or read-file-name-function #'read-file-name-default)
           prompt dir default-filename mustmatch initial predicate))

(defun xp-save-as (filename &optional confirm)
  (interactive
   (list (if buffer-file-name
       (xp-read-file-name "Write file: " nil nil nil nil)
     (xp-read-file-name "Write file: " "C:/Users/Lucas/"
         (expand-file-name
          (file-name-nondirectory (buffer-name))
          "C:/Users/Lucas/")
         nil nil))
   (not current-prefix-arg)))
  (or (null filename) (string-equal filename "")
      (progn
  (if (file-directory-p filename)
      (setq filename (concat (file-name-as-directory filename)
           (file-name-nondirectory
            (or buffer-file-name (buffer-name))))))
  (and confirm
       (file-exists-p filename)
       (not (and (eq (framep-on-display) 'ns)
           (listp last-nonmenu-event)
           use-dialog-box))
       (or (y-or-n-p (format "File `%s' exists; overwrite? " filename))
     (error "Canceled")))
  (set-visited-file-name filename (not confirm))))
  (set-buffer-modified-p t)
  (and buffer-file-name
       (file-writable-p buffer-file-name)
       (setq buffer-read-only nil))
  (save-buffer)
  (vc-find-file-hook))
(defun comment-or-uncomment-region-or-line ()
    "Comments or uncomments the region or the current line if there's no active region."
    (interactive)
    (let (beg end)
        (if (region-active-p)
            (setq beg (region-beginning) end (region-end))
            (setq beg (line-beginning-position) end (line-end-position)))
        (comment-or-uncomment-region beg end)
        (next-line)))
(global-set-key (kbd "C-x C-;") 'comment-region)
(setq lazy-highlight-cleanup nil)
(message "Default Dir: %S" default-directory)

emacs.exe被保存下来C:\emacs\emacs-24.3\bin(这也是我的默认目录,但我想将其更改为C:/Users/Lucas/),而我.emacs在我的家里 - C:\Users\Lucas.

UPDATE

我最近发现我的命令(setq-default default-directory "C:/Users/Lucas/"),应该设置我default-directory,不执行.启动后,这是我的*Messages*缓冲区:

Default Dir: "C:\\emacs\\emacs-24.3\\bin/" [3 times]
For information about GNU Emacs and the GNU system, type C-h C-a.

它表现得就像我重写.emacs文件一样.我检查了双/三,我.emacs在路上找不到另一个.另外,我没有从快捷方式运行Emacs.任何建议,将不胜感激.感谢所有的支持.

2 个回答
  • 我的问题是emacs 的“ 初始启动”屏幕

    可以通过以下方式禁用它:

    ;; no startup msg  
    (setq inhibit-startup-message t)
    

    似乎emacs的默认欢迎屏幕(带有教程链接)迫使您开始$HOME前进。


    之后,您可以cd或者setq default-directory喜欢这样:

    (setq default-directory "~/")
    

    要么

    (cd "~/")
    

    2023-02-04 14:45 回答
  • 从你写的东西,听起来你正在运行Windows.您是否已验证emacs实际上是从目录C:\ Users\Lucas中查找并加载.emacs?如果是,这意味着Windows了解您的主目录是C:\ Users\Lucas.您可以通过查看环境变量HOME来检查.在emacs中,尝试:

    (getenv "HOME")
    

    在.emacs文件中,您可以放入:

    (setq default-directory "~/")
    

    2023-02-04 14:45 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有