Customizing for COBOL
-
Currently the settings I use with NotePad++ gives this view
But I would love to have this view
I also need to add tab stops at columns 7,8, 12 and 72 (hoping the tab stop would show as a vertical column).
I don’t know anything about customization, fonts, etc. Could some one give me a hint.I particularly like the font above. Where to start? What to do?
-
Npp provides something called themes.
See here for more information about it. If something is unclear let us know. -
Do you know of a theme for COBOL language? Thanks.
-
Here is a misunderstanding, a theme is not for one language but for all. Npp comes with a whole bunch of them, which ones have you tried?
-
@Ekopalypse Thanks.
-
@Emmad-Kareem said in Customizing for COBOL:
Do you know of a theme for COBOL language? Thanks.
As @Ekopalypse states, there are many themes for “all” languages, not a specific theme for a specific language. That said, many of the themes in the Notepad++/themes directory have not been updated for quite some time and thus do not reflect the latest changes / additions of languages in Notepad++. For example, I use a custom theme based off the Oblivion theme and in checking this question, realized my theme did not have the Cobol language - so no styling.
Pick the theme you want. If Cobol files do not have styling, the language probably isn’t included in your theme.
- Close Notepad++
- Open the theme file
Notepad++/themes/YOUR_THEME_FILE.xml
with Windows Notepad and open theNotepad++/stylers.xml
. - Copy the relevant section from
Notepad++/stylers.xml
intoNotepad++/themes/YOUR_THEME_FILE.xml
and save. - Reopen Notepad++ and open your Cobol file. It should be styled, probably not to your liking.
- Use the Settings => Style Configurator to adjust the colors for your language (Cobol).
To get you started, here is the relevant Cobol section from my theme:
<LexerType name="cobol" desc="COBOL" ext=""> <WordsStyle name="PREPROCESSOR" styleID="9" fgColor="A082BD" bgColor="293134" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="DEFAULT" styleID="11" fgColor="E0E2E4" bgColor="293134" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="DECLARATION" styleID="5" fgColor="A082BD" bgColor="293134" fontName="" fontStyle="1" fontSize="" keywordClass="instre1" /> <WordsStyle name="INSTRUCTION WORD" styleID="16" fgColor="93C763" bgColor="293134" fontName="" fontStyle="1" fontSize="" keywordClass="instre2" /> <WordsStyle name="KEYWORD" styleID="8" fgColor="93C763" bgColor="293134" fontName="" fontStyle="0" fontSize="" keywordClass="type1" /> <WordsStyle name="NUMBER" styleID="4" fgColor="FFCD22" bgColor="293134" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="STRING" styleID="6" fgColor="EC7600" bgColor="293134" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="CHARACTER" styleID="7" fgColor="FF8409" bgColor="293134" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="OPERATOR" styleID="10" fgColor="E8E2B7" bgColor="293134" fontName="" fontStyle="1" fontSize="" /> <WordsStyle name="COMMENT" styleID="1" fgColor="66747B" bgColor="293134" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="COMMENT LINE" styleID="2" fgColor="66747B" bgColor="293134" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="COMMENT DOC" styleID="3" fgColor="66747B" bgColor="293134" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="COMMENT LINE DOC" styleID="15" fgColor="66747B" bgColor="293134" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="COMMENT DOC KEYWORD" styleID="17" fgColor="66747B" bgColor="293134" fontName="" fontStyle="1" fontSize="" /> <WordsStyle name="COMMENT DOC KEYWORD ERROR" styleID="18" fgColor="FF4040" bgColor="293134" fontName="" fontStyle="0" fontSize="" /> </LexerType>
Cheers.
-
@Emmad-Kareem said in Customizing for COBOL:
I also need to add tab stops at columns 7,8, 12 and 72
Thus far this part of the OP’s question has been missed by the responders. I can’t recall if this one has come up before, but it sure seems like it would have.
Can Notepad++/Scintilla handle variable-width tab stop positions?
-
@Alan-Kilborn said in Customizing for COBOL:
Can Notepad++/Scintilla handle variable-width tab stop positions?
see discussion https://community.notepad-plus-plus.org/topic/18429/need-to-set-tab-stops-not-spacing from a couple years ago. @Ekopalypse was able to get the SCI_CLEARTABSTOPS/SCI_ADDTABSTOP messages via the PythonScript interface
editor.clearTabStops()
/editor.addTabStop()
to set up a custom set of tab locations. Unfortunately, it’s on a per-line basis, and has to be re-applied frequently (every time the buffer is updated). Also, that sets it in pixels, not in characters, so you need to do some sort of conversion factor to convert character location to pixels.My guess is that it would need to be something like the following. Please note this is just a proof of concept and should be treated as code that would need debugging and extra work to make it 100%.
# encoding=utf-8 """in response to https://community.notepad-plus-plus.org/topic/21689/""" from Npp import * cols = (7,8,12, 72) pixperchar = 8 def set_tab_via_callback(): for linenum in range(editor.getLineCount()): editor.clearTabStops(linenum) for tabcol in cols: editor.addTabStop(linenum, tabcol*pixperchar) set_tab_via_callback()
Instead of manually running the
set_tab_via_callback()
, you would have to add callbacks for that function; Eko’s post linked earlier hints at which callbacks are needed; you’d also need to calculate or hardcode the rightpixperchar
to convert characters to pixels correctly for your font; you’d probably also want a check in the callback to make sure it only runs the tab-changer if the active file is COBOL.Maybe Eko still has the example code that was played with (but not published) in that previous topic.
----
PS (edit): I forgot to mention that I had to go to Settings > Preferences > Language > Tab Settings, and setcobol
to not replace by space:
-
Here is what I posted at github regarding the language specific tab width.
-
@Ekopalypse said in Customizing for COBOL:
Here is what I posted at github regarding the language specific tab width.
That looks more like multiEdge than tabs, unless I’ve misunderstood. But the same basic concept should work (replacing the vertical edge clearing with a per-line loop that clears the tabs, and replacing the multiEdge adding with loops like add the tabs in a per-line loop.
-
you are right - my bad.
-
This merger of Eko’s script and mine comes close… I merged my proof-of-concept with Eko’s fancy wrapper-registering to give different updates on a per-language basis, and then checked against the suggested flow from 2 years ago
But I couldn’t find what message(s) were meant by the suggested
on_update_ui
. I think it might have to be one or more Scintilla Notifications for that, so it would use a separateeditor.addCallback()
in addition to thenotepad.addCallback()
So with this version, it will update the tabs whenever you change into a COBOL window or switch the active file’s language to COBOL from something else.
# encoding=utf-8 """in response to https://community.notepad-plus-plus.org/topic/21689/ Merge my suggestion with Eko's pointer to https://github.com/notepad-plus-plus/notepad-plus-plus/issues/9296#issuecomment-751706154 """ from Npp import editor, notepad, NOTIFICATION, EDGEVISUALSTYLE TAB_CONFIG = {} pixperchar = 8 def register_lang(func): def wrapped(): for linenum in range(editor.getLineCount()): editor.clearTabStops(linenum) func(linenum) TAB_CONFIG[func.__name__.replace('on_lang_','')] = wrapped return wrapped @register_lang def on_lang_cobol(linenum): for col in [7,8,12,72]: editor.addTabStop(linenum, (col-1)*pixperchar) @register_lang def on_lang_assembly(linenum): for col in [11, 18, 40, 79]: editor.addTabStop(linenum, (col-1)*pixperchar) def on_lang_default(): pass def on_set_tab_stops(args): lang = notepad.getLanguageName(notepad.getLangType()) config = lang.lower().replace('udf - ', '') func = TAB_CONFIG.get(config, on_lang_default) # print(func) func() notepad.clearCallbacks(on_set_tab_stops) notepad.callback(on_set_tab_stops, [NOTIFICATION.BUFFERACTIVATED, NOTIFICATION.LANGCHANGED])
-
updated with a scintilla MODIFIED notification, with the caveat that it will only trigger for non-zero
linesAdded
value – that is non zero if a line is added or deleted.it’s somewhat slow, but as you switch in to the file, or add or delete lines, the tabs will all be updated.
# encoding=utf-8 """in response to https://community.notepad-plus-plus.org/topic/21689/ Merge my suggestion with Eko's pointer to https://github.com/notepad-plus-plus/notepad-plus-plus/issues/9296#issuecomment-751706154 """ from Npp import editor, notepad, NOTIFICATION, SCINTILLANOTIFICATION, EDGEVISUALSTYLE TAB_CONFIG = {} pixperchar = 8 def register_lang(func): def wrapped(): for linenum in range(editor.getLineCount()): editor.clearTabStops(linenum) func(linenum) TAB_CONFIG[func.__name__.replace('on_lang_','')] = wrapped return wrapped @register_lang def on_lang_cobol(linenum): for col in [7,8,12,72]: editor.addTabStop(linenum, (col-1)*pixperchar) @register_lang def on_lang_assembly(linenum): for col in [11, 18, 40, 79]: editor.addTabStop(linenum, (col-1)*pixperchar) def on_lang_default(): pass def on_set_tab_stops(args): #print(str(args)) lang = notepad.getLanguageName(notepad.getLangType()) config = lang.lower().replace('udf - ', '') func = TAB_CONFIG.get(config, on_lang_default) # print(func) if 'linesAdded' in args: if args['linesAdded'] != 0: func() else: func() notepad.clearCallbacks(on_set_tab_stops) notepad.callback(on_set_tab_stops, [NOTIFICATION.BUFFERACTIVATED, NOTIFICATION.LANGCHANGED]) editor.clearCallbacks(on_set_tab_stops) editor.callback(on_set_tab_stops, [SCINTILLANOTIFICATION.MODIFIED])
-
@Alan-Kilborn said in Customizing for COBOL:
I also need to add tab stops at columns 7,8, 12 and 72
Thus far this part of the OP’s question has been missed by the responders. I can’t recall if this one has come up before, but it sure seems like it would have.
Can Notepad++/Scintilla handle variable-width tab stop positions?Does @dail 's Elastic TabStops plugin solve this? I honestly don’t know and haven’t tried it (never needed this), but sounds like it might?
Cheers.
-
I don’t use that either, but my impression was no. But I grabbed it to test briefly.
the tabstops in Elastic Tabstops will stretch to fit the longest piece of text: for example, with
what about
,x
, andwhatever
, the first tabstop will be wide enough for thewhat about
. And it allows different stops when you give a blank line between paragraphs/sections… but I don’t see a way to pre-define specific widths. -
@Emmad-Kareem said in Customizing for COBOL:
I also need to add tab stops at columns 7,8, 12 and 72 (hoping the tab stop would show as a vertical column).
I don’t think anyone directly addressed this, either. With a recent Notepad++ version, you can have multiple vertical edges drawn: go to Settings > Preferences > Margins / Border / Edge, and fill in the Vertical Edge Settings:
That example doesn’t have the pythonscript callbacks active, so the tab size is a fixed width. Here it is with Elastic Tabstops also active, with a dummy header line to try to force known tab stops:
The drawback to the multiple vertical edges is that it is the same for all languages. Though that multiEdge example that @Ekopalypse linked to will actually solve that problem for you.
Speaking of the tab size/location, one thing you don’t mention: is COBOL okay with using TAB character between fields? Or do you need/want tab-to-spaces conversion (so when you hit TAB, it will actually use enough space characters to fill in the gap)? If you’re okay with keeping TAB as the TAB character, then either the PythonScript or an ElasticTabstops-with-header might work for you; if you need that spacing to be encoded as actual space characters (ASCII 32 = 0x20) in the file, then neither is going to supply what you need.
-
@emmad-kareem I made a copy of the ‘Deep Black’ theme and renamed it to Cobol and incremented the following commands saved and put my cobol file in the themes folder, after the procedure I selected it in notepad ++ see if you like it.
Regarding the tab, I’m seeing how to solve it
<LexerType name="cobol" desc="COBOL" ext=""> <WordsStyle name="PREPROCESSOR" styleID="9" fgColor="DCDCCC" bgColor="3F3F3F" fontName="" fontStyle="2" fontSize="" /> <WordsStyle name="DEFAULT" styleID="11" fgColor="DCDCCC" bgColor="3F3F3F" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="DECLARATION" styleID="5" fgColor="FFEBDD" bgColor="3F3F3F" fontName="" fontStyle="1" fontSize="" keywordClass="instre1" /> <WordsStyle name="INSTRUCTION WORD" styleID="16" fgColor="DFC47D" bgColor="3F3F3F" fontName="" fontStyle="1" fontSize="" keywordClass="instre2">accept access active-class add address advancing after aligned all allocate alphabet alphabetic alphabetic-lower alphabetic-upper alphanumeric alphanumeric-edited also alter alternate and any anycase apply are area areas ascending assign at author b-and b-not b-or b-xor based basis before beginning binary binary-char binary-double binary-long binary-short bit blank block boolean bottom by call cancel cbl cd cf ch character characters class class-id clock-units close cobol code code-set col collating cols column columns com-reg comma common communication comp comp-1 comp-2 comp-3 comp-4 comp-5 computational computational-1 computational-2 computational-3 computational-4 computational-5 compute condition configuration constant contains content continue control controls converting copy corr corresponding count crt currency cursor data data-pointer date date-compiled date-written day day-of-week dbcs de debug-contents debug-item debug-line debug-name debug-sub-1 debug-sub-2 debug-sub-3 debugging decimal-point declaratives default delete delimited delimiter depending descending destination detail disable display display-1 divide division down duplicates dynamic ec egcs egi eject else emi enable end end-accept end-add end-call end-compute end-delete end-display end-divide end-evaluate end-exec end-if end-invoke end-multiply end-of-page end-perform end-read end-receive end-return end-rewrite end-search end-start end-string end-subtract end-unstring end-write end-xml ending enter entry environment eo eop equal error esi evaluate every exception exception-object exec execute exit extend external factory false fd file file-control filler final first float-extended float-long float-short footing for format free from function function-id function-pointer generate get giving global go goback greater group group-usage heading high-value high-values i-o i-o-control id identification if in index indexed indicate inherits initial initialize initiate input input-output insert inspect installation interface interface-id into invalid invoke is jnienvptr just justified kanji key label last leading left length less limit limits linage linage-counter line line-counter lines linkage local-storage locale lock low-value low-values memory merge message method method-id minus mode modules more-labels move multiple multiply national national-edited native negative nested next no not null nulls number numeric numeric-edited object object-computer object-reference occurs of off omitted on open optional options or order organization other output overflow override packed-decimal padding page page-counter password perform pf ph pic picture plus pointer position positive present printing procedure procedure-pointer procedures proceed processing program program-id program-pointer property prototype purge queue quote quotes raise raising random rd read ready receive record recording records recursive redefines reel reference references relative release reload remainder removal renames replace replacing report reporting reports repository rerun reserve reset resume retry return return-code returning reversed rewind rewrite rf rh right rounded run same screen sd search section security segment segment-limit select self send sentence separate sequence sequential service set sharing shift-in shift-out sign size skip1 skip2 skip3 sort sort-control sort-core-size sort-file-size sort-merge sort-message sort-mode-size sort-return source source-computer sources space spaces special-names sql sqlims standard standard-1 standard-2 start status stop string sub-queue-1 sub-queue-2 sub-queue-3 subtract sum super suppress symbolic sync synchronized system-default table tally tallying tape terminal terminate test text than then through thru time times title to top trace trailing true type typedef unit universal unlock unstring until up upon usage use user-default using val-status valid validate validate-status value values varying when when-compiled with words working-storage write write-only xml xml-code xml-event xml-information xml-namespace xml-namespace-prefix xml-nnamespace xml-nnamespace-prefix xml-ntext xml-schema xml-text zero zeroes zeros </WordsStyle> <WordsStyle name="KEYWORD" styleID="8" fgColor="FFCFAF" bgColor="3F3F3F" fontName="" fontStyle="0" fontSize="" keywordClass="type1" /> <WordsStyle name="NUMBER" styleID="4" fgColor="8CD0D3" bgColor="3F3F3F" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="STRING" styleID="6" fgColor="E3CEAB" bgColor="3F3F3F" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="CHARACTER" styleID="7" fgColor="DCA3A3" bgColor="3F3F3F" fontName="" fontStyle="0" fontSize="" /> <WordsStyle name="OPERATOR" styleID="10" fgColor="9F9D6D" bgColor="3F3F3F" fontName="" fontStyle="1" fontSize="" /> <WordsStyle name="COMMENT" styleID="1" fgColor="7F9F7F" bgColor="3F3F3F" fontName="" fontStyle="3" fontSize="" /> <WordsStyle name="COMMENT LINE" styleID="2" fgColor="7F9F7F" bgColor="3F3F3F" fontName="" fontStyle="3" fontSize="" /> <WordsStyle name="COMMENT DOC" styleID="3" fgColor="7F9F7F" bgColor="3F3F3F" fontName="" fontStyle="2" fontSize="" /> <WordsStyle name="COMMENT LINE DOC" styleID="15" fgColor="7F9F7F" bgColor="3F3F3F" fontName="" fontStyle="2" fontSize="" /> <WordsStyle name="COMMENT DOC KEYWORD" styleID="17" fgColor="7F9F7F" bgColor="3F3F3F" fontName="" fontStyle="3" fontSize="" /> <WordsStyle name="COMMENT DOC KEYWORD ERROR" styleID="18" fgColor="7F9F7F" bgColor="3F3F3F" fontName="" fontStyle="2" fontSize="" /> </LexerType>
code_text
-
@Michael-Vincent, Many thanks for your help.