topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 9:50 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: notepad2-mod: custom code folding for txt files?  (Read 24294 times)

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
notepad2-mod: custom code folding for txt files?
« on: October 25, 2013, 04:41 PM »
I want to use the notepad2-mod code folding feature for note outlining. I would write notes using tabbed indentation to mark each sub level. Then use the code folding action to hide/show sub level text.

notepad2-mod presently does folding in tab indented python (.py) files. But I want it for .txt files and I want it without any text highlighting/coloring effects. Does any notepad2 user here think that is doable? Do you even have some idea on how to do it?

(Note: I searched but found no talk of this for notepad2. However, someone back in 2007 had the same idea for UltraEdit. )

Edit: view > Customize schemes... lists types of code files that notepad2 supports highlighting/folding for. I can simply remove .txt from "Default text" and add it under "Python". But then I also get all the other python highlighting for all txt files. I tried to export the schemes settings, copied and renamed the python section to a new name in the settings file and there removed all color highlighting. But that new section does not appear if I import the edited exported settings. I don't want to disable highlighting for all python files either because I have use for it there. Maybe there is some other code language that can be folded at tab or space indentations? Can anyone see one in this list:

list.png
« Last Edit: October 25, 2013, 05:22 PM by Nod5 »

Shades

  • Member
  • Joined in 2006
  • **
  • Posts: 2,939
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #1 on: October 25, 2013, 11:06 PM »
If you are not in the habit of creating installers for software you create, I would restructure one of those to implement your idea (Inno setup, NSIS).

Personally, what I use is Notepad++ and it can do what you ask...creating a new code format for your specific text files, it can do folding and has support for plugins. So if you are still missing functionality, you could peruse through the available plugins or boldly write one yourself.

Notepad2 is a decent text editor, but doesn't allow much beyond its capabilities...unfortunately. (unless forking is an option for you). By now I have seen more than one fork of the Notepad2 source, each addressing a problem specific to its author. Makes you kinda wish the Notepad2 software supported plugins.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #2 on: October 26, 2013, 05:25 AM »
Notepad2-mod is open source so I could attemp to modify this in the source (add a clone of the python syntax scheme that I can then in the UI remove coloring for and link to .txt files only while keeping the .py scheme as is). But that would take a lot of work. So I'll first look into repurposing one of the above throught the UI only. So the key question right now is: does anyone here spot a language in the list above that you know uses tabs/spaces at the start of lines as a separator instead of braces? Besides Python. Yes, I can research them one by one. But I hope someone here will spare me that by spotting one in the list immediately.

Shades

  • Member
  • Joined in 2006
  • **
  • Posts: 2,939
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #3 on: October 26, 2013, 11:21 AM »
With the example file I used (a batch script with a lot of sections) I saw that when I selected the Py scheme as the syntax scheme for this file, code folding options appeared.

With its basic structure, only the YAML, Visual Basic, VB Script, Cmake Script and AutoIt3 syntax schemes showed somewhat similar code folding options, so you likely could use any one of these.

Then I manually indented (4 spaces for each indentation) the content of this file...same set of syntax schemes do code folding.
Replaced all spaced indentations with tabbed indentations and again only the same set of syntax schemes do code folding.

I think it is safe to say that the code folding functionality doesn't respond to the use of tabs or spaces. None of the code folding in the other schemes matches the code folding from the Python syntax scheme, though.

To me it means that there are 3 main solutions to your question.
1. Do the cloning solution you mentioned in your last post in this thread.
2. Adjust the rules of the code folding functionality that is there.
3. Use different software.

For this small test I used Notepad2-mod 4.2.25.870 (64-bit zip).

dr_andus

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 851
    • View Profile
    • Dr Andus's toolbox
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #4 on: October 26, 2013, 04:08 PM »
3. Use different software.

This may not be what you're looking for, but Noteliner can be used as a fairly basic single-pane outliner (ignore the colours, tables, and Gantt chart in the screenshots, those are optional), and you can save its outlines as text files, where the hierarchy is preserved via tab indentation.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #5 on: October 26, 2013, 04:36 PM »
Thanks for testing Shades. I'm leaning towards 1. the cloning idea.

dr_andus: I really want to stick to plaintext .txt files. They just work, on any platform. With space/tab indentation the notes would still be nicely readable everywhere, only with some additional fold/unfold commands when reading in Notepad2-mod or other texteditors with folding.

dr_andus

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 851
    • View Profile
    • Dr Andus's toolbox
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #6 on: October 26, 2013, 06:41 PM »
dr_andus: I really want to stick to plaintext .txt files. They just work, on any platform. With space/tab indentation the notes would still be nicely readable everywhere, only with some additional fold/unfold commands when reading in Notepad2-mod or other texteditors with folding.

Let us know if you come up with/find something like that, I would be also interested. In the meantime I also thought of NoteTab's outlining feature, but that creates a .otl file and is a two-pane outliner, not folding in a single-pane.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #7 on: October 26, 2013, 10:12 PM »
In Notepad2-mod, if you remove all the colour styles from the YAML parser, add the txt extension to it, (and remove it from Default), then it will do folding in plain text files on TAB indents.

