Syntax for functionList.xml for R statistical programming language



  • Hi,

    I use Notepad++ for javascript and PHP and the function list seems to work as expected.

    Not so much for R. No workee. Please help.

    education = function(one)
    	{
    	result = list();
    		result$who 		= one;
    		result$think 	= c("intensitively", "critically");
    		result$goal 	= "intelligences + character";
    	result;	
    	}
    	
    me = education("R");
    me;
    

    is how I format a function using R. The equal operator (=) can also be an assignment (<-) and means the same. Obviously, the nature of the tabbing of the braces may be arbitrary from user to user …

    Please advise …

    QUOTE:
    The function of education is to teach one to think intensively and to think critically. Intelligence plus character – that is the goal of true education. – Martin Luther King, Jr.



  • @Monte-Shaffer said in Syntax for functionList.xml for R statistical programming language:

    Not so much for R. No workee. Please help.

    Have a look here:
    https://github.com/MAPJe71/Languages/tree/master/R

    @MAPJe71 maintains quite the collection of Function List parsers and contributes on this Community as well.

    Cheers.



  • I have tried to merge the solution you suggested: https://github.com/MAPJe71/Languages/blob/master/R/Config/functionList-R.xml

    It just doesn’t work as expected. The UDL format works great, when it works.

    Any ideas?



  • @Monte-Shaffer said in Syntax for functionList.xml for R statistical programming language:

    Any ideas?

    There is another option with ctags.
    Can be easily programmed.
    Unless of course ctags is able to parse your code.
    https://github.com/universal-ctags/ctags



  • @TroshinDV
    +
    I have a javascript script that does this.
    https://github.com/trdm/jn-npp-scripts/blob/master/includes/Intell.js
    This script builds a list from the ctags output and allows code jumping.
    something like this: https://raw.githubusercontent.com/trdm/jn-npp-scripts/master/Doc/funclist.js.gif
    repo: https://github.com/trdm/jn-npp-scripts



  • I tried it. the script works.
    Screenshot_17.png



  • @Monte-Shaffer said in Syntax for functionList.xml for R statistical programming language:

    I have tried to merge the solution you suggested: https://github.com/MAPJe71/Languages/blob/master/R/Config/functionList-R.xml

    It just doesn’t work as expected. The UDL format works great, when it works.

    Any ideas?

    It works for me:

    9b30d28e-08ee-4b04-91a2-84ea6cdb1a97-image.png

    Before following @TroshinDV’s advice to use a completely separate program to accomplish your task, rather than using the fully-functional Function List feature that’s built into Notepad++, I suggest you work with us to troubleshoot what’s going wrong with your configuration – because the feature does work, as my screenshot shows.

    What version of Notepad++ are you using? The easiest way to let us know is to go to your ? menu and click on Debug Info, then click Copy debug info into clipboard and paste in your reply.

    The version is important because the Function List configuration changed significantly recently. If you are using v7.9.1, it will not be the same configuration as it was in v7.9.0 and earlier. Once you know which version, you need to go into the right section of the usermanual’s Config Files: Function List and follow those instructions.

    For example, in my v7.9.1 (from the screenshot above), I added a file called r.xml to the %AppData%\Notepad++\functionList\ folder 🛈. I built that file using the header/structure from another XML in that folder, and overwrote the <parser> section with the <parser> section from @MAPJe71’s archive. Thus, my %AppData%\Notepad++\functionList\r.xml looks like:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!-- ==========================================================================\
    |
    |   To learn how to make your own language parser, please check the following
    |   link:
    |       https://npp-user-manual.org/docs/function-list/
    |
    \=========================================================================== -->
    <NotepadPlus>
    	<functionList>
    			<parser
    				displayName="[TODO] R"
    				id         ="r_function"
    				commentExpr="(?x)                                               # free-spacing (see `RegEx - Pattern Modifiers`)
    						(?m-s:\x23.*$)                                          # Single Line Comment
    					"
    			>
    				<function
    					mainExpr="(?x)                                              # free-spacing (see `RegEx - Pattern Modifiers`)
    							(?m-s)                                              # ^ and $ match at line-breaks, dot does not
    							(?:^|;)
    							\s*
    							(?'ID'
    								[A-Za-z][\w.]*
    							|
    								\.[A-Za-z_.][\w.]*
    							)
    							\s*
    							(?:
    								\x3C-
    							|
    								=
    							)
    							\s*
    							(?-i:function)
    							\s*
    							\(
    							[^()]*
    							\)
    						"
    				>
    					<functionName>
    						<nameExpr expr="(?'ID'[A-Za-z][\w.]*|\.[A-Za-z_.][\w.]*)(?=\s*(?:\x3C-|=))" />
    					</functionName>
    				</function>
    			</parser>
    	</functionList>
    </NotepadPlus>
    

    Because R uses a builtin syntax lexer, and the v7.9.1 %AppData%\Notepad++\functionList\overrideMap.xml already shows that it’s expecting r.xml as the functionList filename for the R syntax lexer, you don’t have to edit overrideMap.xml.

    When I save that file, exit Notepad++ completely (no open Notepad++ windows), open a new Notepad++ instance, and open 19946.r, I got the Function List result shown in my screenshot above.

    If you are using v7.9.1, but %AppData%\Notepad++\ does not contain a folder named functionList and instead just has a file called functionList.xml, let us know – it means that the v7.9.1 update didn’t populate the new config files (probably because of this known issue) – if it didn’t, we can help you get the files you need… but you’ll have to let us know.

    If you are in a version earlier than v7.9.1, follow the instructions for those from the usermanual (linked above). If you need help after reading the “v7.9 and previous versions” section, I can give an example similar to what I just gave.

    ----
    Caveat: all these instructions assume v7.9.1 with a normal installation using %AppData% for storing config files. The ? > Debug Info will confirm or contradict this. If this is wrong, the instructions will change slightly, but we will still be able to make this work. Don’t give up yet.



  • @PeterJones said in Syntax for functionList.xml for R statistical programming language:

    Before following @TroshinDV’s advice to use a completely separate program to accomplish your task, rather than using the fully-functional Function List feature that’s built into Notepad++, I suggest you work with us to troubleshoot what’s going wrong with your configuration – because the feature does work, as my screenshot shows.

    Not every programming language lends itself to regular expressions.
    I already use ctags for hints on methods and code for jumping. And not only ctags.
    And I prefer to work not with the mouse, but with the keyboard.
    It’s easier and faster to press the hot key Ctrl + 1 or Ctrl + 2, Ctrl + 3 and enter a fragment of the name of the method / variable / database table than to poke with the mouse :)



  • @TroshinDV said in Syntax for functionList.xml for R statistical programming language:

    Not every programming language lends itself to regular expressions.
    I already use ctags …

    I guess that implies that ctags has a character-oriented parser builtin for R. It doesn’t for every language, and on languages where it doesn’t have that built in, it can use regular expressions. 🛈

    I already use ctags for hints on methods and code for jumping. And not only ctags.

    Good for you.

    But when there’s a builtin feature that works, and does what the OP requested, I tend to recommend that first. If you want to use something different, that’s fine; if you want to recommend something different, you’re allowed to – though I (or anyone else) am allowed to disagree with that recommendation.

    And I prefer to work not with the mouse, but with the keyboard.

    I’m not sure what that has to do with anything. The Shortcut Mapper (at least in v7.9.1) has the ability to assign keystrokes to Toggle Function List and Switch to Function List; and once you’re in the Function List pane, arrow keys will navigate between the functions and ENTER will take you back to the editor at the right location for the function.

    You might prefer your solution to what’s built into Notepad++. But I think the OP should first try learning how to properly use the builtin Function List feature… and then, only if the they think that it’s not sufficient for their needs should they try an external solution – but that’s just my opinion, and thus how I will recommend things.



  • @PeterJones I understand you. Yes, we should recommend using the built-in tools.
    What can you do, I started working on my way back in 2018. And I used legal tools like the jN plugin and ctags. And the old active-x.


Log in to reply