Last active
April 22, 2021 21:36
-
-
Save monban/6133403 to your computer and use it in GitHub Desktop.
Notepad++ Function List Panel (Ruby) Add this code (plus the association map, which should look like <association langID = "36" id="rb_function"/>) to functionList.xml to get Ruby function parsing. Updated to a version by Menno Vogels, http://sourceforge.net/p/notepad-plus/discussion/331753/thread/c39e2745/#80f0 TODO: Class / module parsing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Author: Menno Vogels; Version: 1.0.0.0 --> | |
<parser | |
id="ruby_function" | |
displayName="Ruby" | |
commentExpr="(?s:#.*?[\r\n]|(?-i:(?<=^|[\r\n])=begin).*?(?-i:[\r\n]=end(?=[\r\n]|$)))" > | |
<function | |
mainExpr="(?s:\b(?-i:def)[\t ]+(?!(?-i:alias|and|BEGIN|begin|break|case|class|def|defined\?|do|else|elsif|END|end|ensure|false|for|if|in|module|next|nil|not|or|redo|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield|__FILE__|__LINE__))(?:[A-Za-z_]\w*[?!=]?(?:[\t ]*\([^)]*\))?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&|\^]|<(?:<|=>?)?|>[>=]?|\[]=?)[\t ]*\([^)]*\)).+?(?-i:end))" | |
displayMode="$functionName" > | |
<functionName> | |
<nameExpr expr="(?s:\b(?-i:def)[\t ]+(?:[A-Za-z_]\w*[?!=]?(?:[\t ]*\()?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&|\^]|<(?:<|=>?)?|>[>=]?|\[]=?)[\t ]*\())" /> | |
<nameExpr expr="(?m:\b(?-i:def)[\t ]+(?:[A-Za-z_]\w*[?!=]?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&|\^]|<(?:<|=>?)?|>[>=]?|\[]=?))(?=(?:\b|[\t ]*\()|.*$))" /> | |
<nameExpr expr="[\t ]+(?:[A-Za-z_]\w*[?!=]?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&|\^]|<(?:<|=>?)?|>[>=]?|\[]=?))" /> | |
<nameExpr expr="(?:[A-Za-z_]\w*[?!=]?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&|\^]|<(?:<|=>?)?|>[>=]?|\[]=?))" /> | |
</functionName> | |
</function> | |
</parser> |
change to
<function mainExpr="^[\s]*def[\s]+(self\.)?[\w_]+">
<functionName>
<nameExpr expr="(?<=(def\s))(self\.)?[\w_]+"/>
</functionName>
</function>
and that will catch
def self.read()
...
end
and
def read somarg
...
end
Hi,
I just integrated as you mention and I could not get to work.
Notepad++ 6.5.1 Unicode
Can someone tell me what I am missing?
I added this in the association map
<association langID="36" id="ruby_function"/>
and the following in parsers list
<parser
id="ruby_function"
displayName="Ruby"
commentExpr="(?s:#.*?[\r\n]|(?-i:(?<=^|[\r\n])=begin).*?(?-i:[\r\n]=end(?=[\r\n]|$)))" >
<function
mainExpr="(?s:\b(?-i:def)[\t ]+(?!(?-i:alias|and|BEGIN|begin|break|case|class|def|defined\?|do|else|elsif|END|end|ensure|false|for|if|in|module|next|nil|not|or|redo|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield|__FILE__|__LINE__))(?:[A-Za-z_]\w*[?!=]?(?:[\t ]*\([^)]*\))?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&|\^]|<(?:<|=>?)?|>[>=]?|\[]=?)[\t ]*\([^)]*\)).+?(?-i:end))"
displayMode="$functionName" >
<functionName>
<nameExpr expr="(?s:\b(?-i:def)[\t ]+(?:[A-Za-z_]\w*[?!=]?(?:[\t ]*\()?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&|\^]|<(?:<|=>?)?|>[>=]?|\[]=?)[\t ]*\())" />
<nameExpr expr="(?m:\b(?-i:def)[\t ]+(?:[A-Za-z_]\w*[?!=]?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&|\^]|<(?:<|=>?)?|>[>=]?|\[]=?))(?=(?:\b|[\t ]*\()|.*$))" />
<nameExpr expr="[\t ]+(?:[A-Za-z_]\w*[?!=]?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&|\^]|<(?:<|=>?)?|>[>=]?|\[]=?))" />
<nameExpr expr="(?:[A-Za-z_]\w*[?!=]?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&|\^]|<(?:<|=>?)?|>[>=]?|\[]=?))" />
</functionName>
</function>
</parser>
This is not working with notepad++ 6.7.4 nor with 6.7.5
not working for 6.8.8
A much simpler parser that works for me:
<parser id="ruby_function" displayName="Ruby">
<function mainExpr="^\s*def\s+\w+" displayMode="$functionName" >
<functionName>
<nameExpr expr="(?<=def\s)\w+" />
</functionName>
</function>
</parser>
Note the association map thing and make sure you are editing the right functionList.xml (the user folder one probably)
A small evolution of the last comment to take classes into account :
<parser id="ruby_function" displayName="Ruby">
<!-- within a class-->
<classRange mainExpr="(?<=^class ).*?(?=\n\S|\Z)" displayMode="node" >
<className>
<nameExpr expr="\w+"/>
</className>
<function mainExpr="^\s*def\s+\w+" displayMode="$className->$functionName" >
<functionName>
<funcNameExpr expr="(?<=def\s)\w+"/>
</functionName>
</function>
</classRange>
<!-- without class-->
<function mainExpr="^\s*def\s+\w+" displayMode="$functionName" >
<functionName>
<nameExpr expr="(?<=def\s)\w+"/>
</functionName>
</function>
</parser>
change to
<function mainExpr="^[\s]*def[\s]+(self\.)?[\w_]+"> <functionName> <nameExpr expr="(?<=(def\s))(self\.)?[\w_]+"/> </functionName> </function>
and that will catch
def self.read() ... end
and
def read somarg ... end
change to
<function mainExpr="^[\s]*def[\s]+(self\.)?[\w_]+"> <functionName> <nameExpr expr="(?<=(def\s))(self\.)?[\w_]+"/> </functionName> </function>
and that will catch
def self.read() ... end
and
def read somarg ... end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you're on SourceForge, can you link this from http://sourceforge.net/p/notepad-plus/discussion/331753/thread/b9d2fe00/ ?