.emacs 编辑以始终以终端模式启动 Emacs?

发布于 2024-10-10 09:17:24 字数 212 浏览 7 评论 0原文

我使用 emacs 作为我选择的编辑器,并且由于我在终端中做了很多工作,所以我总是运行 emacs,以便

emacs -nw

它在终端而不是窗口中运行。

我只想运行 emacs 并让它知道它应该在终端中运行。我的问题是 - 如何编辑我的 .emacs 文件以便这是默认行为?

I use emacs as my editor-of-choice, and since I'm doing a lot of work in a terminal I always run emacs as

emacs -nw

so that it runs in the terminal instead of in a window.

I'd like to just run emacs and have it know that it should run in a terminal. My question is - how do I edit my .emacs file so that this is the default behavior?

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

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

发布评论

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

评论(4

陪你搞怪i 2024-10-17 09:17:25

我使用 bash 别名而不是 .emacs 来执行此操作。
将此行添加到您的 ~/.bashrc 中。

alias emacs='emacs -nw'

I'm using a bash alias instead of .emacs to do that.
Add this line to your ~/.bashrc.

alias emacs='emacs -nw'
稳稳的幸福 2024-10-17 09:17:25

有任何简单的方法可以解决一般问题,与 emacs 完全无关,并且适用于可以在控制台与 X 中运行之间进行选择的任何程序:

unset DISPLAY

当然,您可能不想将其放入配置文件中全局应用于所有 shell 会话,因此如果您希望它仅应用于 emacs,那么可以从命令行调用它,如下所示:

DISPLAY= emacs

注意空格!如果您留出空格,则意味着您将 DISPLAY 设置为 emacs,而不是将 DISPLAY 设置为空...此命令是以下命令的简写:

DISPLAY=; emacs

因此,要么从命令行使用上面的内容,要么将其放入包装器中脚本看起来像这样:

#!/bin/bash
unset DISPLAY
exec emacs

我推荐那里的 exec 因为它会用 emacs 替换你的包装脚本;要查看两者之间的区别,您可以运行:

pstree -p

There is any easy way to solve the problem in general that has nothing to do with emacs at all and will work for any program that can choose between running in the console vs X:

unset DISPLAY

Of course you may not want to put that in your configuration file to be applied globally to all your shell sessions, so if you want it to apply to only emacs, then either call it from the command line like this:

DISPLAY= emacs

note the space!!! if you leave the space out it means you're setting the DISPLAY to emacs instead of setting DISPLAY to nothing... this command is a shorthand for:

DISPLAY=; emacs

So either use the above from the command line(s) or put that in a wrapper script that would look something like this:

#!/bin/bash
unset DISPLAY
exec emacs

I recommend the exec there because it will replace your wrapper script with emacs; to see the difference between the two you can run:

pstree -p
牛↙奶布丁 2024-10-17 09:17:25

当我第一次在 Windows 中为 emacs 设置“emacs -nw”别名时,我陷入了一种我认为 tototoshi 的解释不起作用的情况。然而所需要的只是重新启动我的终端。因此,我认为值得一提的是,在 Windows 中(至少)如果您在 git bash 终端中使用 emacs 来创建 .bashrc 文件并向其添加“alias emacs='emacs -nw”(如 tototoshi 提到的),您将拥有关闭并重新打开您的终端以使其正常工作。

When I was first setting up a "emacs -nw" alias for emacs in windows I got stuck in a situation where I thought tototoshi's explanation hadn't worked. Yet all that was required was a restart of my terminal. Therefore, i think its worth mentioning that in windows (at least) if you are using emacs within the git bash terminal to create the .bashrc file and add "alias emacs='emacs -nw" to it (as tototoshi mentions) you have to close and reopen your terminal for it to work.

心意如水 2024-10-17 09:17:24

您无法在 .emacs 文件中执行此操作。当该文件被解析时,“选择的”emacs 二进制文件已经在运行。

您可以按照一位评论者的建议安装 emacs-nox 软件包,或者在 shell 中创建一个别名,以便“emacs”始终被视为“emacs -nw”。

兰迪

You can't do this in the .emacs file. By the time that file is being parsed, the "chosen" emacs binary is already running.

You can install the emacs-nox package as one commenter suggests, or create an alias in your shell so that "emacs" is always treated as "emacs -nw".

Randy

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