简体   繁体   English

Emacs中的git-commit vim语法高亮

[英]git-commit vim-like syntax highlighting in emacs

I've recently picked up emacs as a general editor to replace gedit and vim. 我最近选择emacs作为通用编辑器来代替gedit和vim。 The one thing I miss terribly about vim is the git syntax highlighting. 我对vim 非常想念的一件事是git语法高亮显示。 I have tried git-el, apparently with no luck. 我尝试了git-el,显然没有运气。

The vim git-commit highlighting features a "subject line" highlight for the first fifty characters of the first line of the commit message, "error" highlights for the second line, comments, and red and green highlighting for added or removed files (which are themselves written in the precomposed comments.) vim git-commit高亮显示了提交消息第一行的前五十个字符的“主题行”高亮,第二行显示了“错误”的高亮,注释以及添加或删除文件的红色和绿色高亮(其中本身写在预先编写的注释中。)

Is there a similarly functional syntax highlighting for emacs, and if so, how would I install it? emacs是否有类似的功能语法突出显示,如果是,我将如何安装它?

I don't really do emacs but I did some quick searching and found git-modes and magit . 我实际上并没有做emacs,但是我做了一些快速搜索,发现了git-modesmagit I imagine that would get you started down the right road. 我想那会让您踏上正确的道路。

2019 update: 2019更新:

The answers presented here are 5 and 7 year old and it took me some time to figure out how to get various git highlightings without magit . 这里给出的答案是5和7岁,我花了一些时间弄清楚如何在没有magit情况下获得各种git突出显示。 Most links now lead to the magit repo and it is not particularly clear from there what the list of git-related packages currently is, nor whether they are on Melpa. 现在大多数链接都指向magit存储库,从那里不清楚当前与git相关的软件包列表是什么,也不清楚它们是否在Melpa上。

The EmacsWiki page does give the information, but with all the history of the movements of those various packages and their minor change of names, it is not totally easy to follow and see where things are now and what they are called. EmacsWiki页面的确提供了信息,但是由于各种软件包的运行历史以及名称的微小更改,要了解并了解现在的位置和名称并不容易。

So I thought that I would post a summary of these packages. 因此,我认为我将发布这些软件包的摘要。

They are all on Melpa and any of these packages can be installed independently of the others, so you can pick and choose what you need. 它们都在Melpa上,并且这些软件包中的任何一个都可以独立于其他软件包进行安装,因此您可以选择所需的软件包。

  • the package which allows syntax highlighting for commit messages is called git-commit 允许突出显示提交消息的语法的包称为git-commit
  • for .gitignore highlighting, it is called gitignore-mode 对于.gitignore突出显示,它称为gitignore-mode
  • for .gitattributes, it is called gitattributes-mode 对于.gitattributes,它称为gitattributes-mode
  • and for .gitconfig, it is called gitconfig-mode 对于.gitconfig,它称为gitconfig-mode

The package which answers the question is thus currently called git-commit and it is on Melpa. 因此,回答问题的软件包当前称为git-commit ,位于Melpa上。

"Git Commit Mode" on EmacsWiki has an overview of mainly historical interest. EmacsWiki上的“ Git Commit Mode”概述了主要的历史兴趣。 The (presently somewhat argumentative) page seems to argue that you should use Magit. (目前有些争论)的页面似乎认为您应该使用Magit。 All roads ultimately lead to git-modes which is allegedly now the default for Magit, too. 所有道路最终都导致git-mode ,据称这也是Magit的默认模式

(My Ubuntu 14.04 magit does not seem to include it, still. Installing git-commit-mode from Marmalade quickly fixed that.) (我的Ubuntu 14.04 magit似乎还没有包括它。从Marmalade安装git-commit-mode很快解决了这个问题。)

A lot of random dot.emacs files in Google seem to include a diff-mode specification for COMMIT_EDITMSG . Google中的许多随机dot.emacs文件似乎都包含COMMIT_EDITMSGdiff-mode规范。 I don't really see why -- the buffer does not contain a diff, and diff mode disables some useful text editing functions. 我真的不明白为什么-缓冲区不包含diff,并且diff模式禁用了一些有用的文本编辑功能。 If you have nothing else out of the box, specifying log-edit-mode would make more sense. 如果您没有其他可用的功能,则指定log-edit-mode会更有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM