如何在Emacs中设置默认工作目录 - 故障排除 [英] How to set default working directory in Emacs - troubleshooting
问题描述
我知道这已经发布了很多次,但解决方案对我来说并不奏效。我从这篇文章中尝试过以下解决方案(更改Emacs中的默认文件夹):
I know this has been posted many times, but the solutions are not working for me. I've tried the following solutions from this post (Changing the default folder in Emacs):
- 解决方案1:添加
(cdC:/ Users / Name / Desktop code>到
.emacs
文件 - 解决方案2:添加
(setq default-directory C:/ Documents and Settings / USER NAME / Desktop /)
到.emacs
文件 - 解决方案3:右键单击emacs快捷方式,点击属性并将该字段中的开始位置更改为所需的目录。
- Solution 1: Add
(cd "C:/Users/Name/Desktop")
to the.emacs
file - Solution 2: Add
(setq default-directory "C:/Documents and Settings/USER NAME/Desktop/" )
to the.emacs
file - Solution 3: Right click the emacs short cut, hit properties and change the start in field to the desired directory.
只有解决方案3工作中。不幸的是,我需要使用解决方案1或2。
and only solution 3 is working. Unfortunately, I need to use either solution 1 or 2.
我相信我的 .emacs
文件是正确的,因为当我从 .emacs $中添加/删除
(load-theme'light-blue t)
时,我的主题正确加载/卸载c $ c>文件。
I believe that my .emacs
file is correct, because my theme is being correctly loaded/unloaded when I add/remove (load-theme 'light-blue t)
from the .emacs
file.
这是我最近的$ code> .emacs 文件:
Here is my MOST RECENT .emacs
file:
(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
。
My emacs.exe
is saved under C:\emacs\emacs-24.3\bin
(which is also my default directory, but I want to change it to C:/Users/Lucas/
), and my .emacs
is under my home - C:\Users\Lucas
.
更新
我最近发现我的命令(setq-default default-directoryC:/ Users / Lucas /)
,它应该设置我的默认目录
,不执行。在启动后,这是我的 *消息*
缓冲区:
I RECENTLY found out that my command (setq-default default-directory "C:/Users/Lucas/")
, which should set my default-directory
, is not performing. Immediately after startup, this is my *Messages*
buffer:
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。任何建议,将不胜感激。感谢所有的支持。
It behaves as if I am overriding the .emacs
file. I double/triple checked, and I cannot find another .emacs
in my path. Also, I am not running Emacs from a shortcut. Any suggestions would be appreciated. Thanks for all of the support.
推荐答案
从你写的,听起来你正在运行窗口。
您是否验证过emacs实际上是从C:\Users\Lucas目录中查找并加载.emacs?如果是这样,那意味着Windows了解你的主目录是C:\Users\Lucas。您可以通过查看环境变量HOME来检查。在emacs中,尝试:
From what you write, it sounds like you are running windows. Have you verified that emacs is actually finding and loading .emacs from the directory C:\Users\Lucas? If it is, that means Windows understands your home directory is C:\Users\Lucas. You can check that by looking at the environment variable HOME. In emacs, try:
(getenv "HOME")
在您的.emacs文件中,您可以:
In your .emacs file, you could then put:
(setq default-directory "~/")
这篇关于如何在Emacs中设置默认工作目录 - 故障排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!