Syntax Highlighting for GNU Linux and MS Windows

Particularly useful chunks of hoc and/or NMODL code. May be pedestrian or stunningly brilliant, may make you gasp or bring tears to your eyes, but always makes you think "I wish I had written that; I'm sure going to steal it."
Post Reply
Keivan
Posts: 127
Joined: Sat Apr 22, 2006 4:28 am

Syntax Highlighting for GNU Linux and MS Windows

Post by Keivan »

Updated: 28 September 2013
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
~/.config/geany/filetype_extensions.conf
and add:

Code: Select all

Neuron=*.hoc;*.nrn;*.ses; 
NMODL=*.mod;
2) create
~/.config/geany/filedefs/filetypes.Neuron.conf
with:

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=
also create
~/.config/geany/filedefs/filetypes.NMODL.conf
with:

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=
3) If you want F5 shortcut to execute your hoc file or check your mod file with modlunit command, go to
Geany -> Edit -> Preferences -> Terminal tab
and check these options:

Code: Select all

[*] Execute programs in the VTE
[*] Don't use run script
An alternate method is using xterm or rxvt instead of VTE. To do so, go to
Geany -> Edit -> Preferences -> Tools tab
and use the following terminal command:

Code: Select all

xterm -e bash -i %c
or

Code: Select all

rxvt -e bash -i %c
the -i switch of bash is the key modification.

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
Geany -> Document -> Set Filetype
choose "Neuron file" or "NMODL file".


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=":!%&()+,-/.*<=>?[]|~^&#59;"/>
      </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>
2) Copy the "neuron.xml" file to "~/.kde4/share/apps/katepart/syntax".
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
Last edited by Keivan on Fri Jan 24, 2014 3:04 am, edited 8 times in total.
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: neuron syntax highlighting

Post by ted »

Thanks, Keivan!
Keivan
Posts: 127
Joined: Sat Apr 22, 2006 4:28 am

Syntax Highlighting for Notepad++ in MS Windows

Post by Keivan »

finally, I made syntax highlighting for Notepad++ (for windows usres). I think it is better than the Kate one.

Instructions:
1) install notepad++
2) Create two new text files and name them "NEURON.xml" and "NMODL.xml. Their content should be change to what is provided hereunder.
3) In the notepad++ -> go to "Language" menu -> choose "User-Defined Dialogue" -> In the "User-Defined Dialogue" press the import button -> import the newly created xml files.
4) If you want to run your hoc code with shift+F5 shortcut, simply install RunMe plug-in of Notpad++.

updates
19/10/2009 --> doEvents doNotify push_section pop_section and some built-in variables added + minor changes and bug fix
11/10/2009 --> added built-in range and segment variables
10/10/2009 --> added more built-in functions and some minor changes
9/2/2010 --> added more built-in functions
14/11/2010 --> added Some built-in constant and variables
10/6/2011 --> added synaptic classes
27/6/2011 --> GUI functions are updated, Text folding problem is solved, text between " " would be in orange color
3/8/2011 --> NMODL Support
11/11/2011 --> NMODL definitions updated
6/12/2011 --> Built-in functions of NMODL + some other changes
20/1/2112 --> ek, ena and eca added
28/8/2012 --> neuron and NMODL sections are separated, NEURON: ko, ki, nai, nao, cao, cai; NMODL: sparse
25/5/2013 --> Instructions are updated to be compatible with the new changes in the notepad++
NEURON.xml:

Code: Select all

<NotepadPlus>
    <UserLang name="Neuron" ext="hoc ses nrn">
        <Settings>
            <Global caseIgnored="no" />
            <TreatAsSymbol comment="yes" commentLine="yes" />
            <Prefix words1="no" words2="no" words3="no" words4="no" />
        </Settings>
        <KeywordLists>
            <Keywords name="Delimiters">"00"00</Keywords>
            <Keywords name="Folder+">{</Keywords>
            <Keywords name="Folder-">}</Keywords>
            <Keywords name="Operators">&apos; - " $ % & ( ) , [ \ ] ^ | + < = ></Keywords>
            <Keywords name="Comment">1/* 2*/ 0//</Keywords>
            <Keywords name="Words1">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</Keywords>
            <Keywords name="Words2">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</Keywords>
            <Keywords name="Words3">access break cai cao celsius cm connect continue create delete depvar diam do double dt eca ek else ena 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</Keywords>
            <Keywords name="Words4">begintemplate endtemplate xmenu xpanel</Keywords>
        </KeywordLists>
        <Styles>
            <WordsStyle name="DEFAULT" styleID="11" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="FOLDEROPEN" styleID="12" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="12" />
            <WordsStyle name="FOLDERCLOSE" styleID="13" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="12" />
            <WordsStyle name="KEYWORD1" styleID="5" fgColor="0080C0" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="KEYWORD2" styleID="6" fgColor="800080" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="KEYWORD3" styleID="7" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="KEYWORD4" styleID="8" fgColor="FF0080" bgColor="FFFFFF" fontName="" fontStyle="3" />
            <WordsStyle name="COMMENT" styleID="1" fgColor="00BF00" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="COMMENT LINE" styleID="2" fgColor="00BF00" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="NUMBER" styleID="4" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="OPERATOR" styleID="10" fgColor="408080" bgColor="FFFFFF" fontName="" fontStyle="1" />
            <WordsStyle name="DELIMINER1" styleID="14" fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="DELIMINER2" styleID="15" fgColor="FFFF00" bgColor="000000" fontName="" fontStyle="0" />
            <WordsStyle name="DELIMINER3" styleID="16" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
        </Styles>
    </UserLang>
</NotepadPlus>
NMODL.xml:

Code: Select all

<NotepadPlus>
    <UserLang name="NMODL" ext="mod">
        <Settings>
            <Global caseIgnored="no" />
            <TreatAsSymbol comment="no" commentLine="no" />
            <Prefix words1="no" words2="no" words3="no" words4="no" />
        </Settings>
        <KeywordLists>
            <Keywords name="Delimiters">000000</Keywords>
            <Keywords name="Folder+">{</Keywords>
            <Keywords name="Folder-">}</Keywords>
            <Keywords name="Operators">&apos; - ( ) * , / ^ + < = ></Keywords>
            <Keywords name="Comment">1COMMENT 2ENDCOMMENT 0:</Keywords>
            <Keywords name="Words1">ASSIGNED BREAKPOINT CONSTANT DERIVATIVE FUNCTION INCLUDE INDEPENDENT INITIAL KINETIC NET_RECEIVE NEURON NONLINEAR PARAMETER PROCEDURE STATE TITLE UNITS</Keywords>
            <Keywords name="Words2">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</Keywords>
            <Keywords name="Words3">acos asin atan atan2 ceil cos cosh exp fabs floor fmod log log10 pow sin sinh sqrt tan tanh</Keywords>
            <Keywords name="Words4">area ca cai cao celsius dt eca ek ena ica ik ina k ki ko na nai nao t v cnexp euler runge derivimplicit sparse</Keywords>
        </KeywordLists>
        <Styles>
            <WordsStyle name="DEFAULT" styleID="11" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="FOLDEROPEN" styleID="12" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="FOLDERCLOSE" styleID="13" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="KEYWORD1" styleID="5" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="KEYWORD2" styleID="6" fgColor="FF8040" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="KEYWORD3" styleID="7" fgColor="FF00FF" bgColor="FFFFFF" fontName="@Adobe Heiti Std R" fontStyle="0" />
            <WordsStyle name="KEYWORD4" styleID="8" fgColor="0080C0" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="COMMENT" styleID="1" fgColor="008080" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="COMMENT LINE" styleID="2" fgColor="008080" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="NUMBER" styleID="4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="OPERATOR" styleID="10" fgColor="800000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="DELIMINER1" styleID="14" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="DELIMINER2" styleID="15" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
            <WordsStyle name="DELIMINER3" styleID="16" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" />
        </Styles>
    </UserLang>
</NotepadPlus>
Notepad++ Website
Last edited by Keivan on Sat Sep 28, 2013 11:01 am, edited 31 times in total.
Keivan
Posts: 127
Joined: Sat Apr 22, 2006 4:28 am

Syntax Highlighting for Gedit

Post by Keivan »

Syntax Highlighting for Gedit
Instructions -->
create
~/.local/share/gtksourceview-3.0/language-specs/neuron.lang
with

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!--
 Authors: Keivan Moradi
