更改 Emacs 中的默认文件夹

发布于 2024-07-05 06:11:13 字数 577 浏览 7 评论 0原文

我对 Emacs 相当陌生,我一直在尝试弄清楚如何在启动时更改 Cx Cf 的默认文件夹。 例如,当我第一次加载 Emacs 并点击 Cx Cf 时,它的默认文件夹是 C:\emacs\emacs-21.3\bin,但我宁愿它是桌面。 我相信有某种方法可以自定义 .emacs 文件来执行此操作,但我仍然不确定那是什么。

更新:我发现该问题有三种可行的解决方案,但我相信解决方案 3 仅适用于 Windows。

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

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

  • 解决方案 3:右键单击 Emacs 快捷方式,点击属性并将起始字段更改为所需的目录。

I am fairly new to Emacs and I have been trying to figure out how to change the default folder for C-x C-f on start-up. For instance when I first load Emacs and hit C-x C-f its default folder is C:\emacs\emacs-21.3\bin, but I would rather it be the desktop. I believe there is some way to customize the .emacs file to do this, but I am still unsure what that is.

Update: There are three solutions to the problem that I found to work, however I believe solution 3 is Windows only.

  • 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

心头的小情儿 2024-07-12 06:11:13

我已经在我的快捷方式(在 Gnome、Linux 中)中添加了一个 pramater,它是一个空白的虚拟文件名,并指定了目录。 由于我的 emacs 默认为“home”,我只需说:

/Desktop/blank_file

,这会打开一个名为“blank_file”的文件,

这还会将该 emacs 会话的当前工作目录移动到桌面。

如果我碰巧将东西放入“blank_file”然后保存它,当然,我已经保存了这些东西。 这可能是一件烦恼,也可能是一件好事,具体取决于!

I have added to my shortcut (in Gnome, Linux) a pramater which is a blank dummy file name, and I specify the directory. Since my emacs defaults to "home" I simply say:

/Desktop/blank_file

and that opens a file called "blank_file"

That also moves the current working directory for that emacs session to the desktop.

If I happen to put stuff in "blank_file" then save it, of course, I've got that stuff saved. Which might be an annoyance or it might be a good thing, depending!

怎会甘心 2024-07-12 06:11:13

当您使用 Windows 时,您可以使用快捷方式来完成此操作。

创建 C:\emacs\emacs-21.3\bin\runemacs.exe 的快捷方式。 编辑快捷方式的属性并将Start In: 的值更改为您想要的默认目录。

As you're on Windows you can do it with a shortcut.

Create a shortcut to C:\emacs\emacs-21.3\bin\runemacs.exe. Edit the properties of the shortcut and change the value of Start In: to be whatever you want your default directory to be.

顾冷 2024-07-12 06:11:13

我在 Windows XP 下使用 emacs 22.2.1,并在上面的答案的帮助下获得了我想要的命令 Cx Cf 的迷你缓冲区的响应。 最初我得到
“查找文件:C:\Program Files\emacs\bin/”,就像 Anton 一样。
我将 HOME 设置为“C:\Documents and settings\USER NAME\My Documents”。
我想要在迷你缓冲区中对 Cx Cf 的响应是“查找文件:~/”。
通过将 (setq default-directory "C:/Documents and Settings/USER NAME/My Documents") 添加到我的 .emacs 文件中,我能够得到响应“查找文件:C:\Documents and settings\USER NAME\My Documents” /”,其功能与“查找文件:~/”相同。
然而,我还注意到了一点。 “选项”下的“自定义 Emacs”允许我禁止启动屏幕。 现在,当我打开 emacs 时,我会立即进入暂存缓冲区。 当我在暂存缓冲区中输入 Cx Cf 时,我得到了我想要的确切响应。

I am using emacs 22.2.1 under Windows XP and have been helped by the answers above to get the response in the minibuffer I want to the command C-x C-f. Initially I was getting
"Find file: C:\Program Files\emacs\bin/" like Anton.
I have HOME set to "C:\Documents and settings\USER NAME\My Documents".
The response to C-x C-f I want in the minibuffer is "Find file: ~/".
By adding (setq default-directory "C:/Documents and Settings/USER NAME/My Documents") to my .emacs file I was able to get the response "Find file: C:\Documents and settings\USER NAME\My Documents/" which is functionally the same as "Find file: ~/".
However, I noticed one further point. "Customize Emacs" under "Options" allowed me to inhibit the startup screen. Now when I open emacs I go immediately to the scratch buffer. When I type C-x C-f in the scratch buffer I get the exact response I want.

