本文介绍了Geany:某些单词的自定义文件类型的语法突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Geany 是一个简单、快速但功能强大的文本编辑器.它对几乎所有类型的语法突出显示都有很强的支持编程语言.

Geany is a simple, fast and yet powerful text editor.It has quite strong support for syntax highlighting for almost all kindsof programming languages.

我想知道如何为我的自定义语法高亮显示名为Phosim"的特殊需要程序,其文件扩展名为.cat.

I was wondering how to make a customized syntax highlighting for myspecial need program called "Phosim" which has the file extension .cat.

到目前为止,我已经做到了:
首先我创建了文件类型扩展配置文件:~/.config/geany/filetype_extensions.conf
内容如下:

So far I have done this:
First I created filetype extension configuration file: ~/.config/geany/filetype_extensions.conf
The contents of this looks like this:

[Extensions]
Gnuplot=*.gp;*.gnu;*.plt;
Galfit=*.gal;
Phosim=*.cat;
[Groups]
Script=Gnuplot;Galfit;Phosim;

在这里,我尝试将自定义突出显示应用于 Gnuplot、Galfit 和 Phosim 程序.对于 Gnuplot 和 Galfit,它工作正常.但是对于 Phosim 我遇到了一些问题.

Here, I am trying to apply custom highlight to programs Gnuplot, Galfit, and Phosim. For Gnuplot and Galfit it works fine. But for Phosim I got some problems.

然后我创建了文件定义配置文件:~/.config/geany/filedefs/filetypes.Phosim.conf
其内容如下所示:

Then I created file definition configuration file: ~/.config/geany/filedefs/filetypes.Phosim.conf
The contents of which looks like this:

# Author  : Bhishan Poudel
# Date    : May 24, 2016
# Version : 1.0


[styling]
# Edit these in the colorscheme .conf file instead
default=default
comment=comment_line
function=keyword_1
variable=string_1,bold
label=label
userdefined=string_2
number=number_2


[keywords]
# all items must be in one line separated by space
variables=object Unrefracted_RA_deg SIM_SEED none
functions=
lables=10
userdefined=angle 30 Angle_RA 20.0 none
numbers=0 1 2 3 4 5 6 7 8 9


[lexer_properties]
nsis.uservars=1
nsis.ignorecase=1


[settings]
# default extension used when saving files
extension=cat

# single comments, like # in this file
comment_single=#
# multiline comments
#comment_open=
#comment_close=


# This setting works only for single line comments
comment_use_indent=true

# context action command (please see Geany's main documentation for details)
 context_action_cmd=

# lexer filetype should be an existing lexer that does not use lexer_filetype itself
lexer_filetype=NSIS


[build-menu]
EX_00_LB=Execute
EX_00_CM=
EX_00_WD=
FT_00_LB=
FT_00_CM=
FT_00_WD=
FT_02_LB=
FT_02_CM=
FT_02_WD=

现在我的 example.cat 看起来像这样:

Now my example.cat looks like this:

# example.cat
angle 30
Angle_RA 20.0
object none

# Till now,
# Words highlighted    : angle 30 object none
# Words not highlighted: Angle_RA 20.0
# I like them also to be highlighted!

我只有两个词的语法高亮,即对象和无.我尝试了与 Fortran 相同的样式,因为它有大写字母,但它也不起作用.

I got syntax highlighting for only two words, viz., object and none.I tried styling equal to Fortran since it has uppercase letters but it also did not work.

我们如何获得包含大写、小写和下划线的变量名称的语法高亮?

例如:
我得到了单词的语法高亮:object none.
但是,没有得到单词的语法高亮:Angle_RA 20.0

此外,我的数字 0,1,..,9 突出显示,但小数点未突出显示.我们如何也突出显示小数?

Also, I my numbers 0,1,..,9 are highlighted but the decimals are not highlighted. How can we highlight decimals too?

