Discussions related to Visual Prolog
Harrison Pratt
VIP Member
Posts: 448
Joined: 5 Nov 2000 0:01

SciLexer tab key - line indent vs. tab insert

Unread post by Harrison Pratt »

How can I change the editor's response to a tab key press from line indent to tab insert ?
User avatar
Thomas Linder Puls
VIP Member
Posts: 1412
Joined: 28 Feb 2000 0:01

Re: SciLexer tab key - line indent vs. tab insert

Unread post by Thomas Linder Puls »

Our show predicate for the sciLexer makes the following settings:

Code: Select all

        tabWidth := 4,         tabIndents := true,         backSpaceUnIndents := true,         useTabs := false,
If you want to change any of them, you will have to change the settings after show has run:

Code: Select all

        mySciLexer_ctl:addShowListener(             {  :-                 mySciLexer_ctltabWidth := 8,                 mySciLexer_ctl:tabIndents := false,                 mySciLexer_ctl:backSpaceUnIndents := false,                 mySciLexer_ctl:useTabs := true             }),
Regards Thomas Linder Puls
PDC
Harrison Pratt
VIP Member
Posts: 448
Joined: 5 Nov 2000 0:01

Re: SciLexer tab key - line indent vs. tab insert

Unread post by Harrison Pratt »

Ahhh ... thank you, Thomas.
Harrison Pratt
VIP Member
Posts: 448
Joined: 5 Nov 2000 0:01

Re: SciLexer tab key - line indent vs. tab insert

Unread post by Harrison Pratt »

The listener works (confirmed by display of Hello in sciLexer_ctl) but the tab parameters do not seem to be changed in the control.

Code: Select all

    new(Parent) :-         dialog::new(Parent),         generatedInitialize(),         sciLexer_ctl:addShowListener(             {  :-                 sciLexer_ctl:tabWidth := 8,                 sciLexer_ctl:tabIndents := false,                 sciLexer_ctl:backSpaceUnIndents := false,                 sciLexer_ctl:useTabs := true,                 sciLexer_ctl:text := "Hello" % confirms that the listener is being called             }).
User avatar
Gukalov
VIP Member
Posts: 64
Joined: 5 Oct 2011 15:16

Re: SciLexer tab key - line indent vs. tab insert

Unread post by Gukalov »

Thomas Linder Puls wrote: 14 Nov 2022 9:30 Our show predicate for the sciLexer makes the following settings:
And further this predicate makes:

Code: Select all

        clearCmdKey(key_tab), % handled in onNative to get old Visual Prolog behaviour         clearCmdKey(shift+key_tab), % handled in onNative to get old Visual Prolog behaviour
So, I would try to add to showListener assignCmdKey(key_tab, whatYouNeedAction)
Harrison Pratt
VIP Member
Posts: 448
Joined: 5 Nov 2000 0:01

Re: SciLexer tab key - line indent vs. tab insert

Unread post by Harrison Pratt »

That doesn't seem to make any difference.

Code: Select all

    new(Parent) :-         dialog::new(Parent),         generatedInitialize(),         sciLexer_ctl:addShowListener(             {  :-                 sciLexer_ctl:tabWidth := 8,                 sciLexer_ctl:tabIndents := false,                 sciLexer_ctl:backSpaceUnIndents := false,                 sciLexer_ctl:useTabs := true,                 sciLexer_ctl:text := "Hello", % confirms that the listener is being called                 sciLexer_ctl:assignCmdKey(sciLexerBase::key_tab, sciLexerBase::key_tab) % <== does not change tab behavior             }).
User avatar
Gukalov
VIP Member
Posts: 64
Joined: 5 Oct 2011 15:16

Re: SciLexer tab key - line indent vs. tab insert

Unread post by Gukalov »

Code: Select all

sciLexer_ctl:assignCmdKey(sciLexerBase::key_tab, sciLexerBase::key_tab)
Hm... sciLexerBase::key_tab - just Key Tab.
Tab Action search somewhere near sci_selectAll, sci_undo, etc. I hope)))
...pfc\windowsapi\scilexer_api\scilexer_native.cl(94,1)
Harrison Pratt
VIP Member
Posts: 448
Joined: 5 Nov 2000 0:01