this is the modification of the original c.lang in ubuntu
-->
<language id="nrn" _name="neuron" version="2.0" _section="Sources">
    <metadata>
      <property name="mimetypes">text/x-c;text/x-csrc;image/x-xpixmap</property>
      <property name="globs">*.hoc</property>
      <property name="line-comment-start">//</property>
      <property name="block-comment-start">/*</property>
      <property name="block-comment-end">*/</property>
    </metadata>

    <styles>
        <style id="comment"           _name="Comment"             map-to="def:comment"/>
        <style id="error"             _name="Error"               map-to="def:error"/>
        <style id="string"            _name="String"              map-to="def:string"/>
        <style id="preprocessor"      _name="Preprocessor"        map-to="def:preprocessor"/>
        <style id="common-defines"    _name="Common Defines"      map-to="def:identifier"/>
        <style id="included-file"     _name="Included File"       map-to="def:string"/>
        <style id="char"              _name="Character"           map-to="def:character"/>
        <style id="keyword"           _name="Keyword"             map-to="def:keyword"/>
        <style id="type"              _name="Data Type"           map-to="def:type"/>
        <style id="storage-class"     _name="Storage Class"       map-to="js:object"/>
        <style id="printf"            _name="printf Conversion"   map-to="def:special-char"/>
        <style id="escaped-character" _name="Escaped Character"   map-to="def:special-char"/>
        <style id="floating-point"    _name="Floating point number" map-to="def:floating-point"/>
        <style id="decimal"           _name="Decimal number"      map-to="def:decimal"/>
        <style id="octal"             _name="Octal number"        map-to="def:base-n-integer"/>
        <style id="hexadecimal"       _name="Hexadecimal number"  map-to="def:base-n-integer"/>
        <style id="boolean"           _name="Boolean value"       map-to="def:note"/>
    </styles>

    <definitions>
        <!-- TODO: what about scanf ? -->
        <!-- man 3 printf -->
        <context id="printf" style-ref="printf" extend-parent="false">
            <match extended="true">
                \%\%|\%
                (?:[1-9][0-9]*\$)?      # argument
                [#0\-\ \+\'I]*          # flags
                (?:[1-9][0-9]*|\*)?     # width
                (?:\.\-?(?:[0-9]+|\*))? # precision
                (?:hh|ll|[hlLqjzt])?    # length modifier
                [diouxXeEfFgGaAcsCSpnm] # conversion specifier
            </match>
        </context>

        <define-regex id="escaped-character" extended="true">
            \\(                   # leading backslash
            [\\\"\'nrbtfav\?] |   # escaped character
            [0-7]{1,3} |          # one, two, or three octal digits
            x[0-9A-Fa-f]+         # 'x' followed by hex digits
            )
        </define-regex>

        <context id="nrn">
            <include>

                <!-- gtk-doc -->
                <context ref="gtk-doc:inline-docs-section"/>

                <!-- Comments -->
                <context id="comment" style-ref="comment" end-at-line-end="true">
                    <start>//</start>
                    <include>
                      <context ref="def:in-line-comment"/>
                    </include>
                </context>

                <context id="comment-multiline" style-ref="comment">
                    <start>/\*</start>
                    <end>\*/</end>
                    <include>
                        <context ref="def:in-comment"/>
                    </include>
                </context>

                <context id="close-comment-outside-comment" style-ref="error">
                    <match>\*/(?!\*)</match>
                </context>

                <!-- Preprocessor -->
                <define-regex id="preproc-start">^\s*#\s*</define-regex>

                <context id="if0-comment" style-ref="comment">
                    <start>\%{preproc-start}if\b\s*0\b</start>
                    <end>\%{preproc-start}(endif|else|elif)\b</end>
                    <include>
                        <context id="if-in-if0">
                            <start>\%{preproc-start}if(n?def)?\b</start>
                            <end>\%{preproc-start}endif\b</end>
                            <include>
                                <context ref="if-in-if0"/>
                                <context ref="def:in-comment"/>
                            </include>
                        </context>
                        <context ref="def:in-comment"/>
                    </include>
                </context>

                <context id="string" style-ref="string" end-at-line-end="true">
                    <start>L?"</start>
                    <end>"</end>
                    <include>
                        <context ref="printf"/>
                        <context id="escaped-character" style-ref="escaped-character">
                            <match>\%{escaped-character}</match>
                        </context>
                        <context ref="def:line-continue"/>
                    </include>
                </context>

                <context id="char" style-ref="char">
                    <match>L?'(\%{escaped-character}|.)'</match>
                </context>

                <!-- http://www.lysator.liu.se/c/ANSI-C-grammar-l.html -->
                <context id="float" style-ref="floating-point">
                    <match extended="true">
                        (?<![\w\.])
                        ((\.[0-9]+ | [0-9]+\.[0-9]*) ([Ee][+-]?[0-9]*)? |
                         ([0-9]+[Ee][+-]?[0-9]*))
                        [fFlL]?
                        (?![\w\.])
                    </match>
                </context>

                <context id="hexadecimal" style-ref="hexadecimal">
                    <match extended="true">
                        (?<![\w\.])
                        0[xX][a-fA-F0-9]+[uUlL]*
                        (?![\w\.])
                    </match>
                </context>

                <context id="octal" style-ref="octal">
                    <match extended="true">
                        (?<![\w\.])
                        0[0-7]+[uUlL]*
                        (?![\w\.])
                    </match>
                </context>

                <context id="decimal" style-ref="decimal">
                    <match extended="true">
                        (?<![\w\.])
                        [0-9]+[uUlL]*
                        (?![\w\.])
                    </match>
                </context>

                <!-- Keywords -->
                <context id="keywords" style-ref="keyword">
                   <keyword>access</keyword>
                   <keyword>break</keyword>
                   <keyword>connect</keyword>
                   <keyword>continue</keyword>
                   <keyword>create</keyword>
                   <keyword>delete</keyword>
                   <keyword>depvar</keyword>
                   <keyword>diam</keyword>
                   <keyword>do</keyword>
                   <keyword>double</keyword>
                   <keyword>else</keyword>
                   <keyword>eqn</keyword>
                   <keyword>external</keyword>
                   <keyword>if</keyword>
                   <keyword>for</keyword>
                   <keyword>proc</keyword>
                   <keyword>for</keyword>
                   <keyword>forall</keyword>
                   <keyword>forsec</keyword>
                   <keyword>func</keyword>
                   <keyword>ifsecl</keyword>
                   <keyword>init</keyword>
                   <keyword>insert</keyword>
                   <keyword>iterator</keyword>
                   <keyword>L</keyword>
                   <keyword>local</keyword>
                   <keyword>localobj</keyword>
                   <keyword>new</keyword>
                   <keyword>nseg</keyword>
                   <keyword>obfunc</keyword>
                   <keyword>objectvar</keyword>
                   <keyword>objref</keyword>
                   <keyword>print</keyword>
                   <keyword>public</keyword>
                   <keyword>Ra</keyword>
                   <keyword>read</keyword>
                   <keyword>return</keyword>
                   <keyword>setpointer</keyword>
                   <keyword>stop</keyword>
                   <keyword>strdef</keyword>
                   <keyword>this</keyword>
                   <keyword>uninsert</keyword>
                   <keyword>while</keyword>
                   <keyword>secondorder</keyword>
                   <keyword>t</keyword>
                   <keyword>dt</keyword>
                   <keyword>stoprun</keyword>
                   <keyword>celsius</keyword>
                </context>

                <context id="classes" style-ref="storage-class">
                   <keyword>Deck</keyword>
                   <keyword>HBox</keyword>
                   <keyword>Random</keyword>
                   <keyword>VBox</keyword>
                   <keyword>File</keyword>
                   <keyword>List</keyword>
                   <keyword>StringFunctions</keyword>
                   <keyword>ValueFieldEditor</keyword>
                   <keyword>GUIMath</keyword>
                   <keyword>Matrix</keyword>
                   <keyword>SymChooser</keyword>
                   <keyword>Vector</keyword>
                   <keyword>Glyph</keyword>
                   <keyword>PWManager</keyword>
                   <keyword>TextEditor</keyword>
                   <keyword>Graph</keyword>
                   <keyword>Pointer</keyword>
                   <keyword>Timer</keyword>
                   <keyword>CVode</keyword>
                   <keyword>KSTrans</keyword>
                   <keyword>ParallelNetManager</keyword>
                   <keyword>SectionList</keyword>
                   <keyword>FInitializeHandler</keyword>
                   <keyword>LinearMechanism</keyword>
                   <keyword>PlotShape</keyword>
                   <keyword>SectionRef</keyword>
                   <keyword>Impedance</keyword>
                   <keyword>MechanismStandard</keyword>
                   <keyword>Python</keyword>
                   <keyword>Shape</keyword>
                   <keyword>KSChan</keyword>
                   <keyword>MechanismType</keyword>
                   <keyword>RangeVarPlot</keyword>
                   <keyword>KSGate</keyword>
                   <keyword>NetCon</keyword>
                   <keyword>SaveState</keyword>
                   <keyword>KSState</keyword>
                   <keyword>ParallelContext</keyword>
                   <keyword>SectionBrowser</keyword>
                </context>

                <context id="builtin-functions" style-ref="common-defines">
                   <keyword>arc3d</keyword>
                   <keyword>area</keyword>
                   <keyword>attr_praxis</keyword>
                   <keyword>batch_run</keyword>
                   <keyword>batch_save</keyword>
                   <keyword>diam3d</keyword>
                   <keyword>define_shape</keyword>
                   <keyword>delete_section</keyword>
                   <keyword>diam_changed</keyword>
                   <keyword>disconnect</keyword>
                   <keyword>distance</keyword>
                   <keyword>execute</keyword>
                   <keyword>fadvance</keyword>
                   <keyword>fclamp</keyword>
                   <keyword>fclampi</keyword>
                   <keyword>fclampv</keyword>
                   <keyword>fcurrent</keyword>
                   <keyword>finitialize</keyword>
                   <keyword>fit_praxis</keyword>
                   <keyword>fmatrix</keyword>
                   <keyword>frecord_init</keyword>
                   <keyword>fstim</keyword>
                   <keyword>fstimi</keyword>
                   <keyword>getSpineArea</keyword>
                   <keyword>hocmech</keyword>
                   <keyword>initnrn</keyword>
                   <keyword>ismembrane</keyword>
                   <keyword>issection</keyword>
                   <keyword>n3d</keyword>
                   <keyword>nrnglobalmechmenu</keyword>
                   <keyword>nrnmechmenu</keyword>
                   <keyword>nrnpointmenu</keyword>
                   <keyword>nrnsecmenu</keyword>
                   <keyword>pt3dchange</keyword>
                   <keyword>pt3dclear</keyword>
                   <keyword>pt3dconst</keyword>
                   <keyword>spine3d</keyword>
                   <keyword>pt3dinsert</keyword>
                   <keyword>pt3dremove</keyword>
                   <keyword>pt3dadd</keyword>
                   <keyword>pt3dstyle</keyword>
                   <keyword>parent_connection</keyword>
                   <keyword>parent_node</keyword>
                   <keyword>parent_section</keyword>
                   <keyword>prstim</keyword>
                   <keyword>psection</keyword>
                   <keyword>pval_praxis</keyword>
                   <keyword>ri</keyword>
                   <keyword>secname</keyword>
                   <keyword>sectionname</keyword>
                   <keyword>section_exists</keyword>
                   <keyword>section_orientation</keyword>
                   <keyword>setSpineArea</keyword>
                   <keyword>sprint</keyword>
                   <keyword>stop_praxis</keyword>
                   <keyword>system</keyword>
                   <keyword>this_node</keyword>
                   <keyword>this_section</keyword>
                   <keyword>topology</keyword>
                   <keyword>unref</keyword>
                   <keyword>x3d</keyword>
                   <keyword>xbutton</keyword>
                   <keyword>xcheckbox</keyword>
                   <keyword>xfixedvalue</keyword>
                   <keyword>xlabel</keyword>
                   <keyword>xmenu</keyword>
                   <keyword>xpvalue</keyword>
                   <keyword>xslider</keyword>
                   <keyword>xstatebutton</keyword>
                   <keyword>xvalue</keyword>
                   <keyword>xvarlabel</keyword>
                   <keyword>y3d</keyword>
                   <keyword>z3d</keyword>
                </context>

		<context id="better-visibility" style-ref="boolean">
		   <keyword>begintemplate</keyword>
		   <keyword>endtemplate</keyword>
		   <keyword>xpanel</keyword>
		</context>
		
            </include>
        </context>
    </definitions>
</language>
Thanks to Cliff Kerr, also create
~/.local/share/gtksourceview-3.0/language-specs/nmodl.lang
with

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!--

NMODL syntax highlighting file for gEdit by Cliff Kerr
(cliffk@neurosim.downstate.edu), based on matlab.lang
and octave.lang, with keywords taken from Keivan Moradi's
Notepad++ syntax file:
http://www.neuron.yale.edu/phpbb/viewtopic.php?f=30&t=1763

See https://wiki.gnome.org/Apps/Gedit/NewLanguage
for a fairly lousy explanation of how to write
these .lang files.

To use this file, simply copy it into
~/.local/share/gtksourceview-3.0/language-specs
(create that directory if it doesn't exist). Then it should
be selectable from gEdit -> View -> Highlight Mode -> Scientific.
Note that you'll need to restart gEdit for changes to take
effect.

Version: 2013sep12

-->

<language id="mod" _name="NMODL" version="2.0" _section="Scientific">
  <metadata>
    <property name="mimetypes">text/x-mod</property>
    <property name="globs">*.mod</property>
    <property name="line-comment-start">:</property>
    <property name="block-comment-start">COMMENT</property>
    <property name="block-comment-end">ENDCOMMENT</property>
  </metadata>

  <styles>
    <style id="comment"          _name="Comment"         map-to="def:comment"/>
    <style id="operator"         _name="Operator"        map-to="def:operator"/>
    <style id="decimal"          _name="Decimal"         map-to="def:decimal"/>
    <style id="floating-point"   _name="Floating Point"  map-to="def:floating-point"/>
    <style id="keyword"          _name="Keyword"         map-to="def:keyword"/>
    <style id="builtin"          _name="Builtin"         map-to="def:builtin"/>
  </styles>

  <definitions>

    <context id="block-comment" style-ref="comment" class="comment" class-disabled="no-spell-check">
      <start>^\s*COMMENT\s*$</start>
      <end>^\s*ENDCOMMENT\s*$</end>
      <include>
        <context ref="block-comment"/>
        <context ref="def:in-comment"/>
      </include>
    </context>

    <context id="line-comment" style-ref="comment" end-at-line-end="true" class="comment" class-disabled="no-spell-check">
      <start>:</start>
      <include>
        <context ref="def:in-comment"/>
      </include>
    </context>

    <context id="operator" style-ref="operator">
      <match extended="true">
        (\.)?\+{1,2}?(?!\+) |   # arithmetic operators
        (\.)?\-{1,2}?(?!\-) |   # already counting
        (\.)?\*{1,2}?(?!\*) |   # with auto increment,
        (\.)?\/(?!\^) |         # element by element,
        (\.)?\\(?!\^) |         # left division
        (\.)?\^(?!\^) |         # and both exp
        (?<=[0-9a-zA-Z_)\]}])(\.)?' |                  # transpose operator
        <=? | >=? | != | ~= | == | <> |       # comparison operators
        &{1,2}?(?!&) | \|{1,2}?(?!\|) | ! | ~ |   # boolean operators
        = |                                               # assignment operator
        : |                                               # range operator
      </match>
    </context>

    <context id="decimal" style-ref="decimal">
      <match>\b([1-9][0-9]*|0)([Uu]([Ll]|LL|ll)?|([Ll]|LL|ll)[Uu]?)?\b</match>
    </context>

    <context id="floating-point-number" style-ref="floating-point">
      <match>\b([0-9]+[Ee][-]?[0-9]+|([0-9]*\.[0-9]+|[0-9]+\.)([Ee][-]?[0-9]+)?)[fFlL]?</match>
    </context>

    <context id="keyword">
      <include>
        <context style-ref="keyword">
            <keyword>if</keyword>
            <keyword>else</keyword>
            <keyword>for</keyword>
            <keyword>while</keyword>
            <keyword>return</keyword>
            <keyword>break</keyword>
            <keyword>switch</keyword>
            <keyword>case</keyword>
            <keyword>acos</keyword>
            <keyword>asin</keyword>
            <keyword>atan</keyword>
            <keyword>atan2</keyword>
            <keyword>ceil</keyword>
            <keyword>cos</keyword>
            <keyword>cosh</keyword>
            <keyword>exp</keyword>
            <keyword>fabs</keyword>
            <keyword>floor</keyword>
            <keyword>fmod</keyword>
            <keyword>log</keyword>
            <keyword>log10</keyword>
            <keyword>pow</keyword>
            <keyword>sin</keyword>
            <keyword>sinh</keyword>
            <keyword>sqrt</keyword>
            <keyword>tan</keyword>
            <keyword>tanh</keyword>
            <keyword>area</keyword>
            <keyword>ca</keyword>
            <keyword>cai</keyword>
            <keyword>cao</keyword>
            <keyword>celsius</keyword>
            <keyword>dt</keyword>
            <keyword>eca</keyword>
            <keyword>ek</keyword>
            <keyword>ena</keyword>
            <keyword>ica</keyword>
            <keyword>ik</keyword>
            <keyword>ina</keyword>
            <keyword>k</keyword>
            <keyword>ki</keyword>
            <keyword>ko</keyword>
            <keyword>na</keyword>
            <keyword>nai</keyword>
            <keyword>nao</keyword>
            <keyword>t</keyword>
            <keyword>v</keyword>
            <keyword>x</keyword>
            <keyword>cnexp</keyword>
            <keyword>euler</keyword>
            <keyword>runge</keyword>
            <keyword>derivimplicit</keyword>
            <keyword>sparse</keyword>
            <keyword>ms</keyword>
        </context>
      </include>
    </context>

    <context id="builtin" style-ref="builtin">
      <keyword>CONSERVE</keyword>
      <keyword>ELECTRODE_CURRENT</keyword>
      <keyword>ENDVERBATIM</keyword>
      <keyword>EXTERNAL</keyword>
      <keyword>FROM</keyword>
      <keyword>GLOBAL</keyword>
      <keyword>LOCAL</keyword>
      <keyword>METHOD</keyword>
      <keyword>MUTEXLOCK</keyword>
      <keyword>MUTEXUNLOCK</keyword>
      <keyword>NONSPECIFIC_CURRENT</keyword>
      <keyword>POINTER</keyword>
      <keyword>POINT_PROCESS</keyword>
      <keyword>RANGE</keyword>
      <keyword>READ</keyword>
      <keyword>SOLVE</keyword>
      <keyword>SUFFIX</keyword>
      <keyword>TABLE</keyword>
      <keyword>THREADSAFE</keyword>
      <keyword>UNITSOFF</keyword>
      <keyword>UNITSON</keyword>
      <keyword>USEION</keyword>
      <keyword>VALENCE</keyword>
      <keyword>VERBATIM</keyword>
      <keyword>WITH</keyword>
      <keyword>WRITE</keyword>
      <keyword>ASSIGNED</keyword>
      <keyword>BREAKPOINT</keyword>
      <keyword>CONSTANT</keyword>
      <keyword>DERIVATIVE</keyword>
      <keyword>FUNCTION</keyword>
      <keyword>INCLUDE</keyword>
      <keyword>INDEPENDENT</keyword>
      <keyword>INITIAL</keyword>
      <keyword>KINETIC</keyword>
      <keyword>NET_RECEIVE</keyword>
      <keyword>NEURON</keyword>
      <keyword>NONLINEAR</keyword>
      <keyword>PARAMETER</keyword>
      <keyword>PROCEDURE</keyword>
      <keyword>STATE</keyword>
      <keyword>TITLE</keyword>
      <keyword>UNITS</keyword>
      <keyword>WATCH</keyword>
    </context>

    <context id="mod" class="no-spell-check">
      <include>
        <context ref="block-comment"/>
        <context ref="line-comment"/>
        <context ref="operator"/>
        <context ref="decimal"/>
        <context ref="floating-point-number"/>
        <context ref="keyword"/>
        <context ref="builtin"/>
      </include>
    </context>

  </definitions>
