SOLVED, 13 Feb 2021…Improvements welcome.
‘The good news is I’m trying to solve a problem. The bad news is I need someone smarter in the room.’
So here’s my problem.
Current “sand-boxed” implementation of kakoune-java.kak inhibits a users interaction due to the poor resolution of and operations to the current static word list.
Regular expressions query a users fully qualified import statements against 410 potential java packages that provide builtin constants. The operations are limited to a push and pop on the static word list.
The implementation file line length is 7866 and represents my best worst effort, hence the cry for help.
Static word list thoughts:
Observations:
- The length of main list (base case) and size of insertion list, enables min and max sub-string positions.
- Continuous operations on a single data structure requires multiple variables to coordinate the insertion positions.
Considerations:
- Main list is a constant, operations of type push and pop begin from this Min sub-string position.
- A running total is needed for the appended list size which will be our Max.
- Substring(Min, Max) represents all push minus pop operations on the list.
- Final operation on the Main list is the concatenation of the newly sized insertion list.
Conclusion:
- Traversal and regular expression matches on the Main data structure is never preformed. Push and pop operations only occur on the sub-string.
Lessons learned:
- Helper functions for stack size, addition (push) and (pop) subtraction confirmation.
:echo %sh{ printf %s "$kak_opt_static_words" | awk '{print NF}' }
:echo %sh{ printf %s "$kak_opt_org_xml_sax_helpers_namespacesupport" | awk '{print NF}' }
References:
- Oracle 2021, Constant Field Values, Java SE 15, viewed 28 January 2021, Constant Field Values (Java SE 15 & JDK 15)
- ftonneau 2020, Branching on a boolean option – without calling the shell, viewed 11 February 2021, Branching on a boolean option -- without calling the shell
Code Snippet:
hook global ModuleLoaded javaConstants %{
require-module java
}
hook global WinSetOption filetype=java %{
require-module javaConstants
# REPEATED 410 TIMES #
declare-option str org_xml_sax_helpers_namespacesupport_active "nop"
hook -group java-constant-field window InsertIdle .* java-constants-add
hook -group java-constant-field window ModeChange push:insert:.* java-constants-remove
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window java-constant-field }
}
provide-module javaConstants %§
define-command java-constants-add %{
# REPEATED 410 TIMES #
try %{
execute-keys -draft '%s (?:org.xml.sax.helpers.NamespaceSupport)<ret>'
evaluate-commands %opt{org_xml_sax_helpers_namespacesupport_active}
set-option -add window static_words %opt{org_xml_sax_helpers_namespacesupport}
set-option window org_xml_sax_helpers_namespacesupport_active "nay"
}
}
define-command java-constants-remove %{
# REPEATED 410 TIMES #
try %{
execute-keys -draft '%s (?:org.xml.sax.helpers.NamespaceSupport)<ret>'
} catch %{
set-option -remove window static_words %opt{org_xml_sax_helpers_namespacesupport}
set-option window org_xml_sax_helpers_namespacesupport_active "nop"
}
}
# YEP, ALL BELOW LOGIC IS REPEATED 410 TIMES #
evaluate-commands %sh{
exec awk -f - <<'EOF'
BEGIN {
split("NSDECL XMLNS", orgXmlSaxHelpersNamespaceSupport);
}
function print_static_words(words) { for (i in words) { printf(" %s", words[i]); } }
BEGIN {
printf("declare-option str-list org_xml_sax_helpers_namespacesupport ");
print_static_words(orgXmlSaxHelpersNamespaceSupport);
printf("\n");
}
EOF
}
§
As always, thanks guys and bye .