Re: SciLexer tab key - line indent vs. tab insert

Unread post by Harrison Pratt »

The IDE flags it as Undeclared identifier and prompts me to prefix it with sciLexerBase::

It doesn't need qualification in the sciLexer.pro code, of course.
User avatar
Thomas Linder Puls
VIP Member
Posts: 1412
Joined: 28 Feb 2000 0:01

Re: SciLexer tab key - line indent vs. tab insert

Unread post by Thomas Linder Puls »

Sorry, I overlooked some details :oops: .

The second argument of assignCmdKey is a command (sciLexer_native::sci_...) not a key:

Code: Select all

        sciLexer_ctl:assignCmdKey(sciLexerBase::key_tab, sciLexer_native::sci_tab),
Regards Thomas Linder Puls
PDC
Harrison Pratt
VIP Member
Posts: 448
Joined: 5 Nov 2000 0:01

Re: SciLexer tab key - line indent vs. tab insert

Unread post by Harrison Pratt »

I can get the Tab key to insert normally, but It looks like the line-indent function is hard-coded in sclLexer.pro staring at line 225.
Screenshot 2022-11-16 084716.png
Screenshot 2022-11-16 084716.png (5.52 KiB) Viewed 955694 times
Note tab_vip and backTab_vip in the code fragment below.

Code: Select all

 % sciLexer.pro, line 225 predicates     tryGetKeydownAction : (vpiDomains::keyModifier Modifier, integer VKey) -> runnable Action determ. clauses     tryGetKeydownAction(c_Control, vk_Ckey) = copy.     tryGetKeydownAction(c_Control, vk_insert) = copy.     tryGetKeydownAction(c_Control, vk_Xkey) = cut.     tryGetKeydownAction(c_Shift, vk_delete) = cut.     tryGetKeydownAction(c_Nothing, vk_tab) = tab_vip.     tryGetKeydownAction(c_Shift, vk_tab) = backTab_vip.   clauses     tab_vip() :-         changeIndent(true).   clauses     backtab_vip() :-         changeIndent(false).   predicates     changeIndent : (boolean Forward). clauses     changeIndent(Forward) :-         beginUndoAction(),         try             IndentStep = indentStep,             IndentIncrease = if true = Forward then IndentStep else -IndentStep end if,             LineStart = lineFromPosition(selectionStart),             LineEnd1 = lineFromPosition(selectionEnd),             LineEnd = if LineStart < LineEnd1 and selectionEnd = positionFromLine(LineEnd1) then LineEnd1 - 1 else LineEnd1 end if,             foreach Line = std::fromTo(LineStart, LineEnd) do                 if Line = LineStart or b_false = sciLexer_api::getReadOnly(native) then                     changeIndentLine(Line, IndentIncrease)                 end if             end foreach,             if currentPos = anchor and 1 = getColumn(currentPos) then                 gotoPos(getLineIndentPosition(LineStart))             end if         finally             endUndoAction()         end try.
I think I have a dim recollection of discussion about making a "shadow" copy of the sciLexer package and modifying/deleting the above code ... or maybe I just imagined it. :wink:

There might be value in having vip_tabbing be controlled by a boolean property in the future.
User avatar
Gukalov
VIP Member
Posts: 64
Joined: 5 Oct 2011 15:16

Re: SciLexer tab key - line indent vs. tab insert

Unread post by Gukalov »

Yes))) If the sciLexerBase::key_tab is assigned they work both - and VIP tab, and command)))

Code: Select all

predicates     tryGetKeydownAction : (vpiDomains::keyModifier Modifier, integer VKey) -> runnable Action determ. clauses ...     tryGetKeydownAction(c_Nothing, vk_tab) = tab_vip.  % :- *** ...
I think *** the best place for not(the sciLexerBase::key_tab is assigned) to stop VIP tab action without any flags.
User avatar
Gukalov
VIP Member
Posts: 64
Joined: 5 Oct 2011 15:16

Re: SciLexer tab key - line indent vs. tab insert

Unread post by Gukalov »