</language>
I only tested it in ubuntu. do not blame me if it does not work properly on other distroes.
Last edited by Keivan on Sat Sep 28, 2013 10:53 am, edited 4 times in total.
Keivan
Posts: 127
Joined: Sat Apr 22, 2006 4:28 am

Syntax Highlighting for IDM UEStudio

Post by Keivan »

I have changed my text editor to IDM UEStudio, because I can modify it to show a function list, also it has a better syntax highlighting. Text Folding is active in this text editor for hoc code.
To activate syntax highlighting in this text editor, go to advanced menu -> configuration -> Editor Display -> Syntax Highlighting
There is an address of wordfiles ("Full directory path for wordfiles"). Go to that address and create a text file named "neuron.uew" (don't forget to remove txt extension). Open it in notepad or whatever text editor you use and copy the following code in it

Code: Select all

/L1"Neuron" C_LANG Line Comment = // Block Comment On = /* Block Comment Off = */ Escape Char = \ String Chars = "' File Extensions = NRN HOC
/Colors = 0,2536238,8421376,8421504,255,
/Colors Back = 16777215,16777215,16777215,16777215,16777215,
/Colors Auto Back = 1,1,1,1,1,
/Font Style = 0,0,0,0,0,
/TGBegin "Function"
/TGFindStr = "%^([a-z_][a-z_0-9^[^]*]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./()!]++)[~;]"
/TGFindStr = "[ ^t]++^([a-z_][a-z_0-9]++::[a-z_^~][a-z_0-9]++^)[ ^t^p]++([^p*&:, ^t^[^]/*^-'=:&a-z_0-9./(!]++)[~;]"
/TGFindStr = "%[a-z_][a-z_0-9^[^]:&]++[ ^t*]+[*&]++^([a-z_][a-z_0-9]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./(!]++)[~;]"
/TGFindStr = "%[a-z_][:a-z_0-9*&$^[^]*]++[ ^t]+[a-z_][:a-z_0-9*&$^[^]]++[ ^t*]+[*&]++^([a-z_][a-z_0-9]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./(!]++)[~;]"
/TGFindStr = "%[a-z_][:a-z_0-9^[^]*&]++[ ^t]+[a-z_][:a-z_0-9*&^[^]]++[ ^t]+[a-z_][:a-z_0-9*&^[^]]++[ ^t]+[*&]++^([a-z_][a-z_0-9]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./(!]++)[~;]"
/TGFindStr = "%[ ^t]++[a-z_][a-z_0-9^[^]:&]++[ ^t*]+[*&]++^([a-z_][a-z_0-9]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./(!]++){++$"
/TGBegin "Parameter"
/TGFindStr = "[ ^t^p]++^([~,]+^)"
/TGFindBStart = "("
/TGFindBEnd = ")"
/TGEnd
/TGBegin "Variable"
/TGFindStr = "%[ ^t]++^([a-z0-9_]+[ ^t^*]+[a-z0-9^[^]_]+^);"
/TGFindBStart = "{"
/TGFindBEnd = "}"
/TGFindStr = "%[ ^t]++^([a-z0-9_]+[ ^t^*]+[a-z0-9^[^]_]+^)[ ^t]++=*;"
/TGFindBStart = "{"
/TGFindBEnd = "}"
/TGEnd
/TGEnd
//return type on separate line from function name and args
//Neuron class member functions, class::name args
//type name args
//type type name args
//type type type name args
//Functions with preceding spaces/tabs(causes false positives)
//type name;
//type name = init;
/Delimiters = ~!@%^&*()-+=|\/{}[]:;"'<> ,	.?
/Member String = "^([a-z0-9_:.]+^)[ ^t^*&]+$S[ ^t^[^]a-z0-9_]++[(-);,]"
/Variable String = "%[ ^t]++^([!-ے~ ^t<>]+*[~a-z^p]^)$S[ ^t;,()^-]"
/Indent Strings = "{" "if" "else" ":"
/Unindent Strings = "}"
/Open Brace Strings =  "{" "(" "["
/Close Brace Strings = "}" ")" "]"
/Open Fold Strings = "{" "begintemplate" "intercept(1)" "xpanel"
/Close Fold Strings = "}" "endtemplate" "intercept(0)" "xpanel"
/C1"Keywords" STYLE_KEYWORD Colors = 16711680 Colors Back = 16777215 Colors Auto Back = 1 Font Style = 0
access 
break 
celsius 
cm 
connect 
continue 
create 
DEG 
delete 
depvar 
diam 
do 
double 
dt 
E 
else 
eqn 
external 
FARADAY 
float_epsilon 
for
forall 
forsec 
func 
GAMMA 
hoc_ac_ 
hoc_cross_x_ 
hoc_cross_y_ 
hoc_obj_ 
if 
ifsec 
ina 
init 
insert 
iterator 
iterator_statement
L 
local 
localobj 
nai 
n_hh 
new 
nseg 
obfunc 
objectvar 
objref 
PI 
PHI 
print 
proc 
public 
R 
Ra 
read 
return 
setpointer 
stdrun 
steps_per_ms 
stop 
stoprun 
strdef 
secondorder 
t 
this 
tstop 
uninsert 
v 
v_init 
while
/C2"Functions" STYLE_KEYWORD Colors = 16744448 Colors Back = 16777215 Colors Auto Back = 1 Font Style = 0
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 
getstr 
ghk 
hoc_pointer_ 
hoc_stdio 
hocmech 
initnrn 
int 
ion_charge 
ion_register 
ion_style 
ismembrane 
issection 
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 
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 
xmenu 
xopen 
xpvalue 
xred 
xslider 
xstatebutton 
xvalue 
xvarlabel 
y3d 
z3d
/C3"Classes" STYLE_EXTENSION Colors = 33023 Colors Back = 16777215 Colors Auto Back = 1 Font Style = 0
Deck 
HBox 
IClamp 
Random 
VBox 
File 
List 
StringFunctions 
ValueFieldEditor 
GUIMath 
Matrix 
SymChooser 
Vector 
Glyph 
PWManager 
TextEditor 
Graph 
Pointer 
Timer 
CVode 
KSTrans 
ParallelNetManager 
SectionList 
FInitializeHandler 
LinearMechanism 
PlotShape 
SectionRef 
Impedance 
MechanismStandard 
Python 
Shape 
KSChan 
MechanismType 
RangeVarPlot 
KSGate 
NetCon 
SaveState 
KSState 
ParallelContext 
SectionBrowser
/C4"Operators" STYLE_OPERATOR Colors = 32768 Colors Back = 16777215 Colors Auto Back = 1 Font Style = 0
!
$
%
&
*
+
-
.
// /
:
<
=
>
?
^
|
~
/C5"Braces, comma, semicolon" Colors = 4210816 Colors Back = 16777215 Colors Auto Back = 1 Font Style = 0
(
)
,
;
[
]
{
}
/C6"Templates" Colors = 8388863 Colors Back = 16777215 Colors Auto Back = 1 Font Style = 0
begintemplate 
endtemplate 
xpanel
intercept
/C7"Arguments" Colors = 8388736 Colors Back = 16777215 Colors Auto Back = 1 Font Style = 0
$1
$2
$3
$4
$5
$6
$7
$8
$9
$10
$11
$12
$13
$14
$15
$16
$17
$18
$19
$20
$o1
$o2
$o3
$o4
$o5
$o6
$o7
$o8
$o9
$o10
$o11
$o12
$o13
$o14
$o15
$o16
$o17
$o18
$o19
$o20
$&1
$&2
$&3
$&4
$&5
$&6
$&7
$&8
$&9
$&10
$&11
$&12
$&13
$&14
$&15
$&16
$&17
$&18
$&19
$&20
$s1
$s2
$s3
$s4
$s5
$s6
$s7
$s8
$s9
$s10
$s11
$s12
$s13
$s14
$s15
$s16
$s17
$s18
$s19
$s20
then save and open your *.hoc or *.nrn files with IDM UEStudio. UEStuio should recognize extension of your neuron code which should be hoc or nrn and activate syntax highlighting automatically.
RTomsett

Re: Syntax Highlighting for KDE4, Gnome and Windows

Post by RTomsett »

Just found these - very useful indeed, thank you!
vladimirov
Posts: 50
Joined: Thu Jul 07, 2011 6:20 pm

Re: Syntax Highlighting for Notepad++

Post by vladimirov »

Keivan wrote:finally, I made syntax highlighting for notepad++ (for windows usres). I think it is better than the kate one.

instructions:
1) install notepad++
2) use a texteditor to replace content of the file userDefineLang.xml with provided one (see below).
windows xp: "C:\Documents and Settings\<your user name>\Application Data\Notepad++\userDefineLang.xml"
windows 7: "C:\Users\<your user name>\AppData\Roaming\Notepad++\userDefineLang.xml"
Thanks a lot, Keivan!
My 5 cents: here is a good instruction how to add user-defined language to NotePad++
Basically, one can save the code you provided in any place (userDefineLang.xml) and import it via Notepad++.
This will help to those who have NO such file under windows xp: "C:\Documents and Settings\<your user name>\Application Data\Notepad++\userDefineLang.xml"
After you import your userDefineLang.xml via NotePad++ User-Defined dialog, save both Neuron and NMODL languages by using "Save as" button, and enjoy the highlighted syntax.
Keivan
Posts: 127
Joined: Sat Apr 22, 2006 4:28 am

