Is there a way to highlight section titles and have a content summary in Notepad++ ?
-
@oeloo said in Is there a way to highlight section titles and have a content summary in Notepad++ ?:
I just need an easier way to view/navigate inside.
I guess I’m not sure then what you expect a text editor to be able to do for you in this regard…do YOU have some specific ideas? If so, maybe we can make further suggestions…
-
@oeloo said in Is there a way to highlight section titles and have a content summary in Notepad++ ?:
I just need an easier way to view/navigate inside.
My first thought after reading your request: since your file seems to have a pretty regular structure, where each section has an obvious
#.
prefix followed by a space then a title, you might be able to figure out a way to make a FunctionList definition for your file (View > Function List). Each “function” shown in the FunctionList could be one of your header lines, with its title text. Depending on your definition of “easy to view/navigate”, that configurable feature might be sufficient for you.Create a dummy User Defined Language (UDL) for your file type (I called it “Oeloo”; make it something meaningful to you): if it always uses the same unique extension (for example
.oeloo
), then put that in the extensions list for the UDL; if your file type has a generic extension (.txt
), you might have to always manually select the UDL using Language > Oeloo to get the Function List to work.Once the UDL is created, you can create a FunctionList definition for that UDL. See the Useful Reference to figure out where the FunctionList definition goes, and what you need to change to get Notepad++ to do a FunctionList for that UDL.
For the FunctionList “function name” regex, I would suggest something like one of the following:
- If you want any level of header to be shown in the FunctionList panel,
(?-s)^(\d+\.)+\h.*
(to capture one or more instances of digit(s)-then-decimal-point as the prefix) - If you want just a few levels of header, then limit it; for example, if you want to show only level-1 or level-2 headers in the panel, then use
(?-s)^(\d\.){1,2}\h.*
(which only accepts1.
or2.3.
as prefixes, but will ignore4.5.6.
)
After creating
oeloo.xml
in the right place (thefunctionList\
folder), and editingoverrideMap.xml
(in the same folder) to include that line, then restarting Notepad++, when you define a file as beeing Language > Oeloo, the Function List panel will show the outline, and double-clicking on the entries there will navigate to that location in your file. (If you had to use Language > Oeloo to change to the UDL language for your.txt
file, you may have to hit the ⟳ refresh button in the panel to get it to show the Function List(Here’s are example
oeloo.xml
files for both use cases:- allows any number of levels in the list
oeloo.xml
:<?xml version="1.0" encoding="UTF-8" ?> <NotepadPlus> <functionList> <parser displayName="Oeloo" id ="oeloo_outline" commentExpr="" > <function mainExpr="(?-s)^(\d+\.)+\h.*" displayMode="$functionName"> <functionName> <nameExpr expr="(?-s)^(\d+\.)+\h.*"/> </functionName> </function> </parser> </functionList> </NotepadPlus>
- only allows 1 or 2 levels of header in the list:
oeloo.xml
:<?xml version="1.0" encoding="UTF-8" ?> <NotepadPlus> <functionList> <parser displayName="Oeloo" id ="oeloo_outline" commentExpr="" > <function mainExpr="(?-s)^(\d+\.){1,2}\h.*" displayMode="$functionName"> <functionName> <nameExpr expr="(?-s)^(\d+\.){1,2}\h.*"/> </functionName> </function> </parser> </functionList> </NotepadPlus>
and finally, in my
overrideMap.xml
(described in the resources below), I use the following line to tell Notepad++ to useoeloo.xml
for FunctionList definitions on the Oeloo UDL:<association id= "oeloo.xml" userDefinedLangName="Oeloo"/>
These examples should get you started.
Note: I called it “Oeloo” after your username. But after generating all the files and screenshots, I realized I should have just called it “Outlining” or something similar, whereupon it would be generically useful. I didn’t feel like regenerating files/screenshots, but if you don’t have any other name in mind, “Outlining” might be a good name.
Useful References
- If you want any level of header to be shown in the FunctionList panel,
-
@PeterJones Thank you for your nice suggestion.
I have tried to use it but it seems I am missing a step. Here is what I have done following the instructions:
1/ I have created the file C:\Program Files\Notepad++\functionList\oleoo.xml and copied your 1st example:
<?xml version="1.0" encoding="UTF-8" ?> <NotepadPlus> <functionList> <parser displayName="Oeloo" id ="oeloo_outline" commentExpr="" > <function mainExpr="(?-s)^(\d+\.)+\h.*" displayMode="$functionName"> <functionName> <nameExpr expr="(?-s)^(\d+\.)+\h.*"/> </functionName> </function> </parser> </functionList> </NotepadPlus>
2/ Then I have modified *C:\Program Files\Notepad++\functionList\overrideMap.xml by adding this line:
3/ I have restarted Notepad++
4/ I open my file with extension .oleoo*
But I do not have Oleoo in the Language menu :
-
@oeloo said in Is there a way to highlight section titles and have a content summary in Notepad++ ?:
But I do not have Oleoo in the Language menu :
As I said, “Create a dummy User Defined Language (UDL) for your file type”. Language > User Defined Language > Define Your Language. Save as Oeloo. Fill in
oeloo
in the Ext: entry. Since you created/loaded the file before you had defined the language, you will need to manually choose Language > Oeloo (it will be below the User Defined Language and not in the O submenu), and may need to ⟳ refresh the Function List and/or restart Notepad++ to get things in the right order (in my original description, creating the UDL came first; I don’t remember whether or not you have to restart if the UDL was created after the Function List was defined and N++ was restarted) -
I have added the entry UDL for Oleoo :
Then I have the menu :
But when I click on Oleoo in the above menu I get this :
What do I have these white highlightings ?I have removed oleoo several times completely and re-done the process exactly as you wrote. I have also fully restarted my PC each time to be sure of the result.
-
@oeloo ,
Any UDL defaults to black text on white background; when you have a dark theme, that conflicts. (By dark theme, I mean Dark Mode, and/or any of the themes that use light-text-on-dark-background)
To fix your UDL text colors: go to Language > User Defined Language > Define Your Language, choose
Oeloo
from the drop-down. Click Styler in theDefault Style
, and right-click on bothForeground color
andBackground color
’s color box. And un-checkmark the Bold/Italic/Underline boxes, if they are checkmarked.Now the dummy UDL “Oeloo” will inherit the colors from your active theme.
Before:
After:
—
update: nearly four years ago, issue #5622 was submitted to request that new UDLs should use the active theme. You might want to upvote that request, though after languishing 4 years, I am doubtful any action will be taken on that request. -
@PeterJones
I have modified the UDL according to the instructions:
The highlighting in white of the whole text is fixed, but I have the number at the end of lines still highlighted in white:
-
@oeloo ,
After you saw that numbers still looked weird, did you try to explore the rest of the UDL dialog, looking for ways to change the colors? Did the tab name Comment & Number not tell you “here would be the place to change the colors for Numbers”? When you went there, did you try changing the Styler for numbers?
Since you had to ask this folloup, I am forced to conclude “No” is the answer to all those. Then why not? I can understand the original confusion, because I hadn’t mentioned stylers (because I didn’t realize it was relevant to you). But now that I’ve pointed out that button, I don’t understand why you didn’t at least look for similar color settings throughout the UDL dialog for setting the colors for the numbers.
-
@PeterJones
The tab named ‘Comment & Number’ does not show this sentence:
did you try to explore the rest of the UDL dialog, looking for ways to change the colors?
When you went there, did you try changing the Styler for numbers?
I did not tried to change anything else, I changed directly what you recommended.But now that I’ve pointed out that button, I don’t understand why you didn’t at least look for similar color settings throughout the UDL dialog for setting the colors for the numbers.
Which Styler button are you referring to: the one in ‘Number style’ ? -
The tab named ‘Comment & Number’ does not show this sentence:
Sorry, I assumed that “did you try changing the Styler for numbers” would lead you to the “Number Style” section to click on the Stylers button.
I did not tried to change anything else, I changed directly what you recommended.
For the first problem – the main text showing up inverted – that makes sense. But when you had a problem with numbers, I would have hoped that you would learn from the first lesson and generalize. I cannot possibly anticipate every problem you might have, and, as my time in this forum is just on a volunteer basis, I cannot spend all my time exploring every possible problem someone might have implementing my advice.
Which Styler button are you referring to: the one in ‘Number style’ ?
Yes.