你与昨日 2024-07-12 06:11:13

默认文件夹实际上与缓冲区的当前工作文件夹相同,即对于您使用的每个文件来说,它可以是不同的。 假设您正在使用的文件位于 C:\dir_a 中,则该缓冲区的工作目录默认为 C:\dir_a。 您可以使用 Mx cd 更改此设置,然后输入您希望作为默认目录的任何目录(默认情况下,我的意思是当您执行 Cx Cf 时会显示的目录) >)。

如果您启动 emacs 而不打开文件,您最终将打开 *scratch* 缓冲区。 如果您从 Windows 快捷方式启动 emacs,则工作目录将与快捷方式属性中指定的目录相同。 如果您从命令行启动它,它将是您启动它的目录。 您仍然可以使用 Mx cd 更改此默认目录,也可以从 *scratch* 缓冲区中更改。

最后,您可以按照 Vadim 的建议操作并放入

(cd "c:/dir_a/")

.emacs 文件,使该目录成为默认目录,无论您如何启动 emacs。

The default folder is actually the same as the current working folder for the buffer, i.e. it can be different for every file you work with. Say that the file you are working with is located in C:\dir_a, then the working directory for that buffer will by default be C:\dir_a. You can change this with M-x cd and type in whatever directory you would like to be the default instead (and by default I mean the one that will show up when you do C-x C-f).

If you start emacs without opening a file, you will end up with the *scratch* buffer open. If you started emacs from a Windows shortcut, the working directory will be the same as that specified in the shortcut properties. If you started it from the command line, it will be the directory from where you started it. You can still change this default directory with M-x cd, also from the *scratch* buffer.

Finally, you can do as Vadim suggests and put

(cd "c:/dir_a/")

in your .emacs file, to make that directory the default no matter how you start emacs.

千纸鹤 2024-07-12 06:11:13

我认为您需要添加到 .emacs 中的行是

(setq default-directory "C:/Documents and Settings/USER NAME/Desktop/" )

Emacs 将以这种方式在您的桌面上启动,除非您打开了文件。 否则,它通常会在与当前缓冲区中的文件相同的目录中启动。

I think the line you need to add to your .emacs is is

(setq default-directory "C:/Documents and Settings/USER NAME/Desktop/" )

Emacs will start in your desktop that way, unless you have a file open. It will usually start in the same directory as the file in your current buffer otherwise.

极度宠爱 2024-07-12 06:11:13

您可以输入“cd”emacs 命令。 ( Mx cd ) 一次性更改默认文件夹。

You can type the 'cd' emacs command. ( M-x cd ) to change the default folder as a one off.

当爱已成负担 2024-07-12 06:11:13

我已经放入

(cd "c:/cvsroot/")

了 .emacs 并且它完成了工作

I've put

(cd "c:/cvsroot/")

in my .emacs and it did the job

在风中等你 2024-07-12 06:11:13

您没有这么说,但听起来您是从 Windows 快捷方式启动 Emacs。

您使用 cx cf 看到的目录是 cwd,用 Emacs 术语来说就是 default-directory (变量)。

当您使用 MS Windows 快捷方式启动 Emacs 时,default-directory 最初是快捷方式属性的“启动于”字段中指定的文件夹(目录)。 右键单击该快捷方式,选择属性,然后在启动字段中输入桌面路径。

如果您从命令行使用 Emacs,default-directory 将作为您启动 Emacs 的目录(cwd)启动。

这种方法比编辑 .emacs 文件更好,因为它允许您拥有多个带有多个起始目录的快捷方式,并且如果需要,它还可以让您拥有 Emacs 的正常命令行行为。

CWD = 当前工作目录 = PWD = 当前工作目录。 它在命令行中比在 GUI 中更有意义。

You didn't say so, but it sounds like you're starting Emacs from a Windows shortcut.

The directory that you see with c-x c-f is the cwd, in Emacs terms, the default-directory (a variable).

