-
- VIP Member
- Posts: 447
- Joined: 5 Nov 2000 0:01
SciLexer tab key - line indent vs. tab insert
How can I change the editor's response to a tab key press from line indent to tab insert ?
- Thomas Linder Puls
- VIP Member
- Posts: 1404
- Joined: 28 Feb 2000 0:01
Re: SciLexer tab key - line indent vs. tab insert
Our show predicate for the sciLexer makes the following settings:
If you want to change any of them, you will have to change the settings after show has run:
Code: Select all
tabWidth := 4,
tabIndents := true,
backSpaceUnIndents := true,
useTabs := false,
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
PDC
-
- VIP Member
- Posts: 447
- Joined: 5 Nov 2000 0:01
Re: SciLexer tab key - line indent vs. tab insert
Ahhh ... thank you, Thomas.
-
- VIP Member
- Posts: 447
- Joined: 5 Nov 2000 0:01
Re: SciLexer tab key - line indent vs. tab insert
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
}).
Re: SciLexer tab key - line indent vs. tab insert
And further this predicate makes:Thomas Linder Puls wrote: ↑14 Nov 2022 9:30 Our show predicate for the sciLexer makes the following settings:
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
-
- VIP Member
- Posts: 447
- Joined: 5 Nov 2000 0:01
Re: SciLexer tab key - line indent vs. tab insert
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
}).
Re: SciLexer tab key - line indent vs. tab insert
Code: Select all
sciLexer_ctl:assignCmdKey(sciLexerBase::key_tab, sciLexerBase::key_tab)
Tab Action search somewhere near sci_selectAll, sci_undo, etc. I hope)))
...pfc\windowsapi\scilexer_api\scilexer_native.cl(94,1)
-
- VIP Member
- Posts: 447
- Joined: 5 Nov 2000 0:01
Re: SciLexer tab key - line indent vs. tab insert
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.
It doesn't need qualification in the sciLexer.pro code, of course.
- Thomas Linder Puls
- VIP Member
- Posts: 1404
- Joined: 28 Feb 2000 0:01
Re: SciLexer tab key - line indent vs. tab insert
Sorry, I overlooked some details
.
The second argument of assignCmdKey is a command (sciLexer_native::sci_...) not a key:
![Embarassed :oops:](./images/smilies/icon_redface.gif)
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
PDC
-
- VIP Member
- Posts: 447
- Joined: 5 Nov 2000 0:01
Re: SciLexer tab key - line indent vs. tab insert
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.
Note tab_vip and backTab_vip in the code fragment below.
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 :wink:](./images/smilies/icon_wink.gif)
There might be value in having vip_tabbing be controlled by a boolean property in the future.
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.
![Wink :wink:](./images/smilies/icon_wink.gif)
There might be value in having vip_tabbing be controlled by a boolean property in the future.
Re: SciLexer tab key - line indent vs. tab insert
Yes))) If the sciLexerBase::key_tab is assigned they work both - and VIP tab, and command)))
I think *** the best place for not(the sciLexerBase::key_tab is assigned) to stop VIP tab action without any flags.
Code: Select all
predicates
tryGetKeydownAction : (vpiDomains::keyModifier Modifier, integer VKey) -> runnable Action determ.
clauses
...
tryGetKeydownAction(c_Nothing, vk_tab) = tab_vip. % :- ***
...
Re: SciLexer tab key - line indent vs. tab insert
Ups... I don't see how to check if the key is assigned(((
But I see "ordinary" tab predicate.
So, with adding vipTab flag:
And it is possible to switch tab mode after show)))
P.S. Finally:
No flags, no swiching... Two different tabs...
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.
P.S. Finally:
Code: Select all
predicates
tryGetKeydownAction : (vpiDomains::keyModifier Modifier, integer VKey) -> runnable Action determ.
clauses
...
tryGetKeydownAction(c_Control, vk_space) = tab.
-
- VIP Member
- Posts: 447
- Joined: 5 Nov 2000 0:01
Re: SciLexer tab key - line indent vs. tab insert
Thanks for the suggestions, Gukalov! ![Very Happy :D](./images/smilies/icon_biggrin.gif)
![Very Happy :D](./images/smilies/icon_biggrin.gif)
Re: SciLexer tab key - line indent vs. tab insert
You are welcome.
Actually, a little trick:
sciLexer.pro
sciLexer.i
And it gives possibility to assign simply all the keys what/when ever you want to assign:
Also it's possible to pick up popUp menu tags from added facts, it just needs more serious "tricking")))
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)).
Code: Select all
predicates
addAssignedKey : (vpiDomains::keyModifier Modifier, integer VKey, core::function_dt{core::runnable Action}).
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).
-
- VIP Member
- Posts: 447
- Joined: 5 Nov 2000 0:01
Re: SciLexer tab key - line indent vs. tab insert
Boom! That's the sound of my brain exploding after seeing a new (to me) way of doing things.
Thanks, Gukalov!
![Shocked :shock:](./images/smilies/icon_eek.gif)
Thanks, Gukalov!