add comment to text files
-
one thing i forgot to mention:
if you enter txt in the Ext.: field (location: see the screenshot above)
all your txt files will be opened using your user defined language
(this overrides the extension setting for “Normal Text”) -
I do not want to create new language, I would like to change how txt are open by default.
-
You can tell it to open .txt as a different language… but you cannot arbitrarily add new “styles” (like “comment”) to the Normal Text lexer. The Preferences > Style Configurator will show you all the available styles for any given language: the “Normal Text” language gets its styles from the Configurator’s Language: Global Styles. You’ll notice that “comment” is not an available choice: that dialog lists all the styles that a given Language’s lexer understands. The normal-text lexer does not know about comments, thus when you put in a line in the config files to try to define the “COMMENT” style, it never applies that style to anything, because the lexer doesn’t identify anything as “COMMENT”, so it never chooses that style.
Your options at this point are:
- Use a UDL, as suggested,
or - Assign the
.txt
extension to some other language which already uses#
to prefix comments (bash, Perl, and Python are three that come to mind).
The problem with this second method is that all those languages will also strangely highlight your other text, which looks like rather malformed syntax for the selected language.
But if you want to be able to define a syntax like “comment” for
.txt
files, you are going to have to associate it with something other than Normal Text. Sorry. - Use a UDL, as suggested,
-
i’m sorry too if the udl suggestion offended you.
it was just to get you going within seconds, letting you style # remark lines on every .txt file as you desired.one other thing i noticed in your test langs.xml:
comment start and comment end have to be different strings for technical reasons.
eg: /* for comment start and */ for comment end instead of / for both.
this applies everywhere, including udl. -
@notepad347 said:
I do not want to create new language, I would like to change how txt are open by default.
@Meta-Chuh said:
i’m sorry too if the udl suggestion offended you.
@Meta-Chuh, sigh, people just want what they want, and too easily dismiss things that aren’t exactly that. People take time here to ponder solutions and type it up (look at how much quantity @PeterJones always puts into his posts), only to be summarily dismissed with a short sentence.
So I say, “Fine, don’t take any of the suggestions, and then don’t have your desired functionality; nobody suffers but you.”
-
@Scott-Sumner
yes, yet still people like us keep helping out for same, similar, and different reasons ;-)i for example originally signed up here, after a year or so of being a guest reader, specifically for this reason:
just to upvote helpful posts i read (yes, many of yours), regardless if needed the information myself or not
(even trying out almost everything if it would or could work for the op before an upvote)
to show some deserved and sometimes overdue 3rd party gratitude, especially because quite a few op’s didn’t (and still don’t) reply even with a simple “works” or “doesn’t work for me”.(so if anyone ever asked themselves why someone, without any own questions or posts back then, had upvoted them, this is the plain reason)
you know i’m not completely selfless, nor a samaritan, but i know that gratitude is sometimes only shown if all people that could help, stop helping for a while, and i know how i’d feel if it happens to me as often.
that was and is my main drive to continue to do so.on the other hand i also understand that a visitor (or long term absent like in this case) sometimes has a load of other things to do and simply either does not know that we aren’t paid employees of np++ (dim some) or someones who just want to channel their daily frustration somewhere they can simply log in via google (without having the obstacle of creating an explicit account)
i know, i know, this is all quite off topic, but being able to do so from time to time is a thing i also like around here :D
(i was a regular at galanter’s scifi bbs until it shut down and the writing styles, regulars, topics (including np++ from time to time) and unwritten rules were very similar to those of the np++ community as it is today.)@PeterJones
i’d tripple upvote your lexer explanation if i could … and i admire your sean connery style “never lose your temper” 👍 -
it is frustrating it does not exactly work the way I want, but I have now tried UDL and it works fine too. I also put on “operators & delimiters” tab in delimiter 1 style " for open and " for close so strings will be in color. I hope I use the correct tab and input field, because there are so many. But it works, so I guess yes.
But I notice when i put ># < in open for “comment line style” on “comment & number” tab (there is a space after #), it removes a space when i open notepad++ again.
Thank you all for help
-
@notepad347
You should create a user defined language who reach # as comment -
I also put on “operators & delimiters” tab in delimiter 1 style " for open and " for close so strings will be in color. I hope I use the correct tab and input field, because there are so many.
yes, that is the correct location
But I notice when i put ># < in open for “comment line style” on “comment & number” tab (there is a space after #), it removes a space when i open notepad++ again.
string delimiters can not contain nor end with spaces, spaces are only used to separate multiple string delimiters.
eg: you can have multiple comment line syntaxes if you type# // ::
in your comment line style > open field.
this makes it more flexible if you get txt files from people who use other remark marker/delimiter strings#this is a remark
# this too
// this too
:: this too
btw:
if you want to deploy your udl easily to other machines, just copy the xml file:
%appdata%\Notepad++\userDefineLang.xml
into the same location on the other machine.
(in case deploying to other machines was the reason why you wanted to do it via the default xml files in the first place) -
@Meta-Chuh said:
PeterJones…i admire your sean connery style “never lose your temper”
Hey, for the record, I don’t lose my temper…even if I get called a “f—king retard”! [In fact I was so “delighted” by that posting of a few days ago (reference not worth looking up) that I screenshotted it and put it in my “Gems” folder.]
But I do try to keep discussions here “on track” and I am rather “short” with posters that can’t ask a question clearly, or refuse to think things through, or just want to be demanding, or…the list goes on. Free software, free support…show some gratitude and forethought, people! :-)
But yes, I agree, @PeterJones has a style all his own! +1
-
even if i get called …
originally i had something about this and more in my post above, but i decided not to post it because it was too long and too much, even for myself.
one part of it was: noone here minds if you lose your temper from time to time, because you have had to deal with such cases the most of all, and if you do you do it with grace, reason and the regular’s support.
another part i removed was that i bet we lost a few very good people, like claudia, because they tend to take such encounters and even little things like a missing feedback emotionally with them, to the extent that they start thinking about it days after, even if they are not in front of any computer nor visiting this community … this makes me sad and i urge every visitor to treat everyone around here as they would treat a friend instead of a hotline kind of slave.
(prerequisite is that they treat friends as normal people do ;-) ) -
@Meta-Chuh said:
i bet we lost a few very good people, like claudia, because they tend to take such encounters …
So we are pretty far OT now…but I don’t want you to have a misperception about Claudia. She was much like Peter is here, very even keel emotionally and eager to keep helping even after being insulted; I observed that many times–not that she got insulted a lot, and certainly never called a “retard”–hehehe, still giggling…
My understanding is she stopped using Notepad++ because she wanted to use a product that was continually being improved–not that Notepad++ isn’t being improved, but that improvement moves too slowly for some peoples’ taste.
I tend to agree–my evidence is that I used 6.7.5 for the longest time, and currently my day-to-day use is 7.2.2, and I see no compelling feature additions (what version of Scintilla is Notepad++ using?–REALLY??) or bug fixes to make me move “forward”–in fact, I would move forward but bugs seem to be on the rise, not the opposite. If I had to pick a version post-7.2.2 I don’t know what that would be–certainly not 7.6.* with the PluginAdmin debacle going on… And…we still can’t “find-in-selection” or “replace-in-a-column-block” or…dang, I could go on all day with a list like this…
But for the moment, I happen to need a text editor, so (again, for the moment ) I’ll hang around. :-)
-
but I don’t want you to have a misperception about Claudia
one more reason why i originally didn’t post it.
just an expression how i would feel if i was her (or any other regular)so (again, for the moment ) I’ll hang around. :-)
hopefully as long as possible, otherwise i’d have to think about something i could do to lure you back here just for the fun of it ;-)
thank god that this is just a far and purely hypothetical future. -
So there is no way I can have a comment delimiter with a space, like hash and a space: ># < ?
-
So there is no way I can have one line comment delimiter with a space, like hash and a space: ># < ?
-
So there is no way I can have one line comment delimiter with a space, like hash and a space: ># < ?
yes, you are correct.
side info: same applies to keywords in programming languages.
so for example a command/function name that can be highlighted ispreg_replace
but if it would be calledpreg replace
the lexer would see it as 2 separate commands to be highlighted and highlight any occurrences ofpreg
as well as any occurrences ofreplace
, regardless if they are written together or not. -
thank you all for all the help, but I must say, notepad++ can be a pain, compare to sublime text I also use, you see, different tool for different tasks. But this community here is great, thanks.