Re: Syntax Highlighting for KDE4, Gnome and Windows

Post by Keivan »

Thank you for the tip vladimirov. I'm going to update my post.
tcleland
Posts: 12
Joined: Tue Jul 18, 2006 11:38 am

Re: Syntax Highlighting for Notepad++

Post by tcleland »

Keivan, vladimirov, and others --

I also use hoc and NMODL syntax highlighting in Notepad++; that works well. But I wonder if you have solved another Notepad++-related problem that is plaguing me. I had a solution in Notepad++ v5.2, but it no longer works in 5.7 or 6.1.

The issue is about hotkey execution of NEURON code. It's straightforward to create a "Launch using NEURON" custom entry under the Run menu, executing, specifically:

c:\nrn72\bin\neuron.exe "$(FULL_CURRENT_PATH)"

where FULL_CURRENT_PATH is the directory where all my hoc files and nrnmech.dll are. This works fine when I load a hoc file from a directory (which also contains nrnmech.dll) in that it executes that hoc file, but it does NOT set NEURON's working directory to the location of the hoc file. Hence, nrnmech.dll is not loaded, which is pretty important. For what it's worth, NEURON's getcwd() command shows that NEURON's current directory is set to Notepad++'s binary directory under Program Files (x86).

Oddly, the working directory of Notepad++ itself *is* set to the directory where the hoc file and nrnmech.dll live, as can be confirmed by selecting "Run | Open curr dir cmd". So the problem is specifically that Notepad++ is not communicating to NEURON where its file lives.

