如何为Geany添加Go支持

huangapple go评论103阅读模式
英文:

How to add Go support to Geany

问题

我正在尝试为Geany实现语法高亮和构建选项,有什么建议吗?

英文:

I am trying to make syntax hightlighting and building options work for Geany, any advice?

答案1

得分: 8

我刚刚注意到这个页面:http://go-lang.cat-v.org/text-editors/geany/

看起来他们在那里提供了你所需要的一切。

英文:

I just noticed this page: http://go-lang.cat-v.org/text-editors/geany/

Seems like they've got everything you need right there.

答案2

得分: 3

在$GOROOT/misc和http://go-lang.cat-v.org/text-editors/中查找其他编辑器的语法文件,以获取一些想法。

如果没有的话,可以从C或C++开始,然后添加/删除像<code>go</code>,<code><-</code>,<code>func</code>等内容。

英文:

Look in $GOROOT/misc and http://go-lang.cat-v.org/text-editors/ for syntax files from other editors to get an idea.

Barring that, start with C or C++ and add/substract things like <code>go</code>, <code><-</code>, <code>func</code>, etc.

答案3

得分: 3

这是由Steve Horsley发布到golang-nuts的Geany格式化指南

  1. 在Geany中,转到工具->配置文件->filetype_extensions.conf,并添加以下新标题:

    Go=*.go;
    
  2. 将C定义文件types.c复制到filedefs/filetypes.Go.conf:

    cp /usr/share/geany/filetypes.c ~/.config/geany/filedefs/filetypes.Go.conf
    
  3. 编辑filetypes.Go.conf并将设置和关键字部分更改为:

    [settings]
    # 保存文件时使用的默认扩展名
    extension=go
    lexer_filetype=C
    
    [keywords]
    # 所有项目必须在一行中
    primary=break case chan const continue default defer else fallthrough for func go goto if import interface map package range return select struct switch type var
    secondary=byte int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 float32 float64 complex64 complex128 uintptr string
    
英文:

Here is the Geany formatting Instructions posted by Steve Horsley to golang-nuts:

  1. In Geany, goto Tools->Configuration Files->filetype_extensions.conf and add in the following new heading:

    Go=*.go;
    
  2. Copy the C definition filetypes.c to filedefs/filetypes.Go.conf:

    cp /usr/share/geany/filetypes.c ~/.config/geany/filedefs/filetypes.Go.conf
    
  3. Edit filetypes.Go.conf and change the setting and keywords sections to this:

    [settings]
    # default extension used when saving files
    extension=go
    lexer_filetype=C
    
    [keywords]
    # all items must be in one line
    primary=break case chan const continue default defer else fallthrough for func go goto if import interface map package range return select struct switch type var
    secondary=byte int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 float32 float64 complex64 complex128 uintptr string
    

答案4

得分: 1

你是否在 ~/.config/geany/filetype_extensions.conf 中定义了 Go 文件类型?

[Extensions]
...
Go=*.go
...

如果配置文件还不存在,可以从 /usr/share/geany 复制它,并在 'Extensions' 下添加这一行(或者在 "工具" > "配置文件" 中查找)。

英文:

Have you defined the Go filetype in ~/.config/geany/filetype_extensions.conf ?

[Extensions]
...
Go=*.go
...

if the conf file doesn't yet exist, copy it from /usr/share/geany and add that line under 'Extensions' (or look for it under Tools > Configuration Files).

答案5

得分: 1

我做了一个Python脚本,可以自动化Jaybill McCarthy提供的链接中的指示。

import shutil, re, os

HOME = os.environ['HOME']

shutil.copy('/usr/share/geany/filetype_extensions.conf', HOME +'/.config/geany/')
with open(HOME + '/.config/geany/filetype_extensions.conf', 'r') as f:
    fileData = f.read()
