在 Mac OS X 上设置 TextMate 以进行 Haskell 编程

发布于 2024-11-01 20:10:42 字数 547 浏览 6 评论 0原文

我是 Mac 新手,正在为我的计算机设置我需要的所有程序,其中之一是 Haskell。

令我惊讶的是,OS X 的 Haskell 平台与 Windows 不同(其中有一个基于平台安装构建的 GUI 编辑器 - winGHiC)。环顾四周后,我发现这个编辑器 TextMate 应该与 Haskell 兼容,但发现设置 Haskell Bundle

我已经下载并安装了以下内容:

  • Haskell Platform for Mac OS X
  • Xcode 3.4(Haskell 先决条件)
  • TextMate
    • haskell.tmbundle 文件(上面提到的)

有人熟悉如何让它工作吗?详细的逐步解释对我来说意义重大,就像我说的,距离我第一次使用 OS X 才过去了 1 天。

非常感谢。

I am new to mac, and am in the process of getting my computer setup with all the programs I need, one of them being Haskell.

To my surprise, the Haskell platform for OS X is not like in Windows (where there is an GUI editor built on the platform installation - winGHiC). After looking a lot around, I found this editor TextMate which is supposed to be compatible with Haskell but am finding it quite complex to setup the Haskell Bundle for it.

I have already downloaded and installed the following:

  • Haskell Platform for Mac OS X
  • Xcode 3.4 (Haskell Prerequisite)
  • TextMate
    • haskell.tmbundle files (mentioned above)

Is anyone familiar on how to get it working? It will mean a lot to me a detailed stepwise explanation, like I said, I has been only 1 day since I used OS X for the first time.

Thanks a bunch.

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

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

发布评论

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

