Syntax for functionList.xml for R statistical programming language
-
I tried it. the script works.
-
@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:
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 expectingr.xml
as the functionList filename for the R syntax lexer, you don’t have to editoverrideMap.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 namedfunctionList
and instead just has a file calledfunctionList.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. -
Thanks for diving into this. I have been using Notepad++ for awhile, and have had to just deal with this issue.
I just updated to the latest version 8.4.4 before writing this note.
I don’t have the folder ‘functionList’ … I have a file ‘functionList.xml’ which I have hacked on several occasions to try and get R to work for my syntax …
Let me uninstall and reinstall. And see if this folder gets created …
-
I put an r.xml file into C:\Program… NOT %appdata% and it works as expected.
I am using Windows 10.
-
@Monte-Shaffer said in Syntax for functionList.xml for R statistical programming language:
just updated to the latest version 8.4.4 before writing this note.
I don’t have the folder ‘functionList’ … I have a file ‘functionList.xml’ which I have hacked on several occasions to try and get R to work for my syntax …That means you had upgraded from a copy of Notepad++ that pre-dated v7.9.1. the old
functionList.xml
will not work in v7.9.1 or newer (which includes Notepad++ v8.4.4).My guess as to why your r.xml wasn’t working for you was because you had conflicting configurations in
c:\program files\notepad++\functionList
compared to%AppData%\Notepad++\functionList\
To be 100% sure, I just verified with one of my UDL-based FunctionList definitions: my
c:\program files\Notepad++
doesn’t have afunctionList\
folder. My%AppData%\Notepad++
does have thefunctionList\
folder; in that folder are all the default function lists, plus my UDL-based function list file, plus the overrideMap which points to it.And I also tried, if I have one variant of my functionList\udl.xml in the installation folder hierarchy, and another variant in the %AppData% hierarchy, Notepad++ will use the one in
%AppData%
. -
@PeterJones Hello,
I do a full uninstall, removed the folders in both
Program Files
and%appdata%
before I did the reinstall. [Windows 10]I placed
r.xml
intoProgram Files
and it worked. Thank you.I think there is a bug in the REGEX, as it fails when you have nested parentheses.
education = function( options=c(1,2,3) ) { }
This is ALLOWABLE syntax which is failing to show in NOTEPAD++.
My life is so much easier with this, thank you!
-
@PeterJones I have had NOTEPAD++ on this laptop for a LONG, LONG time (6+ years).
I was doing some maintenance UPGRADES in R and thought ‘I wonder if I can get this syntax thing to work’ in NOTEPAD++, so here we are.
Here is the actual example of a function that I have failing:
stats.summary = function(x, tukey=TRUE, type=1, signif.digits=options("digits")$digits, names = c("min", "-Q1-", "median", "Mean", "-Q3-", "max"), ... ) { # do stuff here! }
Cheers,