When you start Emacs using an MS Windows shortcut, the default-directory is initially the folder (directory) specified in the "Start In" field of the shortcut properties. Right click the shortcut, select Properties, and type the path to your desktop in the Start In field.

If you're using Emacs from the command line, default-directory starts as the directory where you started Emacs (the cwd).

This approach is better than editing your .emacs file, since it will allow you to have more than one shortcuts with more than one starting directory, and it lets you have the normal command line behavior of Emacs if you need it.

CWD = current working directory = PWD = present working directory. It makes a lot more sense at the command line than in a GUI.

硬不硬你别怂 2024-07-12 06:11:13

在 Windows 8 中,它可以在桌面中创建快捷方式并更改快捷方式的属性“开始于:”。

现在,我按照建议运行程序 emacs-23.3\bin\addpm.exe,Windows-8 屏幕(微软的可怕发明)出现了一个指向 Emacs 的图标链接。 但你必须再次更改属性“开始于”。 (与桌面上的不同)。
只需右键单击,在底部栏中选择“打开文件位置”(或类似的,我用我的语言进行的),您就会被带到带有新快捷方式的文件夹,您还可以(必须)在其中更改属性“开始于:”。

有点复杂,但实际上很简单。

In Windows 8, it works to create a shortcut in the Desktop and change the property 'Start In:' for the shortcut.

Now, I ran the program emacs-23.3\bin\addpm.exe as recommended, and the Windows-8 screen (that horrendous invention from Microsoft) it appeared an icon-link to Emacs. But there you have to change again the property 'Start In'. (It is different from the one in the desktop).
Just right-click, choose in the bottom bar 'Open the file location' (or similar, I did it in my language), and you are taken to the folder with a new shortcut, in which you can (must) also change the property 'Start In:'.

A little involved, but in fact very easy.

守不住的情 2024-07-12 06:11:13

因为最烦人的事情是当你只使用快捷方式时 Windows Emacs 将你转储到 system32,但希望其他所有情况都能工作,只需使用一点 elisp...

(when (string< "C:\WINDOWS\system32 " default-directory) (setq default-directory "~/"))

因此,当您最终进入系统时,它只会默认为您的主目录。 唯一的缺点是如果你真的想在 system32 中启动 emacs...

Since the most annoying thing is having windows Emacs dump you into system32 when you are just using the shortcut, but want every other case to work, just use a bit of elisp...

(when (string< "C:\WINDOWS\system32" default-directory) (setq default-directory "~/"))

So it will only default to your home directory when you end up in system. The only drawback is if you really want to start emacs in system32...

挽心 2024-07-12 06:11:13

要将 Dired 和 shell 中的默认目录更改为 DESKTOP,请将其放入 ~/.emacs 中:

;;这适用于 Windows XP。
(setq 默认目录(连接“C:\Documents and Settings\MY_ACCOUNT\DESKTOP\”))

To change default directory to DESKTOP in Dired and shell put this in your ~/.emacs:

;;This works for Windows XP.
(setq default-directory (concat "C:\Documents and Settings\MY_ACCOUNT\DESKTOP\"))

木落 2024-07-12 06:11:13

对于 Windows 用户,我发现最好的方法是创建 runemacs.exe 的快捷方式并将快捷方式放置在我的笔记文件夹的根目录中。

这样,当您使用此快捷方式打开 emacs 时,它将默认在根目录中打开,而无需专门设置 Start In 属性(您可以保留 Start In 属性空白)。

参考:根据 Microsoft 的说法,如果将“开始于”框留空,脚本将在当前工作目录

提示:

此外,如果您已将笔记组织到多个根文件夹(个人、工作等)中,则可以在每个文件夹中复制多个此类快捷方式,以使用其自己的默认目录打开各种 emacs 实例。

For windows users, the best way that I found is to create the shortcut for runemacs.exe and placing the shortcut in the root directory of my notes folder.

This way, when you use this shortcut to open emacs, it will by default open in the root directory without having to specifically set the Start In property (you can leave the Start In property blank).

Reference: According to Microsoft, if you leave the 'Start In' box empty, the script will run in the current working directory

TIP:

Additionally, if you have organized your notes into multiple root folders (Personal, Work etc...), you can copy multiple such shortcuts in each folder to open various instances of emacs with their own default directories.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文