If NEURON had a "setcwd()" command, then I might be able to fix this as follows:
c:\nrn72\bin\neuron.exe "$(FULL_CURRENT_PATH)" -c "setcwd($(FULL_CURRENT_PATH))"
but it doesn't, at least not to my knowledge.

In Notepad++ 5.2, there was a plugin command called "Follow $(CURRENT_DIRECTORY)" which, when executed prior to the above, would make NEURON load nrnmech.dll properly. But this plugin command is gone from 5.7 and later.

Another editor, Notetab, works just fine for execution and setting the working directory of NEURON, but it lacks syntax highlighting.

So... those are all the details. Has anybody solved the problem of how to get Notepad++ to launch hoc files in NEURON while also setting NEURON's working directory properly so as to load nrnmech.dll files from that same directory?

Many many thanks in advance for any help & ideas -
Thom
tcleland
Posts: 12
Joined: Tue Jul 18, 2006 11:38 am

Re: Syntax Highlighting for Notepad++

Post by tcleland »

Figured it out. I found the FOLLOW command as part of the NppExec plugin to Notepad++, which is not (no longer?) part of the standard installation. Thank you to the kind Kiwis of the University of Auckland for guiding me to this solution:

http://www.cs.auckland.ac.nz/courses/co ... epad++.pdf

Love the intertubes.

thom
cckerr
Posts: 1
Joined: Wed Sep 11, 2013 12:27 pm

Re: Syntax Highlighting for KDE4, Gnome and Windows

Post by cckerr »

I couldn't find a syntax highlighting file for NMODL in gEdit, so here's one I made based on Keivan's syntax highlighting file for Notepad++.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!--

NMODL syntax highlighting file for gEdit by Cliff Kerr 
(cliffk@neurosim.downstate.edu), based on matlab.lang 
and octave.lang, with keywords taken from Keivan Moradi's 
Notepad++ syntax file: 
http://www.neuron.yale.edu/phpbb/viewtopic.php?f=30&t=1763

See https://wiki.gnome.org/Apps/Gedit/NewLanguage
for a fairly lousy explanation of how to write
these .lang files.

To use this file, simply copy it into 
~/.local/share/gtksourceview-3.0/language-specs
(create that directory if it doesn't exist). Then it should
be selectable from gEdit -> View -> Highlight Mode -> Scientific.
Note that you'll need to restart gEdit for changes to take
effect.

Version: 2013sep12

-->

<language id="mod" _name="NMODL" version="2.0" _section="Scientific">
  <metadata>
    <property name="mimetypes">text/x-mod</property>
    <property name="globs">*.mod</property>
    <property name="line-comment-start">:</property>
    <property name="block-comment-start">COMMENT</property>
    <property name="block-comment-end">ENDCOMMENT</property>
  </metadata>

  <styles>
    <style id="comment"          _name="Comment"         map-to="def:comment"/>
    <style id="operator"         _name="Operator"        map-to="def:operator"/>
    <style id="decimal"          _name="Decimal"         map-to="def:decimal"/>
    <style id="floating-point"   _name="Floating Point"  map-to="def:floating-point"/>
    <style id="keyword"          _name="Keyword"         map-to="def:keyword"/>
    <style id="builtin"          _name="Builtin"         map-to="def:builtin"/>
  </styles>

  <definitions>

    <context id="block-comment" style-ref="comment" class="comment" class-disabled="no-spell-check">
      <start>^\s*COMMENT\s*$</start>
      <end>^\s*ENDCOMMENT\s*$</end>
      <include>
        <context ref="block-comment"/>
        <context ref="def:in-comment"/>
      </include>
    </context>

    <context id="line-comment" style-ref="comment" end-at-line-end="true" class="comment" class-disabled="no-spell-check">
      <start>:</start>
      <include>
        <context ref="def:in-comment"/>
      </include>
    </context>

    <context id="operator" style-ref="operator">
      <match extended="true">
        (\.)?\+{1,2}?(?!\+) |   # arithmetic operators
        (\.)?\-{1,2}?(?!\-) |   # already counting
        (\.)?\*{1,2}?(?!\*) |   # with auto increment,
        (\.)?\/(?!\^) |         # element by element,
        (\.)?\\(?!\^) |         # left division
        (\.)?\^(?!\^) |         # and both exp
        (?<=[0-9a-zA-Z_)\]}])(\.)?' |                  # transpose operator
        <=? | >=? | != | ~= | == | <> |       # comparison operators
        &{1,2}?(?!&) | \|{1,2}?(?!\|) | ! | ~ |   # boolean operators
        = |                                               # assignment operator
        : |                                               # range operator
      </match>
    </context>

    <context id="decimal" style-ref="decimal">
      <match>\b([1-9][0-9]*|0)([Uu]([Ll]|LL|ll)?|([Ll]|LL|ll)[Uu]?)?\b</match>
    </context>

    <context id="floating-point-number" style-ref="floating-point">
      <match>\b([0-9]+[Ee][-]?[0-9]+|([0-9]*\.[0-9]+|[0-9]+\.)([Ee][-]?[0-9]+)?)[fFlL]?</match>
    </context>

    <context id="keyword">
      <include>
        <context style-ref="keyword">
            <keyword>if</keyword>
            <keyword>else</keyword>
            <keyword>for</keyword>
            <keyword>while</keyword>
            <keyword>return</keyword>
            <keyword>break</keyword>
            <keyword>switch</keyword>
            <keyword>case</keyword>
            <keyword>acos</keyword>
            <keyword>asin</keyword>
            <keyword>atan</keyword>
            <keyword>atan2</keyword>
            <keyword>ceil</keyword>
            <keyword>cos</keyword>
            <keyword>cosh</keyword>
            <keyword>exp</keyword>
            <keyword>fabs</keyword>
            <keyword>floor</keyword>
            <keyword>fmod</keyword>
            <keyword>log</keyword>
            <keyword>log10</keyword>
            <keyword>pow</keyword>
            <keyword>sin</keyword>
            <keyword>sinh</keyword>
            <keyword>sqrt</keyword>
            <keyword>tan</keyword>
            <keyword>tanh</keyword>
            <keyword>area</keyword>
            <keyword>ca</keyword>
            <keyword>cai</keyword>
            <keyword>cao</keyword>
            <keyword>celsius</keyword>
            <keyword>dt</keyword>
            <keyword>eca</keyword>
            <keyword>ek</keyword>
            <keyword>ena</keyword>
            <keyword>ica</keyword>
            <keyword>ik</keyword>
            <keyword>ina</keyword>
            <keyword>k</keyword>
            <keyword>ki</keyword>
            <keyword>ko</keyword>
            <keyword>na</keyword>
            <keyword>nai</keyword>
            <keyword>nao</keyword>
            <keyword>t</keyword>
            <keyword>v</keyword>
            <keyword>x</keyword>
            <keyword>cnexp</keyword>
            <keyword>euler</keyword>
            <keyword>runge</keyword>
            <keyword>derivimplicit</keyword>
            <keyword>sparse</keyword>
            <keyword>ms</keyword>
        </context>
      </include>
    </context>

    <context id="builtin" style-ref="builtin">
		<keyword>CONSERVE</keyword>
		<keyword>ELECTRODE_CURRENT</keyword>
		<keyword>ENDVERBATIM</keyword>
		<keyword>EXTERNAL</keyword>
		<keyword>FROM</keyword>
		<keyword>GLOBAL</keyword>
		<keyword>LOCAL</keyword>
		<keyword>METHOD</keyword>
		<keyword>MUTEXLOCK</keyword>
		<keyword>MUTEXUNLOCK</keyword>
		<keyword>NONSPECIFIC_CURRENT</keyword>
		<keyword>POINTER</keyword>
		<keyword>POINT_PROCESS</keyword>
		<keyword>RANGE</keyword>
		<keyword>READ</keyword>
		<keyword>SOLVE</keyword>
		<keyword>SUFFIX</keyword>
		<keyword>TABLE</keyword>
		<keyword>THREADSAFE</keyword>
		<keyword>UNITSOFF</keyword>
		<keyword>UNITSON</keyword>
		<keyword>USEION</keyword>
		<keyword>VALENCE</keyword>
		<keyword>VERBATIM</keyword>
		<keyword>WITH</keyword>
		<keyword>WRITE</keyword>
		<keyword>ASSIGNED</keyword>
		<keyword>BREAKPOINT</keyword>
		<keyword>CONSTANT</keyword>
		<keyword>DERIVATIVE</keyword>
		<keyword>FUNCTION</keyword>
		<keyword>INCLUDE</keyword>
		<keyword>INDEPENDENT</keyword>
		<keyword>INITIAL</keyword>
		<keyword>KINETIC</keyword>
		<keyword>NET_RECEIVE</keyword>
		<keyword>NEURON</keyword>
		<keyword>NONLINEAR</keyword>
		<keyword>PARAMETER</keyword> 
		<keyword>PROCEDURE</keyword>
		<keyword>STATE</keyword>
		<keyword>TITLE</keyword> 
		<keyword>UNITS</keyword>
		<keyword>WATCH</keyword>
    </context>

    <context id="mod" class="no-spell-check">
      <include>
        <context ref="block-comment"/>
        <context ref="line-comment"/>
        <context ref="operator"/>
        <context ref="decimal"/>
        <context ref="floating-point-number"/>
        <context ref="keyword"/>
        <context ref="builtin"/>
      </include>
    </context>

  </definitions>
</language>
Nin
Posts: 41
Joined: Thu May 03, 2007 4:04 pm
Location: Institute of Science and Technology (IST Austria)
Contact:

Re: Syntax Highlighting for GNU Linux and MS Windows

Post by Nin »

I wrote a NMODL syntax highlight for VIM that you can download from http://www.ist.ac.at/~jguzman/pub/NMODL.vim

To use it, move the file to $VIM/syntax/ and add the following to your .vimrc file

Code: Select all

" nmodl (see in $VIM/syntax/nmodl.vim)
au BufRead,BufNewFile *.mod set filetype=NMODL
It includes a folding feature that allows to hide NMODL blocks at convenience (i.e za will fold/un-flod the NEURON block under your cursor)

Please, note that this is only a first version that I created for personal use.
Post Reply