Ups... I don't see how to check if the key is assigned(((
But I see "ordinary" tab predicate.
So, with adding vipTab flag:

Code: Select all

predicates     tryGetKeydownAction : (vpiDomains::keyModifier Modifier, integer VKey) -> runnable Action determ. clauses  ...     tryGetKeydownAction(c_ShiftCtl, vk_tab) = { :- vipTab := boolean::logicalNot(vipTab) }.     tryGetKeydownAction(c_Nothing, vk_tab) = if true = vipTab then tab_vip else tab end if. ...   facts     vipTab : boolean := true.
And it is possible to switch tab mode after show)))


P.S. Finally:

Code: Select all

predicates     tryGetKeydownAction : (vpiDomains::keyModifier Modifier, integer VKey) -> runnable Action determ. clauses ...     tryGetKeydownAction(c_Control, vk_space) = tab.
No flags, no swiching... Two different tabs...
Harrison Pratt
VIP Member
Posts: 448
Joined: 5 Nov 2000 0:01

Re: SciLexer tab key - line indent vs. tab insert

Unread post by Harrison Pratt »

Thanks for the suggestions, Gukalov! :D
User avatar
Gukalov
VIP Member
Posts: 64
Joined: 5 Oct 2011 15:16

Re: SciLexer tab key - line indent vs. tab insert

Unread post by Gukalov »

You are welcome.

Actually, a little trick:
sciLexer.pro

Code: Select all

predicates     tryGetKeydownAction : (vpiDomains::keyModifier Modifier, integer VKey) -> runnable Action determ. clauses     tryGetKeydownAction(M, K) = Fun() :-         assignedKey(M, K, Fun),         !. ...... ......   facts     assignedKey : (vpiDomains::keyModifier Modifier, integer VKey, core::function_dt{core::runnable Action}) nondeterm.   clauses %    addAssignedKey(Modifier, VKey, Action) :-  error on try assign "untouchable" ???       addAssignedKey(Modifier, VKey, Action) :-         % clearCmdKey(???)         retractAll(assignedKey(Modifier, VKey, _)),         assert(assignedKey(Modifier, VKey, Action)).
sciLexer.i

Code: Select all

predicates     addAssignedKey : (vpiDomains::keyModifier Modifier, integer VKey, core::function_dt{core::runnable Action}).
And it gives possibility to assign simply all the keys what/when ever you want to assign:

Code: Select all

implement main     open core, console, list   clauses     run() :-         Dlg = dialog::new(window::getActiveWindow()),         Dlg:setFont(vpi::fontCreateByName("Verdana", 22)),         Dlg:setUnit(dialog::pixelUnit),         Dlg:setModal(true),         Dlg:setDecoration(frameDecoration::titlebar([frameDecoration::closeButton])),         Dlg:setPosition(200, 100),         Dlg:setSize(600, 400),           Lexer = sciLexer::new(Dlg),         Lexer:setSize(600, 400),           Lexer:addAssignedKey(vpiDomains::c_Nothing, gui_native::vk_escape, { = Dlg:close }),         Lexer:addAssignedKey(vpiDomains::c_Control, gui_native::vk_space, { = Lexer:tab }),           Lexer:addAssignedKey(vpiDomains::c_Control, gui_native::vk_Skey,                 { = { :- Lexer:insertText("https://discuss.visual-prolog.com/") } :-                             "" = string::trim(Lexer:curLine) }),           Lexer:addAssignedKey(vpiDomains::c_Control, gui_native::vk_Okey,                 { = { :- shell_api::shellOpen(Link) } :-                             Link = string::trim(Lexer:curLine),                             string::hasPrefix(Link, "https://", _) }),           Dlg:show().   end implement main goal     console::runUtf8(main::run).
Also it's possible to pick up popUp menu tags from added facts, it just needs more serious "tricking")))
Harrison Pratt
VIP Member
Posts: 448
Joined: 5 Nov 2000 0:01

Re: SciLexer tab key - line indent vs. tab insert

Unread post by Harrison Pratt »

Boom! That's the sound of my brain exploding after seeing a new (to me) way of doing things. :shock:

Thanks, Gukalov!
Post Reply