fileData = re.sub(r'Haskell=.*;', r'Go=*.go;\nHaskell=*.hs;*.lhs;', fileData)
fileData = re.compile('(\[Groups\][^\[]Programming=.*?$)', re.DOTALL|re.MULTILINE).sub(r'Go;', fileData)
with open(HOME + '/.config/geany/filetype_extensions.conf', 'w') as f:
    f.write(fileData)


textSettings = """[settings]
extension=go
lexer_filetype=C
comment_single=//
comment_open=/*
comment_close=*/
comment_use_indent=true
"""
textKeywords = """[keywords]
primary=break case chan const continue default defer else fallthrough for func go goto if import interface map package range return select struct switch type var
secondary=byte int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 float32 float64 complex64 complex128 uintptr string"""

shutil.copy('/usr/share/geany/filetypes.c', HOME + '/.config/geany/filedefs/filetypes.Go.conf')
with open(HOME + '/.config/geany/filedefs/filetypes.Go.conf', 'r') as f:
    fileData = f.read()
fileData = re.compile(r'\[settings\].*?^\[', re.DOTALL|re.MULTILINE).sub('%s\n\n[' %textSettings, fileData)
fileData = re.compile(r'\[keywords\].*?^\[', re.DOTALL|re.MULTILINE).sub('%s\n\n[' %textKeywords, fileData)
with open(HOME + '/.config/geany/filedefs/filetypes.Go.conf', 'w') as f:
    f.write(fileData)

print "完成!"
英文:

I made a Python script that automates the directions in the link provided by Jaybill McCarthy.

import shutil, re, os

HOME = os.environ[&#39;HOME&#39;]

shutil.copy(&#39;/usr/share/geany/filetype_extensions.conf&#39;, HOME +&#39;/.config/geany/&#39;)
with open(HOME + &#39;/.config/geany/filetype_extensions.conf&#39;, &#39;r&#39;) as f:
    fileData = f.read()
fileData = re.sub(r&#39;Haskell=.*;&#39;, r&#39;Go=*.go;\nHaskell=*.hs;*.lhs;&#39;, fileData)
fileData = re.compile(&#39;(\[Groups\][^\[]Programming=.*?$)&#39;, re.DOTALL|re.MULTILINE).sub(r&#39;Go;&#39;, fileData)
with open(HOME + &#39;/.config/geany/filetype_extensions.conf&#39;, &#39;w&#39;) as f:
    f.write(fileData)


textSettings = &quot;&quot;&quot;[settings]
extension=go
lexer_filetype=C
comment_single=//
comment_open=/*
comment_close=*/
comment_use_indent=true
&quot;&quot;&quot;
textKeywords = &quot;&quot;&quot;[keywords]
primary=break case chan const continue default defer else fallthrough for func go goto if import interface map package range return select struct switch type var
secondary=byte int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 float32 float64 complex64 complex128 uintptr string&quot;&quot;&quot;

shutil.copy(&#39;/usr/share/geany/filetypes.c&#39;, HOME + &#39;/.config/geany/filedefs/filetypes.Go.conf&#39;)
with open(HOME + &#39;/.config/geany/filedefs/filetypes.Go.conf&#39;, &#39;r&#39;) as f:
    fileData = f.read()
fileData = re.compile(r&#39;\[settings\].*?^\[&#39;, re.DOTALL|re.MULTILINE).sub(&#39;%s\n\n[&#39; %textSettings, fileData)
fileData = re.compile(r&#39;\[keywords\].*?^\[&#39;, re.DOTALL|re.MULTILINE).sub(&#39;%s\n\n[&#39; %textKeywords, fileData)
with open(HOME + &#39;/.config/geany/filedefs/filetypes.Go.conf&#39;, &#39;w&#39;) as f:
    f.write(fileData)

print &quot;Complete!&quot;

I'm not sure if this means I am lazy, or the other way around... o.O.

huangapple
  • 本文由 发表于 2010年9月3日 22:37:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/3636792.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定