If you're not likely to use YAML for anything, this is probably the easiest way.

2013-10-27 14_12_39-test.txt [K__] - Notepad2-mod (Administrator).png

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #8 on: October 27, 2013, 04:14 AM »
Jackpot! Thank you 4wd. Folding works. I specified the comment syntax (everything after #) as bold headings and any word suffixed with : gets color background. edit: three hypens ( --- ) at the start of a line triggers the "Document" syntax for YAML, which can be used as a colored horizontal line separator.
n2.png   n.png

This is a very useful intermediate between "plain plaintext" and markdown.
http://www.codinghor...ure-of-markdown.html

edit: I also got curious on markdown text editors. Turns out there are lots of them. But I'll stick to the newfound notepad2 formatting for now.
« Last Edit: October 27, 2013, 09:31 AM by Nod5 »

dr_andus

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 851
    • View Profile
    • Dr Andus's toolbox
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #9 on: October 27, 2013, 07:02 AM »
Jackpot! Thank you 4wd. Folding works. I specified the comment syntax (everything after #) as bold headings and any word suffixed with : gets color background.

Would you mind sharing the file (if it doesn't contravene any legal or moral code)?

edit: I also got curious on markdown text editors. Turns out there are lots of them. But I'll stick to the newfound notepad2 formatting for now.

Most of those are for Macs, iOS or the web. I haven't come across that many decent Markdown editors for Windows. I tend to use WriteMonkey for now.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #10 on: October 27, 2013, 08:01 AM »
Except for a slight colour difference to Nod5's, the settings are attached.

I recommend you Export your current settings in case they differ from the default, otherwise I've included the default in the archive also.

In notepad2-mod, View->Customize Schemes ... and then Import the .ini file.

*.txt will now be identified as YAML files when opened and the relevant formatting applied.

Change the colour and/or text styles to suit your needs.

You can use WinMerge, BeyondCompare or similar to see the differences between the default and modified files.

Shades

  • Member
  • Joined in 2006
  • **
  • Posts: 2,939
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #11 on: October 27, 2013, 08:05 AM »
Now this is weird:

The first result from using YAML scheme went (very) wrong:
YAML_bad_foldingA.png
YAML_bad_foldingB.png

Using a shortened version of my test file went ok:
YAML_good_folding_spaces.png (spaces)
YAML_good_folding_tabs.png (tabs)

And then I reloaded the original test file and all folding went ok in there as well. Odd.

This occurred in this version of NotePad2-mod
Notepad2_version.png

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #12 on: October 27, 2013, 08:09 AM »
The first result from using YAML scheme went (very) wrong:

I noticed that when I was initially playing with it, editing things in and out but, as you found, reloading the file seemed to fix it up.

Do you have Insert TABs as Spaces set, (I do) ?

Shades

  • Member
  • Joined in 2006
  • **
  • Posts: 2,939
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #13 on: October 27, 2013, 09:06 AM »
No, I didn't set that option, although I don't like to use tabs for indentations. But that is a discussion for another thread (which very likely ends up in the Basement after the tenth post... :P).

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #14 on: October 27, 2013, 09:34 AM »
Shades, it feels like the modified syntax scheme doesn't always stick. But I just retried and restarted Notepad2 and then it worked.

One more thing in the YAML syntax to make use of: three hypens ( --- ) at the start of a line triggers the "Document" syntax for YAML, which can be used as a colored horizontal line separator.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #15 on: October 27, 2013, 09:42 AM »
dr_andus: the changes are easy to do manually.

First click view > customize schemes...

Then in the popup window:
- Default text > associated filename editbox: remove txt
- YAML > associated filename editbox: add txt
- YAML >
comment: change to: bold; fore:#0A246A
identifier: change to: bold; fore:#0A246A;back:#D7D7FF
error: clear the style editbox

I think that is it. There are some settings left but I haven't seen them get triggered accidentally in any textfile so far. The popup has dialogs for quickly changing any color and there is a list of possible variables to use.

dr_andus

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 851
    • View Profile
    • Dr Andus's toolbox
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #16 on: November 02, 2013, 04:10 PM »
Nod5 - many thanks for the detailed instructions. Works like a charm! This must be one of the simplest outliners out there...

dojibear

  • Participant
  • Joined in 2012
  • *
  • default avatar
  • Posts: 3
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #17 on: February 24, 2014, 11:17 PM »
How do you create a "fold point"?


Looking for an outliner, followed Dr. Andus here. Clearly to use as an outline, you can set up a hierarchy and collapse/uncollapes portions. Elesewhere I find lists of commands to fold and unfold "fold points" and to jump to the next one. But no explanation of how to turn some parts of a plain text file into a "fold point".

<edit> never mind, I found the problem. I would delete "txt" from the list in Default, click OK, and something somewhere would put it back in. So I was never in the mode that did outlining. Finally I made YAML the default mode, and it works okay. The "fold points" are clearly marked.
« Last Edit: February 25, 2014, 12:45 AM by dojibear »

peter.s

  • Participant
  • Joined in 2013
  • *
  • default avatar
  • Posts: 116
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #18 on: February 27, 2014, 02:55 PM »
"Code Browser" (freeware) has some good explanations on different folding paradigms.

But I doubt ANY editor is perfect for managing text snippets (and even for coding) since they all seem to present that common prob that you have not only to code / mark up the folding point (begin=not hidden title of the hidden text part), but also the end point of that hidden structure, again and again, and it does NOT seem to be possible in any of them to define ANY "begin new part (hidden except for its title line)" code (= begin), as the END of the previous hidden structure, so there is a lot of (imo) unnecessary "hide mark-up" to do here.

On the other hand, most 2-pane outliners perfectly export to plain-text .txt files, so why not manage your code within such an outliner and have the exported text file compiled then; this makes available rtf formatting within the "work copy" of your code, which I find extremely helpful.

All the more so with text notes: Almost any dedicated 2-pane outliner does the M of text notes in a perfect way; why bother with the very limited capabilities of editors (folding or not) instead?

Of course, a 1-pane outliner would often be the worst solution: It lacks many capabilities of editors, and it doesn't offer the clarity of a 2-pane outliner either (which will become very important if you have hundreds or thousands of such items (or folded text bodies within your .txt file).

Again, a capable pc can export thousands of items of a 2-pane outliner into the corresponding .txt files within a second, and with a macro, you can automate this transition from outlining to file-for-compilation (which is not even necessary for text notes, compared with source code), so why clinging to bad editor solutions when there are better, i.e. more appropriate ones?

This being said, I'd be interested in knowing a folding editor in which you would just do some special char before title lines, and which would then fold anything else (folding editor, I said, i.e. not speaking of KEdit and such here, bec there is a prob with those whenever you then want to see the text underneath such a title line, and just that part).

More info would be more than welcome.
When the wise points to the moon, the moron just looks at his pointer. China.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #19 on: March 07, 2014, 05:38 AM »
I'm late on the ball with a reply but here goes: by modifying the YAML syntax in notepad2-mod you can simply use tab indentation. Write a header line without indentation, press enter, press tab, start typing. There is the fold point for you. Notepad2-mod then autoindents to the same tab level on each enter. To end the fold just start a new line without indentation. This is very easy to do and remember and avoids cluttering the text with extra tags/code. Very usful for notes that that fit well in a nested format. Fold all to get a zoomed out view. Unfold for details.

dr_andus

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 851
    • View Profile
    • Dr Andus's toolbox
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #20 on: December 07, 2015, 07:59 AM »
three hypens ( --- ) at the start of a line triggers the "Document" syntax for YAML, which can be used as a colored horizontal line separator.

I had to reinstall Notepad2-mod on a new Win7, 64-bit machine (using the most recent Notepad2-mod (64-bit) v. 4.2.25 r964 (ba441e6)), and for some reason I'm unable to import my old settings, so I tried to recreate the YAML scheme from scratch.

Was it just my imagination or were three hyphens ( --- ) supposed to trigger a horizontal rule that stretched across the entire line or only until you kept adding hyphens (-------------), which is the current behaviour?

dr_andus

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 851
    • View Profile
    • Dr Andus's toolbox
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #21 on: December 08, 2015, 08:31 AM »
I specified the comment syntax (everything after #) as bold headings and any word suffixed with : gets color background.

This also stopped working for me for some reason  :(

Now comment highligthing after hash (#) and colon (:) only works if the line does not start with a Tab. I don't mind that behaviour for the colon (actually I prefer it), but with # this means I can't use them for folding Markdown headers because I can't create foldable sub-headings by hitting Tab and starting a level 2 (##) etc. heading.

Actually starting the line with # even prevents the creation of a folding point now, so it definitely doesn't work for use as Markdown headings.

Any ideas how to fix this? It used to work before.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #22 on: December 13, 2015, 02:57 PM »
Hi, the old steps still work for me

First click view > customize schemes...
Then in the popup window:
- Default text > associated filename editbox: remove txt
- YAML > associated filename editbox: add txt
- YAML >
comment: change to: bold; fore:#0A246A
identifier: change to: bold; fore:#0A246A;back:#D7D7FF
error: clear the style editbox
document: back:#DDDDFF

Now comment highligthing after hash (#) and colon (:) only works if the line does not start with a Tab.
IIRC it always was like that. But you can enable settings > Insert Tabs as Spaces and then #example will be styled even if tab indented.

Was it just my imagination or were three hyphens ( --- ) supposed to trigger a horizontal rule that stretched across the entire line or only until you kept adding hyphens (-------------), which is the current behaviour?

That is configurable. Change from
document: back:#DDDDFF
to
document: back:#DDDDFF; eolfilled
and the color will be to the end of the line filled

dr_andus

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 851
    • View Profile
    • Dr Andus's toolbox
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #23 on: December 14, 2015, 04:17 AM »
Nod5

Thank you very much for your time, it's all working now as expected.  :Thmbsup:

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: notepad2-mod: custom code folding for txt files?
« Reply #24 on: December 14, 2015, 02:00 PM »
Glad to help  :Thmbsup: