FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
librime-lua-script/lua/component/remove_filter.lua at main · shewer/librime-lua-script · GitHub
shewer
librime-lua-script
Repository navigation
Code
Issues
4
(4)
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
librime-lua-script
/
lua
/
component
/
remove_filter.lua
Copy path
More file actions
More file actions
Latest commit
History
History
History
129 lines (114 loc) · 3.08 KB
Breadcrumbs
librime-lua-script
/
lua
/
component
/
remove_filter.lua
Copy path
File metadata and controls
129 lines (114 loc) · 3.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!
/usr/bin/env lua
--
--
remove_filter.lua
--
Copyright (C) 2023 Shewer Lu <shewer@gmail.com>
--
--
Distributed under terms of the MIT license.
--
--
使用 text dada 建立 屏蔽 candidate
--
屏蔽 filename: user_data_dir/[name_space].txt
--
透過 property "delete_candidate" 來更新 Rmdb
--
增加 property 'delect_candidate' 'reload' 重載入檔案
--
增加 property 'delect_candidate' 'enable' enable append() find() match()
--
增加 property 'delect_candidate' 'disable' disable append() find() match()
--
增加 property 'delect_candidate' 'toggle' enable or disable append() find() match()
--
--
--
Rmdb module
--
Rmdb(filename)
--
Rmdb:load() -- reloda text file
--
Rmdb:append() -- update text file
--
Rmdb:find(word) or Rmdb:match(word) -- return bool
--
Rmdb:enable(nil|true|false) return bool | set and return
--
Rmdb:toggle() return bool
--
--
check get_user_data_dir func
if
not
rime_api
.
get_user_data_dir
then
rime_api
.
get_user_data_dir
=
function
()
return
"
.
"
--
set user_data_dir
end
end
local
Rmdb_mt
=
{}
Rmdb_mt
.
__index
=
Rmdb_mt
function
Rmdb_mt
:
load
()
local
tab
=
{}
for
line
in
io.open
(
self
.
__filename
,
"
a+
"
):
lines
()
do
local
word
=
line
:
match
(
"
^([^#_].*)$
"
)
if
word
then
tab
[
word
]
=
true
end
end
self
.
__db
=
tab
end
function
Rmdb_mt
:
append
(
word
)
if
self
:
match
(
word
)
or
not
self
:
enable
()
then
return
end
local
fn
=
io.open
(
self
.
__filename
,
"
a
"
)
if
fn
then
fn
:
write
(
word
..
"
\n
"
)
fn
:
close
()
self
.
__db
[
word
]
=
true
else
log
.
error
(
"
Rmdb Error: can't open file:
"
..
self
.
__filename
)
end
end
function
Rmdb_mt
:
find
(
word
)
return
self
:
enable
()
and
self
.
__db
[
word
]
end
Rmdb_mt
.
match
=
Rmdb_mt
.
find
function
Rmdb_mt
:
enable
(
bool
)
if
bool
==
nil
then
return
self
.
__enable
end
self
.
__enable
=
bool
and
true
or
false
return
self
.
__enable
end
function
Rmdb_mt
:
toggle
()
return
self
:
enable
(
not
self
:
enable
() )
end
function
Rmdb
(
name
)
local
obj
=
setmetatable
({},
Rmdb_mt
)
obj
.
__filename
=
rime_api
.
get_user_data_dir
()
..
package.config
:
sub
(
1
,
1
)
..
name
..
"
.txt
"
obj
.
__enable
=
true
obj
:
load
()
return
obj
end
local
M
=
{}
local
n_name
=
'
delete_candidate
'
function
M
.
init
(
env
)
env
.
rmdb
=
Rmdb
(
env
.
name_space
)
env
.
notifiers
=
{
env
.
engine
.
context
.
property_update_notifier
:
connect
(
function
(
ctx
,
name
)
if
name
~=
n_name
then
return
end
local
word
=
ctx
:
get_property
(
name
)
if
word
==
'
reload
'
then
env
.
rmdb
:
load
()
elseif
word
==
'
enable
'
then
env
.
rmdb
:
enable
(
true
)
elseif
word
==
'
disable
'
then
env
.
rmdb
:
enable
(
false
)
elseif
word
==
'
toggle
'
then
env
.
rmdb
:
toggle
()
else
env
.
rmdb
:
append
(
word
)
end
end
),
env
.
engine
.
context
.
option_update_notifier
:
connect
(
function
(
ctx
,
name
)
if
name
~=
n_name
then
return
end
env
.
rmdb
:
enable
(
ctx
:
get_option
(
name
))
end
),
}
end
function
M
.
fini
(
env
)
for
_
,
notifier
in
ipairs
(
env
.
notifiers
)
do
notifier
:
disconnect
()
end
end
function
M
.
tags_match
(
seg
,
env
)
return
true
end
function
M
.
func
(
inp
,
env
)
for
cand
in
inp
:
iter
()
do
if
not
env
.
rmdb
:
find
(
cand
.
text
)
then
yield
(
cand
)
end
end
end
return
M
Back
|
FazBrowse Home
|
New Git URL