init.lua /size: 5417 b    last modification: 2021-10-28 13:49
1
local
info
=
{
2
version
=
1
.
002
,
3
comment
=
"
ini for textadept for context/metafun
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
,
7
}
8 9
-- Note for myself: I need to check the latest greatest textadept and also see if
10
-- the lpeg lexer interface has been ported to the latest scite. If not I need to
11
-- come up with a backup plan (vscode?).
12 13
if
not
textadept
then
14
return
15
end
16 17
-- The textadept documentation says that there can be a lexers directory under a user
18
-- directory but it's not in the package path. The next involved a bit or trial and
19
-- error in order to avoid crashes so I suppose it can be done better. If I use
20
-- textadept alongside scite I will make a different key binding. The code below is
21
-- a bit of a mess, which is a side effect of stepwise adaption combined with shared
22
-- iuse of code.
23
--
24
-- We use the commandline switch -u to point to the location where this file is located
25
-- as we then can keep it outside the program area. We also put some other files under
26
-- themes.
27
--
28
-- A problem is that scite needs the lexer.lua file while for textadept we don't want
29
-- to touch that one. So we end up with duplicate files. We cannot configure scite to
30
-- use an explicit lexer so both lexer paths have the same files except that the textadept
31
-- one has no lexer.lua there. Unfortunately themes is not requires's but always looked
32
-- up with an explicit path. (Maybe I should patch that.)
33
--
34
-- We are in one of:
35
--
36
-- tex/texmf-context/context/data/textadept/context
37
-- data/develop/context/scite/data/context/textadept
38 39
package
.
path
=
table
.
concat
(
{
40
--
41
_USERHOME
.
.
"
/?.lua
"
,
42
--
43
_USERHOME
.
.
"
/lexers/?.lua
"
,
44
_USERHOME
.
.
"
/modules/?.lua
"
,
45
_USERHOME
.
.
"
/themes/?.lua
"
,
46
_USERHOME
.
.
"
/data/?.lua
"
,
47
--
48
package
.
path
49
--
50
}
,
'
;
'
)
51 52
-- We now reset the session location to a writeable user area. We also take the opportunity
53
-- to increase the list.
54 55
local
sessionpath
=
os
.
getenv
(
not
WIN32
and
'
HOME
'
or
'
USERPROFILE
'
)
.
.
'
/.textadept
'
56
local
sessionfile
=
not
CURSES
and
'
session
'
or
'
session_term
'
57 58
textadept
.
session
.
default_session
=
sessionpath
.
.
"
/
"
.
.
sessionfile
59
textadept
.
session
.
save_on_quit
=
true
60
textadept
.
session
.
max_recent_files
=
25
61 62
-- Let's load our adapted lexer framework.
63 64
require
(
"
scite-context-lexer
"
)
65
require
(
"
textadept-context-runner
"
)
66
require
(
"
textadept-context-files
"
)
67
require
(
"
scite-context-theme
"
)
68
require
(
"
textadept-context-settings
"
)
69
require
(
"
textadept-context-types
"
)
70 71
-- This prevents other themes to spoil our settings.
72 73
-- ui.set_theme("scite-context-theme")
74
buffer
:
set_theme
(
"
scite-context-theme
"
)
75 76
-- Since version 10 there is some settings stuff in the main init file but that
77
-- crashes on load_settings. It has to do with the replacement of properties
78
-- but we already had that replaced for a while. There is some blob made that
79
-- gets loaded but it's not robust (should be done different I think). Anyway,
80
-- intercepting the two event handlers is easiest. Maybe some day I will
81
-- replace that init anyway (if these fundamentals keep changing between
82
-- versions.)
83
--
84
-- I admit that it's not a beautiful solution but it works ok and I already
85
-- spent too much time figuring things out anyway.
86 87
local
events_connect
=
events
.
connect
88 89
local
function
events_newbuffer
(
)
90
local
buffer
=
_G
.
buffer
91
local
SETDIRECTFUNCTION
=
_SCINTILLA
.
properties
.
direct_function
[
1
]
92
local
SETDIRECTPOINTER
=
_SCINTILLA
.
properties
.
doc_pointer
[
2
]
93
local
SETLUASTATE
=
_SCINTILLA
.
functions
.
change_lexer_state
[
1
]
94
local
SETLEXERLANGUAGE
=
_SCINTILLA
.
properties
.
lexer_language
[
2
]
95
buffer
.
lexer_language
=
'
lpeg
'
96
buffer
:
private_lexer_call
(
SETDIRECTFUNCTION
,
buffer
.
direct_function
)
97
buffer
:
private_lexer_call
(
SETDIRECTPOINTER
,
buffer
.
direct_pointer
)
98
buffer
:
private_lexer_call
(
SETLUASTATE
,
_LUA
)
99
buffer
.
property
[
'
lexer.lpeg.home
'
]
=
_USERHOME
.
.
'
/lexers/?.lua;
'
.
.
_HOME
.
.
'
/lexers
'
100
-- load_settings()
101
buffer
:
private_lexer_call
(
SETLEXERLANGUAGE
,
'
text
'
)
102
if
buffer
=
=
ui
.
command_entry
then
103
buffer
.
caret_line_visible
=
false
104
end
105
end
106 107
-- Why these resets:
108 109
local
ctrl_keys
=
{
110
'
[
'
,
'
]
'
,
'
/
'
,
'
\\
'
,
'
Z
'
,
'
Y
'
,
'
X
'
,
'
C
'
,
'
V
'
,
'
A
'
,
'
L
'
,
'
T
'
,
'
D
'
,
'
U
'
111
}
112 113
local
ctrl_shift_keys
=
{
114
'
L
'
,
'
T
'
,
'
U
'
,
'
Z
'
115
}
116 117
local
function
events_newview
(
)
118
local
buffer
=
_G
.
buffer
119
for
i
=
1
,
#
ctrl_keys
do
120
buffer
:
clear_cmd_key
(
string
.
byte
(
ctrl_keys
[
i
]
)
|
buffer
.
MOD_CTRL
<
<
16
)
121
end
122
for
i
=
1
,
#
ctrl_shift_keys
do
123
buffer
:
clear_cmd_key
(
string
.
byte
(
ctrl_shift_keys
[
i
]
)
|
(
buffer
.
MOD_CTRL
|
buffer
.
MOD_SHIFT
)
<
<
16
)
124
end
125
if
#
_VIEWS
>
1
then
126
-- load_settings()
127
local
SETLEXERLANGUAGE
=
_SCINTILLA
.
properties
.
lexer_language
[
2
]
128
buffer
:
private_lexer_call
(
SETLEXERLANGUAGE
,
buffer
.
_lexer
or
'
text
'
)
129
end
130
end
131 132
events
.
connect
=
function
(
where
,
what
,
location
)
133
if
location
=
=
1
then
134
if
where
=
=
events
.
BUFFER_NEW
then
135
return
events_connect
(
where
,
events_newbuffer
,
location
)
136
elseif
where
=
=
events
.
VIEW_NEW
then
137
return
events_connect
(
where
,
events_newview
,
location
)
138
end
139
end
140
return
events_connect
(
where
,
what
,
location
)
141
end
142 143
local
savedrequire
=
require
144 145
require
=
function
(
name
,
...
)
146
return
savedrequire
(
name
=
=
"
lexer
"
and
"
scite-context-lexer
"
or
name
,
...
)
147
end
148