例如:
我得到了单词的语法高亮:1 1000 但是,没有得到单词的语法高亮:49552.3 180.0

For example:
I got syntax highlight for words: 1 1000 but, did not get syntax highlight for words: 49552.3 180.0

一些有用的链接如下:
让 Geany 识别其他文件扩展名
Geany 中的自定义语法高亮
http://www.geany.org/manual/current/index.htmlhtml#custom-filetypeshttp://www.geany.org/manual/#lexer-filetype

推荐答案

我没有创建新的文件定义文件,而是为 Python 添加了文件扩展名,它对我有用.

Instead of creating new file definition files I added file extensions for Python and it worked for me.

例如,我想自定义突出显示扩展名为 .icat 的文件(如果您有兴趣,这是天文学中 Phosim 软件的实例目录文件.)

For example, I wanted to custom highlight the files with extension .icat (If you are interested, this is instance catalog file for Phosim Software in Astronomy.)

缺点:在python脚本(.py、.pyc、.ipy)中额外的词也会高亮显示

Drawback: The additional words are also highlighted in python scripts (.py,.pyc,.ipy)

注意:如果有人发布适用于新文件扩展名的解决方案,~/.config/geany/filedefs/filetypes.Phosim.conf 我会衷心欢迎.我的 example.pcat 文件如下所示:

Note: If anybody posts solution that works with new file extension, ~/.config/geany/filedefs/filetypes.Phosim.conf I would heartly welcome that.My example.pcat file looks like this:

# example.pcat
Unrefracted_RA_deg 0
Unrefracted_Dec_deg 0
Unrefracted_Azimuth 0
Unrefracted_Altitude 89
Slalib_date 1994/7/19/0.298822999997
Opsim_rotskypos 0
Opsim_rottelpos 0
Opsim_moondec -90
Opsim_moonra 180
Opsim_expmjd 49552.3
Opsim_moonalt -90
Opsim_sunalt -90
Opsim_filter 2
Opsim_dist2moon 180.0
Opsim_moonphase 10.0
Opsim_obshistid 99999999
Opsim_rawseeing 0.65
SIM_SEED 1000
SIM_MINSOURCE 1
SIM_TELCONFIG 0
SIM_CAMCONFIG 1
SIM_VISTIME 15000.0
SIM_NSNAP 1
object 0 0.0 0.0 20 ../sky/sed_flat.txt 0 0 0 0 0 0 bhishan.fits 0.09 0.0 none

我希望 geany 用黄色突出显示所有第一个单词,用 mangenta 突出显示数字,用蓝色突出显示none"这个词.

I want geany to highlight all first words with yellow color, numbers with mangenta, and the word 'none' with blue color.

首先我创建(或编辑,如果已经存在)文件:

First I created (or, edited if already exists) the file:

~/.config/geany/filetype_extensions.conf

并在其中添加了以下内容.

And added following stuff inside it.

[Extensions]
Gnuplot=*.gp;*.gnu;*.plt;
Galfit=*.gal;
Phosim=*.pcat;
Python=*.py;*.pyc;*.ipy;*.icat;*.pcat
[Groups]
Script=Gnuplot;Galfit;Phosim;Python;

然后,我在 python 文件类型中已经存在的关键字中添加了额外的关键字.
为此,我创建了(或者,如果已经存在则进行编辑)文件:

Then, I added the additional KEYWORDS to the already existing keywords in python filetype.
For this I created (or, edited if already exists) the file:

~/.config/geany/filedefs/filetypes.python

现在,文件 ~/.config/geany/filedefs/filetypes.python 看起来像这样:

Now, the file ~/.config/geany/filedefs/filetypes.python looks like this:

# Author  : Bhishan Poudel
# Date    : June 9, 2016
# Version : 1.0
# File    : Filetype for both python and phosim_instance_catalogs

