Skip to content

Instantly share code, notes, and snippets.

@monban
Last active April 22, 2021 21:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monban/6133403 to your computer and use it in GitHub Desktop.
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
<!-- Author: Menno Vogels; Version: 1.0.0.0 -->
<parser
id="ruby_function"
displayName="Ruby"
commentExpr="(?s:#.*?[\r\n]|(?-i:(?&lt;=^|[\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})?|[~+\-/%&amp;|\^]|&lt;(?:&lt;|=&gt;?)?|&gt;[&gt;=]?|\[]=?)[\t ]*\([^)]*\)).+?(?-i:end))"
displayMode="$functionName" >
<functionName>
<nameExpr expr="(?s:\b(?-i:def)[\t ]+(?:[A-Za-z_]\w*[?!=]?(?:[\t ]*\()?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&amp;|\^]|&lt;(?:&lt;|=&gt;?)?|&gt;[&gt;=]?|\[]=?)[\t ]*\())" />
<nameExpr expr="(?m:\b(?-i:def)[\t ]+(?:[A-Za-z_]\w*[?!=]?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&amp;|\^]|&lt;(?:&lt;|=&gt;?)?|&gt;[&gt;=]?|\[]=?))(?=(?:\b|[\t ]*\()|.*$))" />
<nameExpr expr="[\t ]+(?:[A-Za-z_]\w*[?!=]?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&amp;|\^]|&lt;(?:&lt;|=&gt;?)?|&gt;[&gt;=]?|\[]=?))" />
<nameExpr expr="(?:[A-Za-z_]\w*[?!=]?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&amp;|\^]|&lt;(?:&lt;|=&gt;?)?|&gt;[&gt;=]?|\[]=?))" />
</functionName>
</function>
</parser>
@michaelblyons
Copy link

If you're on SourceForge, can you link this from http://sourceforge.net/p/notepad-plus/discussion/331753/thread/b9d2fe00/ ?

@jtzero
Copy link

jtzero commented Oct 3, 2013

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

@JoMazM
Copy link

JoMazM commented Feb 12, 2015

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:(?&lt;=^|[\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})?|[~+\-/%&amp;|\^]|&lt;(?:&lt;|=&gt;?)?|&gt;[&gt;=]?|\[]=?)[\t ]*\([^)]*\)).+?(?-i:end))"
        displayMode="$functionName" >
      <functionName>
        <nameExpr expr="(?s:\b(?-i:def)[\t ]+(?:[A-Za-z_]\w*[?!=]?(?:[\t ]*\()?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&amp;|\^]|&lt;(?:&lt;|=&gt;?)?|&gt;[&gt;=]?|\[]=?)[\t ]*\())" />
        <nameExpr expr="(?m:\b(?-i:def)[\t ]+(?:[A-Za-z_]\w*[?!=]?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&amp;|\^]|&lt;(?:&lt;|=&gt;?)?|&gt;[&gt;=]?|\[]=?))(?=(?:\b|[\t ]*\()|.*$))" />
        <nameExpr expr="[\t ]+(?:[A-Za-z_]\w*[?!=]?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&amp;|\^]|&lt;(?:&lt;|=&gt;?)?|&gt;[&gt;=]?|\[]=?))" />
        <nameExpr expr="(?:[A-Za-z_]\w*[?!=]?|(?::{2}|\*{1,2}|![=~]?|=(?:~|={1,2})?|[~+\-/%&amp;|\^]|&lt;(?:&lt;|=&gt;?)?|&gt;[&gt;=]?|\[]=?))" />
      </functionName>
    </function>
  </parser>

@paamonim
Copy link

This is not working with notepad++ 6.7.4 nor with 6.7.5

Copy link

ghost commented Jan 19, 2016

not working for 6.8.8

Copy link

ghost commented Jan 20, 2016

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)

@Jishin42
Copy link

A small evolution of the last comment to take classes into account :

         <parser id="ruby_function" displayName="Ruby">
            <!-- within a class-->
            <classRange mainExpr="(?&lt;=^class ).*?(?=\n\S|\Z)" displayMode="node" >
               <className>
                  <nameExpr expr="\w+"/>
               </className>
               <function mainExpr="^\s*def\s+\w+" displayMode="$className->$functionName" >
                  <functionName>
                     <funcNameExpr expr="(?&lt;=def\s)\w+"/>
                  </functionName>
               </function>                  
            </classRange>

            <!-- without class-->
            <function mainExpr="^\s*def\s+\w+" displayMode="$functionName" >
               <functionName>
                  <nameExpr expr="(?&lt;=def\s)\w+"/>
               </functionName>
            </function>
         </parser>

@sjn001tvh
Copy link

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