c++11 - 最终并覆盖 Geany 中的 C+11 说明符着色

标签 c++11 syntax-highlighting final color-scheme geany

我使用 Geany 1.22 进行开发,但在 C++11 关键字的着色方面遇到了问题。

这是我的 .cpp 配置文件:filetypes.cpp

# For complete documentation of this file, please see Geany's main documentation
[styling]
# foreground;background;bold;italic
default=default
comment=comment
commentline=comment
commentdoc=commentdoc
number=number
word=keyword
word2=keyword2
string=string
character=character
uuid=extra
preprocessor=preprocessor
operator=operator
identifier=default
stringeol=stringeol
# @"verbatim"
verbatim=extra
# (/regex/)
regex=extra
commentlinedoc=commentdoc
commentdockeyword=commentdoc
commentdockeyworderror=commentdoc
globalclass=type

[keywords]
# all items must be in one line
primary=and and_eq asm auto bitand bitor bool break case catch char class compl const const_cast continue default delete do double dynamic_cast else enum explicit export extern false float for friend goto if inline int long mutable namespace new not not_eq operator or or_eq private protected public register reinterpret_cast return short signed sizeof static static_cast struct switch template this throw true try typedef typeid typename union unsigned using virtual void volatile wchar_t while xor xor_eq static_assert decltype
secondary=
# these are some doxygen keywords (incomplete)
docComment=attention author brief bug class code date def enum example exception file fn namespace note param remarks return see since struct throw todo typedef var version warning union

[lexer_properties]
styling.within.preprocessor=1
preprocessor.symbol.$(file.patterns.cpp)=#
preprocessor.start.$(file.patterns.cpp)=if ifdef ifndef
preprocessor.middle.$(file.patterns.cpp)=else elif
preprocessor.end.$(file.patterns.cpp)=endif

[settings]
lexer_filetype=C

# default extension used when saving files
extension=cpp

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

# if only single comment char is supported like # in this file, leave comment_close blank
comment_open=//
comment_close=
# this is an alternative way, so multiline comments are used
#comment_open=/*
#comment_close=*/

# set to false if a comment character/string should start at column 0 of a line, true uses any
# indentation of the line, e.g. setting to true causes the following on pressing CTRL+d
    #command_example();
# setting to false would generate this
#   command_example();
# 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=

[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=g++ -Wall -c "%f"
linker=g++ -Wall -o "%e" "%f"
run_cmd="./%e"

如果我写:

class MyClass
{
};

定义一个新类,然后将 MyClass 的颜色设置为 globalclass 的颜色(这是与 type 关联的颜色)

但是当我用 C++11 编写时:

class MyClass final
{
};

然后 final(而不是 MyClass)设置为 globalclass 的颜色。如果我将 final 添加到主要关键字列表中,那么它会设置为 word 的颜色,这很好,但是 MyClass 仍然不是解释为 globalclass

如何解决这个问题?

最佳答案

问题似乎是在 C++11 中,finaloverride(我怀疑你在那里会遇到同样的问题)实际上并不是关键字。它们是只有在特定上下文中才具有特殊含义的标识符。这意味着您实际上不能随时“只是”为这些标识符赋予颜色,您需要了解它们的上下文。

幸运的是,Geany 1.23 已经为您完成了对 C++11 的支持。不幸的是,Geany 1.23 也不是 100% 正确。也就是说,如果编写 int final = 123; 那么 final 将被着色为关键字(而它实际上不是关键字)。所以他们实际做的是:他们将 final 添加为主要关键字,这并不完全正确,但它有点管用。

所以我的建议是要么从 this link 下载最新版本的 Geany,要么尝试以下配置文件:(来自 Geany 1.23)

# For complete documentation of this file, please see Geany's main documentation
[styling=C]

[keywords]
# all items must be in one line
primary=alignas alignof and and_eq asm auto bitand bitor bool break case catch char char16_t char32_t class compl const const_cast constexpr continue decltype default delete do double dynamic_cast else enum explicit export extern false final float for friend goto if inline int int8_t int16_t int32_t int64_t long mutable namespace new noexcept not not_eq nullptr operator or or_eq override private protected ptrdiff_t public register reinterpret_cast return short signed sizeof size_t static static_assert static_cast struct switch template this thread_local throw true try typedef typeid typename union unsigned using virtual void volatile wchar_t while xor xor_eq
secondary=
# these are the Doxygen keywords
docComment=a addindex addtogroup anchor arg attention author authors b brief bug c callergraph callgraph category cite class code cond copybrief copydetails copydoc copyright date def defgroup deprecated details dir dontinclude dot dotfile e else elseif em endcode endcond enddot endhtmlonly endif endinternal endlatexonly endlink endmanonly endmsc endrtfonly endverbatim endxmlonly enum example exception extends file fn headerfile hideinitializer htmlinclude htmlonly if ifnot image implements include includelineno ingroup interface internal invariant latexonly li line link mainpage manonly memberof msc mscfile n name namespace nosubgrouping note overload p package page par paragraph param post pre private privatesection property protected protectedsection protocol public publicsection ref related relatedalso relates relatesalso remark remarks result return returns retval rtfonly sa section see short showinitializer since skip skipline snippet struct subpage subsection subsubsection tableofcontents test throw throws todo tparam typedef union until var verbatim verbinclude version warning weakgroup xmlonly xrefitem

[lexer_properties]
styling.within.preprocessor=1
lexer.cpp.track.preprocessor=0
preprocessor.symbol.$(file.patterns.cpp)=#
preprocessor.start.$(file.patterns.cpp)=if ifdef ifndef
preprocessor.middle.$(file.patterns.cpp)=else elif
preprocessor.end.$(file.patterns.cpp)=endif

[settings]
lexer_filetype=C

# default extension used when saving files
extension=cpp

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

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

# set to false if a comment character/string should start at column 0 of a line, true uses any
# indentation of the line, e.g. setting to true causes the following on pressing CTRL+d
    #command_example();
# setting to false would generate this
#   command_example();
# 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=

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

[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=g++ -Wall -c "%f"
linker=g++ -Wall -o "%e" "%f"
run_cmd="./%e"

但是,我有点怀疑如果不更新到下一个版本的 Geany,上面的方法是否会起作用,因为你说仅仅添加“final”作为主要关键字对你不起作用。

另一方面,如果您仍想手动执行此操作,请查看 the manual on lexer properties

希望对您有所帮助。

关于c++11 - 最终并覆盖 Geany 中的 C+11 说明符着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15456998/

相关文章:

c++ - 没有匹配的成员函数调用 "insert"std::unordered_map

c++11 - gcc 4.9.2 的 Boost 1.57 文件系统/系统链接器错误

c++ - QSyntaxHighlighter 高亮ascii?

javascript - 如何在语法上突出显示单个文本输入字段?

flutter - 如何用 StatelessWidget 子类中的其他最终成员初始化最终成员?

java - 接口(interface)方法中的最终参数 - 有什么意义?

java - 从其他类访问java中的final字段的正确方法

c++ - 为什么使用 switch-case 时会得到 `warning: control reaches end of non-void function`?

c++ - 将右值引用传递给 boost::in_place 函数

c# - C#-是否有WPF HTML/Javascript/CSS语法编辑器控件?