bash 在 Git 中提交时使用 emacsclient -t

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10355902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 02:08:39  来源:igfitidea点击:

Use emacsclient -t when committing in Git

gitbashshellemacs

提问by newlife

In my .bash_profile, I use this:

在我的.bash_profile,我使用这个:

export EDITOR=emacsclient
alias e='emacsclient -t'

When I commit changes with Git, it will open a new emacs window, but with emacs --daemon. How can I set my default Git editor to be emacs with the t flag enabled?

当我使用 Git 提交更改时,它会打开一个新的 emacs 窗口,但使用emacs --daemon. 如何将我的默认 Git 编辑器设置为启用了 t 标志的 emacs?

采纳答案by newlife

the true reason for this is the version of emacs.there is a default emacs on mac, which version doesnot have the option "-t".Also ,it seems that git doesnot read the setting in .bash_profile

真正的原因是 emacs 的版本。mac 上有一个默认的 emacs,该版本没有选项“-t”。另外,似乎 git 没有读取 .bash_profile 中的设置

回答by tacaswell

git config --global core.editor 'emacsclient -t -a=\"\"'

This will start a daemon if there is not already one running.

如果还没有一个守护进程在运行,这将启动一个守护进程。

You may be having issues with quotation marks, as it shows up in my .gitconfig as

您可能会遇到引号问题,因为它在我的 .gitconfig 中显示为

[core]
    editor = emacsclient -t -a=\\"\\"

回答by Camden Narzt

export GIT_EDITOR="`which emacsclient` -t -s $EMACS_SERVER_FILE"

git seems to muck with the PATH variable before calling your EDITOR or GIT_EDITOR so the built in emacsclient from /usr/bin gets called even if normally the emacsclient from your more up to date Emacs would be called. I solved this by getting the path to the executable from a subprocess which has its own environment I believe (either way it works...).

git 似乎在调用您的 EDITOR 或 GIT_EDITOR 之前混淆了 PATH 变量,因此即使通常会调用来自最新 Emacs 的 emacsclient,也会调用来自 /usr/bin 的内置 emacsclient。我通过从一个子进程获取可执行文件的路径来解决这个问题,我相信这个子进程有自己的环境(无论它以哪种方式工作......)。

Tested on OS X 10.8.2 with Emacs 24.1 built locally, server running and clients connecting via socket.

在 OS X 10.8.2 上测试,Emacs 24.1 本地构建,服务器运行,客户端通过套接字连接。

I have not tested tcp clients.

我还没有测试过 tcp 客户端。

回答by Moritz Bunkus

I usually don't say "Read That Fine Manual", but in this case it simply applies. git commit --helphas this to say about the topic:

我通常不会说“阅读那本精美的手册”,但在这种情况下,它只是适用。git commit --help关于这个话题有这样的说法:

ENVIRONMENT AND CONFIGURATION VARIABLES
   The editor used to edit the commit log message will be chosen
   from the GIT_EDITOR environment variable, the core.editor configuration
   variable, the VISUAL environment variable, or the EDITOR environment
   variable (in that order). See git-var(1) for details.