评论(1

花期渐远 2024-11-08 20:10:42

好吧,这几天你发现 tmbundle 出现在了 Github 上,这真是太好了。

您应该能够通过单击 Bundles,然后单击 Haskell 找到内置选项。标准 Haskell.tmbundle 中的内容相当少。最明显有用的是......加载文件command-shift-rcommand-R。如果您编写了一个以 .hs 或 .lhs 结尾的模块,它...会在 ghci 中打开它。

(有人谈论 TextMate II 中的集成终端,但谁知道呢?非集成终端的一个恼人的功能是,人们很想通过单击 command-R 而不是通过在 中执行 :r 来“重新加载” ghci; 在某些疯狂的情况下,我会打开 15 个终端副本。)

许多不错的功能只是一般的 TextMate 东西,由语言描述决定,所以阅读一般描述可能会很好。 TextMate 的细节。例如,如果多行突出显示,则使用 command-/ 用 -- 注释掉它们;或者,如果它们已被注释,则取消注释。早在我意识到它已经存在之前,我就已经拼凑了一些东西来做到这一点,但没有足够仔细地研究手册。

当然,一切都有键绑定,并且很容易添加自己的键绑定来运行小脚本和插入小片段,比在 Emacs 中要容易得多。

Bundles 下,单击 Bundle Editor 并检查文本中的不同类型内容。

因此,例如,要使制表符触发器启动语言扩展杂注 {-#LANGUAGE ... #-},其中光标位于空格 ...复制Snippet 并替代

{-#LANGUAGE ${1}#-}

选择Activation: Tab Trigger 和(例如)LANG 作为触发器。

一件好事是它们都是 shell 脚本,或者(像这个)带有一些 TextMate 变量的部分 shell 脚本,您几乎可以用自己喜欢的语言编写它们。 (对于 Haskell 捆绑包,我不再有任何 Haskell 可供谈论,但对于其他捆绑包,我有。)

语法突出显示令人惊讶地健全,但跨越了一些花哨的扩展,例如“PackageImports”、GADT 语法, Haddock 文档系统的标记,以及其他一些奇怪的地方。我已经破解了自己的,但我发现语法文件的格式非常难以理解,所以向您发送副本是没有用的。 Haskell.tmbundle 在过去的两三年里由一些知识渊博的 Haskellers 进行了修改。第一个制作它的人刚刚学习 Haskell,并没有编写 Haddocked 模块,但另一方面,幸运的是,他似乎非常熟练,并且对 TextMate 机制有深入的了解。

请注意,TextMate 以一种相当奇怪的方式存储您在 Bundle Editor 中所做的修正。 TextMate 附带的捆绑包,例如 CRubyHTMLLaTeX 等位于 /Applications/Textmate.app/.../Bundles。您安装的文件位于 /Library/Application\ Support/TextMate/Bundles 中。当您通过Bundle Editor进行修正时,它们会存储在您本地的~/Library/Application\ Support/TextMate/Bundles中。这有点道理,但有点复杂,并且阻碍了 Haskell 包的公开改进。 (我与人们共享的捆绑包,而不是 Haskell 捆绑包,我将其保留在 git 修订版下的最后一个、最外层目录中,因此原始文件和我的修正放在一起。)

“Lookup on Hoogle”键绑定/选项作用于突出显示的术语;这是 hayoo 网站的副本,它可以搜索类型签名的使用

echo "<meta http-equiv=\"refresh\" content=\"0; 
http://holumbus.fh-wedel.de/hayoo/hayoo.html?query=${TM_SELECTED_TEXT:=$TM_CURRENT_WORD}\">"

如果您安装了 hoogle,那么您可以使用如下脚本对 hoogle 进行本地调用:

 hoogle --w --n=100 '${TM_SELECTED_TEXT:=$TM_CURRENT_WORD}'

选择“保存:无”,“输入:选定的文本”,或者:Word,输出:显示为 HTML

我所做的其他修正大多都是微不足道的,例如“{-#LANGUAGE ... #-} 的选项卡触发片段或我自己的怪癖。

值得一提的是,我成功集成了来自 Hackage 的 typeof 可执行文件,cabal install typeof,它运行到 ghci 以获取推断的类型签名。我有一个键绑定来显示推断的类型,如显示的 html 位,但也可以插入它。 类型显示的文本

#!/bin/bash
word=${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}
module="${TM_FILEPATH}"
echo $word | typeof $module 

这有点微妙,但这里是选择 Input: Selected Text, Or: Line输出:显示为工具提示激活:等效键(然后选择一个键绑定,我的是control-option-command-j)类似地,通过 typeof 进行类型插入,创建一个新的 C(命令文件)标题并包含以下内容:

#!/bin/bash
word=${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}
module="${TM_FILEPATH}"
echo $word | typeof $module | typeof_wordorder

# typeof_wordorder is the following hack compiled
# in my local ~/bin
# module Main where
# main = interact reword where
#  reword :: String -> String
#  reword xs = 
#     xs ++  (head . words . concat . lines $ xs)

这里 typeoftypeof_worderorder 是 Haskell 可执行文件,第一个 cabal -installed,第二个是上面评论的白痴,在我的本地 ~\bin 中编译以避开一些转义的废话。这里你应该选择Output : Insert as Snippet

抱歉,我只是在想一些随机的事情。你应该继续在这个标题下发布问题,因为我认为值得看看一个人可能会如何出错,但也值得看看我们聪明的 Haskeller 朋友可能想到了什么。我一直想将我的 tmbundle 的“分支”放到 github 上,但这并不是太令人兴奋,而且 Bundle 目录的组织永远让我失败。

Well it's good work that you have found that the tmbundle is on Github these days.

You should be able to find the inbuilt options by clicking Bundles, then Haskell. There are fairly few in the standard Haskell.tmbundle. The most obviously useful one is ... load file command-shift-r or command-R. If you have written a module with ending .hs or .lhs, it ... opens it in ghci.

(There was some talk of an integrated terminal in TextMate II, but who knows? One annoying feature of a non-integrated terminal is that one is tempted to 'reload' by clicking command-R rather than by doing :r inside ghci; in certain frenzies it will develop that I have 15 copies of Terminal open.)

Many of the nice features are just general TextMate things, determined by the language description, so it might be good to read a general description of TextMate niceties. For example, if several lines are highlighed, then command-/ comments them out with --s; or, if they are already commented, uncomments them. I had hacked together something to do this, long before I realized it was already there, not having studied the manual closely enough.

Everything has keybindings, of course, and it is very easy to add your own to run little scripts and insert little snippets, much more so than in Emacs, say.

Under Bundles click Bundle Editor and examine the text for different kinds of things.

So, for example, to make a tab trigger to start a language extension pragma {-#LANGUAGE ... #-} where the cursor is in the space ...make a copy of a Snippet and substitute

{-#LANGUAGE ${1}#-}

selecting Activation: Tab Trigger, and (say) LANG as the trigger.

One nice thing is that they are all shell scripts, or else (like this one) partial shell scripts with some TextMate variables around, and you can pretty much write them in your own preferred language. (For the Haskell bundle I don't have any Haskell ones to speak of any more, but for other bundles I do.)

The syntax highlighting is surprisingly sound, but trips over a few fancy extensions, e.g. "PackageImports" , GADT syntax, markup for the Haddock documentation system, and some other oddities. I have hacked my own, but I find the format of the syntax files pretty unintelligible, so it's no use sending you a copy. The Haskell.tmbundle has been emended by some knowledgeable Haskellers in the last two or three years. The person who first made it was just learning Haskell, and hadn't e.g. composed Haddocked modules, but on the other hand, he seems fortunately to have been very skilled and to have had an intimate knowledge of the TextMate machinery.

Notice by the way that TextMate stores the emendations you make in the Bundle Editor in a rather strange way. The bundles that come with TextMate, e.g. C, Ruby, HTML, LaTeX, etc. are in /Applications/Textmate.app/.../Bundles. The ones you install are in /Library/Application\ Support/TextMate/Bundles. When you make emendations through the Bundle Editor, they are stored in your local ~/Library/Application\ Support/TextMate/Bundles. It sort of makes sense but it's a little complicated, and impedes public improvement of the Haskell bundle. (The one bundle I share with people, not the Haskell one, I keep in the lattermost, outermost directory under git revision, so the original and my emendations are together.)

The "Lookup on Hoogle" keybinding/option acts on highlighted terms; here's a replica for the hayoo website, which can search for uses of a type-signature

echo "<meta http-equiv=\"refresh\" content=\"0; 
http://holumbus.fh-wedel.de/hayoo/hayoo.html?query=${TM_SELECTED_TEXT:=$TM_CURRENT_WORD}\">"

If you cabal install hoogle, then you can make a local call to hoogle with a script like so:

 hoogle --w --n=100 '${TM_SELECTED_TEXT:=$TM_CURRENT_WORD}'

choosing Save: Nothing, Input: Selected Text, Or: Word, Output: Show as HTML

Other emendations I have made are mostly trivial, like a tab trigger snippet for `{-#LANGUAGE ... #-} or else eccentricities of my own.

One thing worth mentioning that I managed to integrate is the typeof executable from Hackage, cabal install typeof, which runs to ghci for an inferred type signature. I have a key binding to show the inferred type as displayed bit of html, but also to insert it. It's a bit delicate but here is the text for the displayer of types

#!/bin/bash
word=${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}
module="${TM_FILEPATH}"
echo $word | typeof $module 

choosing Input: Selected Text, Or: Line ; Output: Show as Tool Tip, Activation : Key Equivalent (then choose a keybinding , mine is control-option-command-j) Similarly, for type insertion via typeof make a new C (command file) heading and include this:

#!/bin/bash
word=${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}
module="${TM_FILEPATH}"
echo $word | typeof $module | typeof_wordorder

# typeof_wordorder is the following hack compiled
# in my local ~/bin
# module Main where
# main = interact reword where
#  reword :: String -> String
#  reword xs = 
#     xs ++  (head . words . concat . lines $ xs)

Here typeof and typeof_worderorder are Haskell executables, the first cabal-installed, the second is the above commented idiocy, compiled in my local ~\bin to get around some escaping nonsense. Here you should choose Output : Insert as Snippet

Sorry, I'm just thinking of random things. You should keep posting questions under this heading, as I think it would be worthwhile to see how one might trip up, but also what hacks our cleverer Haskeller friends may have thought of. I keep meaning to put a 'fork' of my tmbundle on github, but it's not too thrilling, and the organization of Bundle directories forever defeats me.

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