- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我已将我的 git source+repo 名称整合到我的 emacs 框架标题中,因此我可以确定我当前正在处理的分支/repo。为此,我通过 PROMPT_COMMAND
在 bash shell 中设置此信息,然后在 emacs 启动时在 init.el
(或 .emacs
)中获取信息) 通过 getenv
命令设置变量 frame-title-format
。
这是我在 ~/.bashrc
中所做的:
PROMPT_COMMAND="export GIT_REPO_NAME=\$(git remote -v 2> /dev/null | grep \"origin.\*fetch\" | awk '{print \$2}' | sed 's,https://github.com/\(.\*\)/\(.\*\),\1,g'); export GIT_BRANCH=\$(git branch 2> /dev/null | grep \"^*\" | awk '{print \$2}')"
下面是我在 ~/.emacs.d/init.el
中所做的:
;;; Rest of init.el code
(setq-default
frame-title-format
(concat
"%f"
(if (getenv "GIT_BRANCH")
(concat " in [ " (getenv "GIT_BRANCH") "/" (getenv "GIT_REPO_NAME") " ]"))))
;;; All the other goodies in init.el
这一切都很棒,但不幸的是,这并不总是准确的,因为帧标题是由 env
命令设置的,该命令最后在 中计算了我的
当 emacs 启动时。例如,如果在同一个 emacs session 中,我在属于另一个 repo/branch 的另一个目录中打开一个缓冲区,我的框架标题不正确。PROMPT_COMMAND
>pwd
所以我的问题是,我可以通过任何方式让 emacs 在 shell 中重新运行 git 命令以获取缓冲区所在目录的源/repo 名称,以便不同的缓冲区将显示正确的 git 分支/repo 名称?
考虑以下目录结构:
gitRepoA (branch X)
|-> buffer1.txt
|-> buffer2.txt
gitRepoB (branch Y)
|-> buffer1.txt
|-> buffer2.txt
假设我为(目录)gitRepoA
中的文件 buffer1.txt
启动了 emacs。然后我在 repo gitRepoA 的分支 X 中看到一个框架标题 buffer1.txt
如果我在同一个 emacs session 中打开 gitRepoB
的 buffer2.txt
(当前 checkout branch Y
),我希望看到buffer2.txt 在 gitRepoB 分支 Y 中
。目前,当然,它会说 buffer2.txt in branch X in repo gitRepoA
。完全错误。
如果我们能够解决这个问题,我想解决更普遍的问题,即在 git status
级别更改(比如提交,或 checkout 等)。
非常感谢任何帮助/见解。另外,我的问题的标题更合适,我很感激——我在用一个标题表达我的问题时遇到了麻烦。谢谢。
最佳答案
这是设置框架标题的完整示例,目前它仅适用于 git
repo
(defun my-get-frame-title ()
"If inside a git repo return a string containing git repo, branch and file state else
return default frame title"
(let* ((file (buffer-file-name))
(git-directory (when file
(locate-dominating-file (file-truename default-directory) ".git"))))
(if git-directory
(concat (file-name-nondirectory (buffer-file-name))
" on " (vc-working-revision file)
" in " (file-name-nondirectory (directory-file-name git-directory))
" current state is " (symbol-name (vc-state file)))
(concat invocation-name "@" system-name))))
(setq-default
frame-title-format
'(:eval (my-get-frame-title)))
这会在 git
中设置框架标题 repo 格式 <filename> on <branch> in <repo> current state is <state>
否则它会退回到 emacs 的默认框架标题
关于git - 在 emacs 中打开每个缓冲区之前如何重新评估 shell 环境并重新评估 frame-title-format,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21246756/
目前,由于生成变量的评估,我的Makefile遇到了问题。我降低了复杂性,仅保留了导致问题的基本要素。 读取Makefile时, $(LIST)被评估为文件列表。 在步骤1中,其中一个文件被删除。 在
为什么这 eval 没有调用alert("Summer") ? eval('(caption="Summer";alert(caption))'); 和《夏天》里的台词有关系吗? 最佳答案 Uncau
我正在努力让以下工作正常进行。最初似乎可以工作,但不知何故它停止工作了 var setCommonAttr = "1_row1_common"; var val = document.getEleme
eval('({"suc":true})') 以上错误,应该是: eval('{"suc":true}') 为什么? 最佳答案 当尝试评估时,解释器会看到大括号并认为它是一个 block 开头。将其括
我的页面 A 发出了 ajax 调用并引入了片段 B。该片段被添加到 DOM 中,并且该片段中的所有脚本都经过了评估。在该代码片段中,我有 2 个脚本标签: function doOptions()
这里是javascript代码: var test = { "h" : function (a) {return a;}, "say" : "hello" }; 第一次运行: test
我正在查看一些工作代码,并遇到了这一行: eval("\$element = \"$element\";"); 我真的很困惑为什么任何 PHP 开发人员都会写这一行。除了给自己设置一个变量之外,这还有
谁能帮我解决以下问题: 我有这样的代码: if(cond1 && cond2 && .. && cond10) 这里,cond1 是昂贵的操作,其输出是 boolean 值。 现在我的问题是,当 co
**摘要:**华为AppCube应用魔方顺利通过信通院评估,被认证为具备 “低代码开发平台通用能力”的企业服务平台。 本文分享自华为云社区《华为AppCube通过中国信通院“低代码开发平台通用能力要求
我正在尝试通过 PHP 从图像的 EXIF 数据中获取焦距。 这是我目前得到的代码: $exif = exif_read_data("$photo"); $length10 = $exif['Foca
我想使用id =“key”将一个类添加到元素中,但是为什么不起作用?我是js的初学者:这是代码: audio.classList.add('yellow'); 这是错误: null is not an
这是我的 XML: QueWay Password Recovery 现在我想用 php 用 xpath 选择文本“QueWay”。到目前为止我所拥有的一切都很好: $xml =
使用下面的代码,即使我输入的数字大于 18,我也会得到这个结果。 运行:你今年多大? 21你还没有达到成年年龄!构建成功(总时间:3 秒) 我是java新手,正在尝试自学,有人可以帮忙吗? impor
我正在阅读 http://www.cran.r-project.org/doc/manuals/R-lang.pdf手册第 4.3 章,我就是不明白。也许有人可以给我一个快速的解释,为什么 R 的行为
在这个实现中,每次都会评估 hand 并返回另一个列表吗? foreach (Card card in hand.Cards) { } 我们应该用下面的实现替换上面的实现吗? var cards =
我正在制作 LINQ lambda 表达式: Expression> add = (x, y) => x + y; 但现在我将如何评估它,比如说找到 2+3? 最佳答案 这应该适合你: var su
我正在制作一个语言解释器,我已经到了需要评估 if 语句的地步。起初我认为这很简单,我能够让我的解释器评估简单的 if 条件,10 == 10 但是当我试图让它评估更复杂的条件时, 10 == 10
我正在尝试以下代码,该代码向 RDD 中的每一行添加一个数字,并使用 PySpark 返回 RDD 列表。 from pyspark.context import SparkContext file
在阅读了很多关于 Lisp eval-when 运算符的文档后,我仍然无法理解它的用途,我知道使用这个运算符我可以控制表达式的计算时间,但我做不到找出任何可能适用的示例? 最好的问候,utxee. 最
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我是一名优秀的程序员,十分优秀!