Customizing for COBOL
-
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.