简体   繁体   English

使用Haskell模式在Emacs中进行Haskell自动补全

[英]Haskell autocompletion in Emacs using haskell-mode

I installed haskel-mode in emacs. 我在emacs中安装了haskel-mode Then I write in my .emacs: 然后我在.emacs中写:

(load "~/.emacs.d/haskell-mode/haskell-site-file")
(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
(add-hook 'haskell-mode-hook 'haskell-font-lock-symbols t)
(put 'downcase-region 'disabled nil)

What must I add in my conf file that emacs could autocomplete for Haskell? 我必须在conf文件中添加些什么以便emacs可以为Haskell自动完成? Or Haskell mode there is no such possibility? 还是Haskell模式没有这种可能性?

When there is no language-specific support, you can use tags . 如果没有特定语言的支持,则可以使用标签 This is a generic completion mechanism. 这是一种通用的完成机制。

  1. Generate a TAGS file, which contains a list of identifiers and where they are defined. 生成TAGS文件,其中包含标识符列表以及定义它们的位置。 Emacs comes with the etags program to do this in many languages, but not Haskell; Emacs附带了etags程序,可以用多种语言来执行此操作,但Haskell却不行。 ghc comes with hasktags . ghc带有hasktags

  2. Load the TAGS file with Mx visit-tags-table . 使用Mx visit-tags-table加载TAGS文件。

Tags are not context-dependent, so they'll indiscriminately suggest types, values, constructors, etc everywhere. 标签不是上下文相关的,因此它们会在任何地方随意建议类型,值,构造函数等。 They also won't provide advanced features such as easily showing the type of a value. 它们也不会提供高级功能,例如轻松显示值的类型。 The most important tags commands are: 最重要的标记命令是:

  • M-TAB ( complete-symbol ) completes an identifier according to the loaded list of tags. M-TABcomplete-symbol )根据加载的标签列表来完成标识符。

  • M-. ( find-tag ) goes to the place where the identifier at point is defined, opening the containing file if necessary. find-tag )转到定义点标识符的位置,如有必要,打开包含文件。

  • M-* ( pop-tag-mark ) goes back where you were before M-. M-*pop-tag-mark )返回到您在M-.之前的位置M-. .

  • Mx tags-apropos shows a list of identifiers matching a regexp. Mx tags-apropos显示与正则表达式匹配的标识符列表。

For more information, look under "Tags" in the Emacs manual. 有关更多信息,请查看Emacs手册中的“标签”下。


For an even cruder, but fully automatic mechanism, there is the dynamic abbrev feature. 对于更粗略但全自动的机制,它具有动态缩写功能。 CM-/ ( dabbrev-completion ) looks in most open buffers for a completion; CM-/dabbrev-completion )在大多数打开的缓冲区中寻找完成; this is completely language-independent, so it'll even find words in strings, comments, whatever. 这是完全与语言无关的,因此它甚至可以找到字符串,注释之类的单词。 M-/ ( dabbrev-expand ) is similar, but directly completes to the nearest match before point. M-/dabbrev-expand )类似,但是直接完成到点之前最近的匹配。

ghc-mod provides some completion for Haskell within Emacs, as well as checking with hlint and ghc. ghc-mod为Emacs中的Haskell提供了一些完成功能,以及使用hlint和ghc进行检查。 In combination with M-/, it's good enough for me. 与M- /结合使用对我来说已经足够了。

haskell-mode currently provides no such possibility. haskell-mode目前无法提供这种可能性。 There is some work on implementation of haskell parser for CEDET - in this case, users will get autocompletion features automatically. 有一些针对CEDET的haskell解析器实现的工作-在这种情况下,用户将自动获得自动完成功能。 But this work had started not so much time ago... 但是这项工作不是很久以前就开始了...

My setup is a little more complicated. 我的设置有点复杂。 It uses the auto-complete infrastructure which shows a dropdown list of candidates automatically similar to traditional IDEs. 它使用自动完成的基础结构,该基础结构自动显示类似于传统IDE的候选者下拉列表。 I downloaded this script that hardcodes all the keywords. 我下载了此脚本该脚本对所有关键字进行了硬编码。 In addition to that, I use ghc-mod to generate module names. 除此之外,我使用ghc-mod生成模块名称。

As a "cheap and cheerful" autocompletion mechanism, don't overlook M-/ . 作为“便宜而开朗”的自动完成机制,请不要忽略M-/ It's completely heuristic and language-independent, but surprisingly effective. 它是完全启发式的并且与语言无关,但是出奇的有效。

Besides autocompletion for your own code, you can also get autocompletion (with apidocs even) for the standard library, import names, and pragma names using company-ghc . 除了自动完成自己的代码外,您还可以使用company-ghc获得标准库的自动完成功能(甚至使用apidocs),导入名称和编译指示名称。 I found this guide to be very helpful. 我发现本指南非常有帮助。 Note, I didn't get it to work fully for myself yet, but I can feel I'm close :-) 注意,我还没有完全为自己工作,但是我可以感觉到我很接近:-)

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

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