Updated: 13 October 2013 -> begintemplate endtemplate
Syntax Highlighnting in Geany
Geany seems to be one of the preferred IDEs for NEURON simulation environment in GNU Linux. To enable syntax highlighting for geany:
1) edit or create
and add:~/.config/geany/filetype_extensions.conf
Code: Select all
Neuron=*.hoc;*.nrn;*.ses;
NMODL=*.mod;
with:~/.config/geany/filedefs/filetypes.Neuron.conf
Code: Select all
# For complete documentation of this file, please see Geany's main documentation
[styling=D]
[keywords]
# all items must be in one line
primary=abs allobjects allobjectvars arc3d area argtype atan atan2 attr_praxis batch_run batch_save continuerun coredump_on_error cos diam3d define_shape delete_section diam_changed disconnect distance doEvents doNotify eqinit erf erfc execute execute1 exp fadvance fclamp fclampi fclampv fcurrent finitialize fit_praxis fmatrix fprint frecord_init fscan fstim fstimi getSpineArea get_loc get_segment getstr ghk has_loc hoc_pointer_ hoc_stdio hocmech init initnrn int ion_charge ion_register ion_style ismembrane issection loc log log10 load_file load_func load_proc load_template machine_name n3d name_declared nernst nrncontrolmenu nrnglobalmechmenu nrnmainmenu nrnmechmenu nrnpointmenu nrnsecmenu numarg object_id object_push object_pop parent_connection parent_node parent_section pop_section printf print_session prmat prstim psection pt3dchange pt3dclear pt3dconst pt3dinsert pt3dremove pt3dadd pt3dstyle push_section pval_praxis quit retrieveaudit ri ropen run saveaudit save_session secname sectionname section_exists section_orientation setdt setSpineArea show_errmess_always sin solve spine3d sprint sqrt sred sscanf startsw stdinit stopsw stop_praxis strcmp system tanh this_node this_section topology unref wopen x3d xbutton xcheckbox xfixedvalue xlabel xopen xpvalue xradiobutton xred xslider xstatebutton xvalue xvarlabel y3d z3d
secondary=access begintemplate break cai cao celsius cm connect continue create delete depvar diam do double dt eca ek else ena endtemplate eqn external for for forall forsec func if ifsec ina insert iterator iterator_statement ki ko L local localobj nai nao n_hh new nseg obfunc objectvar objref print proc public Ra read return setpointer stdrun steps_per_ms stop stoprun strdef secondorder t this tstop uninsert v v_init while
types=AlphaSynapse APCount CVode Deck ExpSyn Exp2Syn File FInitializeHandler GUIMath Glyph Graph HBox IClamp Impedance IntFire1 IntFire2 IntFire4 KSGate KSState KSTrans List LinearMechanism Matrix MechanismStandard MechanismType NetCon NetStim KSChan ParallelContext ParallelNetManager PlotShape PWManager Pointer Python Random RangeVarPlot SaveState SEClamp SectionBrowser SectionList SectionRef Shape StringFunctions SymChooser TextEditor Timer ValueFieldEditor VBox VClamp Vector
docComment=begintemplate endtemplate xmenu xpanel
[lexer_properties]
fold.d.comment.explicit=0
[settings]
# default extension used when saving files
extension=hoc
lexer_filetype=D
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=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="nrngui ./%f"
[build-menu]
EX_00_LB=_Execute
EX_00_CM=nrngui ./%f
EX_00_WD=
EX_01_LB=Compile Mod Files
EX_01_CM=nrnivmodl
EX_01_WD=
with:~/.config/geany/filedefs/filetypes.NMODL.conf
Code: Select all
[styling=D]
[keywords]
# all items must be in one line
primary=acos asin atan atan2 ceil cos cosh exp fabs floor fmod log log10 pow sin sinh sqrt tan tanh area ca cai cao celsius dt eca ek ena ica ik ina k ki ko na nai nao t v cnexp euler runge derivimplicit
secondary=CONSERVE ELECTRODE_CURRENT else ENDVERBATIM EXTERNAL FROM GLOBAL if LOCAL METHOD MUTEXLOCK MUTEXUNLOCK NONSPECIFIC_CURRENT POINTER POINT_PROCESS RANGE READ SOLVE SUFFIX TABLE THREADSAFE UNITSOFF UNITSON USEION VALENCE VERBATIM WITH WRITE
types=ASSIGNED BREAKPOINT CONSTANT DERIVATIVE FUNCTION INCLUDE INDEPENDENT INITIAL KINETIC NET_RECEIVE NEURON NONLINEAR PARAMETER PROCEDURE STATE TITLE UNITS
docComment=begintemplate endtemplate xmenu xpanel
[lexer_properties]
fold.d.comment.explicit=0
[settings]
# default extension used when saving files
extension=mod
lexer_filetype=D
comment_single=:
# multiline comments
comment_open=COMMENT
comment_close=ENDCOMMENT
# 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=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="nrngui ./%f"
[build-menu]
EX_00_LB=_Execute
EX_00_CM=modlunit ./%f
EX_00_WD=
EX_01_LB=Compile Mod Files
EX_01_CM=nrnivmodl
EX_01_WD=
and check these options:Geany -> Edit -> Preferences -> Terminal tab
Code: Select all
[*] Execute programs in the VTE
[*] Don't use run script
and use the following terminal command:Geany -> Edit -> Preferences -> Tools tab
Code: Select all
xterm -e bash -i %c
Code: Select all
rxvt -e bash -i %c
Note: You can also compile your mod files from an option in the Build menu
4) Restart your Geany and open your *.hoc or *.mod file. If your file type did not recognized automatically From
choose "Neuron file" or "NMODL file".Geany -> Document -> Set Filetype
Syntax Highlighnting in Kate
I have modified the original C++ xml code used in KDE's kate text editor to highlight most common parts of the hoc code. to use this file you should
1) Create a file named "neuron.xml". Open it in a text editor like kate or kwrite. its content should be:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<language name="neuron" section="Scripts"
version=".1" kateversion="2.4"
indenter="cstyle"
extensions="*.hoc;*.nrn;*.ses;"
mimetype="text/x-csrc;text/x-c++src;text/x-chdr"
priority="5">
<!--
##########################################################################
## Written by Keivan Moradi (k.moradi@gmail.com)
##
## NOTE: Please try to improve it
##########################################################################
## <item> </item>
-->
<highlighting>
<list name="keywords">
<item> access </item>
<item> begintemplate </item>
<item> break </item>
<item> connect </item>
<item> continue </item>
<item> create </item>
<item> default </item>
<item> delete </item>
<item> depvar </item>
<item> do </item>
<item> else </item>
<item> endtemplate </item>
<item> eqn </item>
<item> external </item>
<item> for </item>
<item> forall </item>
<item> forsec </item>
<item> func </item>
<item> if </item>
<item> ifsec </item>
<item> init </item>
<item> insert </item>
<item> iterator </item>
<item> local </item>
<item> localobj </item>
<item> new </item>
<item> nseg </item>
<item> obfunc </item>
<item> objectvar </item>
<item> objref </item>
<item> print </item>
<item> proc </item>
<item> public </item>
<item> read </item>
<item> return </item>
<item> setpointer </item>
<item> stop </item>
<item> strdef </item>
<item> this </item>
<item> uninsert </item>
<item> unref </item>
<item> while </item>
<item> xbutton </item>
<item> xlabel </item>
<item> xpanel </item>
<item> xvalue </item>
</list>
<list name="types">
<item> auto </item>
<item> char </item>
<item> const </item>
<item> double </item>
<item> float </item>
<item> int </item>
<item> long </item>
<item> register </item>
<item> restrict </item>
<item> short </item>
<item> signed </item>
<item> static </item>
<item> unsigned </item>
<item> void </item>
<item> volatile </item>
<item> int8_t </item>
<item> int16_t </item>
<item> int32_t </item>
<item> int64_t </item>
<item> uint8_t </item>
<item> uint16_t </item>
<item> uint32_t </item>
<item> uint64_t </item>
<item> wchar_t </item>
<item> _Imaginary </item>
<item> _Complex </item>
<item> _Bool </item>
</list>
<contexts>
<context attribute="Normal Text" lineEndContext="#stay" name="Normal">
<DetectSpaces />
<RegExpr attribute="Preprocessor" context="Outscoped" String="#\s*if\s+0" beginRegion="PP" firstNonSpace="true" />
<DetectChar context="AfterHash" char="#" firstNonSpace="true" lookAhead="true" />
<StringDetect attribute="Region Marker" context="Region Marker" String="//BEGIN" beginRegion="Region1" firstNonSpace="true" />
<StringDetect attribute="Region Marker" context="Region Marker" String="//END" endRegion="Region1" firstNonSpace="true" />
<keyword attribute="Keyword" context="#stay" String="keywords"/>
<keyword attribute="Data Type" context="#stay" String="types"/>
<DetectIdentifier />
<DetectChar attribute="Symbol" context="#stay" char="{" beginRegion="Brace1" />
<DetectChar attribute="Symbol" context="#stay" char="}" endRegion="Brace1" />
<Float attribute="Float" context="#stay">
<AnyChar String="fF" attribute="Float" context="#stay"/>
</Float>
<HlCOct attribute="Octal" context="#stay"/>
<HlCHex attribute="Hex" context="#stay"/>
<Int attribute="Decimal" context="#stay" >
<StringDetect attribute="Decimal" context="#stay" String="ULL" insensitive="TRUE"/>
<StringDetect attribute="Decimal" context="#stay" String="LUL" insensitive="TRUE"/>
<StringDetect attribute="Decimal" context="#stay" String="LLU" insensitive="TRUE"/>
<StringDetect attribute="Decimal" context="#stay" String="UL" insensitive="TRUE"/>
<StringDetect attribute="Decimal" context="#stay" String="LU" insensitive="TRUE"/>
<StringDetect attribute="Decimal" context="#stay" String="LL" insensitive="TRUE"/>
<StringDetect attribute="Decimal" context="#stay" String="U" insensitive="TRUE"/>
<StringDetect attribute="Decimal" context="#stay" String="L" insensitive="TRUE"/>
</Int>
<HlCChar attribute="Char" context="#stay"/>
<DetectChar attribute="String" context="String" char="""/>
<IncludeRules context="##Doxygen" />
<Detect2Chars attribute="Comment" context="Commentar 1" char="/" char1="/"/>
<Detect2Chars attribute="Comment" context="Commentar 2" char="/" char1="*" beginRegion="Comment"/>
<AnyChar attribute="Symbol" context="#stay" String=":!%&()+,-/.*<=>?[]|~^;"/>
</context>
<context attribute="String" lineEndContext="#pop" name="String">
<LineContinue attribute="String" context="#stay"/>
<HlCStringChar attribute="String Char" context="#stay"/>
<DetectChar attribute="String" context="#pop" char="""/>
</context>
<context attribute="Region Marker" lineEndContext="#pop" name="Region Marker">
</context>
<context attribute="Comment" lineEndContext="#pop" name="Commentar 1">
<LineContinue attribute="Comment" context="#stay"/>
<IncludeRules context="##Alerts" />
</context>
<context attribute="Comment" lineEndContext="#stay" name="Commentar 2">
<Detect2Chars attribute="Comment" context="#pop" char="*" char1="/" endRegion="Comment"/>
<IncludeRules context="##Alerts" />
</context>
<context attribute="Error" lineEndContext="#pop" name="AfterHash">
<!-- define, elif, else, endif, error, if, ifdef, ifndef, include, include_next, line, pragma, undef, warning -->
<RegExpr attribute="Preprocessor" context="Preprocessor" String="#\s*if(?:def|ndef)?(?=\s+\S)" insensitive="true" beginRegion="PP" firstNonSpace="true" />
<RegExpr attribute="Preprocessor" context="Preprocessor" String="#\s*endif" insensitive="true" endRegion="PP" firstNonSpace="true" />
<RegExpr attribute="Preprocessor" context="Define" String="#\s*define.*((?=\\))" insensitive="true" firstNonSpace="true" />
<RegExpr attribute="Preprocessor" context="Preprocessor" String="#\s*(?:el(?:se|if)|include(?:_next)?|define|undef|line|error|warning|pragma)" insensitive="true" firstNonSpace="true" />
<RegExpr attribute="Preprocessor" context="Preprocessor" String="#\s+[0-9]+" insensitive="true" firstNonSpace="true" />
</context>
<context attribute="Preprocessor" lineEndContext="#pop" name="Preprocessor">
<LineContinue attribute="Preprocessor" context="#stay"/>
<RangeDetect attribute="Prep. Lib" context="#stay" char=""" char1="""/>
<RangeDetect attribute="Prep. Lib" context="#stay" char="<" char1=">"/>
<IncludeRules context="##Doxygen" />
<Detect2Chars attribute="Comment" context="Commentar/Preprocessor" char="/" char1="*" beginRegion="Comment2" />
</context>
<context attribute="Preprocessor" lineEndContext="#pop" name="Define">
<LineContinue attribute="Preprocessor" context="#stay"/>
</context>
<context attribute="Comment" lineEndContext="#stay" name="Commentar/Preprocessor">
<Detect2Chars attribute="Comment" context="#pop" char="*" char1="/" endRegion="Comment2" />
</context>
<context attribute="Comment" lineEndContext="#stay" name="Outscoped" >
<DetectSpaces />
<IncludeRules context="##Alerts" />
<DetectIdentifier />
<DetectChar attribute="String" context="String" char="""/>
<IncludeRules context="##Doxygen" />
<Detect2Chars attribute="Comment" context="Commentar 1" char="/" char1="/"/>
<Detect2Chars attribute="Comment" context="Commentar 2" char="/" char1="*" beginRegion="Comment"/>
<RegExpr attribute="Comment" context="Outscoped intern" String="#\s*if" beginRegion="PP" firstNonSpace="true" />
<RegExpr attribute="Preprocessor" context="#pop" String="#\s*el(?:se|if)" firstNonSpace="true" />
<RegExpr attribute="Preprocessor" context="#pop" String="#\s*endif" endRegion="PP" firstNonSpace="true" />
</context>
<context attribute="Comment" lineEndContext="#stay" name="Outscoped intern">
<DetectSpaces />
<IncludeRules context="##Alerts" />
<DetectIdentifier />
<DetectChar attribute="String" context="String" char="""/>
<IncludeRules context="##Doxygen" />
<Detect2Chars attribute="Comment" context="Commentar 1" char="/" char1="/"/>
<Detect2Chars attribute="Comment" context="Commentar 2" char="/" char1="*" beginRegion="Comment"/>
<RegExpr attribute="Comment" context="Outscoped intern" String="#\s*if" beginRegion="PP" firstNonSpace="true" />
<RegExpr attribute="Comment" context="#pop" String="#\s*endif" endRegion="PP" firstNonSpace="true" />
</context>
</contexts>
<itemDatas>
<itemData name="Normal Text" defStyleNum="dsNormal"/>
<itemData name="Keyword" defStyleNum="dsKeyword"/>
<itemData name="Data Type" defStyleNum="dsDataType"/>
<itemData name="Decimal" defStyleNum="dsDecVal"/>
<itemData name="Octal" defStyleNum="dsBaseN"/>
<itemData name="Hex" defStyleNum="dsBaseN"/>
<itemData name="Float" defStyleNum="dsFloat"/>
<itemData name="Char" defStyleNum="dsChar"/>
<itemData name="String" defStyleNum="dsString"/>
<itemData name="String Char" defStyleNum="dsChar"/>
<itemData name="Comment" defStyleNum="dsComment"/>
<itemData name="Symbol" defStyleNum="dsNormal"/>
<itemData name="Preprocessor" defStyleNum="dsOthers"/>
<itemData name="Prep. Lib" defStyleNum="dsOthers"/> <!--,Qt::darkYellow,Qt::yellow,false,false)); -->
<itemData name="Alert" defStyleNum="dsAlert" />
<itemData name="Region Marker" defStyleNum="dsRegionMarker" />
<itemData name="Error" defStyleNum="dsError" />
</itemDatas>
</highlighting>
<general>
<comments>
<comment name="singleLine" start="//" />
<comment name="multiLine" start="/*" end="*/" />
</comments>
<keywords casesensitive="1" additionalDeliminator="'"" />
</general>
</language>
3) Close all open documents in kwrite/kate/kdevelop. Restart them, open your hoc files again in kate, and if your code does not automatically recognized go to kate > tools > highlighting > Scripts > and select neuron and marvel at how much nicer they look. :)
It should be safe to use this file, but as I am new to Linux community if you encounter a problem please inform me.
for further information about how to write a new kate's text highlighting xmls refer to the KDE4 documentation