[styling]
default=default
commentline=comment_line
number=number_1
string=string_1
character=character
word=keyword_1
triple=string_2
tripledouble=string_2
classname=type
defname=function
operator=operator
identifier=identifier_1
commentblock=comment
stringeol=string_eol
word2=keyword_2
decorator=decorator


[keywords]
# all items must be in one line
primary=and as assert break class continue def del elif else except exec finally for from global if import in is lambda not or pass print raise return try while with yield False None True  Words_after_this_are_for_Phosim_pcat_files Unrefracted_RA_deg Unrefracted_Dec_deg Unrefracted_Azimuth Unrefracted_Altitude Slalib_date Opsim_moondec Opsim_rotskypos Opsim_rottelpos Opsim_moondec Opsim_moonra Opsim_expmjd Opsim_moonalt Opsim_sunalt Opsim_filter Opsim_dist2moon Opsim_moonphase Opsim_obshistid Opsim_rawseeing SIM_SEED SIM_MINSOURCE SIM_TELCONFIG  SIM_CAMCONFIG SIM_VISTIME SIM_NSNAP object


identifiers=ArithmeticError AssertionError AttributeError BaseException BufferError BytesWarning DeprecationWarning EOFError Ellipsis EnvironmentError Exception FileNotFoundError FloatingPointError FutureWarning GeneratorExit IOError ImportError ImportWarning IndentationError IndexError KeyError KeyboardInterrupt LookupError MemoryError NameError NotImplemented NotImplementedError OSError OverflowError PendingDeprecationWarning ReferenceError RuntimeError RuntimeWarning StandardError StopIteration SyntaxError SyntaxWarning SystemError SystemExit TabError TypeError UnboundLocalError UnicodeDecodeError UnicodeEncodeError UnicodeError UnicodeTranslateError UnicodeWarning UserWarning ValueError Warning ZeroDivisionError __debug__ __doc__ __import__ __name__ __package__ abs all any apply basestring bin bool buffer bytearray bytes callable chr classmethod cmp coerce compile complex copyright credits delattr dict dir divmod enumerate eval execfile exit file filter float format frozenset getattr globals hasattr hash help hex id input int intern isinstance issubclass iter len license list locals long map max memoryview min next object oct open ord pow print property quit range raw_input reduce reload repr reversed round set setattr slice sorted staticmethod str sum super tuple type unichr unicode vars xrange zip array arange Catagorical cStringIO DataFramedate_range genfromtxt  linspace loadtxt matplotlib none numpy np pandas pd plot plt pyplot savefig scipy Series sp StringIO


[lexer_properties]
fold.comment.python=1
fold.quotes.python=1


[settings]
# default extension used when saving files
extension=py

# the following characters are these which a "word" can contains, see documentation
wordchars=_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789

# MIME type
mime_type=text/x-python
comment_single=#
comment_open="""
comment_close="""
comment_use_indent=true

# context action command (please see Geany's main documentation for details)
context_action_cmd=


[indentation]
width=4
# 0 is spaces, 1 is tabs, 2 is tab & spaces
type=0


[build_settings]
# %f will be replaced by the complete filename
# %e will be replaced by the filename without extension
# (use only one of it at one time)
compiler=python -m py_compile "%f"
run_cmd=python "%f"


[build-menu]
FT_00_LB=Execute
FT_00_CM=python %f
FT_00_WD=
FT_01_LB=
FT_01_CM=
FT_01_WD=
FT_02_LB=
FT_02_CM=
FT_02_WD=
EX_00_LB=Execute
EX_00_CM=clear; python %f
EX_00_WD=
error_regex=([^:]+):([0-9]+):([0-9:]+)? .*
EX_01_LB=
EX_01_CM=
EX_01_WD=

现在,我重新启动了 geany,我可以看到所有第一个单词都是黄色的,数字是其他颜色的,而无"这个词是蓝色的.

Now, I restarted the geany and I can see all the first words in yellow, numbers other color and the word 'none' is blue colored.

这篇关于Geany:某些单词的自定义文件类型的语法突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-12 15:28