mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-18 23:05:40 -04:00
Compare commits
735 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5eddf5b85d | ||
![]() |
cd0dc9a701 | ||
![]() |
bf255b6c35 | ||
![]() |
98ff79dbca | ||
![]() |
44d0368747 | ||
![]() |
895d9d2c82 | ||
![]() |
809db4ee24 | ||
![]() |
58b6917526 | ||
![]() |
63b6a1e6cf | ||
![]() |
4769a94fb1 | ||
![]() |
91832d0016 | ||
![]() |
06fe85c8c9 | ||
![]() |
ca32ffbb4a | ||
![]() |
b61c8a4e1a | ||
![]() |
333770bbd0 | ||
![]() |
7e583fe6ff | ||
![]() |
1eef4bb3e0 | ||
![]() |
8e7089993d | ||
![]() |
080d216ffd | ||
![]() |
e5c3a3edc3 | ||
![]() |
c457ae421a | ||
![]() |
0d5b2b73e3 | ||
![]() |
79fe4ae3e3 | ||
![]() |
b88300ef7f | ||
![]() |
d36e7f4057 | ||
![]() |
2bb3c9aa73 | ||
![]() |
f2454c9248 | ||
![]() |
a699cac3be | ||
![]() |
9fdf5f3a26 | ||
![]() |
f4d62a498b | ||
![]() |
948b05745f | ||
![]() |
eadc402ae0 | ||
![]() |
1bd86a8f79 | ||
![]() |
219fb12482 | ||
![]() |
02e69dddbe | ||
![]() |
78f0a9cd30 | ||
![]() |
0b75031ac5 | ||
![]() |
fa317456e9 | ||
![]() |
82b700390d | ||
![]() |
9003243178 | ||
![]() |
7d16dcdaa6 | ||
![]() |
c9f12206e9 | ||
![]() |
98356765c1 | ||
![]() |
2ae9812f47 | ||
![]() |
85e2b3bd86 | ||
![]() |
3c68655f33 | ||
![]() |
8b21724c6e | ||
![]() |
fe134b92d5 | ||
![]() |
6164050425 | ||
![]() |
49aebe8aca | ||
![]() |
79ce93fb7d | ||
![]() |
771aab251c | ||
![]() |
35d295dd04 | ||
![]() |
8c883c6210 | ||
![]() |
c4dcef3e66 | ||
![]() |
e15bb88270 | ||
![]() |
9592bb1549 | ||
![]() |
f8d98558f0 | ||
![]() |
c926649496 | ||
![]() |
63d68ec441 | ||
![]() |
c972360386 | ||
![]() |
022ec0228a | ||
![]() |
4ac8c786f5 | ||
![]() |
21b7080935 | ||
![]() |
1663a1a6e4 | ||
![]() |
9b53257e50 | ||
![]() |
6e8daa117a | ||
![]() |
18a81f043c | ||
![]() |
69064cf808 | ||
![]() |
e828027cc0 | ||
![]() |
c2bc4688dd | ||
![]() |
5aac42dbe7 | ||
![]() |
42ae05b082 | ||
![]() |
0b871e174f | ||
![]() |
7c659d1820 | ||
![]() |
6066c1a10e | ||
![]() |
6bcec2100c | ||
![]() |
edc5ff75e3 | ||
![]() |
3fcaf16074 | ||
![]() |
5c21241fc4 | ||
![]() |
272a308275 | ||
![]() |
c93747926d | ||
![]() |
0985d2cadd | ||
![]() |
ddc6051b33 | ||
![]() |
2e94235905 | ||
![]() |
4a9058c3bd | ||
![]() |
982a4fe065 | ||
![]() |
930fbea74d | ||
![]() |
00e568640c | ||
![]() |
d992c606c5 | ||
![]() |
4abd966a99 | ||
![]() |
5a62a8ead4 | ||
![]() |
bf4156c490 | ||
![]() |
b9f1fc8da2 | ||
![]() |
728526682e | ||
![]() |
c105c940fe | ||
![]() |
cdc9ab17f2 | ||
![]() |
b432bb7cfa | ||
![]() |
e4b0ad7107 | ||
![]() |
57a6e81ddb | ||
![]() |
5ee7fb6014 | ||
![]() |
7aa72b6a96 | ||
![]() |
dc18642985 | ||
![]() |
c02036e52f | ||
![]() |
698511c5b6 | ||
![]() |
c61670e86f | ||
![]() |
6309136322 | ||
![]() |
9e46a38536 | ||
![]() |
f5debdf8fe | ||
![]() |
4377e56e7e | ||
![]() |
9b3f7ff240 | ||
![]() |
f49487dc3a | ||
![]() |
c77ed02778 | ||
![]() |
d9956bde38 | ||
![]() |
ab6e170ec9 | ||
![]() |
4d97076479 | ||
![]() |
a883c14c18 | ||
![]() |
ce356c7957 | ||
![]() |
2ddf461ad8 | ||
![]() |
6600430e88 | ||
![]() |
82467ba9f6 | ||
![]() |
99a27db4f7 | ||
![]() |
58d38af8cd | ||
![]() |
d1f54ea2a4 | ||
![]() |
6b21fc5f92 | ||
![]() |
de84da068d | ||
![]() |
771b84141f | ||
![]() |
415ceee46b | ||
![]() |
aa24590070 | ||
![]() |
505aad8ba0 | ||
![]() |
2898f1590d | ||
![]() |
aa0fefcaa1 | ||
![]() |
8cdf68bbf6 | ||
![]() |
fb20818042 | ||
![]() |
71a26381c0 | ||
![]() |
2c4754d484 | ||
![]() |
831e31d483 | ||
![]() |
50639015d7 | ||
![]() |
aaf45a871f | ||
![]() |
3a16197da7 | ||
![]() |
56c1f75bad | ||
![]() |
b881bf5606 | ||
![]() |
c8eeb788cb | ||
![]() |
aeabd5a7ba | ||
![]() |
b2dbcb3eab | ||
![]() |
eb880d8841 | ||
![]() |
1ead9ce4fd | ||
![]() |
b3227d6049 | ||
![]() |
2c6dc32f5d | ||
![]() |
3cb8069e4a | ||
![]() |
8c0e0fa2ed | ||
![]() |
f293f983bd | ||
![]() |
07f8cfbef1 | ||
![]() |
39b2b2639a | ||
![]() |
47b84f75e1 | ||
![]() |
ff4c5c83f2 | ||
![]() |
acabf2b492 | ||
![]() |
1023c8d1be | ||
![]() |
2c62d4b70c | ||
![]() |
26f0806915 | ||
![]() |
e6ed161ca4 | ||
![]() |
134cd999c6 | ||
![]() |
6214abba9a | ||
![]() |
85afb6eb87 | ||
![]() |
d60413f03c | ||
![]() |
af88b4d2a8 | ||
![]() |
4baac3d3fb | ||
![]() |
ac73f18191 | ||
![]() |
3b3fe63f19 | ||
![]() |
9cd1ce968d | ||
![]() |
71da59fd1c | ||
![]() |
3f1e5ea6df | ||
![]() |
fcc7421bca | ||
![]() |
6722cc81de | ||
![]() |
90525a6a1d | ||
![]() |
6e46ae3090 | ||
![]() |
4d2ddc7940 | ||
![]() |
4f4a13a9a1 | ||
![]() |
9eaeb193d4 | ||
![]() |
ca6012086b | ||
![]() |
1539da7fdc | ||
![]() |
a3211dce57 | ||
![]() |
5f83661fee | ||
![]() |
2e44db1ee9 | ||
![]() |
e6d4e37922 | ||
![]() |
d6d0b26041 | ||
![]() |
f22252e5ae | ||
![]() |
8c52d2426d | ||
![]() |
596da97626 | ||
![]() |
f391b59be6 | ||
![]() |
debef6e51b | ||
![]() |
a9b513a28a | ||
![]() |
5554cd18e3 | ||
![]() |
6e60dede36 | ||
![]() |
5428b3fda2 | ||
![]() |
2308bc5555 | ||
![]() |
d8f7928b74 | ||
![]() |
2b44fc3bbb | ||
![]() |
47fb91e333 | ||
![]() |
cc67b801ce | ||
![]() |
f23c2b6115 | ||
![]() |
e6b20b2ce9 | ||
![]() |
968f5ba1ef | ||
![]() |
04c577049c | ||
![]() |
cc195b6a96 | ||
![]() |
f74eb23827 | ||
![]() |
fa9bc6b98c | ||
![]() |
63ffc40a6b | ||
![]() |
a09c98a6dc | ||
![]() |
7dc78b780a | ||
![]() |
b80ea93486 | ||
![]() |
33b7c9db7c | ||
![]() |
8b31dc79bf | ||
![]() |
4170df89eb | ||
![]() |
832c7deaf8 | ||
![]() |
a678d42861 | ||
![]() |
0542765d95 | ||
![]() |
10511c9baf | ||
![]() |
a3071b173b | ||
![]() |
724e29446f | ||
![]() |
05529596cf | ||
![]() |
f661b64e0a | ||
![]() |
4663927098 | ||
![]() |
395d848980 | ||
![]() |
c741e36d2d | ||
![]() |
521b63a28c | ||
![]() |
62c1c667b8 | ||
![]() |
c67a30e611 | ||
![]() |
c51f848df2 | ||
![]() |
7f6e5bc860 | ||
![]() |
9afcb80c95 | ||
![]() |
fd3a00226c | ||
![]() |
f88ac6d4fe | ||
![]() |
0b15b57e63 | ||
![]() |
d31095fe8f | ||
![]() |
7fe98ccfee | ||
![]() |
93efc9eabe | ||
![]() |
352fd2be22 | ||
![]() |
c0f6b65ed6 | ||
![]() |
e0f5361d97 | ||
![]() |
3737979139 | ||
![]() |
be69b2580b | ||
![]() |
21bb61c5ff | ||
![]() |
d744872f4c | ||
![]() |
a9c359a719 | ||
![]() |
1fae584eea | ||
![]() |
0d51035acd | ||
![]() |
658c20ff2a | ||
![]() |
2259fd10af | ||
![]() |
b8772b69c2 | ||
![]() |
e042bb3514 | ||
![]() |
d173e527ac | ||
![]() |
f8e532b0d7 | ||
![]() |
0373a63b31 | ||
![]() |
765889f610 | ||
![]() |
5c8bf6b3a6 | ||
![]() |
aa9c476b1e | ||
![]() |
2793c37a94 | ||
![]() |
7e09a921e4 | ||
![]() |
e2e8baf4f3 | ||
![]() |
fc5d83f6c6 | ||
![]() |
781f057e6f | ||
![]() |
762e31f2fd | ||
![]() |
1f71667616 | ||
![]() |
a10624cc33 | ||
![]() |
bbf6ec292e | ||
![]() |
dc7759204b | ||
![]() |
a84aa225ab | ||
![]() |
882b98f3f1 | ||
![]() |
0fa4a3a8db | ||
![]() |
531c7d88e2 | ||
![]() |
c58ed0e51a | ||
![]() |
f475220e67 | ||
![]() |
57375e0732 | ||
![]() |
d98fafd2f9 | ||
![]() |
f5a9744bde | ||
![]() |
a3e25e3701 | ||
![]() |
f0f4afa272 | ||
![]() |
3fb34cf4f2 | ||
![]() |
f05d3582b3 | ||
![]() |
dc62dd9d82 | ||
![]() |
26ae1b95cc | ||
![]() |
0a6b32d775 | ||
![]() |
badaba66f3 | ||
![]() |
602acff42f | ||
![]() |
ced6d9487a | ||
![]() |
c701ba66af | ||
![]() |
fc3a5cd038 | ||
![]() |
c965447416 | ||
![]() |
352580a50a | ||
![]() |
bf6584739f | ||
![]() |
55f45ce8ff | ||
![]() |
650c0a8db0 | ||
![]() |
68d6f43c63 | ||
![]() |
bad1a4b8ca | ||
![]() |
5540cae610 | ||
![]() |
25c7fa55b1 | ||
![]() |
a85696d5e0 | ||
![]() |
9face7484e | ||
![]() |
6f724bc424 | ||
![]() |
25f71eec2d | ||
![]() |
33a1bb120f | ||
![]() |
04143c7a89 | ||
![]() |
e6825f0e08 | ||
![]() |
fdacb28962 | ||
![]() |
9f7bdb109b | ||
![]() |
c1bbd7b041 | ||
![]() |
a317aefd6d | ||
![]() |
830768b715 | ||
![]() |
2860efbe3a | ||
![]() |
52ed4315ff | ||
![]() |
8bc67569f9 | ||
![]() |
df8d5285bf | ||
![]() |
19c69f9eaa | ||
![]() |
f4d576b6e0 | ||
![]() |
9eb8782ff2 | ||
![]() |
46e55c8e91 | ||
![]() |
dd913df9e9 | ||
![]() |
e9bd1b35f4 | ||
![]() |
4911a56181 | ||
![]() |
343812bd2e | ||
![]() |
35630aa736 | ||
![]() |
78fcf2fc31 | ||
![]() |
5dbdf8c0e8 | ||
![]() |
889a841575 | ||
![]() |
917650826a | ||
![]() |
b70f0eb113 | ||
![]() |
5a159ce444 | ||
![]() |
bca35a5939 | ||
![]() |
1f51d0b9e2 | ||
![]() |
0a1447b688 | ||
![]() |
2ecdac8405 | ||
![]() |
385437d400 | ||
![]() |
1c35f3dc39 | ||
![]() |
07cda68795 | ||
![]() |
3919cf399f | ||
![]() |
b05df07df2 | ||
![]() |
8af890a0a3 | ||
![]() |
ff5b147639 | ||
![]() |
3f810c24d2 | ||
![]() |
26fa15c147 | ||
![]() |
147943837d | ||
![]() |
24406a5ae8 | ||
![]() |
8632b82cbe | ||
![]() |
fade304667 | ||
![]() |
5b3737fb2a | ||
![]() |
36bf3f6619 | ||
![]() |
8c7f63ac15 | ||
![]() |
18f3e1bf89 | ||
![]() |
e48575f349 | ||
![]() |
eec068a4fc | ||
![]() |
5510317942 | ||
![]() |
169a9a65fa | ||
![]() |
c3052b491f | ||
![]() |
b929c61228 | ||
![]() |
08c516c730 | ||
![]() |
1bddc8d03e | ||
![]() |
f9cad2e448 | ||
![]() |
3aed20fde9 | ||
![]() |
a436dae587 | ||
![]() |
5610d01e08 | ||
![]() |
0806addbd7 | ||
![]() |
6cd39efddc | ||
![]() |
089160a7e4 | ||
![]() |
ed993a4021 | ||
![]() |
4cafa601b5 | ||
![]() |
87ee41ab27 | ||
![]() |
8d8bc58f91 | ||
![]() |
6ffabd626f | ||
![]() |
2c53d1fcab | ||
![]() |
f265179def | ||
![]() |
390794213e | ||
![]() |
430da61314 | ||
![]() |
f386b29e16 | ||
![]() |
4283881591 | ||
![]() |
186817d0c4 | ||
![]() |
2a1790d15a | ||
![]() |
c6dc5a4b1f | ||
![]() |
426aa9bb8b | ||
![]() |
acb0d763df | ||
![]() |
d1d38d1ed7 | ||
![]() |
467c71dbb8 | ||
![]() |
a3ca054371 | ||
![]() |
b6dcbfa846 | ||
![]() |
6e71e37568 | ||
![]() |
dd7134a762 | ||
![]() |
2830c4878e | ||
![]() |
53d56d032c | ||
![]() |
c493e14eb4 | ||
![]() |
69dc54b407 | ||
![]() |
c5d32f625b | ||
![]() |
baca0e5cb2 | ||
![]() |
d67ce731ed | ||
![]() |
828871acdf | ||
![]() |
dc833d3552 | ||
![]() |
08028cf415 | ||
![]() |
93dd8ca729 | ||
![]() |
3d7024e059 | ||
![]() |
b291f27c3f | ||
![]() |
3903859970 | ||
![]() |
839e86849e | ||
![]() |
20bf7096b8 | ||
![]() |
d96f060b4c | ||
![]() |
08892b125f | ||
![]() |
838f371486 | ||
![]() |
fc7efbdbe9 | ||
![]() |
2ab1b3132e | ||
![]() |
d64c9443f5 | ||
![]() |
ee6519f5cb | ||
![]() |
984c32b513 | ||
![]() |
1595c5ddda | ||
![]() |
1021f61a81 | ||
![]() |
053949eac6 | ||
![]() |
9ee82a6cb3 | ||
![]() |
66a3839589 | ||
![]() |
b2a428f1cd | ||
![]() |
5492d30953 | ||
![]() |
6c3b5ad17c | ||
![]() |
39e410aa46 | ||
![]() |
3f4942cedb | ||
![]() |
2b8d925925 | ||
![]() |
0c923aa156 | ||
![]() |
13483602d5 | ||
![]() |
c2c2b2addf | ||
![]() |
8b4e9d2c5e | ||
![]() |
a57d29ada9 | ||
![]() |
bb1f4dad77 | ||
![]() |
426e6c600f | ||
![]() |
9ab9f8bc1c | ||
![]() |
f15db6aa30 | ||
![]() |
4895a29be2 | ||
![]() |
b518bda50c | ||
![]() |
c64add289b | ||
![]() |
5ae2799b70 | ||
![]() |
16e38b988c | ||
![]() |
8a3d83f7c7 | ||
![]() |
55b251ffee | ||
![]() |
8724709cf9 | ||
![]() |
4a53419c62 | ||
![]() |
8af304cc21 | ||
![]() |
399134fe5b | ||
![]() |
db26b5fee5 | ||
![]() |
cb903f414c | ||
![]() |
0a69cc68dc | ||
![]() |
1d1b363fa7 | ||
![]() |
4ffc2206ee | ||
![]() |
9089e9ec83 | ||
![]() |
c24604d1ab | ||
![]() |
606bcecf03 | ||
![]() |
94af5f13bd | ||
![]() |
80db98dc81 | ||
![]() |
e424537ff8 | ||
![]() |
5bfda7b5f6 | ||
![]() |
3dba23a348 | ||
![]() |
00174bb376 | ||
![]() |
c4c5b184c2 | ||
![]() |
7b718cb87c | ||
![]() |
6dc3df646b | ||
![]() |
13d1407f60 | ||
![]() |
53efce72fa | ||
![]() |
f108c90643 | ||
![]() |
b824e767d6 | ||
![]() |
c52ccad14b | ||
![]() |
104caf08dd | ||
![]() |
64370b70d6 | ||
![]() |
8368af3cc8 | ||
![]() |
ca3a9d0794 | ||
![]() |
bd306d67b4 | ||
![]() |
a01ae92541 | ||
![]() |
dcdd3e749a | ||
![]() |
628d9bb37b | ||
![]() |
bfc4b1d195 | ||
![]() |
d2ee6107a3 | ||
![]() |
69eaa9191a | ||
![]() |
14dca7d349 | ||
![]() |
fad4e449fb | ||
![]() |
f0bc6281d4 | ||
![]() |
fe4ade78df | ||
![]() |
88b4498ce0 | ||
![]() |
3fce03dfd0 | ||
![]() |
15b36ce0d6 | ||
![]() |
321322af31 | ||
![]() |
0de16334d3 | ||
![]() |
c15abea64c | ||
![]() |
9fdea82542 | ||
![]() |
eedebd80d4 | ||
![]() |
e5026ef3fa | ||
![]() |
af2ec9d540 | ||
![]() |
59dda01cb7 | ||
![]() |
fce8db80de | ||
![]() |
e5a9b906f3 | ||
![]() |
422305af99 | ||
![]() |
4e383dd110 | ||
![]() |
2d82362a66 | ||
![]() |
359b58a89b | ||
![]() |
a373d22939 | ||
![]() |
12398916c7 | ||
![]() |
c791cef9c6 | ||
![]() |
3c16df87ee | ||
![]() |
2d0d0416e7 | ||
![]() |
2aa386f455 | ||
![]() |
93151f8109 | ||
![]() |
433879046e | ||
![]() |
d8e9d61a95 | ||
![]() |
6fa12743d6 | ||
![]() |
dcc7205699 | ||
![]() |
68d88b571d | ||
![]() |
041ee002dd | ||
![]() |
f7244d09c6 | ||
![]() |
9da6af91c8 | ||
![]() |
2a9a5afbb2 | ||
![]() |
c55fb3329f | ||
![]() |
c27593c163 | ||
![]() |
fe89df1d4e | ||
![]() |
9b81589fba | ||
![]() |
dc6a275e04 | ||
![]() |
db5fcf11a9 | ||
![]() |
db6d4f5461 | ||
![]() |
1231d24279 | ||
![]() |
d8abfd3999 | ||
![]() |
9fabffc880 | ||
![]() |
630b3229ee | ||
![]() |
fbce241753 | ||
![]() |
ffc7118af0 | ||
![]() |
1ab390e1a2 | ||
![]() |
909c1a2dda | ||
![]() |
c2cebaa3d1 | ||
![]() |
75b9a6cefe | ||
![]() |
1cbe1441aa | ||
![]() |
d0f0b95e45 | ||
![]() |
a78c2c3509 | ||
![]() |
ceaa143c62 | ||
![]() |
cb260bf6bf | ||
![]() |
0c28fbf7a5 | ||
![]() |
b02afb1116 | ||
![]() |
e5bbeff8ac | ||
![]() |
7e64a43af6 | ||
![]() |
51022e6162 | ||
![]() |
5cb9d5eaaf | ||
![]() |
ffa7f987b6 | ||
![]() |
9593c2a720 | ||
![]() |
d7c8daad0d | ||
![]() |
0859f4aa36 | ||
![]() |
c46467b5b9 | ||
![]() |
1b4f6ecb12 | ||
![]() |
fa468cac5f | ||
![]() |
ff1107bc5b | ||
![]() |
651a30105b | ||
![]() |
9cef21ecd6 | ||
![]() |
61c90b27ab | ||
![]() |
27ed176a22 | ||
![]() |
04d30ebced | ||
![]() |
d5f6b626d2 | ||
![]() |
5739daffc8 | ||
![]() |
9c2ce486a5 | ||
![]() |
7bef54856c | ||
![]() |
dda79ca70e | ||
![]() |
b16af564a7 | ||
![]() |
127b340a08 | ||
![]() |
7dd88c2f23 | ||
![]() |
c492466583 | ||
![]() |
7ee77d56a6 | ||
![]() |
eb6daab169 | ||
![]() |
b0cd92b70f | ||
![]() |
a929437490 | ||
![]() |
cb66d22b94 | ||
![]() |
d1af21f626 | ||
![]() |
0500cc234d | ||
![]() |
f7677549ea | ||
![]() |
d5caf84788 | ||
![]() |
e31f5ed26e | ||
![]() |
2d95064ff6 | ||
![]() |
e5093892fd | ||
![]() |
124fa9e2e7 | ||
![]() |
34ac83b594 | ||
![]() |
3ef0267f0a | ||
![]() |
d5ff785559 | ||
![]() |
e222ed73b8 | ||
![]() |
432fc7ed58 | ||
![]() |
43b512fd77 | ||
![]() |
980112c071 | ||
![]() |
b0e7efe6a5 | ||
![]() |
64638845e9 | ||
![]() |
97f362b465 | ||
![]() |
f1801f1958 | ||
![]() |
443ede470d | ||
![]() |
c4d4d5fb7d | ||
![]() |
28e0e20651 | ||
![]() |
9a10cac598 | ||
![]() |
0a080ba03c | ||
![]() |
3f0cd019d7 | ||
![]() |
5d3dbde698 | ||
![]() |
87ad67ada7 | ||
![]() |
fba5e2bf36 | ||
![]() |
2e9dabd434 | ||
![]() |
c8c7ad57bd | ||
![]() |
986faa783b | ||
![]() |
f86f56a628 | ||
![]() |
957650c3ee | ||
![]() |
8ff7ec50ef | ||
![]() |
48645907ec | ||
![]() |
3cbbba534c | ||
![]() |
3dcd01f8b8 | ||
![]() |
e7bdcb093b | ||
![]() |
810133d5a8 | ||
![]() |
3d6b0c6dd6 | ||
![]() |
225927b9a2 | ||
![]() |
88e76b367c | ||
![]() |
208a778387 | ||
![]() |
738f131269 | ||
![]() |
639d8a0b08 | ||
![]() |
ce2d186543 | ||
![]() |
091fa9091d | ||
![]() |
7efec130dc | ||
![]() |
cf98b7f824 | ||
![]() |
dde4001170 | ||
![]() |
c226779aca | ||
![]() |
02ef99a3a6 | ||
![]() |
bd9bd3a215 | ||
![]() |
ce98970c06 | ||
![]() |
7cc74491d0 | ||
![]() |
63cb6ce9fd | ||
![]() |
ee6688eb74 | ||
![]() |
ad70480de7 | ||
![]() |
490ee93796 | ||
![]() |
ba11d98fef | ||
![]() |
d629008688 | ||
![]() |
6aa3ea70dc | ||
![]() |
3d4012850a | ||
![]() |
5e035efbcb | ||
![]() |
515ec57b77 | ||
![]() |
585dcc7d19 | ||
![]() |
fc21fc9816 | ||
![]() |
77c784def4 | ||
![]() |
80bfaf1c54 | ||
![]() |
d89db64829 | ||
![]() |
191438b481 | ||
![]() |
37ed9dfe1e | ||
![]() |
0ac7193c4d | ||
![]() |
9ce469f372 | ||
![]() |
03ae049c0f | ||
![]() |
4194c502ae | ||
![]() |
f32da00667 | ||
![]() |
a285e814c1 | ||
![]() |
6948cc88ef | ||
![]() |
25a19e2f21 | ||
![]() |
c57c5c04e5 | ||
![]() |
656e0a8a7b | ||
![]() |
176d1aa17a | ||
![]() |
db3afc1c0d | ||
![]() |
dd69599f37 | ||
![]() |
2f4675eb93 | ||
![]() |
56c825c44c | ||
![]() |
987e409071 | ||
![]() |
fe59e18e69 | ||
![]() |
d3b9b37b07 | ||
![]() |
9ca89ad300 | ||
![]() |
031d953ed5 | ||
![]() |
9ece5c8a3f | ||
![]() |
f20179519f | ||
![]() |
80d0654847 | ||
![]() |
a40d171d9c | ||
![]() |
1cf8cbe546 | ||
![]() |
409ac54605 | ||
![]() |
3a1ec088e2 | ||
![]() |
a2d83132ca | ||
![]() |
580c32bcef | ||
![]() |
cc0af275c1 | ||
![]() |
fd20fc8837 | ||
![]() |
c442d7030d | ||
![]() |
6998cb5602 | ||
![]() |
d2dca2b6c3 | ||
![]() |
0e63224dea | ||
![]() |
0bbc3e7e3d | ||
![]() |
dd8e341de2 | ||
![]() |
d023aef6b5 | ||
![]() |
26c24c25c0 | ||
![]() |
58e3cc1be0 | ||
![]() |
7df91eb038 | ||
![]() |
728d87ceba | ||
![]() |
a6796fcbd9 | ||
![]() |
ffbb257434 | ||
![]() |
9ad4437a98 | ||
![]() |
a21a720941 | ||
![]() |
c2d7b62e8f | ||
![]() |
9270f17378 | ||
![]() |
395bfc2307 | ||
![]() |
a417ec4dcb | ||
![]() |
ec3292e8c4 | ||
![]() |
fe3186ba9d | ||
![]() |
3a97ce820c | ||
![]() |
c44ccb8cc7 | ||
![]() |
0914f158c2 | ||
![]() |
dcf94816fb | ||
![]() |
bb609467dd | ||
![]() |
a4c3f7dad9 | ||
![]() |
dceddcfd83 | ||
![]() |
0c2e139672 | ||
![]() |
fb1e7eabab | ||
![]() |
272f3adcc4 | ||
![]() |
87ad6fc0bb | ||
![]() |
2eeeb0f2e4 | ||
![]() |
aa541d6d6f | ||
![]() |
403a9eb11d | ||
![]() |
77f93bfd93 | ||
![]() |
b97638566e | ||
![]() |
7a1ba01621 | ||
![]() |
2b8cd6b758 | ||
![]() |
cbe339da07 | ||
![]() |
e290ce2de5 | ||
![]() |
c7fd4ba5f1 | ||
![]() |
0efc919f24 | ||
![]() |
c315a91fc6 | ||
![]() |
6e1fe5b301 | ||
![]() |
84a490f14c | ||
![]() |
42a9302636 | ||
![]() |
ae0c28a03d | ||
![]() |
1a5518ebbb | ||
![]() |
160a81c572 | ||
![]() |
4a2a72983f | ||
![]() |
33e064b3b9 | ||
![]() |
005442a4d0 | ||
![]() |
6c666190e2 | ||
![]() |
9ceb69921a | ||
![]() |
4b0db74770 | ||
![]() |
3bfd367d87 | ||
![]() |
6d5beb50ba | ||
![]() |
3d0b5db2e4 | ||
![]() |
ee9c78dc86 | ||
![]() |
b66ec2bf7a | ||
![]() |
2dc2cabe0e | ||
![]() |
56c7744e23 | ||
![]() |
9bc32d4be9 | ||
![]() |
0b0c99f1f5 | ||
![]() |
3d683b27f7 |
46
.github/workflows/nightly.yaml
vendored
Normal file
46
.github/workflows/nightly.yaml
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
name: Nightly builds
|
||||
on:
|
||||
workflow_dispatch: # Allows manual trigger
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
jobs:
|
||||
nightly:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.23.x]
|
||||
os: [ubuntu-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Setup
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
cache: false
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: master
|
||||
fetch-depth: 0
|
||||
fetch-tags: true
|
||||
|
||||
- name: Build
|
||||
run: tools/cross-compile.sh nightly
|
||||
|
||||
- name: Tag
|
||||
uses: rickstaa/action-create-tag@v1
|
||||
with:
|
||||
tag: nightly
|
||||
force_push_tag: true
|
||||
message: "Pre-release nightly"
|
||||
|
||||
- name: Publish
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
name: nightly
|
||||
tag_name: nightly
|
||||
files: binaries/*
|
||||
prerelease: true
|
||||
|
||||
- name: Cleanup
|
||||
run: rm -rf binaries
|
36
.github/workflows/release.yaml
vendored
Normal file
36
.github/workflows/release.yaml
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
name: Release builds
|
||||
on:
|
||||
workflow_dispatch: # Allows manual trigger
|
||||
# push:
|
||||
# tags:
|
||||
# - 'v*.*.*' # automatically react on semantic versioned tags
|
||||
jobs:
|
||||
release:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.23.x]
|
||||
os: [ubuntu-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Setup
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
cache: false
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
fetch-tags: true
|
||||
|
||||
- name: Build
|
||||
run: tools/cross-compile.sh
|
||||
|
||||
- name: Publish
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: binaries/*
|
||||
|
||||
- name: Cleanup
|
||||
run: rm -rf binaries
|
27
.github/workflows/test.yaml
vendored
Normal file
27
.github/workflows/test.yaml
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
on: [push, pull_request]
|
||||
name: Build and Test
|
||||
jobs:
|
||||
test:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.19.x, 1.23.x]
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
cache: false
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
fetch-tags: true
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
make build
|
||||
|
||||
- name: Test
|
||||
run: |
|
||||
make test
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,6 +15,5 @@ benchmark_results*
|
||||
tools/build-version
|
||||
tools/build-date
|
||||
tools/info-plist
|
||||
tools/bindata
|
||||
tools/vscode-tests/
|
||||
*.hdr
|
||||
|
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
||||
[submodule "tools/go-bindata"]
|
||||
path = tools/go-bindata
|
||||
url = https://github.com/zyedidia/go-bindata
|
11
.travis.yml
11
.travis.yml
@ -1,11 +0,0 @@
|
||||
language: go
|
||||
go:
|
||||
- "1.13.x"
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
- windows
|
||||
script:
|
||||
- go build ./cmd/micro
|
||||
- go test ./internal/...
|
||||
- go test ./cmd/...
|
@ -430,7 +430,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
github.com/gdamore/tcell/LICENSE
|
||||
================
|
||||
github.com/zyedidia/tcell/LICENSE (fork)
|
||||
github.com/micro-editor/tcell/LICENSE (fork)
|
||||
================
|
||||
|
||||
|
||||
@ -1048,7 +1048,7 @@ Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||
|
||||
github.com/flynn/json5/LICENSE
|
||||
================
|
||||
github.com/zyedidia/json5/LICENSE (fork)
|
||||
github.com/micro-editor/json5/LICENSE (fork)
|
||||
================
|
||||
|
||||
Decoder code based on package encoding/json from the Go language.
|
||||
@ -1108,7 +1108,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
github.com/james4k/terminal/LICENSE
|
||||
================
|
||||
github.com/zyedidia/terminal/LICENSE (fork)
|
||||
github.com/micro-editor/terminal/LICENSE (fork)
|
||||
================
|
||||
|
||||
Copyright (C) 2013 James Gray
|
||||
|
58
Makefile
58
Makefile
@ -1,58 +1,48 @@
|
||||
.PHONY: runtime
|
||||
.PHONY: runtime build generate build-quick
|
||||
|
||||
VERSION = $(shell GOOS=$(shell go env GOHOSTOS) GOARCH=$(shell go env GOHOSTARCH) \
|
||||
go run tools/build-version.go)
|
||||
HASH = $(shell git rev-parse --short HEAD)
|
||||
DATE = $(shell GOOS=$(shell go env GOHOSTOS) GOARCH=$(shell go env GOHOSTARCH) \
|
||||
go run tools/build-date.go)
|
||||
ADDITIONAL_GO_LINKER_FLAGS = $(shell GOOS=$(shell go env GOHOSTOS) \
|
||||
GOARCH=$(shell go env GOHOSTARCH) \
|
||||
go run tools/info-plist.go "$(VERSION)")
|
||||
GOBIN ?= $(shell go env GOPATH)/bin
|
||||
GOVARS = -X github.com/zyedidia/micro/v2/internal/util.Version=$(VERSION) -X github.com/zyedidia/micro/v2/internal/util.CommitHash=$(HASH) -X 'github.com/zyedidia/micro/v2/internal/util.CompileDate=$(DATE)'
|
||||
DEBUGVAR = -X github.com/zyedidia/micro/v2/internal/util.Debug=ON
|
||||
VSCODE_TESTS_BASE_URL = 'https://raw.githubusercontent.com/microsoft/vscode/e6a45f4242ebddb7aa9a229f85555e8a3bd987e2/src/vs/editor/test/common/model/'
|
||||
CGO_ENABLED := $(if $(CGO_ENABLED),$(CGO_ENABLED),0)
|
||||
|
||||
# Builds micro after checking dependencies but without updating the runtime
|
||||
build:
|
||||
go build -trimpath -ldflags "-s -w $(GOVARS) $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
||||
ADDITIONAL_GO_LINKER_FLAGS := ""
|
||||
GOHOSTOS = $(shell go env GOHOSTOS)
|
||||
ifeq ($(GOHOSTOS), darwin)
|
||||
# Native darwin resp. macOS builds need external and dynamic linking
|
||||
ADDITIONAL_GO_LINKER_FLAGS += $(shell GOOS=$(GOHOSTOS) \
|
||||
GOARCH=$(shell go env GOHOSTARCH) \
|
||||
go run tools/info-plist.go "$(shell go env GOOS)" "$(VERSION)")
|
||||
CGO_ENABLED = 1
|
||||
endif
|
||||
|
||||
build: generate build-quick
|
||||
|
||||
build-quick:
|
||||
CGO_ENABLED=$(CGO_ENABLED) go build -trimpath -ldflags "-s -w $(GOVARS) $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
||||
|
||||
build-dbg:
|
||||
go build -trimpath -ldflags "-s -w $(ADDITIONAL_GO_LINKER_FLAGS) $(DEBUGVAR)" ./cmd/micro
|
||||
CGO_ENABLED=$(CGO_ENABLED) go build -trimpath -ldflags "$(ADDITIONAL_GO_LINKER_FLAGS) $(DEBUGVAR)" ./cmd/micro
|
||||
|
||||
build-tags: fetch-tags
|
||||
go build -trimpath -ldflags "-s -w $(GOVARS) $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
||||
build-tags: fetch-tags build
|
||||
|
||||
# Builds micro after building the runtime and checking dependencies
|
||||
build-all: runtime build
|
||||
build-all: build
|
||||
|
||||
# Builds micro without checking for dependencies
|
||||
build-quick:
|
||||
go build -trimpath -ldflags "-s -w $(GOVARS) $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
||||
|
||||
# Same as 'build' but installs to $GOBIN afterward
|
||||
install:
|
||||
install: generate
|
||||
go install -ldflags "-s -w $(GOVARS) $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
||||
|
||||
# Same as 'build-all' but installs to $GOBIN afterward
|
||||
install-all: runtime install
|
||||
|
||||
# Same as 'build-quick' but installs to $GOBIN afterward
|
||||
install-quick:
|
||||
go install -ldflags "-s -w $(GOVARS) $(ADDITIONAL_GO_LINKER_FLAGS)" ./cmd/micro
|
||||
install-all: install
|
||||
|
||||
fetch-tags:
|
||||
git fetch --tags
|
||||
git fetch --tags --force
|
||||
|
||||
# Builds the runtime
|
||||
runtime:
|
||||
git submodule update --init
|
||||
rm -f runtime/syntax/*.hdr
|
||||
go run runtime/syntax/make_headers.go runtime/syntax
|
||||
go build -o tools/bindata ./tools/go-bindata
|
||||
tools/bindata -pkg config -nomemcopy -nometadata -o runtime.go runtime/...
|
||||
mv runtime.go internal/config
|
||||
gofmt -w internal/config/runtime.go
|
||||
generate:
|
||||
GOOS=$(shell go env GOHOSTOS) GOARCH=$(shell go env GOHOSTARCH) go generate ./runtime
|
||||
|
||||
testgen:
|
||||
mkdir -p tools/vscode-tests
|
||||
|
135
README.md
135
README.md
@ -1,6 +1,6 @@
|
||||
<img alt="micro logo" src="./assets/micro-logo.svg" width="500px"/>
|
||||
<img alt="micro logo" src="./assets/micro-logo-drop.svg" width="500px"/>
|
||||
|
||||
[](https://travis-ci.org/zyedidia/micro)
|
||||

|
||||
[](https://goreportcard.com/report/github.com/zyedidia/micro)
|
||||
[](https://github.com/zyedidia/micro/releases)
|
||||
[](https://github.com/zyedidia/micro/blob/master/LICENSE)
|
||||
@ -21,22 +21,6 @@ To see more screenshots of micro, showcasing some of the default color schemes,
|
||||
|
||||
You can also check out the website for Micro at https://micro-editor.github.io.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Features](#features)
|
||||
- [Installation](#installation)
|
||||
- [Prebuilt binaries](#prebuilt-binaries)
|
||||
- [Package Managers](#package-managers)
|
||||
- [Building from source](#building-from-source)
|
||||
- [Fully static binary](#fully-static-binary)
|
||||
- [macOS terminal](#macos-terminal)
|
||||
- [Linux clipboard support](#linux-clipboard-support)
|
||||
- [Colors and syntax highlighting](#colors-and-syntax-highlighting)
|
||||
- [Cygwin, Mingw, Plan9](#cygwin-mingw-plan9)
|
||||
- [Usage](#usage)
|
||||
- [Documentation and Help](#documentation-and-help)
|
||||
- [Contributing](#contributing)
|
||||
|
||||
- - -
|
||||
|
||||
## Features
|
||||
@ -53,7 +37,7 @@ You can also check out the website for Micro at https://micro-editor.github.io.
|
||||
- Extremely good mouse support.
|
||||
- This means mouse dragging to create a selection, double click to select by word, and triple click to select by line.
|
||||
- Cross-platform (it should work on all the platforms Go runs on).
|
||||
- Note that while Windows is supported Mingw/Cygwin is not (see below).
|
||||
- Note that while Windows is supported, Mingw/Cygwin is not (see below).
|
||||
- Plugin system (plugins are written in Lua).
|
||||
- micro has a built-in plugin manager to automatically install, remove, and update plugins.
|
||||
- Built-in diff gutter.
|
||||
@ -63,11 +47,12 @@ You can also check out the website for Micro at https://micro-editor.github.io.
|
||||
- Syntax highlighting for over [130 languages](runtime/syntax).
|
||||
- Color scheme support.
|
||||
- By default, micro comes with 16, 256, and true color themes.
|
||||
- True color support (set the `MICRO_TRUECOLOR` environment variable to 1 to enable it).
|
||||
- True color support.
|
||||
- Copy and paste with the system clipboard.
|
||||
- Small and simple.
|
||||
- Easily configurable.
|
||||
- Macros.
|
||||
- Smart highlighting of trailing whitespace and tab vs space errors.
|
||||
- Common editor features such as undo/redo, line numbers, Unicode support, soft wrapping, …
|
||||
|
||||
## Installation
|
||||
@ -81,17 +66,13 @@ stable version if you install from the prebuilt binaries, Homebrew, or Snap.
|
||||
|
||||
A desktop entry file and man page can be found in the [assets/packaging](https://github.com/zyedidia/micro/tree/master/assets/packaging) directory.
|
||||
|
||||
### Prebuilt binaries
|
||||
### Pre-built binaries
|
||||
|
||||
All you need to install micro is one file, the binary itself. It's as simple as that!
|
||||
Pre-built binaries are distributed in [releases](https://github.com/zyedidia/micro/releases).
|
||||
|
||||
Download the binary from the [releases](https://github.com/zyedidia/micro/releases) page.
|
||||
To uninstall micro, simply remove the binary, and the configuration directory at `~/.config/micro`.
|
||||
|
||||
### Installation script
|
||||
|
||||
There is a script which can install micro for you by downloading the latest prebuilt binary. You can find it at <https://getmic.ro>.
|
||||
|
||||
You can easily install micro by running
|
||||
#### Third-party quick-install script
|
||||
|
||||
```bash
|
||||
curl https://getmic.ro | bash
|
||||
@ -99,7 +80,24 @@ curl https://getmic.ro | bash
|
||||
|
||||
The script will place the micro binary in the current directory. From there, you can move it to a directory on your path of your choosing (e.g. `sudo mv micro /usr/bin`). See its [GitHub repository](https://github.com/benweissmann/getmic.ro) for more information.
|
||||
|
||||
To uninstall micro, simply remove the binary, and the configuration directory at `~/.config/micro`.
|
||||
#### Eget
|
||||
|
||||
With [Eget](https://github.com/zyedidia/eget) installed, you can easily get a pre-built binary:
|
||||
|
||||
```
|
||||
eget zyedidia/micro
|
||||
```
|
||||
|
||||
Use `--tag VERSION` to download a specific tagged version.
|
||||
|
||||
```
|
||||
eget --tag nightly zyedidia/micro # download the nightly version (compiled every day at midnight UTC)
|
||||
eget --tag v2.0.8 zyedidia/micro # download version 2.0.8 rather than the latest release
|
||||
```
|
||||
|
||||
You can install `micro` by adding `--to /usr/local/bin` to the `eget` command, or move the binary manually to a directory on your `$PATH` after the download completes.
|
||||
|
||||
See [Eget](https://github.com/zyedidia/eget) for more information.
|
||||
|
||||
### Package managers
|
||||
|
||||
@ -119,32 +117,52 @@ On Linux, you can install micro through [snap](https://snapcraft.io/docs/core/in
|
||||
snap install micro --classic
|
||||
```
|
||||
|
||||
**Note for Linux:** for interfacing with the local system clipboard, `xclip` or `xsel`
|
||||
must be installed. Please see the section on [Linux clipboard support](https://github.com/zyedidia/micro#linux-clipboard-support)
|
||||
further below.
|
||||
|
||||
Micro is also available through other package managers on Linux such as apt, dnf, AUR, Nix, and package managers
|
||||
Micro is also available through other package managers on Linux such as dnf, AUR, Nix, and package managers
|
||||
for other operating systems. These packages are not guaranteed to be up-to-date.
|
||||
|
||||
* Linux: Available in distro-specific package managers.
|
||||
* `apt install micro` (Ubuntu 20.04 `focal`, and Debian `unstable | testing | buster-backports`). At the moment, this package (2.0.1-1) is outdated and has a known bug where debug mode is enabled.
|
||||
<!-- * `apt install micro` (Ubuntu 20.04 `focal`, and Debian `unstable | testing | buster-backports`). At the moment, this package (2.0.1-1) is outdated and has a known bug where debug mode is enabled. -->
|
||||
|
||||
* Linux:
|
||||
* distro-specific package managers:
|
||||
* `dnf install micro` (Fedora).
|
||||
* `apt install micro` (Ubuntu and Debian).
|
||||
* `pacman -S micro` (Arch Linux).
|
||||
* `emerge app-editors/micro` (Gentoo).
|
||||
* `zypper install micro-editor` (SUSE)
|
||||
* `eopkg install micro` (Solus).
|
||||
* `pacstall -I micro` (Pacstall).
|
||||
* `apt-get install micro` (ALT Linux)
|
||||
* See [wiki](https://github.com/zyedidia/micro/wiki/Installing-Micro) for details about CRUX, Termux.
|
||||
* Windows: [Chocolatey](https://chocolatey.org) and [Scoop](https://github.com/lukesampson/scoop).
|
||||
* distro-agnostic package managers:
|
||||
* `nix profile install nixpkgs#micro` (with [Nix](https://nixos.org/) and flakes enabled)
|
||||
* `flox install micro` (with [Flox](https://flox.dev))
|
||||
* Windows: [Chocolatey](https://chocolatey.org), [Scoop](https://scoop.sh/) and [WinGet](https://learn.microsoft.com/en-us/windows/package-manager/winget/).
|
||||
* `choco install micro`.
|
||||
* `scoop install micro`.
|
||||
* `winget install zyedidia.micro`
|
||||
* OpenBSD: Available in the ports tree and also available as a binary package.
|
||||
* `pkd_add -v micro`.
|
||||
* `pkg_add -v micro`.
|
||||
* NetBSD, macOS, Linux, Illumos, etc. with [pkgsrc](http://www.pkgsrc.org/)-current:
|
||||
* `pkg_add micro`
|
||||
* macOS: Available in package managers.
|
||||
* `sudo port install micro` (with [MacPorts](https://www.macports.org))
|
||||
* `brew install micro` (with [Homebrew](https://brew.sh/))
|
||||
* `nix profile install nixpkgs#micro` (with [Nix](https://nixos.org/) and flakes enabled)
|
||||
* `flox install micro` (with [Flox](https://flox.dev))
|
||||
|
||||
**Note for Linux desktop environments:**
|
||||
|
||||
For interfacing with the local system clipboard, the following tools need to be installed:
|
||||
* For X11, `xclip` or `xsel`
|
||||
* For [Wayland](https://wayland.freedesktop.org/), `wl-clipboard`
|
||||
|
||||
Without these tools installed, micro will use an internal clipboard for copy and paste, but it won't be accessible to external applications.
|
||||
|
||||
### Building from source
|
||||
|
||||
If your operating system does not have a binary release, but does run Go, you can build from source.
|
||||
|
||||
Make sure that you have Go version 1.11 or greater and Go modules are enabled.
|
||||
Make sure that you have Go version 1.19 or greater and Go modules are enabled.
|
||||
|
||||
```
|
||||
git clone https://github.com/zyedidia/micro
|
||||
@ -162,16 +180,20 @@ You can install directly with `go get` (`go get github.com/zyedidia/micro/cmd/mi
|
||||
recommended because it doesn't build micro with version information (necessary for the plugin manager),
|
||||
and doesn't disable debug mode.
|
||||
|
||||
### Fully static binary
|
||||
### Fully static or dynamically linked binary
|
||||
|
||||
By default, the micro binary will dynamically link with core system libraries (this is generally
|
||||
recommended for security and portability). However, there is a fully static prebuilt binary that
|
||||
is provided for amd64 as `linux-static.tar.gz`, and to build a fully static binary from source, run
|
||||
By default, the micro binary is linked statically to increase the portability of the prebuilt binaries.
|
||||
This behavior can simply be overriden by providing `CGO_ENABLED=1` to the build target.
|
||||
|
||||
```
|
||||
CGO_ENABLED=0 make build
|
||||
CGO_ENABLED=1 make build
|
||||
```
|
||||
|
||||
Afterwards the micro binary will dynamically link with the present core system libraries.
|
||||
|
||||
**Note for Mac:**
|
||||
Native macOS builds are done with `CGO_ENABLED=1` forced set to support adding the "Information Property List" in the linker step.
|
||||
|
||||
### macOS terminal
|
||||
|
||||
If you are using macOS, you should consider using [iTerm2](http://iterm2.com/) instead of the default terminal (Terminal.app). The iTerm2 terminal has much better mouse support as well as better handling of key events. For best keybinding behavior, choose `xterm defaults` under `Preferences->Profiles->Keys->Presets...`, and select `Esc+` for `Left Option Key` in the same menu. The newest versions also support true color.
|
||||
@ -179,14 +201,17 @@ If you are using macOS, you should consider using [iTerm2](http://iterm2.com/) i
|
||||
If you still insist on using the default Mac terminal, be sure to set `Use Option key as Meta key` under
|
||||
`Preferences->Profiles->Keyboard` to use <kbd>option</kbd> as <kbd>alt</kbd>.
|
||||
|
||||
### Linux clipboard support
|
||||
### WSL and Windows Console
|
||||
|
||||
On Linux, clipboard support requires:
|
||||
If you use micro within WSL, it is highly recommended that you use the [Windows
|
||||
Terminal](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701?hl=en-us&gl=us)
|
||||
instead of the default Windows Console.
|
||||
|
||||
- On X11, the `xclip` or `xsel` commands (for Ubuntu: `sudo apt install xclip`)
|
||||
- On Wayland, the `wl-clipboard` command
|
||||
|
||||
If you don't have these commands, micro will use an internal clipboard for copy and paste, but it won't work with external applications.
|
||||
If you must use Windows Console for some reason, note that there is a bug in
|
||||
Windows Console WSL that causes a font change whenever micro tries to access
|
||||
the external clipboard via powershell. To fix this, use an internal clipboard
|
||||
with `set clipboard internal` (though your system clipboard will no longer be
|
||||
available in micro).
|
||||
|
||||
### Colors and syntax highlighting
|
||||
|
||||
@ -194,7 +219,7 @@ If you open micro and it doesn't seem like syntax highlighting is working, this
|
||||
you are using a terminal which does not support 256 color mode. Try changing the color scheme to `simple`
|
||||
by pressing <kbd>Ctrl-e</kbd> in micro and typing `set colorscheme simple`.
|
||||
|
||||
If you are using the default Ubuntu terminal, to enable 256 make sure your `TERM` variable is set
|
||||
If you are using the default Ubuntu terminal, to enable 256 color mode make sure your `TERM` variable is set
|
||||
to `xterm-256color`.
|
||||
|
||||
Many of the Windows terminals don't support more than 16 colors, which means
|
||||
@ -213,7 +238,7 @@ winpty micro.exe ...
|
||||
|
||||
Micro uses the amazing [tcell library](https://github.com/gdamore/tcell), but this
|
||||
means that micro is restricted to the platforms tcell supports. As a result, micro does not support
|
||||
Plan9, and Cygwin (although this may change in the future). Micro also doesn't support NaCl (which is deprecated anyway).
|
||||
Plan9 or Cygwin (although this may change in the future). Micro also doesn't support NaCl (which is deprecated anyway).
|
||||
|
||||
## Usage
|
||||
|
||||
@ -222,7 +247,7 @@ Once you have built the editor, start it by running `micro path/to/file.txt` or
|
||||
micro also supports creating buffers from `stdin`:
|
||||
|
||||
```sh
|
||||
ifconfig | micro
|
||||
ip a | micro
|
||||
```
|
||||
|
||||
You can move the cursor around with the arrow keys and mouse.
|
||||
@ -246,6 +271,8 @@ view the help files here:
|
||||
I also recommend reading the [tutorial](https://github.com/zyedidia/micro/tree/master/runtime/help/tutorial.md) for
|
||||
a brief introduction to the more powerful configuration features micro offers.
|
||||
|
||||
There is also an unofficial Discord, which you can join at https://discord.gg/nhWR6armnR.
|
||||
|
||||
## Contributing
|
||||
|
||||
If you find any bugs, please report them! I am also happy to accept pull requests from anyone.
|
||||
@ -253,6 +280,6 @@ If you find any bugs, please report them! I am also happy to accept pull request
|
||||
You can use the [GitHub issue tracker](https://github.com/zyedidia/micro/issues)
|
||||
to report bugs, ask questions, or suggest new features.
|
||||
|
||||
For a more informal setting to discuss the editor, you can join the [Gitter chat](https://gitter.im/zyedidia/micro).
|
||||
For a more informal setting to discuss the editor, you can join the [Gitter chat](https://gitter.im/zyedidia/micro) or the [Discord](https://discord.gg/nhWR6armnR). You can also use the [Discussions](https://github.com/zyedidia/micro/discussions) section on Github for a forum-like setting or for Q&A.
|
||||
|
||||
Sometimes I am unresponsive, and I apologize! If that happens, please ping me.
|
||||
|
109
assets/micro-logo-drop.svg
Normal file
109
assets/micro-logo-drop.svg
Normal file
@ -0,0 +1,109 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Generator: Adobe Illustrator 18.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
|
||||
<svg
|
||||
version="1.1"
|
||||
id="Layer_1"
|
||||
x="0px"
|
||||
y="0px"
|
||||
viewBox="0 0 304.70001 103.2"
|
||||
enable-background="new 0 0 960 560"
|
||||
xml:space="preserve"
|
||||
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
|
||||
sodipodi:docname="micro-logo-drop.svg"
|
||||
width="304.70001"
|
||||
height="103.2"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"><metadata
|
||||
id="metadata21"><rdf:RDF><cc:Work
|
||||
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
|
||||
id="defs19"><filter
|
||||
style="color-interpolation-filters:sRGB"
|
||||
inkscape:label="Blur"
|
||||
id="filter1040"
|
||||
x="-0.028037383"
|
||||
y="-0.10549451"
|
||||
width="1.0560748"
|
||||
height="1.210989"><feGaussianBlur
|
||||
stdDeviation="2 2"
|
||||
result="blur"
|
||||
id="feGaussianBlur1038" /></filter></defs><sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1080"
|
||||
id="namedview17"
|
||||
showgrid="false"
|
||||
fit-margin-top="0"
|
||||
fit-margin-left="0"
|
||||
fit-margin-right="0"
|
||||
fit-margin-bottom="0"
|
||||
inkscape:zoom="13.204388"
|
||||
inkscape:cx="71.832181"
|
||||
inkscape:cy="63.956011"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="Layer_1"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:deskcolor="#d1d1d1" /><g
|
||||
id="g838"
|
||||
transform="translate(-178,-172.8)"
|
||||
style="fill:#ffffff;fill-opacity:1;filter:url(#filter1040)"><path
|
||||
d="m 306.8,213.8 v -2.6 c 1.6,-0.1 2.9,-0.4 4.1,-0.8 1.2,-0.4 2.5,-1 4,-1.8 h 2.3 v 5.2 c 2.4,-1.9 4.2,-3.1 5.5,-3.8 2,-1 4,-1.5 5.8,-1.5 1.3,0 2.5,0.2 3.7,0.7 1.2,0.5 2.2,1 2.9,1.7 0.7,0.7 1.4,1.6 1.9,2.8 2.2,-1.9 4.2,-3.3 6,-4 1.9,-0.8 3.7,-1.2 5.6,-1.2 1.8,0 3.4,0.4 4.8,1.1 1.4,0.8 2.4,1.7 3,2.8 0.6,1.1 0.9,2.8 0.9,5 v 14.4 c 0,1.5 0,2.4 0.1,2.6 0.1,0.4 0.3,0.8 0.7,1.1 0.3,0.4 0.7,0.6 1.2,0.7 0.4,0.1 1.2,0.2 2.4,0.2 h 1 v 2.6 h -15.5 v -2.6 c 1.8,0 2.9,-0.1 3.5,-0.4 0.5,-0.2 0.9,-0.6 1.2,-1.2 0.3,-0.6 0.4,-1.6 0.4,-3.2 v -13.7 c 0,-1.7 -0.2,-2.9 -0.5,-3.6 -0.3,-0.7 -0.9,-1.2 -1.7,-1.7 -0.8,-0.4 -1.8,-0.7 -3,-0.7 -1.5,0 -3,0.4 -4.6,1.2 -2.2,1.1 -3.9,2.3 -5.1,3.6 v 14.8 c 0,1.4 0.1,2.4 0.2,2.8 0.1,0.4 0.4,0.8 0.7,1.1 0.3,0.3 0.7,0.5 1.1,0.6 0.4,0.1 1.5,0.2 3.1,0.2 v 2.6 h -15.3 v -2.6 h 0.9 c 1.2,0 2.1,-0.1 2.6,-0.4 0.5,-0.3 0.9,-0.7 1.2,-1.3 0.2,-0.5 0.3,-1.5 0.3,-2.9 v -13.2 c 0,-1.9 -0.2,-3.3 -0.5,-3.9 -0.3,-0.7 -0.9,-1.3 -1.7,-1.7 -0.8,-0.5 -1.8,-0.7 -3,-0.7 -1.3,0 -2.7,0.3 -4.1,1 -2,1 -3.9,2.2 -5.6,3.8 v 15.9 c 0,1 0.1,1.6 0.4,2.1 0.3,0.4 0.7,0.8 1.2,1.1 0.6,0.3 1.3,0.4 2.3,0.4 h 1.1 v 2.6 h -15.6 v -2.6 h 0.8 c 1.4,0 2.4,-0.1 2.8,-0.3 0.7,-0.3 1.1,-0.8 1.4,-1.5 0.2,-0.4 0.2,-1.3 0.2,-2.9 v -18.1 h -5.1 z"
|
||||
id="path828"
|
||||
inkscape:connector-curvature="0"
|
||||
style="fill:#ffffff;fill-opacity:1" /><path
|
||||
d="m 366.4,213.7 v -2.6 c 1.7,-0.2 3.2,-0.5 4.3,-0.9 1.2,-0.4 2.5,-1 4,-1.7 h 2.3 v 24.9 c 0,0.9 0.1,1.5 0.4,2 0.2,0.4 0.6,0.8 1,0.9 0.4,0.2 1.3,0.3 2.4,0.3 h 1.5 v 2.6 h -15.9 v -2.6 h 1.3 c 1.4,0 2.3,-0.1 2.8,-0.4 0.5,-0.2 0.8,-0.6 1,-1.1 0.2,-0.5 0.3,-1.5 0.3,-3.2 v -18.3 h -5.4 z m 7.9,-19.2 c 1,0 1.8,0.3 2.5,1 0.7,0.7 1.1,1.5 1.1,2.5 0,1 -0.4,1.8 -1.1,2.5 -0.7,0.7 -1.6,1.1 -2.5,1.1 -1,0 -1.8,-0.4 -2.5,-1.1 -0.7,-0.7 -1.1,-1.6 -1.1,-2.5 0,-1 0.4,-1.8 1.1,-2.5 0.6,-0.6 1.5,-1 2.5,-1 z"
|
||||
id="path830"
|
||||
inkscape:connector-curvature="0"
|
||||
style="fill:#ffffff;fill-opacity:1" /><path
|
||||
d="m 413.1,230.6 2,1.6 c -3.9,5.2 -8.6,7.8 -14,7.8 -4.2,0 -7.8,-1.5 -10.7,-4.5 -2.9,-3 -4.4,-6.8 -4.4,-11.3 0,-3 0.7,-5.7 2,-8.1 1.3,-2.4 3.2,-4.2 5.6,-5.6 2.4,-1.3 5.2,-2 8.3,-2 3.6,0 6.5,0.9 8.9,2.6 2.4,1.7 3.6,3.5 3.6,5.3 0,1 -0.3,1.7 -0.8,2.2 -0.5,0.5 -1.2,0.8 -1.9,0.8 -0.4,0 -0.7,-0.1 -1.1,-0.3 -0.4,-0.2 -0.7,-0.5 -1.1,-0.9 -0.2,-0.2 -0.5,-0.8 -0.9,-1.7 -0.6,-1.2 -1,-2 -1.3,-2.4 -0.6,-0.8 -1.4,-1.5 -2.4,-2 -0.9,-0.5 -2,-0.7 -3.1,-0.7 -1.8,0 -3.4,0.5 -4.9,1.5 -1.5,1 -2.7,2.4 -3.6,4.3 -0.9,1.9 -1.3,4.2 -1.3,6.8 0,4.1 1.1,7.3 3.3,9.7 1.9,2.1 4.1,3.1 6.7,3.1 1.2,0 2.4,-0.2 3.6,-0.6 1.2,-0.4 2.4,-1 3.5,-1.8 0.9,-0.6 2.2,-1.8 4,-3.8 z"
|
||||
id="path832"
|
||||
inkscape:connector-curvature="0"
|
||||
style="fill:#ffffff;fill-opacity:1" /><path
|
||||
d="m 418.7,213.7 v -2.6 c 1.5,-0.1 2.8,-0.4 4,-0.8 1.2,-0.4 2.5,-1 4,-1.9 h 2.3 v 5.9 c 1.5,-1.8 3.2,-3.2 5.1,-4.3 1.9,-1.1 3.7,-1.6 5.2,-1.6 1.5,0 2.7,0.4 3.6,1.1 0.9,0.7 1.3,1.6 1.3,2.6 0,0.7 -0.3,1.4 -0.9,2 -0.6,0.6 -1.3,0.9 -2.1,0.9 -0.4,0 -0.7,-0.1 -1,-0.2 -0.3,-0.1 -0.7,-0.3 -1.2,-0.7 -1.1,-0.7 -2.1,-1.1 -2.9,-1.1 -1,0 -2.2,0.4 -3.4,1.3 -1.6,1.1 -2.8,2.2 -3.7,3.3 V 232 c 0,1.2 0.1,2.1 0.2,2.5 0.1,0.4 0.4,0.8 0.7,1.1 0.3,0.3 0.7,0.6 1.1,0.7 0.5,0.1 1.3,0.2 2.4,0.2 h 1 v 2.6 h -16 v -2.6 h 1.3 c 1.3,0 2.1,-0.1 2.5,-0.3 0.5,-0.3 0.9,-0.7 1.2,-1.3 0.3,-0.5 0.4,-1.5 0.4,-3 v -18.3 h -5.1 z"
|
||||
id="path834"
|
||||
inkscape:connector-curvature="0"
|
||||
style="fill:#ffffff;fill-opacity:1" /><path
|
||||
d="m 462.8,208.5 c 3,0 5.7,0.6 7.9,1.9 2.2,1.3 4,3.1 5.3,5.5 1.3,2.4 1.9,5.2 1.9,8.3 0,3.1 -0.7,5.9 -2,8.3 -1.3,2.4 -3.1,4.3 -5.4,5.5 -2.3,1.3 -5,1.9 -8.1,1.9 -5,0 -8.8,-1.6 -11.3,-4.7 -2.5,-3.1 -3.8,-6.8 -3.8,-11 0,-3.1 0.7,-5.8 2,-8.2 1.3,-2.4 3.1,-4.2 5.5,-5.6 2.4,-1.2 5.1,-1.9 8,-1.9 z m -0.2,3 c -2.4,0 -4.4,0.9 -6,2.8 -2.1,2.3 -3.1,5.7 -3.1,10.1 0,4.3 0.9,7.5 2.6,9.7 1.6,2 3.8,3 6.5,3 1.8,0 3.3,-0.5 4.7,-1.4 1.4,-0.9 2.5,-2.4 3.3,-4.5 0.8,-2 1.3,-4.4 1.3,-7.2 0,-2.7 -0.5,-5.1 -1.4,-7.2 -0.7,-1.7 -1.8,-3 -3.2,-4 -1.3,-0.8 -2.9,-1.3 -4.7,-1.3 z"
|
||||
id="path836"
|
||||
inkscape:connector-curvature="0"
|
||||
style="fill:#ffffff;fill-opacity:1" /></g><g
|
||||
id="g3"
|
||||
transform="translate(-178,-172.8)"><path
|
||||
d="m 306.8,213.8 v -2.6 c 1.6,-0.1 2.9,-0.4 4.1,-0.8 1.2,-0.4 2.5,-1 4,-1.8 h 2.3 v 5.2 c 2.4,-1.9 4.2,-3.1 5.5,-3.8 2,-1 4,-1.5 5.8,-1.5 1.3,0 2.5,0.2 3.7,0.7 1.2,0.5 2.2,1 2.9,1.7 0.7,0.7 1.4,1.6 1.9,2.8 2.2,-1.9 4.2,-3.3 6,-4 1.9,-0.8 3.7,-1.2 5.6,-1.2 1.8,0 3.4,0.4 4.8,1.1 1.4,0.8 2.4,1.7 3,2.8 0.6,1.1 0.9,2.8 0.9,5 v 14.4 c 0,1.5 0,2.4 0.1,2.6 0.1,0.4 0.3,0.8 0.7,1.1 0.3,0.4 0.7,0.6 1.2,0.7 0.4,0.1 1.2,0.2 2.4,0.2 h 1 v 2.6 h -15.5 v -2.6 c 1.8,0 2.9,-0.1 3.5,-0.4 0.5,-0.2 0.9,-0.6 1.2,-1.2 0.3,-0.6 0.4,-1.6 0.4,-3.2 v -13.7 c 0,-1.7 -0.2,-2.9 -0.5,-3.6 -0.3,-0.7 -0.9,-1.2 -1.7,-1.7 -0.8,-0.4 -1.8,-0.7 -3,-0.7 -1.5,0 -3,0.4 -4.6,1.2 -2.2,1.1 -3.9,2.3 -5.1,3.6 v 14.8 c 0,1.4 0.1,2.4 0.2,2.8 0.1,0.4 0.4,0.8 0.7,1.1 0.3,0.3 0.7,0.5 1.1,0.6 0.4,0.1 1.5,0.2 3.1,0.2 v 2.6 h -15.3 v -2.6 h 0.9 c 1.2,0 2.1,-0.1 2.6,-0.4 0.5,-0.3 0.9,-0.7 1.2,-1.3 0.2,-0.5 0.3,-1.5 0.3,-2.9 v -13.2 c 0,-1.9 -0.2,-3.3 -0.5,-3.9 -0.3,-0.7 -0.9,-1.3 -1.7,-1.7 -0.8,-0.5 -1.8,-0.7 -3,-0.7 -1.3,0 -2.7,0.3 -4.1,1 -2,1 -3.9,2.2 -5.6,3.8 v 15.9 c 0,1 0.1,1.6 0.4,2.1 0.3,0.4 0.7,0.8 1.2,1.1 0.6,0.3 1.3,0.4 2.3,0.4 h 1.1 v 2.6 h -15.6 v -2.6 h 0.8 c 1.4,0 2.4,-0.1 2.8,-0.3 0.7,-0.3 1.1,-0.8 1.4,-1.5 0.2,-0.4 0.2,-1.3 0.2,-2.9 v -18.1 h -5.1 z"
|
||||
id="path5"
|
||||
inkscape:connector-curvature="0" /><path
|
||||
d="m 366.4,213.7 v -2.6 c 1.7,-0.2 3.2,-0.5 4.3,-0.9 1.2,-0.4 2.5,-1 4,-1.7 h 2.3 v 24.9 c 0,0.9 0.1,1.5 0.4,2 0.2,0.4 0.6,0.8 1,0.9 0.4,0.2 1.3,0.3 2.4,0.3 h 1.5 v 2.6 h -15.9 v -2.6 h 1.3 c 1.4,0 2.3,-0.1 2.8,-0.4 0.5,-0.2 0.8,-0.6 1,-1.1 0.2,-0.5 0.3,-1.5 0.3,-3.2 v -18.3 h -5.4 z m 7.9,-19.2 c 1,0 1.8,0.3 2.5,1 0.7,0.7 1.1,1.5 1.1,2.5 0,1 -0.4,1.8 -1.1,2.5 -0.7,0.7 -1.6,1.1 -2.5,1.1 -1,0 -1.8,-0.4 -2.5,-1.1 -0.7,-0.7 -1.1,-1.6 -1.1,-2.5 0,-1 0.4,-1.8 1.1,-2.5 0.6,-0.6 1.5,-1 2.5,-1 z"
|
||||
id="path7"
|
||||
inkscape:connector-curvature="0" /><path
|
||||
d="m 413.1,230.6 2,1.6 c -3.9,5.2 -8.6,7.8 -14,7.8 -4.2,0 -7.8,-1.5 -10.7,-4.5 -2.9,-3 -4.4,-6.8 -4.4,-11.3 0,-3 0.7,-5.7 2,-8.1 1.3,-2.4 3.2,-4.2 5.6,-5.6 2.4,-1.3 5.2,-2 8.3,-2 3.6,0 6.5,0.9 8.9,2.6 2.4,1.7 3.6,3.5 3.6,5.3 0,1 -0.3,1.7 -0.8,2.2 -0.5,0.5 -1.2,0.8 -1.9,0.8 -0.4,0 -0.7,-0.1 -1.1,-0.3 -0.4,-0.2 -0.7,-0.5 -1.1,-0.9 -0.2,-0.2 -0.5,-0.8 -0.9,-1.7 -0.6,-1.2 -1,-2 -1.3,-2.4 -0.6,-0.8 -1.4,-1.5 -2.4,-2 -0.9,-0.5 -2,-0.7 -3.1,-0.7 -1.8,0 -3.4,0.5 -4.9,1.5 -1.5,1 -2.7,2.4 -3.6,4.3 -0.9,1.9 -1.3,4.2 -1.3,6.8 0,4.1 1.1,7.3 3.3,9.7 1.9,2.1 4.1,3.1 6.7,3.1 1.2,0 2.4,-0.2 3.6,-0.6 1.2,-0.4 2.4,-1 3.5,-1.8 0.9,-0.6 2.2,-1.8 4,-3.8 z"
|
||||
id="path9"
|
||||
inkscape:connector-curvature="0" /><path
|
||||
d="m 418.7,213.7 v -2.6 c 1.5,-0.1 2.8,-0.4 4,-0.8 1.2,-0.4 2.5,-1 4,-1.9 h 2.3 v 5.9 c 1.5,-1.8 3.2,-3.2 5.1,-4.3 1.9,-1.1 3.7,-1.6 5.2,-1.6 1.5,0 2.7,0.4 3.6,1.1 0.9,0.7 1.3,1.6 1.3,2.6 0,0.7 -0.3,1.4 -0.9,2 -0.6,0.6 -1.3,0.9 -2.1,0.9 -0.4,0 -0.7,-0.1 -1,-0.2 -0.3,-0.1 -0.7,-0.3 -1.2,-0.7 -1.1,-0.7 -2.1,-1.1 -2.9,-1.1 -1,0 -2.2,0.4 -3.4,1.3 -1.6,1.1 -2.8,2.2 -3.7,3.3 V 232 c 0,1.2 0.1,2.1 0.2,2.5 0.1,0.4 0.4,0.8 0.7,1.1 0.3,0.3 0.7,0.6 1.1,0.7 0.5,0.1 1.3,0.2 2.4,0.2 h 1 v 2.6 h -16 v -2.6 h 1.3 c 1.3,0 2.1,-0.1 2.5,-0.3 0.5,-0.3 0.9,-0.7 1.2,-1.3 0.3,-0.5 0.4,-1.5 0.4,-3 v -18.3 h -5.1 z"
|
||||
id="path11"
|
||||
inkscape:connector-curvature="0" /><path
|
||||
d="m 462.8,208.5 c 3,0 5.7,0.6 7.9,1.9 2.2,1.3 4,3.1 5.3,5.5 1.3,2.4 1.9,5.2 1.9,8.3 0,3.1 -0.7,5.9 -2,8.3 -1.3,2.4 -3.1,4.3 -5.4,5.5 -2.3,1.3 -5,1.9 -8.1,1.9 -5,0 -8.8,-1.6 -11.3,-4.7 -2.5,-3.1 -3.8,-6.8 -3.8,-11 0,-3.1 0.7,-5.8 2,-8.2 1.3,-2.4 3.1,-4.2 5.5,-5.6 2.4,-1.2 5.1,-1.9 8,-1.9 z m -0.2,3 c -2.4,0 -4.4,0.9 -6,2.8 -2.1,2.3 -3.1,5.7 -3.1,10.1 0,4.3 0.9,7.5 2.6,9.7 1.6,2 3.8,3 6.5,3 1.8,0 3.3,-0.5 4.7,-1.4 1.4,-0.9 2.5,-2.4 3.3,-4.5 0.8,-2 1.3,-4.4 1.3,-7.2 0,-2.7 -0.5,-5.1 -1.4,-7.2 -0.7,-1.7 -1.8,-3 -3.2,-4 -1.3,-0.8 -2.9,-1.3 -4.7,-1.3 z"
|
||||
id="path13"
|
||||
inkscape:connector-curvature="0" /></g><path
|
||||
d="M 51.6,0 C 23.1,0 0,23.1 0,51.6 c 0,28.5 23.1,51.6 51.6,51.6 28.5,0 51.6,-23.1 51.6,-51.6 C 103.2,23.1 80.1,0 51.6,0 Z m 24.5,58.6 c -0.5,2 -1.3,3.6 -2.4,4.9 -1,1.3 -2,2.1 -3.1,2.5 -1.1,0.4 -2.2,0.6 -3.4,0.6 -1.2,0 -2.2,-0.2 -3,-0.7 C 63.4,65.5 62.8,64.8 62.3,64 61.8,63.2 61.5,62.2 61.3,61.1 61.1,60 61,58.8 61,57.5 c 0,-0.5 0,-1 0.1,-1.7 0.1,-0.7 0.2,-1.6 0.3,-1.6 h -0.2 c -1.6,4 -3.8,6.9 -6.6,9.2 -2.8,2.3 -5.9,3.4 -9.3,3.4 -2.3,0 -4.2,-0.9 -5.5,-2.6 -1.4,-1.7 -2.1,-4.3 -2.1,-7.7 0,-0.5 0,-1 0.1,-1.6 0.1,-0.5 0.1,-0.7 0.2,-1.7 h -0.7 c -0.9,2 -1.7,4.8 -2.3,7.3 -0.6,2.5 -1.1,4.8 -1.4,6.9 -0.4,2.1 -0.6,4 -0.8,5.6 -0.2,1.6 -0.3,2.7 -0.4,3.3 0.1,0.5 0.2,1 0.3,1.6 0.2,0.6 0.3,1.2 0.5,1.7 0.2,0.5 0.3,1.1 0.4,1.6 0.1,0.5 0.2,0.9 0.2,1.2 0,1.4 -0.3,2.5 -0.9,3.2 -0.6,0.7 -1.3,1.1 -2,1.1 -0.9,0 -1.7,-0.3 -2.3,-0.8 -0.7,-0.6 -1,-1.5 -1,-2.7 0,-1.7 0.3,-3.9 0.9,-6.5 0.6,-2.6 1.5,-5.9 2.6,-9.8 0.6,-1.8 1.1,-3.6 1.7,-5.4 0.6,-1.8 1.1,-3.5 1.6,-5 0.5,-1.5 0.9,-2.9 1.3,-4.1 0.4,-1.2 0.6,-2.1 0.7,-2.8 0.1,-0.3 0.2,-1 0.3,-2 0.1,-1 0.2,-2.1 0.4,-3.4 0.2,-1.3 0.3,-2.7 0.5,-4.1 0.2,-1.5 0.4,-2.8 0.5,-4 0.2,-0.9 0.3,-1.9 0.5,-3 0.2,-1.1 0.5,-2.2 0.9,-3.1 0.4,-1 1,-1.8 1.7,-2.5 0.7,-0.7 1.6,-1 2.7,-1 1.2,0 2,0.4 2.4,1.1 0.4,0.7 0.6,1.6 0.5,2.6 -0.1,1 -0.2,2.1 -0.5,3.2 -0.3,1.1 -0.6,2.1 -0.9,2.9 -0.8,2.5 -1.6,4.8 -2.5,6.7 -0.9,1.9 -1.7,4 -2.4,6.2 -0.6,1.5 -0.8,2.9 -0.8,4.1 0,2.2 0.7,3.8 2,5 1.4,1.2 3,1.7 4.9,1.7 1.5,0 3,-0.5 4.4,-1.6 1.4,-1.1 2.7,-2.4 3.9,-3.9 1.2,-1.5 2.2,-3.1 3,-4.9 0.8,-1.7 1.4,-3.3 1.8,-4.6 0.1,-0.2 0.2,-0.6 0.3,-1.4 0.2,-0.8 0.3,-1.7 0.5,-2.7 0.2,-1 0.4,-2 0.6,-3.1 0.2,-1.1 0.4,-2 0.5,-2.7 0.2,-0.8 0.3,-1.6 0.5,-2.6 0.2,-1 0.5,-1.9 0.9,-2.8 0.4,-0.9 1,-1.6 1.6,-2.2 0.7,-0.6 1.5,-0.9 2.6,-0.9 1.3,0 2.1,0.4 2.6,1.1 0.4,0.7 0.6,1.6 0.6,2.6 -0.1,1 -0.2,2 -0.5,3 -0.3,1 -0.5,1.8 -0.7,2.4 -0.8,2.5 -1.6,4.7 -2.4,6.7 -0.8,2 -1.5,3.8 -2.2,5.2 -0.6,1.5 -1.1,2.6 -1.5,3.5 -0.4,0.9 -0.6,1.5 -0.6,1.8 0,2.6 0.6,4.5 1.7,5.6 1.1,1.1 2.3,1.7 3.6,1.7 2.2,0 3.9,-0.7 5.2,-2 1.3,-1.4 2.3,-3.9 2.9,-6.9 h 0.8 c 0.2,2.9 -0.1,5.3 -0.6,7.3 z"
|
||||
id="path15"
|
||||
inkscape:connector-curvature="0"
|
||||
style="fill:#2e3192" /><path
|
||||
style="fill:#ffffff;stroke-width:0.0757324"
|
||||
d="m 30.026506,86.559353 c -1.017302,-0.241662 -1.787869,-0.887419 -2.143612,-1.796406 -0.545654,-1.394246 -0.158934,-4.812615 1.126179,-9.954732 1.255925,-5.025324 2.459082,-9.096362 5.109736,-17.289458 0.344312,-1.064257 1.654133,-5.2136 1.888607,-5.982859 0.296596,-0.97307 0.598551,-2.708021 0.79743,-4.581811 0.108312,-1.020494 0.246431,-2.186451 0.306932,-2.591018 0.0605,-0.404565 0.178758,-1.341754 0.262796,-2.082641 0.224837,-1.982189 0.649291,-5.218012 0.916787,-6.98913 0.444542,-2.943359 0.753682,-4.198397 1.354756,-5.499991 0.686842,-1.487323 1.771061,-2.655188 2.805126,-3.021538 0.542395,-0.19216 1.381388,-0.270583 1.982594,-0.185316 1.252526,0.17764 1.883508,0.754167 2.211742,2.020866 0.313761,1.21084 -0.05565,3.930951 -0.877141,6.458782 -1.290698,3.971623 -2.036395,5.990995 -2.986916,8.088674 -1.185138,2.61545 -2.712212,6.873258 -2.939609,8.196258 -0.49042,2.853282 0.04972,5.146283 1.578225,6.6999 0.913915,0.928929 2.023939,1.521458 3.413442,1.82209 0.903748,0.195534 2.608483,0.179674 3.407958,-0.03171 1.383427,-0.365777 2.763884,-1.250325 4.377299,-2.804821 3.163126,-3.047616 5.113532,-6.222841 6.797438,-11.066108 0.353971,-1.018094 0.493359,-1.574562 0.749316,-2.991429 0.271014,-1.500218 1.040858,-5.574621 1.51657,-8.026458 0.08082,-0.416528 0.218253,-1.149239 0.305416,-1.628246 0.472088,-2.594388 1.148516,-4.178722 2.330295,-5.458032 0.763841,-0.826879 1.674493,-1.206419 2.894632,-1.206419 1.24359,0 2.138991,0.401576 2.574266,1.154526 0.974305,1.685378 0.683954,4.053139 -1.163626,9.489195 -0.954432,2.808181 -2.572717,6.998752 -3.493593,9.046702 -0.971745,2.161077 -2.201912,5.041664 -2.441809,5.717796 l -0.268706,0.757324 0.09021,1.120423 c 0.212423,2.638199 0.889316,4.086035 2.469149,5.281365 0.932959,0.705895 1.786459,0.982601 3.026274,0.981126 2.426542,-0.0029 4.480731,-1.028876 5.685658,-2.839769 0.811784,-1.220036 1.58443,-3.158397 2.044887,-5.130071 l 0.207813,-0.889855 h 0.356374 0.356373 l 0.04799,0.892492 c 0.0554,1.030319 -0.04881,3.015268 -0.219241,4.175846 -0.345822,2.354993 -1.040859,4.427262 -1.983165,5.91286 -0.701565,1.106055 -1.958204,2.491062 -2.717404,2.994989 -1.555814,1.032691 -4.187858,1.499135 -6.161832,1.091984 -0.603718,-0.124523 -1.72865,-0.689523 -2.178956,-1.094387 -1.477985,-1.328835 -2.187139,-3.341642 -2.360358,-6.699454 -0.08196,-1.588814 0.0522,-3.504923 0.298559,-4.263967 0.05681,-0.175039 0.04587,-0.208265 -0.06857,-0.208265 -0.09667,0 -0.197671,0.148268 -0.348229,0.511194 -0.711765,1.715746 -1.965261,3.867832 -3.142896,5.395934 -0.680786,0.883388 -2.612844,2.822501 -3.483678,3.496397 -2.517073,1.947843 -5.073167,2.951502 -8.060525,3.164993 -1.592379,0.1138 -2.868371,-0.07567 -4.016971,-0.596469 -1.69649,-0.769225 -3.109446,-2.469115 -3.819014,-4.594555 -0.614034,-1.839276 -0.863382,-4.754214 -0.580679,-6.788275 0.05951,-0.428202 0.126068,-0.957467 0.147897,-1.176145 l 0.03969,-0.397595 H 37.651633 37.254872 L 36.96284,53.90253 c -0.705326,1.783387 -1.458627,4.293583 -2.085205,6.948448 -1.027173,4.352223 -1.56307,7.486558 -2.197428,12.852248 -0.310323,2.624858 -0.310577,2.629265 -0.189513,3.294359 0.13956,0.766706 0.417018,1.85334 0.68249,2.672894 0.306093,0.944956 0.565598,2.296449 0.565598,2.945615 0,1.819491 -0.751236,3.258298 -2.006909,3.84374 -0.402074,0.187462 -1.15114,0.231172 -1.705369,0.09951 z"
|
||||
id="path218" /></svg>
|
After Width: | Height: | Size: 16 KiB |
@ -2,13 +2,6 @@
|
||||
<!-- Generator: Adobe Illustrator 18.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
version="1.1"
|
||||
id="Layer_1"
|
||||
x="0px"
|
||||
@ -16,13 +9,20 @@
|
||||
viewBox="0 0 103.2 103.2"
|
||||
enable-background="new 0 0 960 560"
|
||||
xml:space="preserve"
|
||||
inkscape:version="0.91 r13725"
|
||||
sodipodi:docname="micro-logo-notext.svg"
|
||||
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
|
||||
sodipodi:docname="micro-logo-mark.svg"
|
||||
width="103.2"
|
||||
height="103.2"><metadata
|
||||
height="103.2"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"><metadata
|
||||
id="metadata9"><rdf:RDF><cc:Work
|
||||
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:Work></rdf:RDF></metadata><defs
|
||||
id="defs7" /><sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
@ -32,22 +32,28 @@
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="733"
|
||||
inkscape:window-height="480"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1080"
|
||||
id="namedview5"
|
||||
showgrid="false"
|
||||
fit-margin-top="0"
|
||||
fit-margin-left="0"
|
||||
fit-margin-right="0"
|
||||
fit-margin-bottom="0"
|
||||
inkscape:zoom="0.28541667"
|
||||
inkscape:cx="302"
|
||||
inkscape:cy="-4"
|
||||
inkscape:window-x="1699"
|
||||
inkscape:window-y="277"
|
||||
inkscape:zoom="5.405335"
|
||||
inkscape:cx="75.573484"
|
||||
inkscape:cy="51.153166"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="0"
|
||||
inkscape:current-layer="Layer_1" /><path
|
||||
inkscape:current-layer="Layer_1"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1" /><path
|
||||
d="M 51.6,0 C 23.1,0 0,23.1 0,51.6 c 0,28.5 23.1,51.6 51.6,51.6 28.5,0 51.6,-23.1 51.6,-51.6 C 103.2,23.1 80.1,0 51.6,0 Z m 24.5,58.6 c -0.5,2 -1.3,3.6 -2.4,4.9 -1,1.3 -2,2.1 -3.1,2.5 -1.1,0.4 -2.2,0.6 -3.4,0.6 -1.2,0 -2.2,-0.2 -3,-0.7 C 63.4,65.5 62.8,64.8 62.3,64 61.8,63.2 61.5,62.2 61.3,61.1 61.1,60 61,58.8 61,57.5 c 0,-0.5 0,-1 0.1,-1.7 0.1,-0.7 0.2,-1.6 0.3,-1.6 l -0.2,0 c -1.6,4 -3.8,6.9 -6.6,9.2 -2.8,2.3 -5.9,3.4 -9.3,3.4 -2.3,0 -4.2,-0.9 -5.5,-2.6 -1.4,-1.7 -2.1,-4.3 -2.1,-7.7 0,-0.5 0,-1 0.1,-1.6 0.1,-0.5 0.1,-0.7 0.2,-1.7 l -0.7,0 c -0.9,2 -1.7,4.8 -2.3,7.3 -0.6,2.5 -1.1,4.8 -1.4,6.9 -0.4,2.1 -0.6,4 -0.8,5.6 -0.2,1.6 -0.3,2.7 -0.4,3.3 0.1,0.5 0.2,1 0.3,1.6 0.2,0.6 0.3,1.2 0.5,1.7 0.2,0.5 0.3,1.1 0.4,1.6 0.1,0.5 0.2,0.9 0.2,1.2 0,1.4 -0.3,2.5 -0.9,3.2 -0.6,0.7 -1.3,1.1 -2,1.1 -0.9,0 -1.7,-0.3 -2.3,-0.8 -0.7,-0.6 -1,-1.5 -1,-2.7 0,-1.7 0.3,-3.9 0.9,-6.5 0.6,-2.6 1.5,-5.9 2.6,-9.8 0.6,-1.8 1.1,-3.6 1.7,-5.4 0.6,-1.8 1.1,-3.5 1.6,-5 0.5,-1.5 0.9,-2.9 1.3,-4.1 0.4,-1.2 0.6,-2.1 0.7,-2.8 0.1,-0.3 0.2,-1 0.3,-2 0.1,-1 0.2,-2.1 0.4,-3.4 0.2,-1.3 0.3,-2.7 0.5,-4.1 0.2,-1.5 0.4,-2.8 0.5,-4 0.2,-0.9 0.3,-1.9 0.5,-3 0.2,-1.1 0.5,-2.2 0.9,-3.1 0.4,-1 1,-1.8 1.7,-2.5 0.7,-0.7 1.6,-1 2.7,-1 1.2,0 2,0.4 2.4,1.1 0.4,0.7 0.6,1.6 0.5,2.6 -0.1,1 -0.2,2.1 -0.5,3.2 -0.3,1.1 -0.6,2.1 -0.9,2.9 -0.8,2.5 -1.6,4.8 -2.5,6.7 -0.9,1.9 -1.7,4 -2.4,6.2 -0.6,1.5 -0.8,2.9 -0.8,4.1 0,2.2 0.7,3.8 2,5 1.4,1.2 3,1.7 4.9,1.7 1.5,0 3,-0.5 4.4,-1.6 1.4,-1.1 2.7,-2.4 3.9,-3.9 1.2,-1.5 2.2,-3.1 3,-4.9 0.8,-1.7 1.4,-3.3 1.8,-4.6 0.1,-0.2 0.2,-0.6 0.3,-1.4 0.2,-0.8 0.3,-1.7 0.5,-2.7 0.2,-1 0.4,-2 0.6,-3.1 0.2,-1.1 0.4,-2 0.5,-2.7 0.2,-0.8 0.3,-1.6 0.5,-2.6 0.2,-1 0.5,-1.9 0.9,-2.8 0.4,-0.9 1,-1.6 1.6,-2.2 0.7,-0.6 1.5,-0.9 2.6,-0.9 1.3,0 2.1,0.4 2.6,1.1 0.4,0.7 0.6,1.6 0.6,2.6 -0.1,1 -0.2,2 -0.5,3 -0.3,1 -0.5,1.8 -0.7,2.4 -0.8,2.5 -1.6,4.7 -2.4,6.7 -0.8,2 -1.5,3.8 -2.2,5.2 -0.6,1.5 -1.1,2.6 -1.5,3.5 -0.4,0.9 -0.6,1.5 -0.6,1.8 0,2.6 0.6,4.5 1.7,5.6 1.1,1.1 2.3,1.7 3.6,1.7 2.2,0 3.9,-0.7 5.2,-2 1.3,-1.4 2.3,-3.9 2.9,-6.9 l 0.8,0 c 0.2,2.9 -0.1,5.3 -0.6,7.3 z"
|
||||
id="path3"
|
||||
inkscape:connector-curvature="0"
|
||||
style="fill:#2e3192" /></svg>
|
||||
style="fill:#2e3192" /><path
|
||||
style="fill:#ffffff;stroke-width:0.185002"
|
||||
d="m 29.320064,86.164872 c -1.277771,-0.647664 -1.573829,-1.327981 -1.549788,-3.561297 0.04016,-3.730697 1.622887,-10.030031 5.903272,-23.495306 2.770635,-8.715885 2.799071,-8.822813 3.148729,-11.840154 0.585284,-5.050637 1.565844,-12.45598 1.8369,-13.872547 0.43516,-2.274196 0.976755,-3.690519 1.880879,-4.918684 0.974445,-1.323691 1.896478,-1.826405 3.360953,-1.832474 3.009215,-0.01247 3.55713,2.574946 1.786201,8.434969 -0.742771,2.45784 -2.2493,6.487571 -3.407575,9.114735 -0.420971,0.954834 -1.151241,2.827983 -1.622823,4.162554 -0.839682,2.376289 -0.857669,2.47434 -0.869358,4.739023 -0.01095,2.122185 0.02796,2.3976 0.472736,3.346042 0.91751,1.956495 2.602228,3.131322 5.078862,3.541714 2.587757,0.428804 4.551892,-0.347899 7.187533,-2.842264 2.232774,-2.113092 3.746907,-4.117682 4.998184,-6.617188 1.816108,-3.627792 2.213624,-4.978174 3.527565,-11.983266 0.66466,-3.543546 1.376157,-6.951356 1.581104,-7.57291 0.970636,-2.943689 2.922262,-4.567831 5.096985,-4.241711 1.740397,0.260989 2.500104,1.361773 2.494406,3.614287 -0.0068,2.696563 -2.48184,9.966491 -6.424307,18.870246 l -1.269708,2.867537 0.02005,1.757523 c 0.01504,1.318294 0.119434,2.015481 0.417735,2.789716 1.028756,2.67011 3.517063,4.054736 6.342356,3.529224 3.19144,-0.593617 4.98902,-2.612828 6.217715,-6.984325 0.403553,-1.435775 0.552101,-1.739647 0.850428,-1.739647 0.34646,0 0.356492,0.101757 0.241656,2.451282 -0.238951,4.888854 -1.330826,7.853563 -3.80789,10.339358 -1.255532,1.259957 -1.547319,1.456015 -2.694109,1.81022 -1.395674,0.431082 -3.784736,0.537505 -4.865716,0.216749 -1.759682,-0.522141 -3.031085,-2.027386 -3.686869,-4.364972 -0.336042,-1.197843 -0.516218,-5.455318 -0.283812,-6.706338 0.266094,-1.432359 -0.105859,-1.235144 -0.879069,0.466093 -1.724383,3.794037 -4.750586,7.236231 -8.063683,9.172148 -2.368072,1.383716 -5.903865,2.143782 -8.230062,1.769159 -2.672688,-0.430424 -4.588062,-2.213422 -5.66376,-5.272324 -0.491128,-1.396592 -0.514658,-1.618704 -0.512739,-4.840059 0.0018,-3.093063 -0.02515,-3.376294 -0.321772,-3.376294 -0.414677,0 -0.706335,0.582138 -1.434591,2.863386 -1.443227,4.52088 -2.73082,10.895957 -3.516703,17.411762 l -0.381426,3.162426 0.469219,1.740138 c 0.927877,3.441104 1.066474,4.326417 0.841521,5.375336 -0.537458,2.506081 -2.272098,3.528416 -4.269226,2.516133 z"
|
||||
id="path210" /></svg>
|
||||
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 6.2 KiB |
@ -2,13 +2,6 @@
|
||||
<!-- Generator: Adobe Illustrator 18.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
version="1.1"
|
||||
id="Layer_1"
|
||||
x="0px"
|
||||
@ -16,13 +9,20 @@
|
||||
viewBox="0 0 299.89999 103.2"
|
||||
enable-background="new 0 0 960 560"
|
||||
xml:space="preserve"
|
||||
inkscape:version="0.91 r13725"
|
||||
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
|
||||
sodipodi:docname="micro-logo.svg"
|
||||
width="299.89999"
|
||||
height="103.2"><metadata
|
||||
height="103.2"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"><metadata
|
||||
id="metadata21"><rdf:RDF><cc:Work
|
||||
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:Work></rdf:RDF></metadata><defs
|
||||
id="defs19" /><sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
@ -32,21 +32,24 @@
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1237"
|
||||
inkscape:window-height="867"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1080"
|
||||
id="namedview17"
|
||||
showgrid="false"
|
||||
fit-margin-top="0"
|
||||
fit-margin-left="0"
|
||||
fit-margin-right="0"
|
||||
fit-margin-bottom="0"
|
||||
inkscape:zoom="1.1416667"
|
||||
inkscape:cx="75.655934"
|
||||
inkscape:cy="-4"
|
||||
inkscape:window-x="1097"
|
||||
inkscape:window-y="185"
|
||||
inkscape:zoom="16.645603"
|
||||
inkscape:cx="65.092264"
|
||||
inkscape:cy="49.051992"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="0"
|
||||
inkscape:current-layer="Layer_1" /><g
|
||||
inkscape:current-layer="Layer_1"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1" /><g
|
||||
id="g3"
|
||||
transform="translate(-178,-172.8)"><path
|
||||
d="m 306.8,213.8 0,-2.6 c 1.6,-0.1 2.9,-0.4 4.1,-0.8 1.2,-0.4 2.5,-1 4,-1.8 l 2.3,0 0,5.2 c 2.4,-1.9 4.2,-3.1 5.5,-3.8 2,-1 4,-1.5 5.8,-1.5 1.3,0 2.5,0.2 3.7,0.7 1.2,0.5 2.2,1 2.9,1.7 0.7,0.7 1.4,1.6 1.9,2.8 2.2,-1.9 4.2,-3.3 6,-4 1.9,-0.8 3.7,-1.2 5.6,-1.2 1.8,0 3.4,0.4 4.8,1.1 1.4,0.8 2.4,1.7 3,2.8 0.6,1.1 0.9,2.8 0.9,5 l 0,14.4 c 0,1.5 0,2.4 0.1,2.6 0.1,0.4 0.3,0.8 0.7,1.1 0.3,0.4 0.7,0.6 1.2,0.7 0.4,0.1 1.2,0.2 2.4,0.2 l 1,0 0,2.6 -15.5,0 0,-2.6 c 1.8,0 2.9,-0.1 3.5,-0.4 0.5,-0.2 0.9,-0.6 1.2,-1.2 0.3,-0.6 0.4,-1.6 0.4,-3.2 l 0,-13.7 c 0,-1.7 -0.2,-2.9 -0.5,-3.6 -0.3,-0.7 -0.9,-1.2 -1.7,-1.7 -0.8,-0.4 -1.8,-0.7 -3,-0.7 -1.5,0 -3,0.4 -4.6,1.2 -2.2,1.1 -3.9,2.3 -5.1,3.6 l 0,14.8 c 0,1.4 0.1,2.4 0.2,2.8 0.1,0.4 0.4,0.8 0.7,1.1 0.3,0.3 0.7,0.5 1.1,0.6 0.4,0.1 1.5,0.2 3.1,0.2 l 0,2.6 -15.3,0 0,-2.6 0.9,0 c 1.2,0 2.1,-0.1 2.6,-0.4 0.5,-0.3 0.9,-0.7 1.2,-1.3 0.2,-0.5 0.3,-1.5 0.3,-2.9 l 0,-13.2 c 0,-1.9 -0.2,-3.3 -0.5,-3.9 -0.3,-0.7 -0.9,-1.3 -1.7,-1.7 -0.8,-0.5 -1.8,-0.7 -3,-0.7 -1.3,0 -2.7,0.3 -4.1,1 -2,1 -3.9,2.2 -5.6,3.8 l 0,15.9 c 0,1 0.1,1.6 0.4,2.1 0.3,0.4 0.7,0.8 1.2,1.1 0.6,0.3 1.3,0.4 2.3,0.4 l 1.1,0 0,2.6 -15.6,0 0,-2.6 0.8,0 c 1.4,0 2.4,-0.1 2.8,-0.3 0.7,-0.3 1.1,-0.8 1.4,-1.5 0.2,-0.4 0.2,-1.3 0.2,-2.9 l 0,-18.1 -5.1,0 z"
|
||||
@ -67,4 +70,7 @@
|
||||
d="M 51.6,0 C 23.1,0 0,23.1 0,51.6 c 0,28.5 23.1,51.6 51.6,51.6 28.5,0 51.6,-23.1 51.6,-51.6 C 103.2,23.1 80.1,0 51.6,0 Z m 24.5,58.6 c -0.5,2 -1.3,3.6 -2.4,4.9 -1,1.3 -2,2.1 -3.1,2.5 -1.1,0.4 -2.2,0.6 -3.4,0.6 -1.2,0 -2.2,-0.2 -3,-0.7 C 63.4,65.5 62.8,64.8 62.3,64 61.8,63.2 61.5,62.2 61.3,61.1 61.1,60 61,58.8 61,57.5 c 0,-0.5 0,-1 0.1,-1.7 0.1,-0.7 0.2,-1.6 0.3,-1.6 l -0.2,0 c -1.6,4 -3.8,6.9 -6.6,9.2 -2.8,2.3 -5.9,3.4 -9.3,3.4 -2.3,0 -4.2,-0.9 -5.5,-2.6 -1.4,-1.7 -2.1,-4.3 -2.1,-7.7 0,-0.5 0,-1 0.1,-1.6 0.1,-0.5 0.1,-0.7 0.2,-1.7 l -0.7,0 c -0.9,2 -1.7,4.8 -2.3,7.3 -0.6,2.5 -1.1,4.8 -1.4,6.9 -0.4,2.1 -0.6,4 -0.8,5.6 -0.2,1.6 -0.3,2.7 -0.4,3.3 0.1,0.5 0.2,1 0.3,1.6 0.2,0.6 0.3,1.2 0.5,1.7 0.2,0.5 0.3,1.1 0.4,1.6 0.1,0.5 0.2,0.9 0.2,1.2 0,1.4 -0.3,2.5 -0.9,3.2 -0.6,0.7 -1.3,1.1 -2,1.1 -0.9,0 -1.7,-0.3 -2.3,-0.8 -0.7,-0.6 -1,-1.5 -1,-2.7 0,-1.7 0.3,-3.9 0.9,-6.5 0.6,-2.6 1.5,-5.9 2.6,-9.8 0.6,-1.8 1.1,-3.6 1.7,-5.4 0.6,-1.8 1.1,-3.5 1.6,-5 0.5,-1.5 0.9,-2.9 1.3,-4.1 0.4,-1.2 0.6,-2.1 0.7,-2.8 0.1,-0.3 0.2,-1 0.3,-2 0.1,-1 0.2,-2.1 0.4,-3.4 0.2,-1.3 0.3,-2.7 0.5,-4.1 0.2,-1.5 0.4,-2.8 0.5,-4 0.2,-0.9 0.3,-1.9 0.5,-3 0.2,-1.1 0.5,-2.2 0.9,-3.1 0.4,-1 1,-1.8 1.7,-2.5 0.7,-0.7 1.6,-1 2.7,-1 1.2,0 2,0.4 2.4,1.1 0.4,0.7 0.6,1.6 0.5,2.6 -0.1,1 -0.2,2.1 -0.5,3.2 -0.3,1.1 -0.6,2.1 -0.9,2.9 -0.8,2.5 -1.6,4.8 -2.5,6.7 -0.9,1.9 -1.7,4 -2.4,6.2 -0.6,1.5 -0.8,2.9 -0.8,4.1 0,2.2 0.7,3.8 2,5 1.4,1.2 3,1.7 4.9,1.7 1.5,0 3,-0.5 4.4,-1.6 1.4,-1.1 2.7,-2.4 3.9,-3.9 1.2,-1.5 2.2,-3.1 3,-4.9 0.8,-1.7 1.4,-3.3 1.8,-4.6 0.1,-0.2 0.2,-0.6 0.3,-1.4 0.2,-0.8 0.3,-1.7 0.5,-2.7 0.2,-1 0.4,-2 0.6,-3.1 0.2,-1.1 0.4,-2 0.5,-2.7 0.2,-0.8 0.3,-1.6 0.5,-2.6 0.2,-1 0.5,-1.9 0.9,-2.8 0.4,-0.9 1,-1.6 1.6,-2.2 0.7,-0.6 1.5,-0.9 2.6,-0.9 1.3,0 2.1,0.4 2.6,1.1 0.4,0.7 0.6,1.6 0.6,2.6 -0.1,1 -0.2,2 -0.5,3 -0.3,1 -0.5,1.8 -0.7,2.4 -0.8,2.5 -1.6,4.7 -2.4,6.7 -0.8,2 -1.5,3.8 -2.2,5.2 -0.6,1.5 -1.1,2.6 -1.5,3.5 -0.4,0.9 -0.6,1.5 -0.6,1.8 0,2.6 0.6,4.5 1.7,5.6 1.1,1.1 2.3,1.7 3.6,1.7 2.2,0 3.9,-0.7 5.2,-2 1.3,-1.4 2.3,-3.9 2.9,-6.9 l 0.8,0 c 0.2,2.9 -0.1,5.3 -0.6,7.3 z"
|
||||
id="path15"
|
||||
inkscape:connector-curvature="0"
|
||||
style="fill:#2e3192" /></svg>
|
||||
style="fill:#2e3192" /><path
|
||||
style="fill:#ffffff;stroke-width:0.0600759"
|
||||
d="m 30.192709,86.597991 c -0.530828,-0.09608 -1.19875,-0.411872 -1.578921,-0.746511 -0.792953,-0.697985 -1.054327,-1.680313 -0.947823,-3.562219 0.16271,-2.875042 0.852662,-6.034057 2.963728,-13.569713 0.66017,-2.356543 0.955814,-3.307037 3.762987,-12.097989 1.219825,-3.820007 1.435496,-4.505244 1.616654,-5.136492 0.306236,-1.067081 0.590331,-2.663175 0.753866,-4.235353 0.08592,-0.826044 0.236455,-2.096649 0.334514,-2.823568 0.09806,-0.726919 0.246246,-1.916422 0.329306,-2.643341 0.08306,-0.726918 0.231698,-1.902905 0.330307,-2.613302 0.09861,-0.710398 0.231242,-1.724179 0.294741,-2.252848 0.19473,-1.621264 0.604712,-4.037809 0.845956,-4.986301 0.495326,-1.947452 1.158621,-3.216325 2.26111,-4.325467 0.731983,-0.736399 1.547763,-1.051329 2.723316,-1.051329 1.344787,0 2.103359,0.409522 2.539237,1.370828 0.373167,0.823003 0.432731,1.702332 0.227502,3.358553 -0.206897,1.669687 -0.429401,2.498899 -1.62432,6.053417 -0.891865,2.653022 -1.418886,4.025585 -2.237847,5.828196 -0.890733,1.960586 -1.401439,3.281416 -2.291175,5.925621 -0.696894,2.071095 -0.858755,3.003396 -0.79649,4.587665 0.05016,1.276299 0.270881,2.168068 0.761945,3.078469 1.114561,2.066325 3.341124,3.259541 6.082361,3.259541 0.831865,0 1.52957,-0.113832 2.245267,-0.366322 1.037155,-0.365895 1.69838,-0.767468 2.829986,-1.718697 2.058613,-1.730473 4.031033,-4.098263 5.356083,-6.429706 1.132231,-1.992175 2.742129,-5.986041 2.978686,-7.389579 0.126006,-0.747618 0.37151,-2.073261 0.753923,-4.070941 0.459374,-2.399719 0.965049,-5.073707 1.26106,-6.668427 0.439666,-2.368642 0.948255,-3.731056 1.831386,-4.905927 1.000947,-1.33161 1.919678,-1.818989 3.424905,-1.816884 1.371199,0.0019 2.259901,0.453797 2.692584,1.369104 0.199937,0.42295 0.37898,1.160518 0.431897,1.779189 0.0423,0.494585 -0.08313,1.707742 -0.270194,2.613303 -0.520247,2.51845 -2.995194,9.527499 -4.836622,13.697311 -0.189691,0.429543 -0.709117,1.619046 -1.154281,2.64334 -0.445164,1.024295 -0.903857,2.078627 -1.019317,2.342962 -0.593057,1.357747 -0.644155,1.607255 -0.563046,2.7493 0.142046,2.000035 0.604952,3.420811 1.436759,4.409774 0.719848,0.85585 1.902762,1.62255 2.859809,1.853569 0.533147,0.128695 1.669602,0.128252 2.472607,-9.67e-4 1.437635,-0.231339 2.769133,-0.900566 3.72751,-1.873493 1.098243,-1.114915 2.227996,-3.662559 2.785802,-6.282105 l 0.13752,-0.645816 h 0.37414 0.37414 l 0.04419,0.94284 c 0.124949,2.666054 -0.382363,6.016009 -1.237138,8.16926 -0.848692,2.137927 -2.617365,4.354096 -4.156972,5.208738 -1.58257,0.878493 -4.420415,1.19721 -6.111929,0.68643 -0.649563,-0.196146 -1.47209,-0.685817 -1.961392,-1.167665 -1.354216,-1.333585 -1.999054,-3.254244 -2.18916,-6.52045 -0.03525,-0.60571 -0.04689,-1.38515 -0.02584,-1.732089 0.04435,-0.731258 0.257009,-2.357205 0.335205,-2.562875 0.04613,-0.121335 0.03516,-0.140427 -0.08025,-0.139702 -0.11259,7.09e-4 -0.171074,0.09313 -0.370649,0.58574 -0.571777,1.411317 -1.625409,3.288777 -2.58713,4.609988 -2.555402,3.510606 -5.935984,6.014779 -9.311242,6.897323 -1.386313,0.362485 -1.927076,0.42829 -3.514441,0.427668 -1.398071,-5.41e-4 -1.500695,-0.0084 -2.047014,-0.157216 -1.248806,-0.340101 -2.244463,-0.904197 -3.05944,-1.733346 -1.343156,-1.366511 -2.129105,-3.116872 -2.494126,-5.554581 -0.150028,-1.001927 -0.191427,-3.616227 -0.06949,-4.388291 0.05195,-0.328906 0.113311,-0.84947 0.136367,-1.156809 l 0.04192,-0.558799 -0.380315,0.01812 -0.380315,0.01812 -0.231805,0.570721 c -1.478913,3.641182 -3.072314,10.383891 -3.918324,16.580955 -0.190557,1.395837 -0.701916,5.676121 -0.706953,5.917479 -0.0093,0.446744 0.454257,2.427922 0.818884,3.499628 0.121802,0.358001 0.382754,1.549663 0.538684,2.459961 0.04595,0.268246 -0.06655,1.468043 -0.178759,1.906478 -0.165253,0.645686 -0.477741,1.20884 -0.915337,1.649588 -0.463951,0.467293 -0.819805,0.689321 -1.309045,0.816755 -0.410787,0.106995 -0.564727,0.106887 -1.159735,-7.81e-4 z"
|
||||
id="path240" /></svg>
|
||||
|
Before Width: | Height: | Size: 7.7 KiB After Width: | Height: | Size: 12 KiB |
9
assets/packaging/deb/micro.postinst
Executable file
9
assets/packaging/deb/micro.postinst
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
|
||||
update-alternatives --install /usr/bin/editor editor /usr/bin/micro 40 \
|
||||
--slave /usr/share/man/man1/editor.1 editor.1 \
|
||||
/usr/share/man/man1/micro.1
|
||||
fi
|
7
assets/packaging/deb/micro.prerm
Executable file
7
assets/packaging/deb/micro.prerm
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$1" != "upgrade" ]; then
|
||||
update-alternatives --remove editor /usr/bin/micro
|
||||
fi
|
@ -3,8 +3,8 @@ package main
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/gob"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/zyedidia/micro/v2/internal/buffer"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
)
|
||||
|
||||
func shouldContinue() bool {
|
||||
@ -23,12 +24,9 @@ func shouldContinue() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(text) <= 1 {
|
||||
// default continue
|
||||
return true
|
||||
}
|
||||
text = strings.TrimRight(text, "\r\n")
|
||||
|
||||
return strings.ToLower(text)[0] == 'y'
|
||||
return len(text) == 0 || strings.ToLower(text)[0] == 'y'
|
||||
}
|
||||
|
||||
// CleanConfig performs cleanup in the user's configuration directory
|
||||
@ -42,7 +40,16 @@ func CleanConfig() {
|
||||
}
|
||||
|
||||
fmt.Println("Cleaning default settings")
|
||||
config.WriteSettings(filepath.Join(config.ConfigDir, "settings.json"))
|
||||
|
||||
settingsFile := filepath.Join(config.ConfigDir, "settings.json")
|
||||
err := config.WriteSettings(settingsFile)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrOverwrite) {
|
||||
fmt.Println(err.Error())
|
||||
} else {
|
||||
fmt.Println("Error writing settings.json file: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// detect unused options
|
||||
var unusedOptions []string
|
||||
@ -70,16 +77,20 @@ func CleanConfig() {
|
||||
fmt.Printf("%s (value: %v)\n", s, config.GlobalSettings[s])
|
||||
}
|
||||
|
||||
fmt.Printf("These options will be removed from %s\n", filepath.Join(config.ConfigDir, "settings.json"))
|
||||
fmt.Printf("These options will be removed from %s\n", settingsFile)
|
||||
|
||||
if shouldContinue() {
|
||||
for _, s := range unusedOptions {
|
||||
delete(config.GlobalSettings, s)
|
||||
}
|
||||
|
||||
err := config.OverwriteSettings(filepath.Join(config.ConfigDir, "settings.json"))
|
||||
err := config.OverwriteSettings(settingsFile)
|
||||
if err != nil {
|
||||
fmt.Println("Error writing settings.json file: " + err.Error())
|
||||
if errors.Is(err, util.ErrOverwrite) {
|
||||
fmt.Println(err.Error())
|
||||
} else {
|
||||
fmt.Println("Error overwriting settings.json file: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("Removed unused options")
|
||||
@ -88,12 +99,13 @@ func CleanConfig() {
|
||||
}
|
||||
|
||||
// detect incorrectly formatted buffer/ files
|
||||
files, err := ioutil.ReadDir(filepath.Join(config.ConfigDir, "buffers"))
|
||||
buffersPath := filepath.Join(config.ConfigDir, "buffers")
|
||||
files, err := os.ReadDir(buffersPath)
|
||||
if err == nil {
|
||||
var badFiles []string
|
||||
var buffer buffer.SerializedBuffer
|
||||
for _, f := range files {
|
||||
fname := filepath.Join(config.ConfigDir, "buffers", f.Name())
|
||||
fname := filepath.Join(buffersPath, f.Name())
|
||||
file, e := os.Open(fname)
|
||||
|
||||
if e == nil {
|
||||
@ -108,9 +120,9 @@ func CleanConfig() {
|
||||
}
|
||||
|
||||
if len(badFiles) > 0 {
|
||||
fmt.Printf("Detected %d files with an invalid format in %s\n", len(badFiles), filepath.Join(config.ConfigDir, "buffers"))
|
||||
fmt.Printf("Detected %d files with an invalid format in %s\n", len(badFiles), buffersPath)
|
||||
fmt.Println("These files store cursor and undo history.")
|
||||
fmt.Printf("Removing badly formatted files in %s\n", filepath.Join(config.ConfigDir, "buffers"))
|
||||
fmt.Printf("Removing badly formatted files in %s\n", buffersPath)
|
||||
|
||||
if shouldContinue() {
|
||||
removed := 0
|
||||
|
@ -18,7 +18,7 @@ func (NullWriter) Write(data []byte) (n int, err error) {
|
||||
// InitLog sets up the debug log system for micro if it has been enabled by compile-time variables
|
||||
func InitLog() {
|
||||
if util.Debug == "ON" {
|
||||
f, err := os.OpenFile("log.txt", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
f, err := os.OpenFile("log.txt", os.O_RDWR|os.O_CREATE|os.O_TRUNC, util.FileMode)
|
||||
if err != nil {
|
||||
log.Fatalf("error opening file: %v", err)
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
luar "layeh.com/gopher-luar"
|
||||
@ -47,14 +48,18 @@ func luaImportMicro() *lua.LTable {
|
||||
ulua.L.SetField(pkg, "InfoBar", luar.New(ulua.L, action.GetInfoBar))
|
||||
ulua.L.SetField(pkg, "Log", luar.New(ulua.L, log.Println))
|
||||
ulua.L.SetField(pkg, "SetStatusInfoFn", luar.New(ulua.L, display.SetStatusInfoFnLua))
|
||||
ulua.L.SetField(pkg, "CurPane", luar.New(ulua.L, func() action.Pane {
|
||||
ulua.L.SetField(pkg, "CurPane", luar.New(ulua.L, func() *action.BufPane {
|
||||
return action.MainTab().CurPane()
|
||||
}))
|
||||
ulua.L.SetField(pkg, "CurTab", luar.New(ulua.L, action.MainTab))
|
||||
ulua.L.SetField(pkg, "Tabs", luar.New(ulua.L, func() *action.TabList {
|
||||
return action.Tabs
|
||||
}))
|
||||
ulua.L.SetField(pkg, "Lock", luar.New(ulua.L, ulua.Lock))
|
||||
ulua.L.SetField(pkg, "After", luar.New(ulua.L, func(t time.Duration, f func()) {
|
||||
time.AfterFunc(t, func() {
|
||||
timerChan <- f
|
||||
})
|
||||
}))
|
||||
|
||||
return pkg
|
||||
}
|
||||
@ -150,6 +155,7 @@ func luaImportMicroUtil() *lua.LTable {
|
||||
ulua.L.SetField(pkg, "Unzip", luar.New(ulua.L, util.Unzip))
|
||||
ulua.L.SetField(pkg, "Version", luar.New(ulua.L, util.Version))
|
||||
ulua.L.SetField(pkg, "SemVersion", luar.New(ulua.L, util.SemVersion))
|
||||
ulua.L.SetField(pkg, "HttpRequest", luar.New(ulua.L, util.HttpRequest))
|
||||
ulua.L.SetField(pkg, "CharacterCountInString", luar.New(ulua.L, util.CharacterCountInString))
|
||||
ulua.L.SetField(pkg, "RuneStr", luar.New(ulua.L, func(r rune) string {
|
||||
return string(r)
|
||||
|
@ -3,12 +3,14 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"sort"
|
||||
"strconv"
|
||||
"syscall"
|
||||
@ -16,33 +18,31 @@ import (
|
||||
|
||||
"github.com/go-errors/errors"
|
||||
isatty "github.com/mattn/go-isatty"
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
"github.com/zyedidia/micro/v2/internal/action"
|
||||
"github.com/zyedidia/micro/v2/internal/buffer"
|
||||
"github.com/zyedidia/micro/v2/internal/clipboard"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
ulua "github.com/zyedidia/micro/v2/internal/lua"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/micro/v2/internal/shell"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
// Event channel
|
||||
autosave chan bool
|
||||
|
||||
// Command line flags
|
||||
flagVersion = flag.Bool("version", false, "Show the version number and information")
|
||||
flagConfigDir = flag.String("config-dir", "", "Specify a custom location for the configuration directory")
|
||||
flagOptions = flag.Bool("options", false, "Show all option help")
|
||||
flagDebug = flag.Bool("debug", false, "Enable debug mode (prints debug info to ./log.txt)")
|
||||
flagProfile = flag.Bool("profile", false, "Enable CPU profiling (writes profile info to ./micro.prof)")
|
||||
flagPlugin = flag.String("plugin", "", "Plugin command")
|
||||
flagClean = flag.Bool("clean", false, "Clean configuration directory")
|
||||
optionFlags map[string]*string
|
||||
|
||||
sigterm chan os.Signal
|
||||
sighup chan os.Signal
|
||||
|
||||
timerChan chan func()
|
||||
)
|
||||
|
||||
func InitFlags() {
|
||||
@ -59,10 +59,13 @@ func InitFlags() {
|
||||
fmt.Println(" \tShow all option help")
|
||||
fmt.Println("-debug")
|
||||
fmt.Println(" \tEnable debug mode (enables logging to ./log.txt)")
|
||||
fmt.Println("-profile")
|
||||
fmt.Println(" \tEnable CPU profiling (writes profile info to ./micro.prof")
|
||||
fmt.Println(" \tso it can be analyzed later with \"go tool pprof micro.prof\")")
|
||||
fmt.Println("-version")
|
||||
fmt.Println(" \tShow the version number and information")
|
||||
|
||||
fmt.Print("\nMicro's plugin's can be managed at the command line with the following commands.\n")
|
||||
fmt.Print("\nMicro's plugins can be managed at the command line with the following commands.\n")
|
||||
fmt.Println("-plugin install [PLUGIN]...")
|
||||
fmt.Println(" \tInstall plugin(s)")
|
||||
fmt.Println("-plugin remove [PLUGIN]...")
|
||||
@ -96,7 +99,7 @@ func InitFlags() {
|
||||
fmt.Println("Version:", util.Version)
|
||||
fmt.Println("Commit hash:", util.CommitHash)
|
||||
fmt.Println("Compiled on", util.CompileDate)
|
||||
os.Exit(0)
|
||||
exit(0)
|
||||
}
|
||||
|
||||
if *flagOptions {
|
||||
@ -112,7 +115,7 @@ func InitFlags() {
|
||||
fmt.Printf("-%s value\n", k)
|
||||
fmt.Printf(" \tDefault value: '%v'\n", v)
|
||||
}
|
||||
os.Exit(0)
|
||||
exit(0)
|
||||
}
|
||||
|
||||
if util.Debug == "OFF" && *flagDebug {
|
||||
@ -133,7 +136,7 @@ func DoPluginFlags() {
|
||||
CleanConfig()
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,7 +209,7 @@ func LoadInput(args []string) []*buffer.Buffer {
|
||||
// Option 2
|
||||
// The input is not a terminal, so something is being piped in
|
||||
// and we should read from stdin
|
||||
input, err = ioutil.ReadAll(os.Stdin)
|
||||
input, err = io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
screen.TermMessage("Error reading from stdin: ", err)
|
||||
input = []byte{}
|
||||
@ -220,23 +223,72 @@ func LoadInput(args []string) []*buffer.Buffer {
|
||||
return buffers
|
||||
}
|
||||
|
||||
func checkBackup(name string) error {
|
||||
target := filepath.Join(config.ConfigDir, name)
|
||||
backup := util.AppendBackupSuffix(target)
|
||||
if info, err := os.Stat(backup); err == nil {
|
||||
input, err := os.ReadFile(backup)
|
||||
if err == nil {
|
||||
t := info.ModTime()
|
||||
msg := fmt.Sprintf(buffer.BackupMsg, target, t.Format("Mon Jan _2 at 15:04, 2006"), backup)
|
||||
choice := screen.TermPrompt(msg, []string{"r", "i", "a", "recover", "ignore", "abort"}, true)
|
||||
|
||||
if choice%3 == 0 {
|
||||
// recover
|
||||
err := os.WriteFile(target, input, util.FileMode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Remove(backup)
|
||||
} else if choice%3 == 1 {
|
||||
// delete
|
||||
return os.Remove(backup)
|
||||
} else if choice%3 == 2 {
|
||||
// abort
|
||||
return errors.New("Aborted")
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func exit(rc int) {
|
||||
for _, b := range buffer.OpenBuffers {
|
||||
if !b.Modified() {
|
||||
b.Fini()
|
||||
}
|
||||
}
|
||||
|
||||
if screen.Screen != nil {
|
||||
screen.Screen.Fini()
|
||||
}
|
||||
|
||||
os.Exit(rc)
|
||||
}
|
||||
|
||||
func main() {
|
||||
defer func() {
|
||||
if util.Stdout.Len() > 0 {
|
||||
fmt.Fprint(os.Stdout, util.Stdout.String())
|
||||
}
|
||||
os.Exit(0)
|
||||
exit(0)
|
||||
}()
|
||||
|
||||
// runtime.SetCPUProfileRate(400)
|
||||
// f, _ := os.Create("micro.prof")
|
||||
// pprof.StartCPUProfile(f)
|
||||
// defer pprof.StopCPUProfile()
|
||||
|
||||
var err error
|
||||
|
||||
InitFlags()
|
||||
|
||||
if *flagProfile {
|
||||
f, err := os.Create("micro.prof")
|
||||
if err != nil {
|
||||
log.Fatal("error creating CPU profile: ", err)
|
||||
}
|
||||
if err := pprof.StartCPUProfile(f); err != nil {
|
||||
log.Fatal("error starting CPU profile: ", err)
|
||||
}
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
InitLog()
|
||||
|
||||
err = config.InitConfigDir(*flagConfigDir)
|
||||
@ -244,7 +296,15 @@ func main() {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
|
||||
config.InitRuntimeFiles()
|
||||
config.InitRuntimeFiles(true)
|
||||
config.InitPlugins()
|
||||
|
||||
err = checkBackup("settings.json")
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
exit(1)
|
||||
}
|
||||
|
||||
err = config.ReadSettings()
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
@ -262,7 +322,12 @@ func main() {
|
||||
screen.TermMessage(err)
|
||||
continue
|
||||
}
|
||||
if err = config.OptionIsValid(k, nativeValue); err != nil {
|
||||
screen.TermMessage(err)
|
||||
continue
|
||||
}
|
||||
config.GlobalSettings[k] = nativeValue
|
||||
config.VolatileSettings[k] = true
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,14 +337,8 @@ func main() {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Println("Fatal: Micro could not initialize a Screen.")
|
||||
os.Exit(1)
|
||||
exit(1)
|
||||
}
|
||||
|
||||
sigterm = make(chan os.Signal, 1)
|
||||
sighup = make(chan os.Signal, 1)
|
||||
signal.Notify(sigterm, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
|
||||
signal.Notify(sighup, syscall.SIGHUP)
|
||||
|
||||
m := clipboard.SetMethod(config.GetGlobalOption("clipboard").(string))
|
||||
clipErr := clipboard.Initialize(m)
|
||||
|
||||
@ -297,7 +356,7 @@ func main() {
|
||||
for _, b := range buffer.OpenBuffers {
|
||||
b.Backup()
|
||||
}
|
||||
os.Exit(1)
|
||||
exit(1)
|
||||
}
|
||||
}()
|
||||
|
||||
@ -306,6 +365,12 @@ func main() {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
|
||||
err = checkBackup("bindings.json")
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
exit(1)
|
||||
}
|
||||
|
||||
action.InitBindings()
|
||||
action.InitCommands()
|
||||
|
||||
@ -319,6 +384,8 @@ func main() {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
|
||||
action.InitGlobals()
|
||||
buffer.SetMessager(action.InfoBar)
|
||||
args := flag.Args()
|
||||
b := LoadInput(args)
|
||||
|
||||
@ -329,7 +396,6 @@ func main() {
|
||||
}
|
||||
|
||||
action.InitTabs(b)
|
||||
action.InitGlobals()
|
||||
|
||||
err = config.RunPluginFn("init")
|
||||
if err != nil {
|
||||
@ -345,13 +411,20 @@ func main() {
|
||||
log.Println(clipErr, " or change 'clipboard' option")
|
||||
}
|
||||
|
||||
if a := config.GetGlobalOption("autosave").(float64); a > 0 {
|
||||
config.SetAutoTime(int(a))
|
||||
config.StartAutoSave()
|
||||
if a := config.GetGlobalOption("autosave").(float64); a > 0 {
|
||||
config.SetAutoTime(a)
|
||||
}
|
||||
|
||||
screen.Events = make(chan tcell.Event)
|
||||
|
||||
util.Sigterm = make(chan os.Signal, 1)
|
||||
sighup = make(chan os.Signal, 1)
|
||||
signal.Notify(util.Sigterm, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGABRT)
|
||||
signal.Notify(sighup, syscall.SIGHUP)
|
||||
|
||||
timerChan = make(chan func())
|
||||
|
||||
// Here is the event loop which runs in a separate thread
|
||||
go func() {
|
||||
for {
|
||||
@ -402,48 +475,52 @@ func DoEvent() {
|
||||
select {
|
||||
case f := <-shell.Jobs:
|
||||
// If a new job has finished while running in the background we should execute the callback
|
||||
ulua.Lock.Lock()
|
||||
f.Function(f.Output, f.Args)
|
||||
ulua.Lock.Unlock()
|
||||
case <-config.Autosave:
|
||||
ulua.Lock.Lock()
|
||||
for _, b := range buffer.OpenBuffers {
|
||||
b.Save()
|
||||
b.AutoSave()
|
||||
}
|
||||
ulua.Lock.Unlock()
|
||||
case <-shell.CloseTerms:
|
||||
action.Tabs.CloseTerms()
|
||||
case event = <-screen.Events:
|
||||
case <-screen.DrawChan():
|
||||
for len(screen.DrawChan()) > 0 {
|
||||
<-screen.DrawChan()
|
||||
}
|
||||
case f := <-timerChan:
|
||||
f()
|
||||
case b := <-buffer.BackupCompleteChan:
|
||||
b.RequestedBackup = false
|
||||
case <-sighup:
|
||||
for _, b := range buffer.OpenBuffers {
|
||||
if !b.Modified() {
|
||||
b.Fini()
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
case <-sigterm:
|
||||
for _, b := range buffer.OpenBuffers {
|
||||
if !b.Modified() {
|
||||
b.Fini()
|
||||
}
|
||||
exit(0)
|
||||
case <-util.Sigterm:
|
||||
exit(0)
|
||||
}
|
||||
|
||||
if screen.Screen != nil {
|
||||
screen.Screen.Fini()
|
||||
if e, ok := event.(*tcell.EventError); ok {
|
||||
log.Println("tcell event error: ", e.Error())
|
||||
|
||||
if e.Err() == io.EOF {
|
||||
// shutdown due to terminal closing/becoming inaccessible
|
||||
exit(0)
|
||||
}
|
||||
os.Exit(0)
|
||||
return
|
||||
}
|
||||
|
||||
ulua.Lock.Lock()
|
||||
// if event != nil {
|
||||
if action.InfoBar.HasPrompt {
|
||||
if event != nil {
|
||||
_, resize := event.(*tcell.EventResize)
|
||||
if resize {
|
||||
action.InfoBar.HandleEvent(event)
|
||||
action.Tabs.HandleEvent(event)
|
||||
} else if action.InfoBar.HasPrompt {
|
||||
action.InfoBar.HandleEvent(event)
|
||||
} else {
|
||||
action.Tabs.HandleEvent(event)
|
||||
}
|
||||
// }
|
||||
ulua.Lock.Unlock()
|
||||
}
|
||||
|
||||
err := config.RunPluginFn("onAnyEvent")
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
}
|
||||
|
@ -2,18 +2,17 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zyedidia/micro/v2/internal/action"
|
||||
"github.com/zyedidia/micro/v2/internal/buffer"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
)
|
||||
|
||||
var tempDir string
|
||||
@ -26,7 +25,7 @@ func init() {
|
||||
func startup(args []string) (tcell.SimulationScreen, error) {
|
||||
var err error
|
||||
|
||||
tempDir, err = ioutil.TempDir("", "micro_test")
|
||||
tempDir, err = os.MkdirTemp("", "micro_test")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -35,7 +34,9 @@ func startup(args []string) (tcell.SimulationScreen, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
config.InitRuntimeFiles()
|
||||
config.InitRuntimeFiles(true)
|
||||
config.InitPlugins()
|
||||
|
||||
err = config.ReadSettings()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -60,7 +61,6 @@ func startup(args []string) (tcell.SimulationScreen, error) {
|
||||
}
|
||||
// Print the stack trace too
|
||||
log.Fatalf(errors.Wrap(err, 2).ErrorStack())
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
|
||||
@ -108,8 +108,11 @@ func handleEvent() {
|
||||
if e != nil {
|
||||
screen.Events <- e
|
||||
}
|
||||
|
||||
for len(screen.DrawChan()) > 0 || len(screen.Events) > 0 {
|
||||
DoEvent()
|
||||
}
|
||||
}
|
||||
|
||||
func injectKey(key tcell.Key, r rune, mod tcell.ModMask) {
|
||||
sim.InjectKey(key, r, mod)
|
||||
@ -150,20 +153,32 @@ func openFile(file string) {
|
||||
injectKey(tcell.KeyEnter, rune(tcell.KeyEnter), tcell.ModNone)
|
||||
}
|
||||
|
||||
func createTestFile(name string, content string) (string, error) {
|
||||
testf, err := ioutil.TempFile("", name)
|
||||
func findBuffer(file string) *buffer.Buffer {
|
||||
var buf *buffer.Buffer
|
||||
for _, b := range buffer.OpenBuffers {
|
||||
if b.Path == file {
|
||||
buf = b
|
||||
}
|
||||
}
|
||||
return buf
|
||||
}
|
||||
|
||||
func createTestFile(t *testing.T, content string) string {
|
||||
f, err := os.CreateTemp(t.TempDir(), "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
if _, err := f.WriteString(content); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := testf.Write([]byte(content)); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := testf.Close(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return testf.Name(), nil
|
||||
return f.Name()
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
@ -171,7 +186,6 @@ func TestMain(m *testing.M) {
|
||||
sim, err = startup([]string{})
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
retval := m.Run()
|
||||
@ -181,25 +195,12 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func TestSimpleEdit(t *testing.T) {
|
||||
file, err := createTestFile("micro_simple_edit_test", "base content")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
defer os.Remove(file)
|
||||
file := createTestFile(t, "base content")
|
||||
|
||||
openFile(file)
|
||||
|
||||
var buf *buffer.Buffer
|
||||
for _, b := range buffer.OpenBuffers {
|
||||
if b.Path == file {
|
||||
buf = b
|
||||
}
|
||||
}
|
||||
|
||||
if buf == nil {
|
||||
t.Errorf("Could not find buffer %s", file)
|
||||
return
|
||||
if findBuffer(file) == nil {
|
||||
t.Fatalf("Could not find buffer %s", file)
|
||||
}
|
||||
|
||||
injectKey(tcell.KeyEnter, rune(tcell.KeyEnter), tcell.ModNone)
|
||||
@ -217,25 +218,23 @@ func TestSimpleEdit(t *testing.T) {
|
||||
|
||||
injectKey(tcell.KeyCtrlS, rune(tcell.KeyCtrlS), tcell.ModCtrl)
|
||||
|
||||
data, err := ioutil.ReadFile(file)
|
||||
data, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "firstfoobar\nbase content\n", string(data))
|
||||
}
|
||||
|
||||
func TestMouse(t *testing.T) {
|
||||
file, err := createTestFile("micro_mouse_test", "base content")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
defer os.Remove(file)
|
||||
file := createTestFile(t, "base content")
|
||||
|
||||
openFile(file)
|
||||
|
||||
if findBuffer(file) == nil {
|
||||
t.Fatalf("Could not find buffer %s", file)
|
||||
}
|
||||
|
||||
// buffer:
|
||||
// base content
|
||||
// the selections need to happen at different locations to avoid a double click
|
||||
@ -264,10 +263,9 @@ func TestMouse(t *testing.T) {
|
||||
// base content
|
||||
injectKey(tcell.KeyCtrlS, rune(tcell.KeyCtrlS), tcell.ModCtrl)
|
||||
|
||||
data, err := ioutil.ReadFile(file)
|
||||
data, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "firstline\nsecondline\nbase content\n", string(data))
|
||||
@ -290,25 +288,23 @@ Ernleȝe test_string æðelen
|
||||
`
|
||||
|
||||
func TestSearchAndReplace(t *testing.T) {
|
||||
file, err := createTestFile("micro_search_replace_test", srTestStart)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
defer os.Remove(file)
|
||||
file := createTestFile(t, srTestStart)
|
||||
|
||||
openFile(file)
|
||||
|
||||
if findBuffer(file) == nil {
|
||||
t.Fatalf("Could not find buffer %s", file)
|
||||
}
|
||||
|
||||
injectKey(tcell.KeyCtrlE, rune(tcell.KeyCtrlE), tcell.ModCtrl)
|
||||
injectString(fmt.Sprintf("replaceall %s %s", "foo", "test_string"))
|
||||
injectKey(tcell.KeyEnter, rune(tcell.KeyEnter), tcell.ModNone)
|
||||
|
||||
injectKey(tcell.KeyCtrlS, rune(tcell.KeyCtrlS), tcell.ModCtrl)
|
||||
|
||||
data, err := ioutil.ReadFile(file)
|
||||
data, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, srTest2, string(data))
|
||||
@ -321,10 +317,9 @@ func TestSearchAndReplace(t *testing.T) {
|
||||
|
||||
injectKey(tcell.KeyCtrlS, rune(tcell.KeyCtrlS), tcell.ModCtrl)
|
||||
|
||||
data, err = ioutil.ReadFile(file)
|
||||
data, err = os.ReadFile(file)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, srTest3, string(data))
|
||||
|
@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<component>
|
||||
<id>com.github.zyedidia.micro</id>
|
||||
<name>Micro Text Editor</name>
|
||||
<summary>A modern and intuitive terminal-based text editor</summary>
|
||||
<metadata_license>MIT</metadata_license>
|
||||
<categories>
|
||||
<category>Development</category>
|
||||
<category>TextEditor</category>
|
||||
</categories>
|
||||
<provides>
|
||||
<binary>micro</binary>
|
||||
</provides>
|
||||
<developer_name>Zachary Yedidia</developer_name>
|
||||
<screenshots>
|
||||
<screenshot type="default">
|
||||
<caption>Micro Text Editor editing its source code.</caption>
|
||||
<image type="source">https://raw.githubusercontent.com/zyedidia/micro/master/assets/micro-solarized.png</image>
|
||||
</screenshot>
|
||||
</screenshots>
|
||||
<url type="homepage">https://micro-editor.github.io</url>
|
||||
<url type="bugtracker">https://github.com/zyedidia/micro/issues</url>
|
||||
</component>
|
52
data/io.github.zyedidia.micro.metainfo.xml
Normal file
52
data/io.github.zyedidia.micro.metainfo.xml
Normal file
@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<component type="desktop-application">
|
||||
<id>io.github.zyedidia.micro</id>
|
||||
<launchable type="desktop-id">micro.desktop</launchable>
|
||||
<name>Micro Text Editor</name>
|
||||
<summary>A modern and intuitive terminal-based text editor</summary>
|
||||
<description>
|
||||
<p>
|
||||
micro is a terminal-based text editor that aims to be easy to use and
|
||||
intuitive, while also taking advantage of the capabilities of modern terminals.
|
||||
It comes as a single, batteries-included, static binary with no dependencies;
|
||||
you can download and use it right now!
|
||||
</p>
|
||||
<p>
|
||||
As its name indicates, micro aims to be somewhat of a successor to the nano
|
||||
editor by being easy to install and use. It strives to be enjoyable as a full-time
|
||||
editor for people who prefer to work in a terminal, or those who regularly
|
||||
edit files over SSH.
|
||||
</p>
|
||||
</description>
|
||||
<metadata_license>MIT</metadata_license>
|
||||
<project_license>MIT</project_license>
|
||||
<categories>
|
||||
<category>Development</category>
|
||||
<category>TextEditor</category>
|
||||
</categories>
|
||||
<releases>
|
||||
<release version="2.0.14" date="2024-08-27"/>
|
||||
<release version="2.0.13" date="2023-10-22"/>
|
||||
<release version="2.0.12" date="2023-09-06"/>
|
||||
<release version="2.0.11" date="2022-08-01"/>
|
||||
</releases>
|
||||
<provides>
|
||||
<binary>micro</binary>
|
||||
<id>com.github.zyedidia.micro</id>
|
||||
</provides>
|
||||
<developer_name>Zachary Yedidia</developer_name>
|
||||
<screenshots>
|
||||
<screenshot type="default">
|
||||
<caption>Micro Text Editor editing its source code</caption>
|
||||
<image type="source">https://raw.githubusercontent.com/zyedidia/micro/master/assets/micro-solarized.png</image>
|
||||
</screenshot>
|
||||
</screenshots>
|
||||
<content_rating type="oars-1.1" />
|
||||
<url type="homepage">https://micro-editor.github.io</url>
|
||||
<url type="bugtracker">https://github.com/zyedidia/micro/issues</url>
|
||||
<url type="faq">https://micro-editor.github.io/about.html</url>
|
||||
<url type="help">https://micro-editor.github.io/about.html</url>
|
||||
<url type="contact">https://github.com/zyedidia</url>
|
||||
<url type="vcs-browser">https://github.com/zyedidia/micro</url>
|
||||
<url type="contribute">https://github.com/zyedidia/micro#contributing</url>
|
||||
</component>
|
367
data/micro.json
Normal file
367
data/micro.json
Normal file
@ -0,0 +1,367 @@
|
||||
{
|
||||
"$comment": "https://github.com/zyedidia/micro",
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "options",
|
||||
"description": "A micro editor config schema",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"autoindent": {
|
||||
"description": "Whether to use the same indentation as a previous line\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"autosave": {
|
||||
"description": "A delay between automatic saves\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"default": 0
|
||||
},
|
||||
"autosu": {
|
||||
"description": "Whether attempt to use super user privileges\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"backup": {
|
||||
"description": "Whether to backup all open buffers\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"backupdir": {
|
||||
"description": "A directory to store backups\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "string",
|
||||
"default": ""
|
||||
},
|
||||
"basename": {
|
||||
"description": "Whether to show a basename instead of a full path\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"clipboard": {
|
||||
"description": "A way to access the system clipboard\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"external",
|
||||
"terminal",
|
||||
"internal"
|
||||
],
|
||||
"default": "external"
|
||||
},
|
||||
"colorcolumn": {
|
||||
"description": "A position to display a column\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"default": 0
|
||||
},
|
||||
"colorscheme": {
|
||||
"description": "A color scheme\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"atom-dark",
|
||||
"bubblegum",
|
||||
"cmc-16",
|
||||
"cmc-tc",
|
||||
"darcula",
|
||||
"default",
|
||||
"dracula-tc",
|
||||
"dukedark-tc",
|
||||
"dukelight-tc",
|
||||
"dukeubuntu-tc",
|
||||
"geany",
|
||||
"gotham",
|
||||
"gruvbox",
|
||||
"gruvbox-tc",
|
||||
"material-tc",
|
||||
"monokai-dark",
|
||||
"monokai",
|
||||
"one-dark",
|
||||
"railscast",
|
||||
"simple",
|
||||
"solarized",
|
||||
"solarized-tc",
|
||||
"sunny-day",
|
||||
"twilight",
|
||||
"zenburn"
|
||||
],
|
||||
"default": "default"
|
||||
},
|
||||
"cursorline": {
|
||||
"description": "Whether to highlight a line with a cursor with a different color\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"diffgutter": {
|
||||
"description": "Whether to display diff inticators before lines\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"divchars": {
|
||||
"description": "Divider chars for vertical and horizontal splits\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "string",
|
||||
"default": "|-"
|
||||
},
|
||||
"divreverse": {
|
||||
"description": "Whether to use inversed color scheme colors for splits\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"encoding": {
|
||||
"description": "An encoding used to open and save files\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "string",
|
||||
"default": "utf-8"
|
||||
},
|
||||
"eofnewline": {
|
||||
"description": "Whether to add a missing trailing new line\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"fastdirty": {
|
||||
"description": "Whether to use a fast algorithm to determine whether a file is changed\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"fileformat": {
|
||||
"description": "A line ending format\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"unix",
|
||||
"dos"
|
||||
],
|
||||
"default": "unix"
|
||||
},
|
||||
"filetype": {
|
||||
"description": "A filetype for the current buffer\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "string",
|
||||
"default": "unknown"
|
||||
},
|
||||
"hlsearch": {
|
||||
"description": "Whether to highlight all instances of a searched text after a successful search\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"incsearch": {
|
||||
"description": "Whether to enable an incremental search in `Find` prompt\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"ignorecase": {
|
||||
"description": "Whether to perform case-insensitive searches\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"indentchar": {
|
||||
"description": "An indentation character\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "string",
|
||||
"maxLength": 1,
|
||||
"default": " "
|
||||
},
|
||||
"infobar": {
|
||||
"description": "Whether to enable a line at the bottom where messages are printed\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"keepautoindent": {
|
||||
"description": "Whether add a whitespace while using autoindent\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"keymenu": {
|
||||
"description": "Whether to display nano-style key menu at the bottom\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"matchbrace": {
|
||||
"description": "Whether to show matching braces\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"matchbracestyle": {
|
||||
"description": "Whether to underline or highlight matching braces\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"underline",
|
||||
"highlight"
|
||||
],
|
||||
"default": "underline"
|
||||
},
|
||||
"mkparents": {
|
||||
"description": "Whether to create missing directories\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"mouse": {
|
||||
"description": "Whether to enable mouse support\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"paste": {
|
||||
"description": "Whether to treat characters sent from the terminal in a single chunk as a paste event\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"parsecursor": {
|
||||
"description": "Whether to extract a line number and a column to open files with from file names\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"permbackup": {
|
||||
"description": "Whether to permanently save backups\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"pluginchannels": {
|
||||
"description": "A file with list of plugin channels\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "string",
|
||||
"default": "https://raw.githubusercontent.com/micro-editor/plugin-channel/master/channel.json"
|
||||
},
|
||||
"pluginrepos": {
|
||||
"description": "Plugin repositories\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "array",
|
||||
"uniqueItems": true,
|
||||
"items": {
|
||||
"description": "A pluging repository\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "string"
|
||||
},
|
||||
"default": []
|
||||
},
|
||||
"readonly": {
|
||||
"description": "Whether to forbid buffer editing\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"rmtrailingws": {
|
||||
"description": "Whether to remove trailing whitespaces\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"ruler": {
|
||||
"description": "Whether to display line numbers\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"relativeruler": {
|
||||
"description": "Whether to display relative line numbers\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"savecursor": {
|
||||
"description": "Whether to save cursor position in files\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"savehistory": {
|
||||
"description": "Whether to save command history between closing and re-opening editor\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"saveundo": {
|
||||
"description": "Whether to save undo after closing file\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"scrollbar": {
|
||||
"description": "Whether to save undo after closing file\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"scrollmargin": {
|
||||
"description": "A margin at which a view starts scrolling when a cursor approaches an edge of a view\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "integer",
|
||||
"default": 3
|
||||
},
|
||||
"scrollspeed": {
|
||||
"description": "Line count to scroll for one scroll event\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "integer",
|
||||
"default": 2
|
||||
},
|
||||
"smartpaste": {
|
||||
"description": "Whether to add a leading whitespace while pasting multiple lines\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"softwrap": {
|
||||
"description": "Whether to wrap long lines\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"splitbottom": {
|
||||
"description": "Whether to create a new horizontal split below the current one\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"splitright": {
|
||||
"description": "Whether to create a new vertical split right of the current one\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"statusformatl": {
|
||||
"description": "Format string of left-justified part of the statusline\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "string",
|
||||
"default": "$(filename) $(modified)($(line),$(col)) $(status.paste)| ft:$(opt:filetype) | $(opt:fileformat) | $(opt:encoding)"
|
||||
},
|
||||
"statusformatr": {
|
||||
"description": "Format string of right-justified part of the statusline\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "string",
|
||||
"default": "$(bind:ToggleKeyMenu): bindings, $(bind:ToggleHelp): help"
|
||||
},
|
||||
"statusline": {
|
||||
"description": "Whether to display a status line\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"sucmd": {
|
||||
"description": "A super user command\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "string",
|
||||
"default": "sudo",
|
||||
"examples": [
|
||||
"sudo",
|
||||
"doas"
|
||||
]
|
||||
},
|
||||
"syntax": {
|
||||
"description": "Whether to enable a syntax highlighting\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"tabmovement": {
|
||||
"description": "Whether to navigate spaces at the beginning of lines as if they are tabs\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"tabhighlight": {
|
||||
"description": "Whether to invert tab character colors\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"tabreverse": {
|
||||
"description": "Whether to reverse tab bar colors\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"tabsize": {
|
||||
"description": "A tab size\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "integer",
|
||||
"default": 4
|
||||
},
|
||||
"tabstospaces": {
|
||||
"description": "Whether to use spaces instead of tabs\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"useprimary": {
|
||||
"description": "Whether to use primary clipboard to copy selections in the background\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
"wordwrap": {
|
||||
"description": "Whether to wrap long lines by words\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"xterm": {
|
||||
"description": "Whether to assume that the current terminal is `xterm`\nhttps://github.com/zyedidia/micro/blob/master/runtime/help/options.md#options",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
41
go.mod
41
go.mod
@ -5,28 +5,35 @@ require (
|
||||
github.com/dustin/go-humanize v1.0.0
|
||||
github.com/go-errors/errors v1.0.1
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
|
||||
github.com/mattn/go-isatty v0.0.11
|
||||
github.com/mattn/go-runewidth v0.0.7
|
||||
github.com/mattn/go-isatty v0.0.20
|
||||
github.com/mattn/go-runewidth v0.0.16
|
||||
github.com/micro-editor/json5 v1.0.1-micro
|
||||
github.com/micro-editor/tcell/v2 v2.0.11
|
||||
github.com/micro-editor/terminal v0.0.0-20250324214352-e587e959c6b5
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff
|
||||
github.com/sergi/go-diff v1.1.0
|
||||
github.com/stretchr/testify v1.4.0
|
||||
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb
|
||||
github.com/zyedidia/clipboard v1.0.3
|
||||
github.com/yuin/gopher-lua v1.1.1
|
||||
github.com/zyedidia/clipper v0.1.1
|
||||
github.com/zyedidia/glob v0.0.0-20170209203856-dd4023a66dc3
|
||||
github.com/zyedidia/highlight v0.0.0-20170330143449-201131ce5cf5
|
||||
github.com/zyedidia/json5 v0.0.0-20200102012142-2da050b1a98d
|
||||
github.com/zyedidia/pty v2.0.0+incompatible // indirect
|
||||
github.com/zyedidia/tcell/v2 v2.0.7
|
||||
github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415
|
||||
golang.org/x/text v0.3.2
|
||||
gopkg.in/sourcemap.v1 v1.0.5 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.7
|
||||
layeh.com/gopher-luar v1.0.7
|
||||
golang.org/x/text v0.4.0
|
||||
gopkg.in/yaml.v2 v2.2.8
|
||||
layeh.com/gopher-luar v1.0.11
|
||||
)
|
||||
|
||||
replace github.com/kballard/go-shellquote => github.com/zyedidia/go-shellquote v0.0.0-20200613203517-eccd813c0655
|
||||
require (
|
||||
github.com/creack/pty v1.1.18 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/gdamore/encoding v1.0.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.0.3 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/zyedidia/poller v1.0.1 // indirect
|
||||
golang.org/x/sys v0.28.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/mattn/go-runewidth => github.com/zyedidia/go-runewidth v0.0.12
|
||||
replace github.com/kballard/go-shellquote => github.com/micro-editor/go-shellquote v0.0.0-20250101105543-feb6c39314f5
|
||||
|
||||
go 1.11
|
||||
replace layeh.com/gopher-luar v1.0.11 => github.com/layeh/gopher-luar v1.0.11
|
||||
|
||||
go 1.19
|
||||
|
72
go.sum
72
go.sum
@ -3,6 +3,8 @@ github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnweb
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
|
||||
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@ -17,69 +19,59 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/layeh/gopher-luar v1.0.11 h1:ss6t9OtykOiETBScJylSMPhuYAtOmpH5rSX10/wCcis=
|
||||
github.com/layeh/gopher-luar v1.0.11/go.mod h1:TPnIVCZ2RJBndm7ohXyaqfhzjlZ+OA2SZR/YwL8tECk=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
|
||||
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/micro-editor/go-shellquote v0.0.0-20250101105543-feb6c39314f5 h1:D7BPnsedXiKo/e8RTFX419/52ICNhU8UKPQGZ/0yiLc=
|
||||
github.com/micro-editor/go-shellquote v0.0.0-20250101105543-feb6c39314f5/go.mod h1:zaPgW/fDiW4MUfEwxpC+GB/bhvX44NJaNHmRAC9auHQ=
|
||||
github.com/micro-editor/json5 v1.0.1-micro h1:5Y4MuzhkmW0sQQNPvrIVevIOKi557qsznwjRr4iq1AI=
|
||||
github.com/micro-editor/json5 v1.0.1-micro/go.mod h1:cmlPHZ1JKOXNse0/3zwwKj/GUpzAVkzx4lZDkpHl4q0=
|
||||
github.com/micro-editor/tcell/v2 v2.0.11 h1:USjdpBSmbocx2yPARbY19KcUSj+ZerScrdmBqGjzoX4=
|
||||
github.com/micro-editor/tcell/v2 v2.0.11/go.mod h1:kVYk6NOwYJrboL/7IA7cCupk4o2NzyF/0UMLjeEJN/s=
|
||||
github.com/micro-editor/terminal v0.0.0-20250324214352-e587e959c6b5 h1:czSkYUNmHuWS2lv8VreufENEXZNOCGZcXd744YKf8yM=
|
||||
github.com/micro-editor/terminal v0.0.0-20250324214352-e587e959c6b5/go.mod h1:OszIG7ockt4osicVHq6gI2QmV4PBDK6H5/Bj8GDGv4Q=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/p-e-w/go-runewidth v0.0.10-0.20200613030200-3e1705c5c059 h1:/+h2b6i15wh4EWsFkfdNdBE1jjGA872tpXEyhPM5aYg=
|
||||
github.com/p-e-w/go-runewidth v0.0.10-0.20200613030200-3e1705c5c059/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff h1:+6NUiITWwE5q1KO6SAfUX918c+Tab0+tGAM/mtdlUyA=
|
||||
github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff/go.mod h1:xvqspoSXJTIpemEonrMDFq6XzwHYYgToXWj5eRX1OtY=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/robertkrimen/otto v0.2.1 h1:FVP0PJ0AHIjC+N4pKCG9yCDz6LHNPCwi/GKID5pGGF0=
|
||||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/xo/terminfo v0.0.0-20200218205459-454e5b68f9e8 h1:woqigIZtZUZxws1zZA99nAvuz2mQrxtWsuZSR9c8I/A=
|
||||
github.com/xo/terminfo v0.0.0-20200218205459-454e5b68f9e8/go.mod h1:6Yhx5ZJl5942QrNRWLwITArVT9okUXc5c3brgWJMoDc=
|
||||
github.com/yuin/gopher-lua v0.0.0-20190206043414-8bfc7677f583/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
|
||||
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb h1:ZkM6LRnq40pR1Ox0hTHlnpkcOTuFIDQpZ1IN8rKKhX0=
|
||||
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
|
||||
github.com/zyedidia/clipboard v1.0.3 h1:F/nCDVYMdbDWTmY8s8cJl0tnwX32q96IF09JHM14bUI=
|
||||
github.com/zyedidia/clipboard v1.0.3/go.mod h1:zykFnZUXX0ErxqvYLUFEq7QDJKId8rmh2FgD0/Y8cjA=
|
||||
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
|
||||
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
|
||||
github.com/zyedidia/clipper v0.1.1 h1:HBgguFNDq/QmSQKBnhy4sMKzILINr139VEgAhftOUTw=
|
||||
github.com/zyedidia/clipper v0.1.1/go.mod h1:7YApPNiiTZTXdKKZG92G50qj6mnWEX975Sdu65J7YpQ=
|
||||
github.com/zyedidia/glob v0.0.0-20170209203856-dd4023a66dc3 h1:oMHjjTLfGXVuyOQBYj5/td9WC0mw4g1xDBPovIqmHew=
|
||||
github.com/zyedidia/glob v0.0.0-20170209203856-dd4023a66dc3/go.mod h1:YKbIYP//Eln8eDgAJGI3IDvR3s4Tv9Z9TGIOumiyQ5c=
|
||||
github.com/zyedidia/go-runewidth v0.0.12 h1:aHWj8qL3aH7caRzoPBJXe1pEaZBXHpKtfTuiBo5p74Q=
|
||||
github.com/zyedidia/go-runewidth v0.0.12/go.mod h1:vF8djYdLmG8BJaUZ4CznFYCJ3pFR8m4B4VinTvTTarU=
|
||||
github.com/zyedidia/go-shellquote v0.0.0-20200613203517-eccd813c0655 h1:Z3RhH6hvcSx7eX6Q/pP6YVsgea/1eMDG99vtWwi3nK4=
|
||||
github.com/zyedidia/go-shellquote v0.0.0-20200613203517-eccd813c0655/go.mod h1:1sTqqO+kcYzZp43M5VsJe1tns9IzlSeC9jB6c2+o/5Y=
|
||||
github.com/zyedidia/highlight v0.0.0-20170330143449-201131ce5cf5 h1:Zs6mpwXvlqpF9zHl5XaN0p5V4J9XvP+WBuiuXyIgqvc=
|
||||
github.com/zyedidia/highlight v0.0.0-20170330143449-201131ce5cf5/go.mod h1:c1r+Ob9tUTPB0FKWO1+x+Hsc/zNa45WdGq7Y38Ybip0=
|
||||
github.com/zyedidia/json5 v0.0.0-20200102012142-2da050b1a98d h1:zmDMkh22zXOB7gz8jFaI4GpI7llsPgzm38/jG0UgxjE=
|
||||
github.com/zyedidia/json5 v0.0.0-20200102012142-2da050b1a98d/go.mod h1:NDJSTTYWivnza6zkRapeX2/LwhKPEMQ7bJxqgDVT78I=
|
||||
github.com/zyedidia/poller v1.0.1 h1:Tt9S3AxAjXwWGNiC2TUdRJkQDZSzCBNVQ4xXiQ7440s=
|
||||
github.com/zyedidia/poller v1.0.1/go.mod h1:vZXJOHGDcuK08GXhF6IAY0ZFd2WcgOR5DOTp84Uk5eE=
|
||||
github.com/zyedidia/pty v2.0.0+incompatible h1:Ou5vXL6tvjst+RV8sUFISbuKDnUJPhnpygApMFGweqw=
|
||||
github.com/zyedidia/pty v2.0.0+incompatible/go.mod h1:4y9l9yJZNxRa7GB/fB+mmDmGkG3CqmzLf4vUxGGotEA=
|
||||
github.com/zyedidia/tcell/v2 v2.0.6 h1:v0GoNpPYJ+Wbd1RiSL09SUFzoq4eVKTuT5awbW6aqGs=
|
||||
github.com/zyedidia/tcell/v2 v2.0.6/go.mod h1:i4NNlquIQXFeNecrOgxDQQJdu+7LmTi3g62asvmwUws=
|
||||
github.com/zyedidia/tcell/v2 v2.0.7 h1:kFzCRq9jgx5lOXBT8fVZidbTgVuX0ws++aMCj/MTCYY=
|
||||
github.com/zyedidia/tcell/v2 v2.0.7/go.mod h1:i4NNlquIQXFeNecrOgxDQQJdu+7LmTi3g62asvmwUws=
|
||||
github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415 h1:752dTQ5OatJ9M5ULK2+9lor+nzyZz+LYDo3WGngg3Rc=
|
||||
github.com/zyedidia/terminal v0.0.0-20180726154117-533c623e2415/go.mod h1:8leT8G0Cm8NoJHdrrKHyR9MirWoF4YW7pZh06B6H+1E=
|
||||
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
|
||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/sourcemap.v1 v1.0.5 h1:inv58fC9f9J3TK2Y2R1NPntXEn3/wjWHkonhIUODNTI=
|
||||
gopkg.in/sourcemap.v1 v1.0.5/go.mod h1:2RlvNNSMglmRrcvhfuzp4hQHwOtjxlbjX7UPY/GXb78=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
|
||||
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
layeh.com/gopher-luar v1.0.7 h1:53iv6CCkRs5wyofZ+qVXcyAYQOIG52s6pt4xkqZdq7k=
|
||||
layeh.com/gopher-luar v1.0.7/go.mod h1:TPnIVCZ2RJBndm7ohXyaqfhzjlZ+OA2SZR/YwL8tECk=
|
||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
// +build plan9 nacl windows
|
||||
//go:build plan9 || nacl || windows
|
||||
|
||||
package action
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// +build linux darwin dragonfly solaris openbsd netbsd freebsd
|
||||
//go:build linux || darwin || dragonfly || solaris || openbsd || netbsd || freebsd
|
||||
|
||||
package action
|
||||
|
||||
|
@ -4,17 +4,18 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/zyedidia/json5"
|
||||
"github.com/micro-editor/json5"
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
)
|
||||
|
||||
var Binder = map[string]func(e Event, action string){
|
||||
@ -23,9 +24,13 @@ var Binder = map[string]func(e Event, action string){
|
||||
"terminal": TermMapEvent,
|
||||
}
|
||||
|
||||
func writeFile(name string, txt []byte) error {
|
||||
return util.SafeWrite(name, txt, false)
|
||||
}
|
||||
|
||||
func createBindingsIfNotExist(fname string) {
|
||||
if _, e := os.Stat(fname); os.IsNotExist(e) {
|
||||
ioutil.WriteFile(fname, []byte("{}"), 0644)
|
||||
if _, e := os.Stat(fname); errors.Is(e, fs.ErrNotExist) {
|
||||
writeFile(fname, []byte("{}"))
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +42,7 @@ func InitBindings() {
|
||||
createBindingsIfNotExist(filename)
|
||||
|
||||
if _, e := os.Stat(filename); e == nil {
|
||||
input, err := ioutil.ReadFile(filename)
|
||||
input, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
screen.TermMessage("Error reading bindings.json file: " + err.Error())
|
||||
return
|
||||
@ -88,6 +93,10 @@ func BindKey(k, v string, bind func(e Event, a string)) {
|
||||
return
|
||||
}
|
||||
|
||||
if strings.HasPrefix(k, "\x1b") {
|
||||
screen.RegisterRawSeq(k)
|
||||
}
|
||||
|
||||
bind(event, v)
|
||||
|
||||
// switch e := event.(type) {
|
||||
@ -139,7 +148,7 @@ func findSingleEvent(k string) (b Event, ok bool) {
|
||||
modSearch:
|
||||
for {
|
||||
switch {
|
||||
case strings.HasPrefix(k, "-"):
|
||||
case strings.HasPrefix(k, "-") && k != "-":
|
||||
// We optionally support dashes between modifiers
|
||||
k = k[1:]
|
||||
case strings.HasPrefix(k, "Ctrl") && k != "CtrlH":
|
||||
@ -153,7 +162,6 @@ modSearch:
|
||||
k = k[5:]
|
||||
modifiers |= tcell.ModShift
|
||||
case strings.HasPrefix(k, "\x1b"):
|
||||
screen.Screen.RegisterRawSeq(k)
|
||||
return RawEvent{
|
||||
esc: k,
|
||||
}, true
|
||||
@ -173,39 +181,35 @@ modSearch:
|
||||
// see if the key is in bindingKeys with the Ctrl prefix.
|
||||
k = string(unicode.ToUpper(rune(k[0]))) + k[1:]
|
||||
if code, ok := keyEvents["Ctrl"+k]; ok {
|
||||
var r tcell.Key
|
||||
// Special case for escape, for some reason tcell doesn't send it with the esc character
|
||||
if code < 256 && code != 27 {
|
||||
r = code
|
||||
}
|
||||
// It is, we're done.
|
||||
return KeyEvent{
|
||||
code: code,
|
||||
mod: modifiers,
|
||||
r: rune(r),
|
||||
}, true
|
||||
}
|
||||
}
|
||||
|
||||
// See if we can find the key in bindingKeys
|
||||
if code, ok := keyEvents[k]; ok {
|
||||
var r tcell.Key
|
||||
// Special case for escape, for some reason tcell doesn't send it with the esc character
|
||||
if code < 256 && code != 27 {
|
||||
r = code
|
||||
}
|
||||
return KeyEvent{
|
||||
code: code,
|
||||
mod: modifiers,
|
||||
r: rune(r),
|
||||
}, true
|
||||
}
|
||||
|
||||
var mstate MouseState = MousePress
|
||||
if strings.HasSuffix(k, "Drag") {
|
||||
k = k[:len(k)-4]
|
||||
mstate = MouseDrag
|
||||
} else if strings.HasSuffix(k, "Release") {
|
||||
k = k[:len(k)-7]
|
||||
mstate = MouseRelease
|
||||
}
|
||||
// See if we can find the key in bindingMouse
|
||||
if code, ok := mouseEvents[k]; ok {
|
||||
return MouseEvent{
|
||||
btn: code,
|
||||
mod: modifiers,
|
||||
state: mstate,
|
||||
}, true
|
||||
}
|
||||
|
||||
@ -239,6 +243,24 @@ func findEvent(k string) (Event, error) {
|
||||
return event, nil
|
||||
}
|
||||
|
||||
func eventsEqual(e1 Event, e2 Event) bool {
|
||||
seq1, ok1 := e1.(KeySequenceEvent)
|
||||
seq2, ok2 := e2.(KeySequenceEvent)
|
||||
if ok1 && ok2 {
|
||||
if len(seq1.keys) != len(seq2.keys) {
|
||||
return false
|
||||
}
|
||||
for i := 0; i < len(seq1.keys); i++ {
|
||||
if seq1.keys[i] != seq2.keys[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
return e1 == e2
|
||||
}
|
||||
|
||||
// TryBindKey tries to bind a key by writing to config.ConfigDir/bindings.json
|
||||
// Returns true if the keybinding already existed and a possible error
|
||||
func TryBindKey(k, v string, overwrite bool) (bool, error) {
|
||||
@ -248,7 +270,7 @@ func TryBindKey(k, v string, overwrite bool) (bool, error) {
|
||||
filename := filepath.Join(config.ConfigDir, "bindings.json")
|
||||
createBindingsIfNotExist(filename)
|
||||
if _, e = os.Stat(filename); e == nil {
|
||||
input, err := ioutil.ReadFile(filename)
|
||||
input, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return false, errors.New("Error reading bindings.json file: " + err.Error())
|
||||
}
|
||||
@ -264,28 +286,31 @@ func TryBindKey(k, v string, overwrite bool) (bool, error) {
|
||||
}
|
||||
|
||||
found := false
|
||||
for ev := range parsed {
|
||||
var ev string
|
||||
for ev = range parsed {
|
||||
if e, err := findEvent(ev); err == nil {
|
||||
if e == key {
|
||||
if overwrite {
|
||||
parsed[ev] = v
|
||||
}
|
||||
if eventsEqual(e, key) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if found && !overwrite {
|
||||
if found {
|
||||
if overwrite {
|
||||
parsed[ev] = v
|
||||
} else {
|
||||
return true, nil
|
||||
} else if !found {
|
||||
}
|
||||
} else {
|
||||
parsed[k] = v
|
||||
}
|
||||
|
||||
BindKey(k, v, Binder["buffer"])
|
||||
|
||||
txt, _ := json.MarshalIndent(parsed, "", " ")
|
||||
return true, ioutil.WriteFile(filename, append(txt, '\n'), 0644)
|
||||
txt = append(txt, '\n')
|
||||
return true, writeFile(filename, txt)
|
||||
}
|
||||
return false, e
|
||||
}
|
||||
@ -298,7 +323,7 @@ func UnbindKey(k string) error {
|
||||
filename := filepath.Join(config.ConfigDir, "bindings.json")
|
||||
createBindingsIfNotExist(filename)
|
||||
if _, e = os.Stat(filename); e == nil {
|
||||
input, err := ioutil.ReadFile(filename)
|
||||
input, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return errors.New("Error reading bindings.json file: " + err.Error())
|
||||
}
|
||||
@ -315,13 +340,17 @@ func UnbindKey(k string) error {
|
||||
|
||||
for ev := range parsed {
|
||||
if e, err := findEvent(ev); err == nil {
|
||||
if e == key {
|
||||
if eventsEqual(e, key) {
|
||||
delete(parsed, ev)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if strings.HasPrefix(k, "\x1b") {
|
||||
screen.UnregisterRawSeq(k)
|
||||
}
|
||||
|
||||
defaults := DefaultBindings("buffer")
|
||||
if a, ok := defaults[k]; ok {
|
||||
BindKey(k, a, Binder["buffer"])
|
||||
@ -331,7 +360,8 @@ func UnbindKey(k string) error {
|
||||
}
|
||||
|
||||
txt, _ := json.MarshalIndent(parsed, "", " ")
|
||||
return ioutil.WriteFile(filename, append(txt, '\n'), 0644)
|
||||
txt = append(txt, '\n')
|
||||
return writeFile(filename, txt)
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
@ -6,27 +6,35 @@ import (
|
||||
|
||||
luar "layeh.com/gopher-luar"
|
||||
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
"github.com/zyedidia/micro/v2/internal/buffer"
|
||||
"github.com/zyedidia/micro/v2/internal/clipboard"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/display"
|
||||
ulua "github.com/zyedidia/micro/v2/internal/lua"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
)
|
||||
|
||||
type BufAction interface{}
|
||||
|
||||
// BufKeyAction represents an action bound to a key.
|
||||
type BufKeyAction func(*BufPane) bool
|
||||
|
||||
// BufMouseAction is an action that must be bound to a mouse event.
|
||||
type BufMouseAction func(*BufPane, *tcell.EventMouse) bool
|
||||
|
||||
// BufBindings stores the bindings for the buffer pane type.
|
||||
var BufBindings *KeyTree
|
||||
|
||||
// BufKeyActionGeneral makes a general pane action from a BufKeyAction.
|
||||
func BufKeyActionGeneral(a BufKeyAction) PaneKeyAction {
|
||||
return func(p Pane) bool {
|
||||
return a(p.(*BufPane))
|
||||
}
|
||||
}
|
||||
|
||||
// BufMouseActionGeneral makes a general pane mouse action from a BufKeyAction.
|
||||
func BufMouseActionGeneral(a BufMouseAction) PaneMouseAction {
|
||||
return func(p Pane, me *tcell.EventMouse) bool {
|
||||
return a(p.(*BufPane), me)
|
||||
@ -37,7 +45,9 @@ func init() {
|
||||
BufBindings = NewKeyTree()
|
||||
}
|
||||
|
||||
func LuaAction(fn string) func(*BufPane) bool {
|
||||
// LuaAction makes an action from a lua function. It returns either a BufKeyAction
|
||||
// or a BufMouseAction depending on the event type.
|
||||
func LuaAction(fn string, k Event) BufAction {
|
||||
luaFn := strings.Split(fn, ".")
|
||||
if len(luaFn) <= 1 {
|
||||
return nil
|
||||
@ -47,7 +57,11 @@ func LuaAction(fn string) func(*BufPane) bool {
|
||||
if pl == nil {
|
||||
return nil
|
||||
}
|
||||
return func(h *BufPane) bool {
|
||||
|
||||
var action BufAction
|
||||
switch k.(type) {
|
||||
case KeyEvent, KeySequenceEvent, RawEvent:
|
||||
action = BufKeyAction(func(h *BufPane) bool {
|
||||
val, err := pl.Call(plFn, luar.New(ulua.L, h))
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
@ -57,23 +71,28 @@ func LuaAction(fn string) func(*BufPane) bool {
|
||||
} else {
|
||||
return bool(v)
|
||||
}
|
||||
})
|
||||
case MouseEvent:
|
||||
action = BufMouseAction(func(h *BufPane, te *tcell.EventMouse) bool {
|
||||
val, err := pl.Call(plFn, luar.New(ulua.L, h), luar.New(ulua.L, te))
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
if v, ok := val.(lua.LBool); !ok {
|
||||
return false
|
||||
} else {
|
||||
return bool(v)
|
||||
}
|
||||
})
|
||||
}
|
||||
return action
|
||||
}
|
||||
|
||||
// BufMapKey maps an event to an action
|
||||
// BufMapEvent maps an event to an action
|
||||
func BufMapEvent(k Event, action string) {
|
||||
config.Bindings["buffer"][k.Name()] = action
|
||||
|
||||
switch e := k.(type) {
|
||||
case KeyEvent, KeySequenceEvent, RawEvent:
|
||||
bufMapKey(e, action)
|
||||
case MouseEvent:
|
||||
bufMapMouse(e, action)
|
||||
}
|
||||
}
|
||||
|
||||
func bufMapKey(k Event, action string) {
|
||||
var actionfns []func(*BufPane) bool
|
||||
var actionfns []BufAction
|
||||
var names []string
|
||||
var types []byte
|
||||
for i := 0; ; i++ {
|
||||
@ -81,9 +100,7 @@ func bufMapKey(k Event, action string) {
|
||||
break
|
||||
}
|
||||
|
||||
// TODO: fix problem when complex bindings have these
|
||||
// characters (escape them?)
|
||||
idx := strings.IndexAny(action, "&|,")
|
||||
idx := util.IndexAnyUnquoted(action, "&|,")
|
||||
a := action
|
||||
if idx >= 0 {
|
||||
a = action[:idx]
|
||||
@ -94,7 +111,7 @@ func bufMapKey(k Event, action string) {
|
||||
action = ""
|
||||
}
|
||||
|
||||
var afn func(*BufPane) bool
|
||||
var afn BufAction
|
||||
if strings.HasPrefix(a, "command:") {
|
||||
a = strings.SplitN(a, ":", 2)[1]
|
||||
afn = CommandAction(a)
|
||||
@ -105,7 +122,7 @@ func bufMapKey(k Event, action string) {
|
||||
names = append(names, "")
|
||||
} else if strings.HasPrefix(a, "lua:") {
|
||||
a = strings.SplitN(a, ":", 2)[1]
|
||||
afn = LuaAction(a)
|
||||
afn = LuaAction(a, k)
|
||||
if afn == nil {
|
||||
screen.TermMessage("Lua Error:", a, "does not exist")
|
||||
continue
|
||||
@ -121,47 +138,52 @@ func bufMapKey(k Event, action string) {
|
||||
} else if f, ok := BufKeyActions[a]; ok {
|
||||
afn = f
|
||||
names = append(names, a)
|
||||
} else if f, ok := BufMouseActions[a]; ok {
|
||||
afn = f
|
||||
names = append(names, a)
|
||||
} else {
|
||||
screen.TermMessage("Error in bindings: action", a, "does not exist")
|
||||
continue
|
||||
}
|
||||
actionfns = append(actionfns, afn)
|
||||
}
|
||||
bufAction := func(h *BufPane) bool {
|
||||
cursors := h.Buf.GetCursors()
|
||||
success := true
|
||||
bufAction := func(h *BufPane, te *tcell.EventMouse) bool {
|
||||
for i, a := range actionfns {
|
||||
innerSuccess := true
|
||||
for j, c := range cursors {
|
||||
if c == nil {
|
||||
continue
|
||||
}
|
||||
var success bool
|
||||
if _, ok := MultiActions[names[i]]; ok {
|
||||
success = true
|
||||
for _, c := range h.Buf.GetCursors() {
|
||||
h.Buf.SetCurCursor(c.Num)
|
||||
h.Cursor = c
|
||||
if i == 0 || (success && types[i-1] == '&') || (!success && types[i-1] == '|') || (types[i-1] == ',') {
|
||||
innerSuccess = innerSuccess && h.execAction(a, names[i], j)
|
||||
success = success && h.execAction(a, names[i], te)
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
h.Buf.SetCurCursor(0)
|
||||
h.Cursor = h.Buf.GetActiveCursor()
|
||||
success = h.execAction(a, names[i], te)
|
||||
}
|
||||
|
||||
// if the action changed the current pane, update the reference
|
||||
h = MainTab().CurPane()
|
||||
success = innerSuccess
|
||||
if h == nil {
|
||||
// stop, in case the current pane is not a BufPane
|
||||
break
|
||||
}
|
||||
|
||||
if (!success && types[i] == '&') || (success && types[i] == '|') {
|
||||
break
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
BufBindings.RegisterKeyBinding(k, BufKeyActionGeneral(bufAction))
|
||||
}
|
||||
|
||||
// BufMapMouse maps a mouse event to an action
|
||||
func bufMapMouse(k MouseEvent, action string) {
|
||||
if f, ok := BufMouseActions[action]; ok {
|
||||
BufBindings.RegisterMouseBinding(k, BufMouseActionGeneral(f))
|
||||
} else {
|
||||
// TODO
|
||||
// delete(BufMouseBindings, k)
|
||||
bufMapKey(k, action)
|
||||
switch e := k.(type) {
|
||||
case KeyEvent, KeySequenceEvent, RawEvent:
|
||||
BufBindings.RegisterKeyBinding(e, BufKeyActionGeneral(func(h *BufPane) bool {
|
||||
return bufAction(h, nil)
|
||||
}))
|
||||
case MouseEvent:
|
||||
BufBindings.RegisterMouseBinding(e, BufMouseActionGeneral(bufAction))
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,36 +214,32 @@ type BufPane struct {
|
||||
// Cursor is the currently active buffer cursor
|
||||
Cursor *buffer.Cursor
|
||||
|
||||
// Since tcell doesn't differentiate between a mouse release event
|
||||
// and a mouse move event with no keys pressed, we need to keep
|
||||
// track of whether or not the mouse was pressed (or not released) last event to determine
|
||||
// mouse release events
|
||||
mouseReleased bool
|
||||
// Since tcell doesn't differentiate between a mouse press event
|
||||
// and a mouse move event with button pressed (nor between a mouse
|
||||
// release event and a mouse move event with no buttons pressed),
|
||||
// we need to keep track of whether or not the mouse was previously
|
||||
// pressed, to determine mouse release and mouse drag events.
|
||||
// Moreover, since in case of a release event tcell doesn't tell us
|
||||
// which button was released, we need to keep track of which
|
||||
// (possibly multiple) buttons were pressed previously.
|
||||
mousePressed map[MouseEvent]bool
|
||||
|
||||
// We need to keep track of insert key press toggle
|
||||
isOverwriteMode bool
|
||||
// This stores when the last click was
|
||||
// This is useful for detecting double and triple clicks
|
||||
lastClickTime time.Time
|
||||
lastLoc buffer.Loc
|
||||
|
||||
// lastCutTime stores when the last ctrl+k was issued.
|
||||
// It is used for clearing the clipboard to replace it with fresh cut lines.
|
||||
lastCutTime time.Time
|
||||
|
||||
// freshClip returns true if the clipboard has never been pasted.
|
||||
// freshClip returns true if one or more lines have been cut to the clipboard
|
||||
// and have never been pasted yet.
|
||||
freshClip bool
|
||||
|
||||
// Was the last mouse event actually a double click?
|
||||
// Useful for detecting triple clicks -- if a double click is detected
|
||||
// but the last mouse event was actually a double click, it's a triple click
|
||||
doubleClick bool
|
||||
DoubleClick bool
|
||||
// Same here, just to keep track for mouse move events
|
||||
tripleClick bool
|
||||
TripleClick bool
|
||||
|
||||
// Last search stores the last successful search for FindNext and FindPrev
|
||||
lastSearch string
|
||||
lastSearchRegex bool
|
||||
// Should the current multiple cursor selection search based on word or
|
||||
// based on selection (false for selection, true for word)
|
||||
multiWord bool
|
||||
@ -231,31 +249,67 @@ type BufPane struct {
|
||||
|
||||
// remember original location of a search in case the search is canceled
|
||||
searchOrig buffer.Loc
|
||||
|
||||
// The pane may not yet be fully initialized after its creation
|
||||
// since we may not know the window geometry yet. In such case we finish
|
||||
// its initialization a bit later, after the initial resize.
|
||||
initialized bool
|
||||
}
|
||||
|
||||
func NewBufPane(buf *buffer.Buffer, win display.BWindow, tab *Tab) *BufPane {
|
||||
func newBufPane(buf *buffer.Buffer, win display.BWindow, tab *Tab) *BufPane {
|
||||
h := new(BufPane)
|
||||
h.Buf = buf
|
||||
h.BWindow = win
|
||||
h.tab = tab
|
||||
|
||||
h.Cursor = h.Buf.GetActiveCursor()
|
||||
h.mouseReleased = true
|
||||
|
||||
config.RunPluginFn("onBufPaneOpen", luar.New(ulua.L, h))
|
||||
h.mousePressed = make(map[MouseEvent]bool)
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
func NewBufPaneFromBuf(buf *buffer.Buffer, tab *Tab) *BufPane {
|
||||
w := display.NewBufWindow(0, 0, 0, 0, buf)
|
||||
return NewBufPane(buf, w, tab)
|
||||
// NewBufPane creates a new buffer pane with the given window.
|
||||
func NewBufPane(buf *buffer.Buffer, win display.BWindow, tab *Tab) *BufPane {
|
||||
h := newBufPane(buf, win, tab)
|
||||
h.finishInitialize()
|
||||
return h
|
||||
}
|
||||
|
||||
// NewBufPaneFromBuf constructs a new pane from the given buffer and automatically
|
||||
// creates a buf window.
|
||||
func NewBufPaneFromBuf(buf *buffer.Buffer, tab *Tab) *BufPane {
|
||||
w := display.NewBufWindow(0, 0, 0, 0, buf)
|
||||
h := newBufPane(buf, w, tab)
|
||||
// Postpone finishing initializing the pane until we know the actual geometry
|
||||
// of the buf window.
|
||||
return h
|
||||
}
|
||||
|
||||
// TODO: make sure splitID and tab are set before finishInitialize is called
|
||||
func (h *BufPane) finishInitialize() {
|
||||
h.initialRelocate()
|
||||
h.initialized = true
|
||||
|
||||
err := config.RunPluginFn("onBufPaneOpen", luar.New(ulua.L, h))
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Resize resizes the pane
|
||||
func (h *BufPane) Resize(width, height int) {
|
||||
h.BWindow.Resize(width, height)
|
||||
if !h.initialized {
|
||||
h.finishInitialize()
|
||||
}
|
||||
}
|
||||
|
||||
// SetTab sets this pane's tab.
|
||||
func (h *BufPane) SetTab(t *Tab) {
|
||||
h.tab = t
|
||||
}
|
||||
|
||||
// Tab returns this pane's tab.
|
||||
func (h *BufPane) Tab() *Tab {
|
||||
return h.tab
|
||||
}
|
||||
@ -266,51 +320,93 @@ func (h *BufPane) ResizePane(size int) {
|
||||
h.tab.Resize()
|
||||
}
|
||||
|
||||
// PluginCB calls all plugin callbacks with a certain name and
|
||||
// displays an error if there is one and returns the aggregrate
|
||||
// boolean response
|
||||
// PluginCB calls all plugin callbacks with a certain name and displays an
|
||||
// error if there is one and returns the aggregate boolean response
|
||||
func (h *BufPane) PluginCB(cb string) bool {
|
||||
b, err := config.RunPluginFnBool(cb, luar.New(ulua.L, h))
|
||||
b, err := config.RunPluginFnBool(h.Buf.Settings, cb, luar.New(ulua.L, h))
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// PluginCBRune is the same as PluginCB but also passes a rune to
|
||||
// the plugins
|
||||
// PluginCBRune is the same as PluginCB but also passes a rune to the plugins
|
||||
func (h *BufPane) PluginCBRune(cb string, r rune) bool {
|
||||
b, err := config.RunPluginFnBool(cb, luar.New(ulua.L, h), luar.New(ulua.L, string(r)))
|
||||
b, err := config.RunPluginFnBool(h.Buf.Settings, cb, luar.New(ulua.L, h), luar.New(ulua.L, string(r)))
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func (h *BufPane) resetMouse() {
|
||||
for me := range h.mousePressed {
|
||||
delete(h.mousePressed, me)
|
||||
}
|
||||
}
|
||||
|
||||
// OpenBuffer opens the given buffer in this pane.
|
||||
func (h *BufPane) OpenBuffer(b *buffer.Buffer) {
|
||||
h.Buf.Close()
|
||||
h.Buf = b
|
||||
h.BWindow.SetBuffer(b)
|
||||
h.Cursor = b.GetActiveCursor()
|
||||
h.Resize(h.GetView().Width, h.GetView().Height)
|
||||
h.Relocate()
|
||||
// Set mouseReleased to true because we assume the mouse is not being pressed when
|
||||
// the editor is opened
|
||||
h.mouseReleased = true
|
||||
// Set isOverwriteMode to false, because we assume we are in the default mode when editor
|
||||
// is opened
|
||||
h.isOverwriteMode = false
|
||||
h.initialRelocate()
|
||||
// Set mouseReleased to true because we assume the mouse is not being
|
||||
// pressed when the editor is opened
|
||||
h.resetMouse()
|
||||
h.lastClickTime = time.Time{}
|
||||
}
|
||||
|
||||
// GotoLoc moves the cursor to a new location and adjusts the view accordingly.
|
||||
// Use GotoLoc when the new location may be far away from the current location.
|
||||
func (h *BufPane) GotoLoc(loc buffer.Loc) {
|
||||
sloc := h.SLocFromLoc(loc)
|
||||
d := h.Diff(h.SLocFromLoc(h.Cursor.Loc), sloc)
|
||||
|
||||
h.Cursor.GotoLoc(loc)
|
||||
|
||||
// If the new location is far away from the previous one,
|
||||
// ensure the cursor is at 25% of the window height
|
||||
height := h.BufView().Height
|
||||
if util.Abs(d) >= height {
|
||||
v := h.GetView()
|
||||
v.StartLine = h.Scroll(sloc, -height/4)
|
||||
h.ScrollAdjust()
|
||||
v.StartCol = 0
|
||||
}
|
||||
h.Relocate()
|
||||
}
|
||||
|
||||
func (h *BufPane) initialRelocate() {
|
||||
sloc := h.SLocFromLoc(h.Cursor.Loc)
|
||||
height := h.BufView().Height
|
||||
|
||||
// If the initial cursor location is far away from the beginning
|
||||
// of the buffer, ensure the cursor is at 25% of the window height
|
||||
v := h.GetView()
|
||||
if h.Diff(display.SLoc{0, 0}, sloc) < height {
|
||||
v.StartLine = display.SLoc{0, 0}
|
||||
} else {
|
||||
v.StartLine = h.Scroll(sloc, -height/4)
|
||||
h.ScrollAdjust()
|
||||
}
|
||||
v.StartCol = 0
|
||||
h.Relocate()
|
||||
}
|
||||
|
||||
// ID returns this pane's split id.
|
||||
func (h *BufPane) ID() uint64 {
|
||||
return h.splitID
|
||||
}
|
||||
|
||||
// SetID sets the split ID of this pane.
|
||||
func (h *BufPane) SetID(i uint64) {
|
||||
h.splitID = i
|
||||
}
|
||||
|
||||
// Name returns the BufPane's name.
|
||||
func (h *BufPane) Name() string {
|
||||
n := h.Buf.GetName()
|
||||
if h.Buf.Modified() {
|
||||
@ -319,9 +415,23 @@ func (h *BufPane) Name() string {
|
||||
return n
|
||||
}
|
||||
|
||||
// ReOpen reloads the file opened in the bufpane from disk
|
||||
func (h *BufPane) ReOpen() {
|
||||
h.Buf.ReOpen()
|
||||
h.Relocate()
|
||||
}
|
||||
|
||||
func (h *BufPane) getReloadSetting() string {
|
||||
reloadSetting := h.Buf.Settings["reload"]
|
||||
return reloadSetting.(string)
|
||||
}
|
||||
|
||||
// HandleEvent executes the tcell event properly
|
||||
func (h *BufPane) HandleEvent(event tcell.Event) {
|
||||
if h.Buf.ExternallyModified() && !h.Buf.ReloadDisabled {
|
||||
reload := h.getReloadSetting()
|
||||
|
||||
if reload == "prompt" {
|
||||
InfoBar.YNPrompt("The file on disk has changed. Reload file? (y,n,esc)", func(yes, canceled bool) {
|
||||
if canceled {
|
||||
h.Buf.DisableReload()
|
||||
@ -329,10 +439,16 @@ func (h *BufPane) HandleEvent(event tcell.Event) {
|
||||
if !yes || canceled {
|
||||
h.Buf.UpdateModTime()
|
||||
} else {
|
||||
h.Buf.ReOpen()
|
||||
h.ReOpen()
|
||||
}
|
||||
})
|
||||
|
||||
} else if reload == "auto" {
|
||||
h.ReOpen()
|
||||
} else if reload == "disabled" {
|
||||
h.Buf.DisableReload()
|
||||
} else {
|
||||
InfoBar.Message("Invalid reload setting")
|
||||
}
|
||||
}
|
||||
|
||||
switch e := event.(type) {
|
||||
@ -345,61 +461,44 @@ func (h *BufPane) HandleEvent(event tcell.Event) {
|
||||
h.paste(e.Text())
|
||||
h.Relocate()
|
||||
case *tcell.EventKey:
|
||||
ke := KeyEvent{
|
||||
code: e.Key(),
|
||||
mod: metaToAlt(e.Modifiers()),
|
||||
r: e.Rune(),
|
||||
}
|
||||
ke := keyEvent(e)
|
||||
|
||||
done := h.DoKeyEvent(ke)
|
||||
if !done && e.Key() == tcell.KeyRune {
|
||||
h.DoRuneInsert(e.Rune())
|
||||
}
|
||||
case *tcell.EventMouse:
|
||||
cancel := false
|
||||
switch e.Buttons() {
|
||||
case tcell.Button1:
|
||||
_, my := e.Position()
|
||||
if h.Buf.Type.Kind != buffer.BTInfo.Kind && h.Buf.Settings["statusline"].(bool) && my >= h.GetView().Y+h.GetView().Height-1 {
|
||||
cancel = true
|
||||
}
|
||||
case tcell.ButtonNone:
|
||||
// Mouse event with no click
|
||||
if !h.mouseReleased {
|
||||
// Mouse was just released
|
||||
|
||||
// mx, my := e.Position()
|
||||
// mouseLoc := h.LocFromVisual(buffer.Loc{X: mx, Y: my})
|
||||
|
||||
// we could finish the selection based on the release location as described
|
||||
// below but when the mouse click is within the scroll margin this will
|
||||
// cause a scroll and selection even for a simple mouse click which is
|
||||
// not good
|
||||
// for terminals that don't support mouse motion events, selection via
|
||||
// the mouse won't work but this is ok
|
||||
|
||||
// Relocating here isn't really necessary because the cursor will
|
||||
// be in the right place from the last mouse event
|
||||
// However, if we are running in a terminal that doesn't support mouse motion
|
||||
// events, this still allows the user to make selections, except only after they
|
||||
// release the mouse
|
||||
|
||||
// if !h.doubleClick && !h.tripleClick {
|
||||
// h.Cursor.SetSelectionEnd(h.Cursor.Loc)
|
||||
// }
|
||||
if h.Cursor.HasSelection() {
|
||||
h.Cursor.CopySelection(clipboard.PrimaryReg)
|
||||
}
|
||||
h.mouseReleased = true
|
||||
}
|
||||
}
|
||||
|
||||
if !cancel {
|
||||
if e.Buttons() != tcell.ButtonNone {
|
||||
me := MouseEvent{
|
||||
btn: e.Buttons(),
|
||||
mod: metaToAlt(e.Modifiers()),
|
||||
state: MousePress,
|
||||
}
|
||||
isDrag := len(h.mousePressed) > 0
|
||||
|
||||
if e.Buttons() & ^(tcell.WheelUp|tcell.WheelDown|tcell.WheelLeft|tcell.WheelRight) != tcell.ButtonNone {
|
||||
h.mousePressed[me] = true
|
||||
}
|
||||
|
||||
if isDrag {
|
||||
me.state = MouseDrag
|
||||
}
|
||||
h.DoMouseEvent(me, e)
|
||||
} else {
|
||||
// Mouse event with no click - mouse was just released.
|
||||
// If there were multiple mouse buttons pressed, we don't know which one
|
||||
// was actually released, so we assume they all were released.
|
||||
pressed := len(h.mousePressed) > 0
|
||||
for me := range h.mousePressed {
|
||||
delete(h.mousePressed, me)
|
||||
|
||||
me.state = MouseRelease
|
||||
h.DoMouseEvent(me, e)
|
||||
}
|
||||
if !pressed {
|
||||
// Propagate the mouse release in case the press wasn't for this BufPane
|
||||
Tabs.ResetMouse()
|
||||
}
|
||||
}
|
||||
}
|
||||
h.Buf.MergeCursors()
|
||||
@ -419,8 +518,17 @@ func (h *BufPane) HandleEvent(event tcell.Event) {
|
||||
InfoBar.ClearGutter()
|
||||
}
|
||||
}
|
||||
|
||||
cursors := h.Buf.GetCursors()
|
||||
for _, c := range cursors {
|
||||
if c.NewTrailingWsY != c.Y && (!c.HasSelection() ||
|
||||
(c.NewTrailingWsY != c.CurSelection[0].Y && c.NewTrailingWsY != c.CurSelection[1].Y)) {
|
||||
c.NewTrailingWsY = -1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bindings returns the current bindings tree for this buffer.
|
||||
func (h *BufPane) Bindings() *KeyTree {
|
||||
if h.bindings != nil {
|
||||
return h.bindings
|
||||
@ -429,7 +537,10 @@ func (h *BufPane) Bindings() *KeyTree {
|
||||
}
|
||||
|
||||
// DoKeyEvent executes a key event by finding the action it is bound
|
||||
// to and executing it (possibly multiple times for multiple cursors)
|
||||
// to and executing it (possibly multiple times for multiple cursors).
|
||||
// Returns true if the action was executed OR if there are more keys
|
||||
// remaining to process before executing an action (if this is a key
|
||||
// sequence event). Returns false if no action found.
|
||||
func (h *BufPane) DoKeyEvent(e Event) bool {
|
||||
binds := h.Bindings()
|
||||
action, more := binds.NextEvent(e, nil)
|
||||
@ -443,19 +554,26 @@ func (h *BufPane) DoKeyEvent(e Event) bool {
|
||||
return more
|
||||
}
|
||||
|
||||
func (h *BufPane) execAction(action func(*BufPane) bool, name string, cursor int) bool {
|
||||
func (h *BufPane) execAction(action BufAction, name string, te *tcell.EventMouse) bool {
|
||||
if name != "Autocomplete" && name != "CycleAutocompleteBack" {
|
||||
h.Buf.HasSuggestions = false
|
||||
}
|
||||
|
||||
_, isMulti := MultiActions[name]
|
||||
if (!isMulti && cursor == 0) || isMulti {
|
||||
if h.PluginCB("pre" + name) {
|
||||
success := action(h)
|
||||
if !h.PluginCB("pre" + name) {
|
||||
return false
|
||||
}
|
||||
|
||||
var success bool
|
||||
switch a := action.(type) {
|
||||
case BufKeyAction:
|
||||
success = a(h)
|
||||
case BufMouseAction:
|
||||
success = a(h, te)
|
||||
}
|
||||
success = success && h.PluginCB("on"+name)
|
||||
|
||||
if isMulti {
|
||||
if recording_macro {
|
||||
if _, ok := MultiActions[name]; ok {
|
||||
if recordingMacro {
|
||||
if name != "ToggleMacro" && name != "PlayMacro" {
|
||||
curmacro = append(curmacro, action)
|
||||
}
|
||||
@ -464,10 +582,6 @@ func (h *BufPane) execAction(action func(*BufPane) bool, name string, cursor int
|
||||
|
||||
return success
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (h *BufPane) completeAction(action string) {
|
||||
h.PluginCB("on" + action)
|
||||
@ -520,14 +634,14 @@ func (h *BufPane) DoRuneInsert(r rune) {
|
||||
c.ResetSelection()
|
||||
}
|
||||
|
||||
if h.isOverwriteMode {
|
||||
if h.Buf.OverwriteMode {
|
||||
next := c.Loc
|
||||
next.X++
|
||||
h.Buf.Replace(c.Loc, next, string(r))
|
||||
} else {
|
||||
h.Buf.Insert(c.Loc, string(r))
|
||||
}
|
||||
if recording_macro {
|
||||
if recordingMacro {
|
||||
curmacro = append(curmacro, r)
|
||||
}
|
||||
h.Relocate()
|
||||
@ -535,34 +649,55 @@ func (h *BufPane) DoRuneInsert(r rune) {
|
||||
}
|
||||
}
|
||||
|
||||
// VSplitIndex opens the given buffer in a vertical split on the given side.
|
||||
func (h *BufPane) VSplitIndex(buf *buffer.Buffer, right bool) *BufPane {
|
||||
e := NewBufPaneFromBuf(buf, h.tab)
|
||||
e.splitID = MainTab().GetNode(h.splitID).VSplit(right)
|
||||
MainTab().Panes = append(MainTab().Panes, e)
|
||||
MainTab().Resize()
|
||||
MainTab().SetActive(len(MainTab().Panes) - 1)
|
||||
return e
|
||||
e.splitID = h.tab.GetNode(h.splitID).VSplit(right)
|
||||
currentPaneIdx := h.tab.GetPane(h.splitID)
|
||||
if right {
|
||||
currentPaneIdx++
|
||||
}
|
||||
func (h *BufPane) HSplitIndex(buf *buffer.Buffer, bottom bool) *BufPane {
|
||||
e := NewBufPaneFromBuf(buf, h.tab)
|
||||
e.splitID = MainTab().GetNode(h.splitID).HSplit(bottom)
|
||||
MainTab().Panes = append(MainTab().Panes, e)
|
||||
MainTab().Resize()
|
||||
MainTab().SetActive(len(MainTab().Panes) - 1)
|
||||
h.tab.AddPane(e, currentPaneIdx)
|
||||
h.tab.Resize()
|
||||
h.tab.SetActive(currentPaneIdx)
|
||||
return e
|
||||
}
|
||||
|
||||
// HSplitIndex opens the given buffer in a horizontal split on the given side.
|
||||
func (h *BufPane) HSplitIndex(buf *buffer.Buffer, bottom bool) *BufPane {
|
||||
e := NewBufPaneFromBuf(buf, h.tab)
|
||||
e.splitID = h.tab.GetNode(h.splitID).HSplit(bottom)
|
||||
currentPaneIdx := h.tab.GetPane(h.splitID)
|
||||
if bottom {
|
||||
currentPaneIdx++
|
||||
}
|
||||
h.tab.AddPane(e, currentPaneIdx)
|
||||
h.tab.Resize()
|
||||
h.tab.SetActive(currentPaneIdx)
|
||||
return e
|
||||
}
|
||||
|
||||
// VSplitBuf opens the given buffer in a new vertical split.
|
||||
func (h *BufPane) VSplitBuf(buf *buffer.Buffer) *BufPane {
|
||||
return h.VSplitIndex(buf, h.Buf.Settings["splitright"].(bool))
|
||||
}
|
||||
|
||||
// HSplitBuf opens the given buffer in a new horizontal split.
|
||||
func (h *BufPane) HSplitBuf(buf *buffer.Buffer) *BufPane {
|
||||
return h.HSplitIndex(buf, h.Buf.Settings["splitbottom"].(bool))
|
||||
}
|
||||
|
||||
// Close this pane.
|
||||
func (h *BufPane) Close() {
|
||||
h.Buf.Close()
|
||||
}
|
||||
|
||||
// SetActive marks this pane as active.
|
||||
func (h *BufPane) SetActive(b bool) {
|
||||
if h.IsActive() == b {
|
||||
return
|
||||
}
|
||||
|
||||
h.BWindow.SetActive(b)
|
||||
if b {
|
||||
// Display any gutter messages for this line
|
||||
@ -578,8 +713,12 @@ func (h *BufPane) SetActive(b bool) {
|
||||
if none && InfoBar.HasGutter {
|
||||
InfoBar.ClearGutter()
|
||||
}
|
||||
}
|
||||
|
||||
err := config.RunPluginFn("onSetActive", luar.New(ulua.L, h))
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// BufKeyActions contains the list of all possible key actions the bufhandler could execute
|
||||
@ -592,6 +731,9 @@ var BufKeyActions = map[string]BufKeyAction{
|
||||
"CursorRight": (*BufPane).CursorRight,
|
||||
"CursorStart": (*BufPane).CursorStart,
|
||||
"CursorEnd": (*BufPane).CursorEnd,
|
||||
"CursorToViewTop": (*BufPane).CursorToViewTop,
|
||||
"CursorToViewCenter": (*BufPane).CursorToViewCenter,
|
||||
"CursorToViewBottom": (*BufPane).CursorToViewBottom,
|
||||
"SelectToStart": (*BufPane).SelectToStart,
|
||||
"SelectToEnd": (*BufPane).SelectToEnd,
|
||||
"SelectUp": (*BufPane).SelectUp,
|
||||
@ -600,10 +742,16 @@ var BufKeyActions = map[string]BufKeyAction{
|
||||
"SelectRight": (*BufPane).SelectRight,
|
||||
"WordRight": (*BufPane).WordRight,
|
||||
"WordLeft": (*BufPane).WordLeft,
|
||||
"SubWordRight": (*BufPane).SubWordRight,
|
||||
"SubWordLeft": (*BufPane).SubWordLeft,
|
||||
"SelectWordRight": (*BufPane).SelectWordRight,
|
||||
"SelectWordLeft": (*BufPane).SelectWordLeft,
|
||||
"SelectSubWordRight": (*BufPane).SelectSubWordRight,
|
||||
"SelectSubWordLeft": (*BufPane).SelectSubWordLeft,
|
||||
"DeleteWordRight": (*BufPane).DeleteWordRight,
|
||||
"DeleteWordLeft": (*BufPane).DeleteWordLeft,
|
||||
"DeleteSubWordRight": (*BufPane).DeleteSubWordRight,
|
||||
"DeleteSubWordLeft": (*BufPane).DeleteSubWordLeft,
|
||||
"SelectLine": (*BufPane).SelectLine,
|
||||
"SelectToStartOfLine": (*BufPane).SelectToStartOfLine,
|
||||
"SelectToStartOfText": (*BufPane).SelectToStartOfText,
|
||||
@ -611,6 +759,8 @@ var BufKeyActions = map[string]BufKeyAction{
|
||||
"SelectToEndOfLine": (*BufPane).SelectToEndOfLine,
|
||||
"ParagraphPrevious": (*BufPane).ParagraphPrevious,
|
||||
"ParagraphNext": (*BufPane).ParagraphNext,
|
||||
"SelectToParagraphPrevious": (*BufPane).SelectToParagraphPrevious,
|
||||
"SelectToParagraphNext": (*BufPane).SelectToParagraphNext,
|
||||
"InsertNewline": (*BufPane).InsertNewline,
|
||||
"Backspace": (*BufPane).Backspace,
|
||||
"Delete": (*BufPane).Delete,
|
||||
@ -622,6 +772,8 @@ var BufKeyActions = map[string]BufKeyAction{
|
||||
"FindLiteral": (*BufPane).FindLiteral,
|
||||
"FindNext": (*BufPane).FindNext,
|
||||
"FindPrevious": (*BufPane).FindPrevious,
|
||||
"DiffNext": (*BufPane).DiffNext,
|
||||
"DiffPrevious": (*BufPane).DiffPrevious,
|
||||
"Center": (*BufPane).Center,
|
||||
"Undo": (*BufPane).Undo,
|
||||
"Redo": (*BufPane).Redo,
|
||||
@ -629,6 +781,7 @@ var BufKeyActions = map[string]BufKeyAction{
|
||||
"CopyLine": (*BufPane).CopyLine,
|
||||
"Cut": (*BufPane).Cut,
|
||||
"CutLine": (*BufPane).CutLine,
|
||||
"Duplicate": (*BufPane).Duplicate,
|
||||
"DuplicateLine": (*BufPane).DuplicateLine,
|
||||
"DeleteLine": (*BufPane).DeleteLine,
|
||||
"MoveLinesUp": (*BufPane).MoveLinesUp,
|
||||
@ -659,6 +812,9 @@ var BufKeyActions = map[string]BufKeyAction{
|
||||
"ToggleKeyMenu": (*BufPane).ToggleKeyMenu,
|
||||
"ToggleDiffGutter": (*BufPane).ToggleDiffGutter,
|
||||
"ToggleRuler": (*BufPane).ToggleRuler,
|
||||
"ToggleHighlightSearch": (*BufPane).ToggleHighlightSearch,
|
||||
"UnhighlightSearch": (*BufPane).UnhighlightSearch,
|
||||
"ResetSearch": (*BufPane).ResetSearch,
|
||||
"ClearStatus": (*BufPane).ClearStatus,
|
||||
"ShellMode": (*BufPane).ShellMode,
|
||||
"CommandMode": (*BufPane).CommandMode,
|
||||
@ -670,8 +826,12 @@ var BufKeyActions = map[string]BufKeyAction{
|
||||
"AddTab": (*BufPane).AddTab,
|
||||
"PreviousTab": (*BufPane).PreviousTab,
|
||||
"NextTab": (*BufPane).NextTab,
|
||||
"FirstTab": (*BufPane).FirstTab,
|
||||
"LastTab": (*BufPane).LastTab,
|
||||
"NextSplit": (*BufPane).NextSplit,
|
||||
"PreviousSplit": (*BufPane).PreviousSplit,
|
||||
"FirstSplit": (*BufPane).FirstSplit,
|
||||
"LastSplit": (*BufPane).LastSplit,
|
||||
"Unsplit": (*BufPane).Unsplit,
|
||||
"VSplit": (*BufPane).VSplitAction,
|
||||
"HSplit": (*BufPane).HSplitAction,
|
||||
@ -687,6 +847,7 @@ var BufKeyActions = map[string]BufKeyAction{
|
||||
"RemoveMultiCursor": (*BufPane).RemoveMultiCursor,
|
||||
"RemoveAllMultiCursors": (*BufPane).RemoveAllMultiCursors,
|
||||
"SkipMultiCursor": (*BufPane).SkipMultiCursor,
|
||||
"SkipMultiCursorBack": (*BufPane).SkipMultiCursorBack,
|
||||
"JumpToMatchingBrace": (*BufPane).JumpToMatchingBrace,
|
||||
"JumpLine": (*BufPane).JumpLine,
|
||||
"Deselect": (*BufPane).Deselect,
|
||||
@ -700,6 +861,8 @@ var BufKeyActions = map[string]BufKeyAction{
|
||||
// BufMouseActions contains the list of all possible mouse actions the bufhandler could execute
|
||||
var BufMouseActions = map[string]BufMouseAction{
|
||||
"MousePress": (*BufPane).MousePress,
|
||||
"MouseDrag": (*BufPane).MouseDrag,
|
||||
"MouseRelease": (*BufPane).MouseRelease,
|
||||
"MouseMultiCursor": (*BufPane).MouseMultiCursor,
|
||||
}
|
||||
|
||||
@ -724,10 +887,16 @@ var MultiActions = map[string]bool{
|
||||
"SelectRight": true,
|
||||
"WordRight": true,
|
||||
"WordLeft": true,
|
||||
"SubWordRight": true,
|
||||
"SubWordLeft": true,
|
||||
"SelectWordRight": true,
|
||||
"SelectWordLeft": true,
|
||||
"SelectSubWordRight": true,
|
||||
"SelectSubWordLeft": true,
|
||||
"DeleteWordRight": true,
|
||||
"DeleteWordLeft": true,
|
||||
"DeleteSubWordRight": true,
|
||||
"DeleteSubWordLeft": true,
|
||||
"SelectLine": true,
|
||||
"SelectToStartOfLine": true,
|
||||
"SelectToStartOfText": true,
|
||||
@ -745,6 +914,7 @@ var MultiActions = map[string]bool{
|
||||
"Copy": true,
|
||||
"Cut": true,
|
||||
"CutLine": true,
|
||||
"Duplicate": true,
|
||||
"DuplicateLine": true,
|
||||
"DeleteLine": true,
|
||||
"MoveLinesUp": true,
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -41,6 +42,7 @@ func InitCommands() {
|
||||
"unbind": {(*BufPane).UnbindCmd, nil},
|
||||
"quit": {(*BufPane).QuitCmd, nil},
|
||||
"goto": {(*BufPane).GotoCmd, nil},
|
||||
"jump": {(*BufPane).JumpCmd, nil},
|
||||
"save": {(*BufPane).SaveCmd, nil},
|
||||
"replace": {(*BufPane).ReplaceCmd, nil},
|
||||
"replaceall": {(*BufPane).ReplaceAllCmd, nil},
|
||||
@ -137,10 +139,11 @@ func (h *BufPane) TextFilterCmd(args []string) {
|
||||
InfoBar.Error("usage: textfilter arguments")
|
||||
return
|
||||
}
|
||||
sel := h.Cursor.GetSelection()
|
||||
for _, c := range h.Buf.GetCursors() {
|
||||
sel := c.GetSelection()
|
||||
if len(sel) == 0 {
|
||||
h.Cursor.SelectWord()
|
||||
sel = h.Cursor.GetSelection()
|
||||
c.SelectWord()
|
||||
sel = c.GetSelection()
|
||||
}
|
||||
var bout, berr bytes.Buffer
|
||||
cmd := exec.Command(args[0], args[1:]...)
|
||||
@ -152,8 +155,9 @@ func (h *BufPane) TextFilterCmd(args []string) {
|
||||
InfoBar.Error(err.Error() + " " + berr.String())
|
||||
return
|
||||
}
|
||||
h.Cursor.DeleteSelection()
|
||||
h.Buf.Insert(h.Cursor.Loc, bout.String())
|
||||
c.DeleteSelection()
|
||||
h.Buf.Insert(c.Loc, bout.String())
|
||||
}
|
||||
}
|
||||
|
||||
// TabMoveCmd moves the current tab to a given index (starts at 1). The
|
||||
@ -197,10 +201,11 @@ func (h *BufPane) TabMoveCmd(args []string) {
|
||||
idxTo = util.Clamp(idxTo, 0, len(Tabs.List)-1)
|
||||
|
||||
activeTab := Tabs.List[idxFrom]
|
||||
Tabs.RemoveTab(activeTab.ID())
|
||||
Tabs.RemoveTab(activeTab.Panes[0].ID())
|
||||
Tabs.List = append(Tabs.List, nil)
|
||||
copy(Tabs.List[idxTo+1:], Tabs.List[idxTo:])
|
||||
Tabs.List[idxTo] = activeTab
|
||||
Tabs.Resize()
|
||||
Tabs.UpdateNames()
|
||||
Tabs.SetActive(idxTo)
|
||||
// InfoBar.Message(fmt.Sprintf("Moved tab from slot %d to %d", idxFrom+1, idxTo+1))
|
||||
@ -303,15 +308,8 @@ func (h *BufPane) OpenCmd(args []string) {
|
||||
}
|
||||
h.OpenBuffer(b)
|
||||
}
|
||||
if h.Buf.Modified() {
|
||||
InfoBar.YNPrompt("Save changes to "+h.Buf.GetName()+" before closing? (y,n,esc)", func(yes, canceled bool) {
|
||||
if !canceled && !yes {
|
||||
open()
|
||||
} else if !canceled && yes {
|
||||
h.Save()
|
||||
open()
|
||||
}
|
||||
})
|
||||
if h.Buf.Modified() && !h.Buf.Shared() {
|
||||
h.closePrompt("Save", open)
|
||||
} else {
|
||||
open()
|
||||
}
|
||||
@ -329,31 +327,84 @@ func (h *BufPane) ToggleLogCmd(args []string) {
|
||||
}
|
||||
}
|
||||
|
||||
// ReloadCmd reloads all files (syntax files, colorschemes...)
|
||||
// ReloadCmd reloads all files (syntax files, colorschemes, plugins...)
|
||||
func (h *BufPane) ReloadCmd(args []string) {
|
||||
ReloadConfig()
|
||||
reloadRuntime(true)
|
||||
}
|
||||
|
||||
// ReloadConfig reloads only the configuration
|
||||
func ReloadConfig() {
|
||||
config.InitRuntimeFiles()
|
||||
reloadRuntime(false)
|
||||
}
|
||||
|
||||
func reloadRuntime(reloadPlugins bool) {
|
||||
if reloadPlugins {
|
||||
err := config.RunPluginFn("deinit")
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
}
|
||||
|
||||
config.InitRuntimeFiles(true)
|
||||
|
||||
if reloadPlugins {
|
||||
config.InitPlugins()
|
||||
}
|
||||
|
||||
err := config.ReadSettings()
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
} else {
|
||||
parsedSettings := config.ParsedSettings()
|
||||
defaultSettings := config.DefaultAllSettings()
|
||||
for k := range defaultSettings {
|
||||
if _, ok := config.VolatileSettings[k]; ok {
|
||||
// reload should not override volatile settings
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := parsedSettings[k]; ok {
|
||||
err = doSetGlobalOptionNative(k, parsedSettings[k])
|
||||
} else {
|
||||
err = doSetGlobalOptionNative(k, defaultSettings[k])
|
||||
}
|
||||
err = config.InitGlobalSettings()
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if reloadPlugins {
|
||||
err = config.LoadAllPlugins()
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
}
|
||||
|
||||
InitBindings()
|
||||
InitCommands()
|
||||
|
||||
if reloadPlugins {
|
||||
err = config.RunPluginFn("preinit")
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
err = config.RunPluginFn("init")
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
err = config.RunPluginFn("postinit")
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
}
|
||||
|
||||
err = config.InitColorscheme()
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
|
||||
for _, b := range buffer.OpenBuffers {
|
||||
b.UpdateRules()
|
||||
b.ReloadSettings(true)
|
||||
}
|
||||
}
|
||||
|
||||
@ -363,50 +414,93 @@ func (h *BufPane) ReopenCmd(args []string) {
|
||||
InfoBar.YNPrompt("Save file before reopen?", func(yes, canceled bool) {
|
||||
if !canceled && yes {
|
||||
h.Save()
|
||||
h.Buf.ReOpen()
|
||||
h.ReOpen()
|
||||
} else if !canceled {
|
||||
h.Buf.ReOpen()
|
||||
h.ReOpen()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
h.Buf.ReOpen()
|
||||
h.ReOpen()
|
||||
}
|
||||
}
|
||||
|
||||
func (h *BufPane) openHelp(page string) error {
|
||||
func (h *BufPane) openHelp(page string, hsplit bool, forceSplit bool) error {
|
||||
if data, err := config.FindRuntimeFile(config.RTHelp, page).Data(); err != nil {
|
||||
return errors.New(fmt.Sprint("Unable to load help text", page, "\n", err))
|
||||
return errors.New(fmt.Sprintf("Unable to load help text for %s: %v", page, err))
|
||||
} else {
|
||||
helpBuffer := buffer.NewBufferFromString(string(data), page+".md", buffer.BTHelp)
|
||||
helpBuffer.SetName("Help " + page)
|
||||
helpBuffer.SetOptionNative("hltaberrors", false)
|
||||
helpBuffer.SetOptionNative("hltrailingws", false)
|
||||
|
||||
if h.Buf.Type == buffer.BTHelp {
|
||||
if h.Buf.Type == buffer.BTHelp && !forceSplit {
|
||||
h.OpenBuffer(helpBuffer)
|
||||
} else {
|
||||
} else if hsplit {
|
||||
h.HSplitBuf(helpBuffer)
|
||||
} else {
|
||||
h.VSplitBuf(helpBuffer)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// HelpCmd tries to open the given help page in a horizontal split
|
||||
// HelpCmd tries to open the given help page according to the split type
|
||||
// configured with the "helpsplit" option. It can be overriden by the optional
|
||||
// arguments "-vpslit" or "-hsplit". In case more than one help page is given
|
||||
// as argument then it opens all of them with the defined split type.
|
||||
func (h *BufPane) HelpCmd(args []string) {
|
||||
hsplit := config.GlobalSettings["helpsplit"] == "hsplit"
|
||||
if len(args) < 1 {
|
||||
// Open the default help if the user just typed "> help"
|
||||
h.openHelp("help")
|
||||
h.openHelp("help", hsplit, false)
|
||||
} else {
|
||||
if config.FindRuntimeFile(config.RTHelp, args[0]) != nil {
|
||||
err := h.openHelp(args[0])
|
||||
var topics []string
|
||||
forceSplit := false
|
||||
const errSplit = "hsplit and vsplit are not allowed at the same time"
|
||||
for _, arg := range args {
|
||||
switch arg {
|
||||
case "-vsplit":
|
||||
if forceSplit {
|
||||
InfoBar.Error(errSplit)
|
||||
return
|
||||
}
|
||||
hsplit = false
|
||||
forceSplit = true
|
||||
case "-hsplit":
|
||||
if forceSplit {
|
||||
InfoBar.Error(errSplit)
|
||||
return
|
||||
}
|
||||
hsplit = true
|
||||
forceSplit = true
|
||||
default:
|
||||
topics = append(topics, arg)
|
||||
}
|
||||
}
|
||||
|
||||
if len(topics) < 1 {
|
||||
// Do the same as without arg
|
||||
h.openHelp("help", hsplit, forceSplit)
|
||||
return
|
||||
}
|
||||
if len(topics) > 1 {
|
||||
forceSplit = true
|
||||
}
|
||||
|
||||
for _, topic := range topics {
|
||||
if config.FindRuntimeFile(config.RTHelp, topic) != nil {
|
||||
err := h.openHelp(topic, hsplit, forceSplit)
|
||||
if err != nil {
|
||||
InfoBar.Error(err)
|
||||
}
|
||||
} else {
|
||||
InfoBar.Error("Sorry, no help for ", args[0])
|
||||
InfoBar.Error("Sorry, no help for ", topic)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// VSplitCmd opens a vertical split with file given in the first argument
|
||||
// VSplitCmd opens one or more vertical splits with the files given as arguments
|
||||
// If no file is given, it opens an empty buffer in a new split
|
||||
func (h *BufPane) VSplitCmd(args []string) {
|
||||
if len(args) == 0 {
|
||||
@ -415,7 +509,8 @@ func (h *BufPane) VSplitCmd(args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
buf, err := buffer.NewBufferFromFile(args[0], buffer.BTDefault)
|
||||
for _, a := range args {
|
||||
buf, err := buffer.NewBufferFromFile(a, buffer.BTDefault)
|
||||
if err != nil {
|
||||
InfoBar.Error(err)
|
||||
return
|
||||
@ -423,8 +518,9 @@ func (h *BufPane) VSplitCmd(args []string) {
|
||||
|
||||
h.VSplitBuf(buf)
|
||||
}
|
||||
}
|
||||
|
||||
// HSplitCmd opens a horizontal split with file given in the first argument
|
||||
// HSplitCmd opens one or more horizontal splits with the files given as arguments
|
||||
// If no file is given, it opens an empty buffer in a new split
|
||||
func (h *BufPane) HSplitCmd(args []string) {
|
||||
if len(args) == 0 {
|
||||
@ -433,7 +529,8 @@ func (h *BufPane) HSplitCmd(args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
buf, err := buffer.NewBufferFromFile(args[0], buffer.BTDefault)
|
||||
for _, a := range args {
|
||||
buf, err := buffer.NewBufferFromFile(a, buffer.BTDefault)
|
||||
if err != nil {
|
||||
InfoBar.Error(err)
|
||||
return
|
||||
@ -441,13 +538,15 @@ func (h *BufPane) HSplitCmd(args []string) {
|
||||
|
||||
h.HSplitBuf(buf)
|
||||
}
|
||||
}
|
||||
|
||||
// EvalCmd evaluates a lua expression
|
||||
func (h *BufPane) EvalCmd(args []string) {
|
||||
InfoBar.Error("Eval unsupported")
|
||||
}
|
||||
|
||||
// NewTabCmd opens the given file in a new tab
|
||||
// NewTabCmd opens one or more tabs with the files given as arguments
|
||||
// If no file is given, it opens an empty buffer in a new tab
|
||||
func (h *BufPane) NewTabCmd(args []string) {
|
||||
width, height := screen.Screen.Size()
|
||||
iOffset := config.GetInfoBarOffset()
|
||||
@ -470,18 +569,14 @@ func (h *BufPane) NewTabCmd(args []string) {
|
||||
}
|
||||
}
|
||||
|
||||
func SetGlobalOptionNative(option string, nativeValue interface{}) error {
|
||||
local := false
|
||||
for _, s := range config.LocalSettings {
|
||||
if s == option {
|
||||
local = true
|
||||
break
|
||||
}
|
||||
func doSetGlobalOptionNative(option string, nativeValue interface{}) error {
|
||||
if reflect.DeepEqual(config.GlobalSettings[option], nativeValue) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !local {
|
||||
config.GlobalSettings[option] = nativeValue
|
||||
config.ModifiedSettings[option] = true
|
||||
delete(config.VolatileSettings, option)
|
||||
|
||||
if option == "colorscheme" {
|
||||
// LoadSyntaxFiles()
|
||||
@ -499,8 +594,7 @@ func SetGlobalOptionNative(option string, nativeValue interface{}) error {
|
||||
}
|
||||
} else if option == "autosave" {
|
||||
if nativeValue.(float64) > 0 {
|
||||
config.SetAutoTime(int(nativeValue.(float64)))
|
||||
config.StartAutoSave()
|
||||
config.SetAutoTime(nativeValue.(float64))
|
||||
} else {
|
||||
config.SetAutoTime(0)
|
||||
}
|
||||
@ -530,13 +624,43 @@ func SetGlobalOptionNative(option string, nativeValue interface{}) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetGlobalOptionNative(option string, nativeValue interface{}) error {
|
||||
if err := config.OptionIsValid(option, nativeValue); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// check for local option first...
|
||||
for _, s := range config.LocalSettings {
|
||||
if s == option {
|
||||
return MainTab().CurPane().Buf.SetOptionNative(option, nativeValue)
|
||||
}
|
||||
}
|
||||
|
||||
// ...if it's not local continue with the globals...
|
||||
if err := doSetGlobalOptionNative(option, nativeValue); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// ...at last check the buffer locals
|
||||
for _, b := range buffer.OpenBuffers {
|
||||
b.SetOptionNative(option, nativeValue)
|
||||
b.DoSetOptionNative(option, nativeValue)
|
||||
delete(b.LocalSettings, option)
|
||||
}
|
||||
|
||||
return config.WriteSettings(filepath.Join(config.ConfigDir, "settings.json"))
|
||||
err := config.WriteSettings(filepath.Join(config.ConfigDir, "settings.json"))
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrOverwrite) {
|
||||
screen.TermMessage(err)
|
||||
err = errors.Unwrap(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetGlobalOption(option, value string) error {
|
||||
@ -560,16 +684,10 @@ func (h *BufPane) ResetCmd(args []string) {
|
||||
}
|
||||
|
||||
option := args[0]
|
||||
defaults := config.DefaultAllSettings()
|
||||
|
||||
defaultGlobals := config.DefaultGlobalSettings()
|
||||
defaultLocals := config.DefaultCommonSettings()
|
||||
|
||||
if _, ok := defaultGlobals[option]; ok {
|
||||
SetGlobalOptionNative(option, defaultGlobals[option])
|
||||
return
|
||||
}
|
||||
if _, ok := defaultLocals[option]; ok {
|
||||
h.Buf.SetOptionNative(option, defaultLocals[option])
|
||||
if _, ok := defaults[option]; ok {
|
||||
SetGlobalOptionNative(option, defaults[option])
|
||||
return
|
||||
}
|
||||
InfoBar.Error(config.ErrInvalidOption)
|
||||
@ -634,6 +752,11 @@ func (h *BufPane) ShowCmd(args []string) {
|
||||
InfoBar.Message(option)
|
||||
}
|
||||
|
||||
func parseKeyArg(arg string) string {
|
||||
// If this is a raw escape sequence, convert it to its raw byte form
|
||||
return strings.ReplaceAll(arg, "\\x1b", "\x1b")
|
||||
}
|
||||
|
||||
// ShowKeyCmd displays the action that a key is bound to
|
||||
func (h *BufPane) ShowKeyCmd(args []string) {
|
||||
if len(args) < 1 {
|
||||
@ -641,7 +764,7 @@ func (h *BufPane) ShowKeyCmd(args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
event, err := findEvent(args[0])
|
||||
event, err := findEvent(parseKeyArg(args[0]))
|
||||
if err != nil {
|
||||
InfoBar.Error(err)
|
||||
return
|
||||
@ -660,11 +783,15 @@ func (h *BufPane) BindCmd(args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
_, err := TryBindKey(args[0], args[1], true)
|
||||
_, err := TryBindKey(parseKeyArg(args[0]), args[1], true)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrOverwrite) {
|
||||
screen.TermMessage(err)
|
||||
} else {
|
||||
InfoBar.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UnbindCmd binds a key to its default action
|
||||
func (h *BufPane) UnbindCmd(args []string) {
|
||||
@ -673,11 +800,15 @@ func (h *BufPane) UnbindCmd(args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
err := UnbindKey(args[0])
|
||||
err := UnbindKey(parseKeyArg(args[0]))
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrOverwrite) {
|
||||
screen.TermMessage(err)
|
||||
} else {
|
||||
InfoBar.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RunCmd runs a shell command in the background
|
||||
func (h *BufPane) RunCmd(args []string) {
|
||||
@ -701,42 +832,67 @@ func (h *BufPane) QuitCmd(args []string) {
|
||||
// position in the buffer
|
||||
// For example: `goto line`, or `goto line:col`
|
||||
func (h *BufPane) GotoCmd(args []string) {
|
||||
if len(args) <= 0 {
|
||||
InfoBar.Error("Not enough arguments")
|
||||
} else {
|
||||
h.RemoveAllMultiCursors()
|
||||
if strings.Contains(args[0], ":") {
|
||||
parts := strings.SplitN(args[0], ":", 2)
|
||||
line, err := strconv.Atoi(parts[0])
|
||||
if err != nil {
|
||||
InfoBar.Error(err)
|
||||
return
|
||||
}
|
||||
col, err := strconv.Atoi(parts[1])
|
||||
line, col, err := h.parseLineCol(args)
|
||||
if err != nil {
|
||||
InfoBar.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
if line < 0 {
|
||||
line = h.Buf.LinesNum() + 1 + line
|
||||
}
|
||||
line = util.Clamp(line-1, 0, h.Buf.LinesNum()-1)
|
||||
col = util.Clamp(col-1, 0, util.CharacterCount(h.Buf.LineBytes(line)))
|
||||
h.Cursor.GotoLoc(buffer.Loc{col, line})
|
||||
} else {
|
||||
line, err := strconv.Atoi(args[0])
|
||||
|
||||
h.RemoveAllMultiCursors()
|
||||
h.Cursor.Deselect(true)
|
||||
h.GotoLoc(buffer.Loc{col, line})
|
||||
}
|
||||
|
||||
// JumpCmd is a command that will send the cursor to a certain relative
|
||||
// position in the buffer
|
||||
// For example: `jump line`, `jump -line`, or `jump -line:col`
|
||||
func (h *BufPane) JumpCmd(args []string) {
|
||||
line, col, err := h.parseLineCol(args)
|
||||
if err != nil {
|
||||
InfoBar.Error(err)
|
||||
return
|
||||
}
|
||||
if line < 0 {
|
||||
line = h.Buf.LinesNum() + 1 + line
|
||||
}
|
||||
|
||||
line = h.Buf.GetActiveCursor().Y + 1 + line
|
||||
line = util.Clamp(line-1, 0, h.Buf.LinesNum()-1)
|
||||
h.Cursor.GotoLoc(buffer.Loc{0, line})
|
||||
col = util.Clamp(col-1, 0, util.CharacterCount(h.Buf.LineBytes(line)))
|
||||
|
||||
h.RemoveAllMultiCursors()
|
||||
h.Cursor.Deselect(true)
|
||||
h.GotoLoc(buffer.Loc{col, line})
|
||||
}
|
||||
h.Relocate()
|
||||
|
||||
// parseLineCol is a helper to parse the input of GotoCmd and JumpCmd
|
||||
func (h *BufPane) parseLineCol(args []string) (line int, col int, err error) {
|
||||
if len(args) <= 0 {
|
||||
return 0, 0, errors.New("Not enough arguments")
|
||||
}
|
||||
|
||||
line, col = 0, 0
|
||||
if strings.Contains(args[0], ":") {
|
||||
parts := strings.SplitN(args[0], ":", 2)
|
||||
line, err = strconv.Atoi(parts[0])
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
col, err = strconv.Atoi(parts[1])
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
} else {
|
||||
line, err = strconv.Atoi(args[0])
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
}
|
||||
|
||||
return line, col, nil
|
||||
}
|
||||
|
||||
// SaveCmd saves the buffer optionally with an argument file name
|
||||
@ -744,7 +900,7 @@ func (h *BufPane) SaveCmd(args []string) {
|
||||
if len(args) == 0 {
|
||||
h.Save()
|
||||
} else {
|
||||
h.Buf.SaveAs(args[0])
|
||||
h.saveBufToFile(args[0], "SaveAs", nil)
|
||||
}
|
||||
}
|
||||
|
||||
@ -805,19 +961,21 @@ func (h *BufPane) ReplaceCmd(args []string) {
|
||||
nreplaced := 0
|
||||
start := h.Buf.Start()
|
||||
end := h.Buf.End()
|
||||
searchLoc := h.Cursor.Loc
|
||||
selection := h.Cursor.HasSelection()
|
||||
if selection {
|
||||
start = h.Cursor.CurSelection[0]
|
||||
end = h.Cursor.CurSelection[1]
|
||||
searchLoc = start // otherwise me might start at the end
|
||||
}
|
||||
if all {
|
||||
nreplaced, _ = h.Buf.ReplaceRegex(start, end, regex, replace)
|
||||
nreplaced, _ = h.Buf.ReplaceRegex(start, end, regex, replace, !noRegex)
|
||||
} else {
|
||||
inRange := func(l buffer.Loc) bool {
|
||||
return l.GreaterEqual(start) && l.LessEqual(end)
|
||||
}
|
||||
|
||||
searchLoc := h.Cursor.Loc
|
||||
lastMatchEnd := buffer.Loc{-1, -1}
|
||||
var doReplacement func()
|
||||
doReplacement = func() {
|
||||
locs, found, err := h.Buf.FindNext(search, start, end, searchLoc, true, true)
|
||||
@ -832,15 +990,28 @@ func (h *BufPane) ReplaceCmd(args []string) {
|
||||
return
|
||||
}
|
||||
|
||||
if lastMatchEnd == locs[1] {
|
||||
// skip empty match right after previous match
|
||||
if searchLoc == end {
|
||||
searchLoc = start
|
||||
lastMatchEnd = buffer.Loc{-1, -1}
|
||||
} else {
|
||||
searchLoc = searchLoc.Move(1, h.Buf)
|
||||
}
|
||||
doReplacement()
|
||||
return
|
||||
}
|
||||
|
||||
h.Cursor.SetSelectionStart(locs[0])
|
||||
h.Cursor.SetSelectionEnd(locs[1])
|
||||
h.Cursor.GotoLoc(locs[0])
|
||||
|
||||
h.Relocate()
|
||||
h.GotoLoc(locs[0])
|
||||
h.Buf.LastSearch = search
|
||||
h.Buf.LastSearchRegex = true
|
||||
h.Buf.HighlightSearch = h.Buf.Settings["hlsearch"].(bool)
|
||||
|
||||
InfoBar.YNPrompt("Perform replacement (y,n,esc)", func(yes, canceled bool) {
|
||||
if !canceled && yes {
|
||||
_, nrunes := h.Buf.ReplaceRegex(locs[0], locs[1], regex, replace)
|
||||
_, nrunes := h.Buf.ReplaceRegex(locs[0], locs[1], regex, replace, !noRegex)
|
||||
|
||||
searchLoc = locs[0]
|
||||
searchLoc.X += nrunes + locs[0].Diff(locs[1], h.Buf)
|
||||
@ -850,13 +1021,13 @@ func (h *BufPane) ReplaceCmd(args []string) {
|
||||
h.Cursor.Loc = searchLoc
|
||||
nreplaced++
|
||||
} else if !canceled && !yes {
|
||||
searchLoc = locs[0]
|
||||
searchLoc.X += util.CharacterCount(replace)
|
||||
searchLoc = locs[1]
|
||||
} else if canceled {
|
||||
h.Cursor.ResetSelection()
|
||||
h.Buf.RelocateCursors()
|
||||
return
|
||||
}
|
||||
lastMatchEnd = searchLoc
|
||||
doReplacement()
|
||||
})
|
||||
}
|
||||
@ -888,10 +1059,42 @@ func (h *BufPane) ReplaceAllCmd(args []string) {
|
||||
h.ReplaceCmd(append(args, "-a"))
|
||||
}
|
||||
|
||||
func (h *BufPane) openTerm(args []string, newtab bool) {
|
||||
t := new(shell.Terminal)
|
||||
err := t.Start(args, false, true, nil, nil)
|
||||
if err != nil {
|
||||
InfoBar.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
pane := 0
|
||||
id := h.ID()
|
||||
if newtab {
|
||||
h.AddTab()
|
||||
id = MainTab().Panes[pane].ID()
|
||||
} else {
|
||||
for i, p := range MainTab().Panes {
|
||||
if p.IsActive() {
|
||||
pane = i
|
||||
id = p.ID()
|
||||
p.Close()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
v := h.GetView()
|
||||
tp, err := NewTermPane(v.X, v.Y, v.Width, v.Height, t, id, MainTab())
|
||||
if err != nil {
|
||||
InfoBar.Error(err)
|
||||
return
|
||||
}
|
||||
MainTab().Panes[pane] = tp
|
||||
MainTab().SetActive(pane)
|
||||
}
|
||||
|
||||
// TermCmd opens a terminal in the current view
|
||||
func (h *BufPane) TermCmd(args []string) {
|
||||
ps := h.tab.Panes
|
||||
|
||||
if !TermEmuSupported {
|
||||
InfoBar.Error("Terminal emulator not supported on this system")
|
||||
return
|
||||
@ -906,56 +1109,19 @@ func (h *BufPane) TermCmd(args []string) {
|
||||
args = []string{sh}
|
||||
}
|
||||
|
||||
term := func(i int, newtab bool) {
|
||||
t := new(shell.Terminal)
|
||||
err := t.Start(args, false, true, nil, nil)
|
||||
if err != nil {
|
||||
InfoBar.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
id := h.ID()
|
||||
if newtab {
|
||||
h.AddTab()
|
||||
i = 0
|
||||
id = MainTab().Panes[0].ID()
|
||||
} else {
|
||||
MainTab().Panes[i].Close()
|
||||
}
|
||||
|
||||
v := h.GetView()
|
||||
tp, err := NewTermPane(v.X, v.Y, v.Width, v.Height, t, id, MainTab())
|
||||
if err != nil {
|
||||
InfoBar.Error(err)
|
||||
return
|
||||
}
|
||||
MainTab().Panes[i] = tp
|
||||
MainTab().SetActive(i)
|
||||
}
|
||||
|
||||
// If there is only one open file we make a new tab instead of overwriting it
|
||||
newtab := len(MainTab().Panes) == 1 && len(Tabs.List) == 1
|
||||
|
||||
if newtab {
|
||||
term(0, true)
|
||||
h.openTerm(args, true)
|
||||
return
|
||||
}
|
||||
|
||||
for i, p := range ps {
|
||||
if p.ID() == h.ID() {
|
||||
if h.Buf.Modified() {
|
||||
InfoBar.YNPrompt("Save changes to "+h.Buf.GetName()+" before closing? (y,n,esc)", func(yes, canceled bool) {
|
||||
if !canceled && !yes {
|
||||
term(i, false)
|
||||
} else if !canceled && yes {
|
||||
h.Save()
|
||||
term(i, false)
|
||||
}
|
||||
if h.Buf.Modified() && !h.Buf.Shared() {
|
||||
h.closePrompt("Save", func() {
|
||||
h.openTerm(args, false)
|
||||
})
|
||||
} else {
|
||||
term(i, false)
|
||||
}
|
||||
}
|
||||
h.openTerm(args, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ package action
|
||||
var termdefaults = map[string]string{
|
||||
"<Ctrl-q><Ctrl-q>": "Exit",
|
||||
"<Ctrl-e><Ctrl-e>": "CommandMode",
|
||||
"<Ctrl-w><Ctrl-w>": "NextSplit",
|
||||
"<Ctrl-w><Ctrl-w>": "NextSplit|FirstSplit",
|
||||
}
|
||||
|
||||
// DefaultBindings returns a map containing micro's default keybindings
|
||||
|
@ -38,27 +38,32 @@ var bufdefaults = map[string]string{
|
||||
"Ctrl-o": "OpenFile",
|
||||
"Ctrl-s": "Save",
|
||||
"Ctrl-f": "Find",
|
||||
"Alt-F": "FindLiteral",
|
||||
"Ctrl-n": "FindNext",
|
||||
"Ctrl-p": "FindPrevious",
|
||||
"Alt-[": "DiffPrevious|CursorStart",
|
||||
"Alt-]": "DiffNext|CursorEnd",
|
||||
"Ctrl-z": "Undo",
|
||||
"Ctrl-y": "Redo",
|
||||
"Ctrl-c": "CopyLine|Copy",
|
||||
"Ctrl-x": "Cut",
|
||||
"Ctrl-c": "Copy|CopyLine",
|
||||
"Ctrl-x": "Cut|CutLine",
|
||||
"Ctrl-k": "CutLine",
|
||||
"Ctrl-d": "DuplicateLine",
|
||||
"Ctrl-d": "Duplicate|DuplicateLine",
|
||||
"Ctrl-v": "Paste",
|
||||
"Ctrl-a": "SelectAll",
|
||||
"Ctrl-t": "AddTab",
|
||||
"Alt-,": "PreviousTab",
|
||||
"Alt-.": "NextTab",
|
||||
"Alt-,": "PreviousTab|LastTab",
|
||||
"Alt-.": "NextTab|FirstTab",
|
||||
"Home": "StartOfTextToggle",
|
||||
"End": "EndOfLine",
|
||||
"CtrlHome": "CursorStart",
|
||||
"CtrlEnd": "CursorEnd",
|
||||
"PageUp": "CursorPageUp",
|
||||
"PageDown": "CursorPageDown",
|
||||
"CtrlPageUp": "PreviousTab",
|
||||
"CtrlPageDown": "NextTab",
|
||||
"CtrlPageUp": "PreviousTab|LastTab",
|
||||
"CtrlPageDown": "NextTab|FirstTab",
|
||||
"ShiftPageUp": "SelectPageUp",
|
||||
"ShiftPageDown": "SelectPageDown",
|
||||
"Ctrl-g": "ToggleHelp",
|
||||
"Alt-g": "ToggleKeyMenu",
|
||||
"Ctrl-r": "ToggleRuler",
|
||||
@ -67,7 +72,7 @@ var bufdefaults = map[string]string{
|
||||
"Ctrl-b": "ShellMode",
|
||||
"Ctrl-q": "Quit",
|
||||
"Ctrl-e": "CommandMode",
|
||||
"Ctrl-w": "NextSplit",
|
||||
"Ctrl-w": "NextSplit|FirstSplit",
|
||||
"Ctrl-u": "ToggleMacro",
|
||||
"Ctrl-j": "PlayMacro",
|
||||
"Insert": "ToggleOverwriteMode",
|
||||
@ -86,12 +91,14 @@ var bufdefaults = map[string]string{
|
||||
"F4": "Quit",
|
||||
"F7": "Find",
|
||||
"F10": "Quit",
|
||||
"Esc": "Escape,Deselect,ClearInfo,RemoveAllMultiCursors",
|
||||
"Esc": "Escape,Deselect,ClearInfo,RemoveAllMultiCursors,UnhighlightSearch",
|
||||
|
||||
// Mouse bindings
|
||||
"MouseWheelUp": "ScrollUp",
|
||||
"MouseWheelDown": "ScrollDown",
|
||||
"MouseLeft": "MousePress",
|
||||
"MouseLeftDrag": "MouseDrag",
|
||||
"MouseLeftRelease": "MouseRelease",
|
||||
"MouseMiddle": "PastePrimary",
|
||||
"Ctrl-MouseLeft": "MouseMultiCursor",
|
||||
|
||||
@ -139,8 +146,8 @@ var infodefaults = map[string]string{
|
||||
"Backtab": "CycleAutocompleteBack",
|
||||
"Ctrl-z": "Undo",
|
||||
"Ctrl-y": "Redo",
|
||||
"Ctrl-c": "CopyLine|Copy",
|
||||
"Ctrl-x": "Cut",
|
||||
"Ctrl-c": "Copy|CopyLine",
|
||||
"Ctrl-x": "Cut|CutLine",
|
||||
"Ctrl-k": "CutLine",
|
||||
"Ctrl-v": "Paste",
|
||||
"Home": "StartOfTextToggle",
|
||||
@ -175,5 +182,7 @@ var infodefaults = map[string]string{
|
||||
"MouseWheelUp": "HistoryUp",
|
||||
"MouseWheelDown": "HistoryDown",
|
||||
"MouseLeft": "MousePress",
|
||||
"MouseLeftDrag": "MouseDrag",
|
||||
"MouseLeftRelease": "MouseRelease",
|
||||
"MouseMiddle": "PastePrimary",
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
//go:build !darwin
|
||||
// +build !darwin
|
||||
|
||||
package action
|
||||
@ -40,27 +41,32 @@ var bufdefaults = map[string]string{
|
||||
"Ctrl-o": "OpenFile",
|
||||
"Ctrl-s": "Save",
|
||||
"Ctrl-f": "Find",
|
||||
"Alt-F": "FindLiteral",
|
||||
"Ctrl-n": "FindNext",
|
||||
"Ctrl-p": "FindPrevious",
|
||||
"Alt-[": "DiffPrevious|CursorStart",
|
||||
"Alt-]": "DiffNext|CursorEnd",
|
||||
"Ctrl-z": "Undo",
|
||||
"Ctrl-y": "Redo",
|
||||
"Ctrl-c": "CopyLine|Copy",
|
||||
"Ctrl-x": "Cut",
|
||||
"Ctrl-c": "Copy|CopyLine",
|
||||
"Ctrl-x": "Cut|CutLine",
|
||||
"Ctrl-k": "CutLine",
|
||||
"Ctrl-d": "DuplicateLine",
|
||||
"Ctrl-d": "Duplicate|DuplicateLine",
|
||||
"Ctrl-v": "Paste",
|
||||
"Ctrl-a": "SelectAll",
|
||||
"Ctrl-t": "AddTab",
|
||||
"Alt-,": "PreviousTab",
|
||||
"Alt-.": "NextTab",
|
||||
"Alt-,": "PreviousTab|LastTab",
|
||||
"Alt-.": "NextTab|FirstTab",
|
||||
"Home": "StartOfTextToggle",
|
||||
"End": "EndOfLine",
|
||||
"CtrlHome": "CursorStart",
|
||||
"CtrlEnd": "CursorEnd",
|
||||
"PageUp": "CursorPageUp",
|
||||
"PageDown": "CursorPageDown",
|
||||
"CtrlPageUp": "PreviousTab",
|
||||
"CtrlPageDown": "NextTab",
|
||||
"CtrlPageUp": "PreviousTab|LastTab",
|
||||
"CtrlPageDown": "NextTab|FirstTab",
|
||||
"ShiftPageUp": "SelectPageUp",
|
||||
"ShiftPageDown": "SelectPageDown",
|
||||
"Ctrl-g": "ToggleHelp",
|
||||
"Alt-g": "ToggleKeyMenu",
|
||||
"Ctrl-r": "ToggleRuler",
|
||||
@ -69,7 +75,7 @@ var bufdefaults = map[string]string{
|
||||
"Ctrl-b": "ShellMode",
|
||||
"Ctrl-q": "Quit",
|
||||
"Ctrl-e": "CommandMode",
|
||||
"Ctrl-w": "NextSplit",
|
||||
"Ctrl-w": "NextSplit|FirstSplit",
|
||||
"Ctrl-u": "ToggleMacro",
|
||||
"Ctrl-j": "PlayMacro",
|
||||
"Insert": "ToggleOverwriteMode",
|
||||
@ -88,12 +94,14 @@ var bufdefaults = map[string]string{
|
||||
"F4": "Quit",
|
||||
"F7": "Find",
|
||||
"F10": "Quit",
|
||||
"Esc": "Escape,Deselect,ClearInfo,RemoveAllMultiCursors",
|
||||
"Esc": "Escape,Deselect,ClearInfo,RemoveAllMultiCursors,UnhighlightSearch",
|
||||
|
||||
// Mouse bindings
|
||||
"MouseWheelUp": "ScrollUp",
|
||||
"MouseWheelDown": "ScrollDown",
|
||||
"MouseLeft": "MousePress",
|
||||
"MouseLeftDrag": "MouseDrag",
|
||||
"MouseLeftRelease": "MouseRelease",
|
||||
"MouseMiddle": "PastePrimary",
|
||||
"Ctrl-MouseLeft": "MouseMultiCursor",
|
||||
|
||||
@ -141,8 +149,8 @@ var infodefaults = map[string]string{
|
||||
"Backtab": "CycleAutocompleteBack",
|
||||
"Ctrl-z": "Undo",
|
||||
"Ctrl-y": "Redo",
|
||||
"Ctrl-c": "CopyLine|Copy",
|
||||
"Ctrl-x": "Cut",
|
||||
"Ctrl-c": "Copy|CopyLine",
|
||||
"Ctrl-x": "Cut|CutLine",
|
||||
"Ctrl-k": "CutLine",
|
||||
"Ctrl-v": "Paste",
|
||||
"Home": "StartOfTextToggle",
|
||||
@ -177,5 +185,7 @@ var infodefaults = map[string]string{
|
||||
"MouseWheelUp": "HistoryUp",
|
||||
"MouseWheelDown": "HistoryDown",
|
||||
"MouseLeft": "MousePress",
|
||||
"MouseLeftDrag": "MouseDrag",
|
||||
"MouseLeftRelease": "MouseRelease",
|
||||
"MouseMiddle": "PastePrimary",
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
)
|
||||
|
||||
type Event interface {
|
||||
@ -44,6 +44,17 @@ func metaToAlt(mod tcell.ModMask) tcell.ModMask {
|
||||
return mod
|
||||
}
|
||||
|
||||
func keyEvent(e *tcell.EventKey) KeyEvent {
|
||||
ke := KeyEvent{
|
||||
code: e.Key(),
|
||||
mod: metaToAlt(e.Modifiers()),
|
||||
}
|
||||
if e.Key() == tcell.KeyRune {
|
||||
ke.r = e.Rune()
|
||||
}
|
||||
return ke
|
||||
}
|
||||
|
||||
func (k KeyEvent) Name() string {
|
||||
if k.any {
|
||||
return "<any>"
|
||||
@ -68,7 +79,7 @@ func (k KeyEvent) Name() string {
|
||||
if k.code == tcell.KeyRune {
|
||||
s = string(k.r)
|
||||
} else {
|
||||
s = fmt.Sprintf("Key[%d,%d]", k.code, int(k.r))
|
||||
s = fmt.Sprintf("Key[%d]", k.code)
|
||||
}
|
||||
}
|
||||
if len(m) != 0 {
|
||||
@ -100,11 +111,20 @@ func (k KeySequenceEvent) Name() string {
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
type MouseState int
|
||||
|
||||
const (
|
||||
MousePress = iota
|
||||
MouseDrag
|
||||
MouseRelease
|
||||
)
|
||||
|
||||
// MouseEvent is a mouse event with a mouse button and
|
||||
// any possible key modifiers
|
||||
type MouseEvent struct {
|
||||
btn tcell.ButtonMask
|
||||
mod tcell.ModMask
|
||||
state MouseState
|
||||
}
|
||||
|
||||
func (m MouseEvent) Name() string {
|
||||
@ -122,9 +142,17 @@ func (m MouseEvent) Name() string {
|
||||
mod = "Ctrl-"
|
||||
}
|
||||
|
||||
state := ""
|
||||
switch m.state {
|
||||
case MouseDrag:
|
||||
state = "Drag"
|
||||
case MouseRelease:
|
||||
state = "Release"
|
||||
}
|
||||
|
||||
for k, v := range mouseEvents {
|
||||
if v == m.btn {
|
||||
return fmt.Sprintf("%s%s", mod, k)
|
||||
return fmt.Sprintf("%s%s%s", mod, k, state)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
@ -138,11 +166,7 @@ func (m MouseEvent) Name() string {
|
||||
func ConstructEvent(event tcell.Event) (Event, error) {
|
||||
switch e := event.(type) {
|
||||
case *tcell.EventKey:
|
||||
return KeyEvent{
|
||||
code: e.Key(),
|
||||
mod: metaToAlt(e.Modifiers()),
|
||||
r: e.Rune(),
|
||||
}, nil
|
||||
return keyEvent(e), nil
|
||||
case *tcell.EventRaw:
|
||||
return RawEvent{
|
||||
esc: e.EscSeq(),
|
||||
|
@ -2,7 +2,10 @@ package action
|
||||
|
||||
import "github.com/zyedidia/micro/v2/internal/buffer"
|
||||
|
||||
// InfoBar is the global info bar.
|
||||
var InfoBar *InfoPane
|
||||
|
||||
// LogBufPane is a global log buffer.
|
||||
var LogBufPane *BufPane
|
||||
|
||||
// InitGlobals initializes the log buffer and the info bar
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/zyedidia/micro/v2/internal/buffer"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
"github.com/zyedidia/micro/v2/pkg/highlight"
|
||||
)
|
||||
|
||||
// This file is meant (for now) for autocompletion in command mode, not
|
||||
@ -17,7 +18,7 @@ import (
|
||||
// CommandComplete autocompletes commands
|
||||
func CommandComplete(b *buffer.Buffer) ([]string, []string) {
|
||||
c := b.GetActiveCursor()
|
||||
input, argstart := buffer.GetArg(b)
|
||||
input, argstart := b.GetArg()
|
||||
|
||||
var suggestions []string
|
||||
for cmd := range commands {
|
||||
@ -38,7 +39,7 @@ func CommandComplete(b *buffer.Buffer) ([]string, []string) {
|
||||
// HelpComplete autocompletes help topics
|
||||
func HelpComplete(b *buffer.Buffer) ([]string, []string) {
|
||||
c := b.GetActiveCursor()
|
||||
input, argstart := buffer.GetArg(b)
|
||||
input, argstart := b.GetArg()
|
||||
|
||||
var suggestions []string
|
||||
|
||||
@ -77,19 +78,67 @@ func colorschemeComplete(input string) (string, []string) {
|
||||
return chosen, suggestions
|
||||
}
|
||||
|
||||
func contains(s []string, e string) bool {
|
||||
for _, a := range s {
|
||||
if a == e {
|
||||
return true
|
||||
// filetypeComplete autocompletes filetype
|
||||
func filetypeComplete(input string) (string, []string) {
|
||||
var suggestions []string
|
||||
|
||||
// We cannot match filetypes just by names of syntax files,
|
||||
// since those names may be different from the actual filetype values
|
||||
// specified inside syntax files (e.g. "c++" filetype in cpp.yaml).
|
||||
// So we need to parse filetype values out of those files.
|
||||
for _, f := range config.ListRealRuntimeFiles(config.RTSyntax) {
|
||||
data, err := f.Data()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
header, err := highlight.MakeHeaderYaml(data)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
// Prevent duplicated defaults
|
||||
if header.FileType == "off" || header.FileType == "unknown" {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(header.FileType, input) {
|
||||
suggestions = append(suggestions, header.FileType)
|
||||
}
|
||||
}
|
||||
return false
|
||||
headerLoop:
|
||||
for _, f := range config.ListRuntimeFiles(config.RTSyntaxHeader) {
|
||||
data, err := f.Data()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
header, err := highlight.MakeHeader(data)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for _, v := range suggestions {
|
||||
if v == header.FileType {
|
||||
continue headerLoop
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(header.FileType, input) {
|
||||
suggestions = append(suggestions, header.FileType)
|
||||
}
|
||||
}
|
||||
|
||||
if strings.HasPrefix("off", input) {
|
||||
suggestions = append(suggestions, "off")
|
||||
}
|
||||
|
||||
var chosen string
|
||||
if len(suggestions) == 1 {
|
||||
chosen = suggestions[0]
|
||||
}
|
||||
|
||||
return chosen, suggestions
|
||||
}
|
||||
|
||||
// OptionComplete autocompletes options
|
||||
func OptionComplete(b *buffer.Buffer) ([]string, []string) {
|
||||
c := b.GetActiveCursor()
|
||||
input, argstart := buffer.GetArg(b)
|
||||
input, argstart := b.GetArg()
|
||||
|
||||
var suggestions []string
|
||||
for option := range config.GlobalSettings {
|
||||
@ -116,7 +165,7 @@ func OptionValueComplete(b *buffer.Buffer) ([]string, []string) {
|
||||
c := b.GetActiveCursor()
|
||||
l := b.LineBytes(c.Y)
|
||||
l = util.SliceStart(l, c.X)
|
||||
input, argstart := buffer.GetArg(b)
|
||||
input, argstart := b.GetArg()
|
||||
|
||||
completeValue := false
|
||||
args := bytes.Split(l, []byte{' '})
|
||||
@ -172,13 +221,8 @@ func OptionValueComplete(b *buffer.Buffer) ([]string, []string) {
|
||||
switch inputOpt {
|
||||
case "colorscheme":
|
||||
_, suggestions = colorschemeComplete(input)
|
||||
case "fileformat":
|
||||
if strings.HasPrefix("unix", input) {
|
||||
suggestions = append(suggestions, "unix")
|
||||
}
|
||||
if strings.HasPrefix("dos", input) {
|
||||
suggestions = append(suggestions, "dos")
|
||||
}
|
||||
case "filetype":
|
||||
_, suggestions = filetypeComplete(input)
|
||||
case "sucmd":
|
||||
if strings.HasPrefix("sudo", input) {
|
||||
suggestions = append(suggestions, "sudo")
|
||||
@ -186,15 +230,13 @@ func OptionValueComplete(b *buffer.Buffer) ([]string, []string) {
|
||||
if strings.HasPrefix("doas", input) {
|
||||
suggestions = append(suggestions, "doas")
|
||||
}
|
||||
case "clipboard":
|
||||
if strings.HasPrefix("external", input) {
|
||||
suggestions = append(suggestions, "external")
|
||||
default:
|
||||
if choices, ok := config.OptionChoices[inputOpt]; ok {
|
||||
for _, choice := range choices {
|
||||
if strings.HasPrefix(choice, input) {
|
||||
suggestions = append(suggestions, choice)
|
||||
}
|
||||
if strings.HasPrefix("internal", input) {
|
||||
suggestions = append(suggestions, "internal")
|
||||
}
|
||||
if strings.HasPrefix("terminal", input) {
|
||||
suggestions = append(suggestions, "terminal")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -210,7 +252,7 @@ func OptionValueComplete(b *buffer.Buffer) ([]string, []string) {
|
||||
// PluginCmdComplete autocompletes the plugin command
|
||||
func PluginCmdComplete(b *buffer.Buffer) ([]string, []string) {
|
||||
c := b.GetActiveCursor()
|
||||
input, argstart := buffer.GetArg(b)
|
||||
input, argstart := b.GetArg()
|
||||
|
||||
var suggestions []string
|
||||
for _, cmd := range PluginCmds {
|
||||
@ -232,7 +274,7 @@ func PluginComplete(b *buffer.Buffer) ([]string, []string) {
|
||||
c := b.GetActiveCursor()
|
||||
l := b.LineBytes(c.Y)
|
||||
l = util.SliceStart(l, c.X)
|
||||
input, argstart := buffer.GetArg(b)
|
||||
input, argstart := b.GetArg()
|
||||
|
||||
completeValue := false
|
||||
args := bytes.Split(l, []byte{' '})
|
||||
|
@ -3,12 +3,12 @@ package action
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
"github.com/zyedidia/micro/v2/internal/buffer"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/display"
|
||||
"github.com/zyedidia/micro/v2/internal/info"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
)
|
||||
|
||||
type InfoKeyAction func(*InfoPane)
|
||||
@ -83,22 +83,22 @@ func (h *InfoPane) Close() {
|
||||
|
||||
func (h *InfoPane) HandleEvent(event tcell.Event) {
|
||||
switch e := event.(type) {
|
||||
case *tcell.EventResize:
|
||||
// TODO
|
||||
case *tcell.EventKey:
|
||||
ke := KeyEvent{
|
||||
code: e.Key(),
|
||||
mod: metaToAlt(e.Modifiers()),
|
||||
r: e.Rune(),
|
||||
}
|
||||
ke := keyEvent(e)
|
||||
|
||||
done := h.DoKeyEvent(ke)
|
||||
hasYN := h.HasYN
|
||||
if e.Key() == tcell.KeyRune && hasYN {
|
||||
if e.Rune() == 'y' && hasYN {
|
||||
h.YNResp = true
|
||||
h.DonePrompt(false)
|
||||
} else if e.Rune() == 'n' && hasYN {
|
||||
h.YNResp = false
|
||||
y := e.Rune() == 'y' || e.Rune() == 'Y'
|
||||
n := e.Rune() == 'n' || e.Rune() == 'N'
|
||||
if y || n {
|
||||
h.YNResp = y
|
||||
h.DonePrompt(false)
|
||||
|
||||
InfoBindings.ResetEvents()
|
||||
InfoBufBindings.ResetEvents()
|
||||
}
|
||||
}
|
||||
if e.Key() == tcell.KeyRune && !done && !hasYN {
|
||||
@ -108,7 +108,11 @@ func (h *InfoPane) HandleEvent(event tcell.Event) {
|
||||
if done && h.HasPrompt && !hasYN {
|
||||
resp := string(h.LineBytes(0))
|
||||
hist := h.History[h.PromptType]
|
||||
if resp != hist[h.HistoryNum] {
|
||||
h.HistoryNum = len(hist) - 1
|
||||
hist[h.HistoryNum] = resp
|
||||
h.HistorySearch = false
|
||||
}
|
||||
if h.EventCallback != nil {
|
||||
h.EventCallback(resp)
|
||||
}
|
||||
@ -118,7 +122,10 @@ func (h *InfoPane) HandleEvent(event tcell.Event) {
|
||||
}
|
||||
}
|
||||
|
||||
// DoKeyEvent executes a key event for the command bar, doing any overridden actions
|
||||
// DoKeyEvent executes a key event for the command bar, doing any overridden actions.
|
||||
// Returns true if the action was executed OR if there are more keys remaining
|
||||
// to process before executing an action (if this is a key sequence event).
|
||||
// Returns false if no action found.
|
||||
func (h *InfoPane) DoKeyEvent(e KeyEvent) bool {
|
||||
action, more := InfoBindings.NextEvent(e, nil)
|
||||
if action != nil && !more {
|
||||
@ -132,11 +139,25 @@ func (h *InfoPane) DoKeyEvent(e KeyEvent) bool {
|
||||
}
|
||||
|
||||
if !more {
|
||||
// If no infopane action found, try to find a bufpane action.
|
||||
//
|
||||
// TODO: this is buggy. For example, if the command bar has the following
|
||||
// two bindings:
|
||||
//
|
||||
// "<Ctrl-x><Ctrl-p>": "HistoryUp",
|
||||
// "<Ctrl-x><Ctrl-v>": "Paste",
|
||||
//
|
||||
// the 2nd binding (with a bufpane action) doesn't work, since <Ctrl-x>
|
||||
// has been already consumed by the 1st binding (with an infopane action).
|
||||
//
|
||||
// We should either iterate both InfoBindings and InfoBufBindings keytrees
|
||||
// together, or just use the same keytree for both infopane and bufpane
|
||||
// bindings.
|
||||
action, more = InfoBufBindings.NextEvent(e, nil)
|
||||
if action != nil && !more {
|
||||
done := action(h.BufPane)
|
||||
action(h.BufPane)
|
||||
InfoBufBindings.ResetEvents()
|
||||
return done
|
||||
return true
|
||||
} else if action == nil && !more {
|
||||
InfoBufBindings.ResetEvents()
|
||||
}
|
||||
@ -155,6 +176,18 @@ func (h *InfoPane) HistoryDown() {
|
||||
h.DownHistory(h.History[h.PromptType])
|
||||
}
|
||||
|
||||
// HistorySearchUp fetches the previous history item beginning with the text
|
||||
// in the infobuffer before cursor
|
||||
func (h *InfoPane) HistorySearchUp() {
|
||||
h.SearchUpHistory(h.History[h.PromptType])
|
||||
}
|
||||
|
||||
// HistorySearchDown fetches the next history item beginning with the text
|
||||
// in the infobuffer before cursor
|
||||
func (h *InfoPane) HistorySearchDown() {
|
||||
h.SearchDownHistory(h.History[h.PromptType])
|
||||
}
|
||||
|
||||
// Autocomplete begins autocompletion
|
||||
func (h *InfoPane) CommandComplete() {
|
||||
b := h.Buf
|
||||
@ -200,6 +233,8 @@ func (h *InfoPane) AbortCommand() {
|
||||
var InfoKeyActions = map[string]InfoKeyAction{
|
||||
"HistoryUp": (*InfoPane).HistoryUp,
|
||||
"HistoryDown": (*InfoPane).HistoryDown,
|
||||
"HistorySearchUp": (*InfoPane).HistorySearchUp,
|
||||
"HistorySearchDown": (*InfoPane).HistorySearchDown,
|
||||
"CommandComplete": (*InfoPane).CommandComplete,
|
||||
"ExecuteCommand": (*InfoPane).ExecuteCommand,
|
||||
"AbortCommand": (*InfoPane).AbortCommand,
|
||||
|
@ -3,7 +3,7 @@ package action
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
)
|
||||
|
||||
type PaneKeyAction func(Pane) bool
|
||||
@ -229,7 +229,7 @@ func (k *KeyTree) ResetEvents() {
|
||||
k.cursor.mouseInfo = nil
|
||||
}
|
||||
|
||||
// CurrentEventsStr returns the list of recorded events as a string
|
||||
// RecordedEventsStr returns the list of recorded events as a string
|
||||
func (k *KeyTree) RecordedEventsStr() string {
|
||||
buf := &bytes.Buffer{}
|
||||
for _, e := range k.cursor.recordedEvents {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/zyedidia/micro/v2/internal/display"
|
||||
)
|
||||
|
||||
// A Pane is a general interface for a window in the editor.
|
||||
type Pane interface {
|
||||
Handler
|
||||
display.Window
|
||||
|
@ -4,9 +4,9 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
"github.com/zyedidia/micro/v2/internal/buffer"
|
||||
"github.com/zyedidia/micro/v2/internal/display"
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
)
|
||||
|
||||
type RawPane struct {
|
||||
|
@ -1,12 +1,15 @@
|
||||
package action
|
||||
|
||||
import (
|
||||
luar "layeh.com/gopher-luar"
|
||||
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
"github.com/zyedidia/micro/v2/internal/buffer"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/display"
|
||||
ulua "github.com/zyedidia/micro/v2/internal/lua"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/micro/v2/internal/views"
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
)
|
||||
|
||||
// The TabList is a list of tabs and a window to display the tab bar
|
||||
@ -104,30 +107,32 @@ func (t *TabList) HandleEvent(event tcell.Event) {
|
||||
mx, my := e.Position()
|
||||
switch e.Buttons() {
|
||||
case tcell.Button1:
|
||||
if my == t.Y && mx == 0 {
|
||||
if my == t.Y && len(t.List) > 1 {
|
||||
if mx == 0 {
|
||||
t.Scroll(-4)
|
||||
return
|
||||
} else if my == t.Y && mx == t.Width-1 {
|
||||
} else if mx == t.Width-1 {
|
||||
t.Scroll(4)
|
||||
return
|
||||
}
|
||||
if len(t.List) > 1 {
|
||||
} else {
|
||||
ind := t.LocFromVisual(buffer.Loc{mx, my})
|
||||
if ind != -1 {
|
||||
t.SetActive(ind)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
if my == 0 {
|
||||
case tcell.ButtonNone:
|
||||
if t.List[t.Active()].release {
|
||||
// Mouse release received, while already released
|
||||
t.ResetMouse()
|
||||
return
|
||||
}
|
||||
}
|
||||
case tcell.WheelUp:
|
||||
if my == t.Y {
|
||||
if my == t.Y && len(t.List) > 1 {
|
||||
t.Scroll(4)
|
||||
return
|
||||
}
|
||||
case tcell.WheelDown:
|
||||
if my == t.Y {
|
||||
if my == t.Y && len(t.List) > 1 {
|
||||
t.Scroll(-4)
|
||||
return
|
||||
}
|
||||
@ -144,11 +149,75 @@ func (t *TabList) Display() {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TabList) SetActive(a int) {
|
||||
t.TabWindow.SetActive(a)
|
||||
|
||||
for i, p := range t.List {
|
||||
if i == a {
|
||||
if !p.isActive {
|
||||
p.isActive = true
|
||||
|
||||
err := config.RunPluginFn("onSetActive", luar.New(ulua.L, p.CurPane()))
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
p.isActive = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ResetMouse resets the mouse release state after the screen was stopped
|
||||
// or the pane changed.
|
||||
// This prevents situations in which mouse releases are received at the wrong place
|
||||
// and the mouse state is still pressed.
|
||||
func (t *TabList) ResetMouse() {
|
||||
for _, tab := range t.List {
|
||||
if !tab.release && tab.resizing != nil {
|
||||
tab.resizing = nil
|
||||
}
|
||||
|
||||
tab.release = true
|
||||
|
||||
for _, p := range tab.Panes {
|
||||
if bp, ok := p.(*BufPane); ok {
|
||||
bp.resetMouse()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CloseTerms notifies term panes that a terminal job has finished.
|
||||
func (t *TabList) CloseTerms() {
|
||||
for _, tab := range t.List {
|
||||
for _, p := range tab.Panes {
|
||||
if tp, ok := p.(*TermPane); ok {
|
||||
tp.HandleTermClose()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tabs is the global tab list
|
||||
var Tabs *TabList
|
||||
|
||||
func InitTabs(bufs []*buffer.Buffer) {
|
||||
multiopen := config.GetGlobalOption("multiopen").(string)
|
||||
if multiopen == "tab" {
|
||||
Tabs = NewTabList(bufs)
|
||||
} else {
|
||||
Tabs = NewTabList(bufs[:1])
|
||||
for _, b := range bufs[1:] {
|
||||
if multiopen == "vsplit" {
|
||||
MainTab().CurPane().VSplitBuf(b)
|
||||
} else { // default hsplit
|
||||
MainTab().CurPane().HSplitBuf(b)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
screen.RestartCallback = Tabs.ResetMouse
|
||||
}
|
||||
|
||||
func MainTab() *Tab {
|
||||
@ -162,6 +231,9 @@ func MainTab() *Tab {
|
||||
type Tab struct {
|
||||
*views.Node
|
||||
*display.UIWindow
|
||||
|
||||
isActive bool
|
||||
|
||||
Panes []Pane
|
||||
active int
|
||||
|
||||
@ -199,16 +271,20 @@ func NewTabFromPane(x, y, width, height int, pane Pane) *Tab {
|
||||
// HandleEvent takes a tcell event and usually dispatches it to the current
|
||||
// active pane. However if the event is a resize or a mouse event where the user
|
||||
// is interacting with the UI (resizing splits) then the event is consumed here
|
||||
// If the event is a mouse event in a pane, that pane will become active and get
|
||||
// the event
|
||||
// If the event is a mouse press event in a pane, that pane will become active
|
||||
// and get the event
|
||||
func (t *Tab) HandleEvent(event tcell.Event) {
|
||||
switch e := event.(type) {
|
||||
case *tcell.EventMouse:
|
||||
mx, my := e.Position()
|
||||
switch e.Buttons() {
|
||||
case tcell.Button1:
|
||||
btn := e.Buttons()
|
||||
switch {
|
||||
case btn & ^(tcell.WheelUp|tcell.WheelDown|tcell.WheelLeft|tcell.WheelRight) != tcell.ButtonNone:
|
||||
// button press or drag
|
||||
wasReleased := t.release
|
||||
t.release = false
|
||||
|
||||
if btn == tcell.Button1 {
|
||||
if t.resizing != nil {
|
||||
var size int
|
||||
if t.resizing.Kind == views.STVert {
|
||||
@ -220,13 +296,15 @@ func (t *Tab) HandleEvent(event tcell.Event) {
|
||||
t.Resize()
|
||||
return
|
||||
}
|
||||
|
||||
if wasReleased {
|
||||
t.resizing = t.GetMouseSplitNode(buffer.Loc{mx, my})
|
||||
if t.resizing != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if wasReleased {
|
||||
for i, p := range t.Panes {
|
||||
v := p.GetView()
|
||||
inpane := mx >= v.X && mx < v.X+v.Width && my >= v.Y && my < v.Y+v.Height
|
||||
@ -236,10 +314,15 @@ func (t *Tab) HandleEvent(event tcell.Event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
case tcell.ButtonNone:
|
||||
t.resizing = nil
|
||||
case btn == tcell.ButtonNone:
|
||||
// button release
|
||||
t.release = true
|
||||
if t.resizing != nil {
|
||||
t.resizing = nil
|
||||
return
|
||||
}
|
||||
default:
|
||||
// wheel move
|
||||
for _, p := range t.Panes {
|
||||
v := p.GetView()
|
||||
inpane := mx >= v.X && mx < v.X+v.Width && my >= v.Y && my < v.Y+v.Height
|
||||
@ -266,6 +349,16 @@ func (t *Tab) SetActive(i int) {
|
||||
}
|
||||
}
|
||||
|
||||
// AddPane adds a pane at a given index
|
||||
func (t *Tab) AddPane(pane Pane, i int) {
|
||||
if len(t.Panes) == i {
|
||||
t.Panes = append(t.Panes, pane)
|
||||
return
|
||||
}
|
||||
t.Panes = append(t.Panes[:i+1], t.Panes[i:]...)
|
||||
t.Panes[i] = pane
|
||||
}
|
||||
|
||||
// GetPane returns the pane with the given split index
|
||||
func (t *Tab) GetPane(splitid uint64) int {
|
||||
for i, p := range t.Panes {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// +build linux darwin dragonfly openbsd_amd64 freebsd
|
||||
//go:build linux || darwin || dragonfly || solaris || openbsd || netbsd || freebsd
|
||||
|
||||
package action
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// +build !linux,!darwin,!freebsd,!dragonfly,!openbsd_amd64
|
||||
//go:build plan9 || nacl || windows
|
||||
|
||||
package action
|
||||
|
||||
|
@ -4,13 +4,13 @@ import (
|
||||
"errors"
|
||||
"runtime"
|
||||
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
"github.com/micro-editor/terminal"
|
||||
"github.com/zyedidia/micro/v2/internal/clipboard"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/display"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/micro/v2/internal/shell"
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
"github.com/zyedidia/terminal"
|
||||
)
|
||||
|
||||
type TermKeyAction func(*TermPane)
|
||||
@ -81,6 +81,10 @@ func (t *TermPane) SetID(i uint64) {
|
||||
t.id = i
|
||||
}
|
||||
|
||||
func (t *TermPane) Name() string {
|
||||
return t.Terminal.Name()
|
||||
}
|
||||
|
||||
func (t *TermPane) SetTab(tab *Tab) {
|
||||
t.tab = tab
|
||||
}
|
||||
@ -121,11 +125,7 @@ func (t *TermPane) Unsplit() {
|
||||
// copy-paste
|
||||
func (t *TermPane) HandleEvent(event tcell.Event) {
|
||||
if e, ok := event.(*tcell.EventKey); ok {
|
||||
ke := KeyEvent{
|
||||
code: e.Key(),
|
||||
mod: metaToAlt(e.Modifiers()),
|
||||
r: e.Rune(),
|
||||
}
|
||||
ke := keyEvent(e)
|
||||
action, more := TermBindings.NextEvent(ke, nil)
|
||||
|
||||
if !more {
|
||||
@ -159,9 +159,9 @@ func (t *TermPane) HandleEvent(event tcell.Event) {
|
||||
if t.Status != shell.TTDone {
|
||||
t.WriteString(event.EscSeq())
|
||||
}
|
||||
} else if e, ok := event.(*tcell.EventMouse); e != nil && (!ok || t.State.Mode(terminal.ModeMouseMask)) {
|
||||
} else if e, ok := event.(*tcell.EventMouse); !ok || t.State.Mode(terminal.ModeMouseMask) {
|
||||
// t.WriteString(event.EscSeq())
|
||||
} else if e != nil {
|
||||
} else {
|
||||
x, y := e.Position()
|
||||
v := t.GetView()
|
||||
x -= v.X
|
||||
@ -188,7 +188,12 @@ func (t *TermPane) HandleEvent(event tcell.Event) {
|
||||
t.mouseReleased = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HandleTermClose is called when a terminal has finished its job
|
||||
// and should be closed. If that terminal is this termpane's terminal,
|
||||
// HandleTermClose will close the terminal and the termpane itself.
|
||||
func (t *TermPane) HandleTermClose() {
|
||||
if t.Status == shell.TTClose {
|
||||
t.Quit()
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package buffer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io/fs"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
@ -64,7 +64,7 @@ func (b *Buffer) CycleAutocomplete(forward bool) {
|
||||
|
||||
// GetWord gets the most recent word separated by any separator
|
||||
// (whitespace, punctuation, any non alphanumeric character)
|
||||
func GetWord(b *Buffer) ([]byte, int) {
|
||||
func (b *Buffer) GetWord() ([]byte, int) {
|
||||
c := b.GetActiveCursor()
|
||||
l := b.LineBytes(c.Y)
|
||||
l = util.SliceStart(l, c.X)
|
||||
@ -73,17 +73,17 @@ func GetWord(b *Buffer) ([]byte, int) {
|
||||
return []byte{}, -1
|
||||
}
|
||||
|
||||
if util.IsNonAlphaNumeric(b.RuneAt(c.Loc.Move(-1, b))) {
|
||||
if util.IsNonWordChar(b.RuneAt(c.Loc.Move(-1, b))) {
|
||||
return []byte{}, c.X
|
||||
}
|
||||
|
||||
args := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
|
||||
args := bytes.FieldsFunc(l, util.IsNonWordChar)
|
||||
input := args[len(args)-1]
|
||||
return input, c.X - util.CharacterCount(input)
|
||||
}
|
||||
|
||||
// GetArg gets the most recent word (separated by ' ' only)
|
||||
func GetArg(b *Buffer) (string, int) {
|
||||
func (b *Buffer) GetArg() (string, int) {
|
||||
c := b.GetActiveCursor()
|
||||
l := b.LineBytes(c.Y)
|
||||
l = util.SliceStart(l, c.X)
|
||||
@ -104,20 +104,20 @@ func GetArg(b *Buffer) (string, int) {
|
||||
// FileComplete autocompletes filenames
|
||||
func FileComplete(b *Buffer) ([]string, []string) {
|
||||
c := b.GetActiveCursor()
|
||||
input, argstart := GetArg(b)
|
||||
input, argstart := b.GetArg()
|
||||
|
||||
sep := string(os.PathSeparator)
|
||||
dirs := strings.Split(input, sep)
|
||||
|
||||
var files []os.FileInfo
|
||||
var files []fs.DirEntry
|
||||
var err error
|
||||
if len(dirs) > 1 {
|
||||
directories := strings.Join(dirs[:len(dirs)-1], sep) + sep
|
||||
|
||||
directories, _ = util.ReplaceHome(directories)
|
||||
files, err = ioutil.ReadDir(directories)
|
||||
files, err = os.ReadDir(directories)
|
||||
} else {
|
||||
files, err = ioutil.ReadDir(".")
|
||||
files, err = os.ReadDir(".")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@ -153,7 +153,7 @@ func FileComplete(b *Buffer) ([]string, []string) {
|
||||
// BufferComplete autocompletes based on previous words in the buffer
|
||||
func BufferComplete(b *Buffer) ([]string, []string) {
|
||||
c := b.GetActiveCursor()
|
||||
input, argstart := GetWord(b)
|
||||
input, argstart := b.GetWord()
|
||||
|
||||
if argstart == -1 {
|
||||
return []string{}, []string{}
|
||||
@ -166,7 +166,7 @@ func BufferComplete(b *Buffer) ([]string, []string) {
|
||||
var suggestions []string
|
||||
for i := c.Y; i >= 0; i-- {
|
||||
l := b.LineBytes(i)
|
||||
words := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
|
||||
words := bytes.FieldsFunc(l, util.IsNonWordChar)
|
||||
for _, w := range words {
|
||||
if bytes.HasPrefix(w, input) && util.CharacterCount(w) > inputLen {
|
||||
strw := string(w)
|
||||
@ -179,7 +179,7 @@ func BufferComplete(b *Buffer) ([]string, []string) {
|
||||
}
|
||||
for i := c.Y + 1; i < b.LinesNum(); i++ {
|
||||
l := b.LineBytes(i)
|
||||
words := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
|
||||
words := bytes.FieldsFunc(l, util.IsNonWordChar)
|
||||
for _, w := range words {
|
||||
if bytes.HasPrefix(w, input) && util.CharacterCount(w) > inputLen {
|
||||
strw := string(w)
|
||||
|
@ -1,24 +1,26 @@
|
||||
package buffer
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
"golang.org/x/text/encoding"
|
||||
)
|
||||
|
||||
const backupMsg = `A backup was detected for this file. This likely means that micro
|
||||
crashed while editing this file, or another instance of micro is currently
|
||||
editing this file.
|
||||
const BackupMsg = `A backup was detected for:
|
||||
|
||||
The backup was created on %s, and the file is
|
||||
%s
|
||||
|
||||
This likely means that micro crashed while editing this file,
|
||||
or another instance of micro is currently editing this file,
|
||||
or an error occurred while saving this file so it may be corrupted.
|
||||
|
||||
The backup was created on %s and its path is:
|
||||
|
||||
%s
|
||||
|
||||
@ -26,121 +28,114 @@ The backup was created on %s, and the file is
|
||||
When the buffer is closed, the backup will be removed.
|
||||
* 'ignore' will ignore the backup, discarding its changes. The backup file
|
||||
will be removed.
|
||||
* 'abort' will abort the open operation, and instead open an empty buffer.
|
||||
|
||||
Options: [r]ecover, [i]gnore: `
|
||||
Options: [r]ecover, [i]gnore, [a]bort: `
|
||||
|
||||
var backupRequestChan chan *Buffer
|
||||
const backupSeconds = 8
|
||||
|
||||
func backupThread() {
|
||||
for {
|
||||
time.Sleep(time.Second * 8)
|
||||
|
||||
for len(backupRequestChan) > 0 {
|
||||
b := <-backupRequestChan
|
||||
bfini := atomic.LoadInt32(&(b.fini)) != 0
|
||||
if !bfini {
|
||||
b.Backup()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var BackupCompleteChan chan *Buffer
|
||||
|
||||
func init() {
|
||||
backupRequestChan = make(chan *Buffer, 10)
|
||||
|
||||
go backupThread()
|
||||
BackupCompleteChan = make(chan *Buffer, 10)
|
||||
}
|
||||
|
||||
func (b *Buffer) RequestBackup() {
|
||||
if !b.requestedBackup {
|
||||
if !b.RequestedBackup {
|
||||
select {
|
||||
case backupRequestChan <- b:
|
||||
default:
|
||||
// channel is full
|
||||
}
|
||||
b.requestedBackup = true
|
||||
b.RequestedBackup = true
|
||||
}
|
||||
}
|
||||
|
||||
// Backup saves the current buffer to ConfigDir/backups
|
||||
func (b *Buffer) backupDir() string {
|
||||
backupdir, err := util.ReplaceHome(b.Settings["backupdir"].(string))
|
||||
if backupdir == "" || err != nil {
|
||||
backupdir = filepath.Join(config.ConfigDir, "backups")
|
||||
}
|
||||
return backupdir
|
||||
}
|
||||
|
||||
func (b *Buffer) keepBackup() bool {
|
||||
return b.forceKeepBackup || b.Settings["permbackup"].(bool)
|
||||
}
|
||||
|
||||
// Backup saves the current buffer to the backups directory
|
||||
func (b *Buffer) Backup() error {
|
||||
if !b.Settings["backup"].(bool) || b.Path == "" || b.Type != BTDefault {
|
||||
return nil
|
||||
}
|
||||
|
||||
backupdir, err := util.ReplaceHome(b.Settings["backupdir"].(string))
|
||||
if backupdir == "" || err != nil {
|
||||
backupdir = filepath.Join(config.ConfigDir, "backups")
|
||||
}
|
||||
if _, err := os.Stat(backupdir); os.IsNotExist(err) {
|
||||
backupdir := b.backupDir()
|
||||
if _, err := os.Stat(backupdir); errors.Is(err, fs.ErrNotExist) {
|
||||
os.Mkdir(backupdir, os.ModePerm)
|
||||
}
|
||||
|
||||
name := filepath.Join(backupdir, util.EscapePath(b.AbsPath))
|
||||
|
||||
err = overwriteFile(name, encoding.Nop, func(file io.Writer) (e error) {
|
||||
if len(b.lines) == 0 {
|
||||
return
|
||||
name := util.DetermineEscapePath(backupdir, b.AbsPath)
|
||||
if _, err := os.Stat(name); errors.Is(err, fs.ErrNotExist) {
|
||||
_, err = b.overwriteFile(name)
|
||||
if err == nil {
|
||||
BackupCompleteChan <- b
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// end of line
|
||||
eol := []byte{'\n'}
|
||||
|
||||
// write lines
|
||||
if _, e = file.Write(b.lines[0].data); e != nil {
|
||||
return
|
||||
tmp := util.AppendBackupSuffix(name)
|
||||
_, err := b.overwriteFile(tmp)
|
||||
if err != nil {
|
||||
os.Remove(tmp)
|
||||
return err
|
||||
}
|
||||
err = os.Rename(tmp, name)
|
||||
if err != nil {
|
||||
os.Remove(tmp)
|
||||
return err
|
||||
}
|
||||
|
||||
for _, l := range b.lines[1:] {
|
||||
if _, e = file.Write(eol); e != nil {
|
||||
return
|
||||
}
|
||||
if _, e = file.Write(l.data); e != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}, false)
|
||||
|
||||
b.requestedBackup = false
|
||||
BackupCompleteChan <- b
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// RemoveBackup removes any backup file associated with this buffer
|
||||
func (b *Buffer) RemoveBackup() {
|
||||
if !b.Settings["backup"].(bool) || b.Settings["permbackup"].(bool) || b.Path == "" || b.Type != BTDefault {
|
||||
if !b.Settings["backup"].(bool) || b.keepBackup() || b.Path == "" || b.Type != BTDefault {
|
||||
return
|
||||
}
|
||||
f := filepath.Join(config.ConfigDir, "backups", util.EscapePath(b.AbsPath))
|
||||
f := util.DetermineEscapePath(b.backupDir(), b.AbsPath)
|
||||
os.Remove(f)
|
||||
}
|
||||
|
||||
// ApplyBackup applies the corresponding backup file to this buffer (if one exists)
|
||||
// Returns true if a backup was applied
|
||||
func (b *Buffer) ApplyBackup(fsize int64) bool {
|
||||
func (b *Buffer) ApplyBackup(fsize int64) (bool, bool) {
|
||||
if b.Settings["backup"].(bool) && !b.Settings["permbackup"].(bool) && len(b.Path) > 0 && b.Type == BTDefault {
|
||||
backupfile := filepath.Join(config.ConfigDir, "backups", util.EscapePath(b.AbsPath))
|
||||
backupfile := util.DetermineEscapePath(b.backupDir(), b.AbsPath)
|
||||
if info, err := os.Stat(backupfile); err == nil {
|
||||
backup, err := os.Open(backupfile)
|
||||
if err == nil {
|
||||
defer backup.Close()
|
||||
t := info.ModTime()
|
||||
msg := fmt.Sprintf(backupMsg, t.Format("Mon Jan _2 at 15:04, 2006"), util.EscapePath(b.AbsPath))
|
||||
choice := screen.TermPrompt(msg, []string{"r", "i", "recover", "ignore"}, true)
|
||||
msg := fmt.Sprintf(BackupMsg, b.Path, t.Format("Mon Jan _2 at 15:04, 2006"), backupfile)
|
||||
choice := screen.TermPrompt(msg, []string{"r", "i", "a", "recover", "ignore", "abort"}, true)
|
||||
|
||||
if choice%2 == 0 {
|
||||
if choice%3 == 0 {
|
||||
// recover
|
||||
b.LineArray = NewLineArray(uint64(fsize), FFAuto, backup)
|
||||
b.isModified = true
|
||||
return true
|
||||
} else if choice%2 == 1 {
|
||||
return true, true
|
||||
} else if choice%3 == 1 {
|
||||
// delete
|
||||
os.Remove(backupfile)
|
||||
} else if choice%3 == 2 {
|
||||
return false, false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return false, true
|
||||
}
|
||||
|
@ -7,9 +7,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -25,13 +24,12 @@ import (
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
"github.com/zyedidia/micro/v2/pkg/highlight"
|
||||
"golang.org/x/text/encoding"
|
||||
"golang.org/x/text/encoding/htmlindex"
|
||||
"golang.org/x/text/encoding/unicode"
|
||||
"golang.org/x/text/transform"
|
||||
)
|
||||
|
||||
const backupTime = 8000
|
||||
|
||||
var (
|
||||
// OpenBuffers is a list of the currently open buffers
|
||||
OpenBuffers []*Buffer
|
||||
@ -57,17 +55,13 @@ var (
|
||||
BTLog = BufType{2, true, true, false}
|
||||
// BTScratch is a buffer that cannot be saved (for scratch work)
|
||||
BTScratch = BufType{3, false, true, false}
|
||||
// BTRaw is is a buffer that shows raw terminal events
|
||||
// BTRaw is a buffer that shows raw terminal events
|
||||
BTRaw = BufType{4, false, true, false}
|
||||
// BTInfo is a buffer for inputting information
|
||||
BTInfo = BufType{5, false, true, false}
|
||||
// BTStdout is a buffer that only writes to stdout
|
||||
// when closed
|
||||
BTStdout = BufType{6, false, true, true}
|
||||
|
||||
// ErrFileTooLarge is returned when the file is too large to hash
|
||||
// (fastdirty is automatically enabled)
|
||||
ErrFileTooLarge = errors.New("File is too large to hash")
|
||||
)
|
||||
|
||||
// SharedBuffer is a struct containing info that is shared among buffers
|
||||
@ -90,6 +84,10 @@ type SharedBuffer struct {
|
||||
|
||||
// Settings customized by the user
|
||||
Settings map[string]interface{}
|
||||
// LocalSettings customized by the user for this buffer only
|
||||
LocalSettings map[string]bool
|
||||
|
||||
encoding encoding.Encoding
|
||||
|
||||
Suggestions []string
|
||||
Completions []string
|
||||
@ -103,7 +101,8 @@ type SharedBuffer struct {
|
||||
diffLock sync.RWMutex
|
||||
diff map[int]DiffStatus
|
||||
|
||||
requestedBackup bool
|
||||
RequestedBackup bool
|
||||
forceKeepBackup bool
|
||||
|
||||
// ReloadDisabled allows the user to disable reloads if they
|
||||
// are viewing a file that is constantly changing
|
||||
@ -146,13 +145,10 @@ func (b *SharedBuffer) remove(start, end Loc) []byte {
|
||||
func (b *SharedBuffer) MarkModified(start, end int) {
|
||||
b.ModifiedThisFrame = true
|
||||
|
||||
if !b.Settings["syntax"].(bool) || b.SyntaxDef == nil {
|
||||
return
|
||||
}
|
||||
|
||||
start = util.Clamp(start, 0, len(b.lines)-1)
|
||||
end = util.Clamp(end, 0, len(b.lines)-1)
|
||||
|
||||
if b.Settings["syntax"].(bool) && b.SyntaxDef != nil {
|
||||
l := -1
|
||||
for i := start; i <= end; i++ {
|
||||
l = util.Max(b.Highlighter.ReHighlightStates(b, i), l)
|
||||
@ -160,6 +156,11 @@ func (b *SharedBuffer) MarkModified(start, end int) {
|
||||
b.Highlighter.HighlightMatches(b, start, l)
|
||||
}
|
||||
|
||||
for i := start; i <= end; i++ {
|
||||
b.LineArray.invalidateSearchMatches(i)
|
||||
}
|
||||
}
|
||||
|
||||
// DisableReload disables future reloads of this sharedbuffer
|
||||
func (b *SharedBuffer) DisableReload() {
|
||||
b.ReloadDisabled = true
|
||||
@ -181,6 +182,7 @@ type DiffStatus byte
|
||||
// The syntax highlighting info must be stored with the buffer because the syntax
|
||||
// highlighter attaches information to each line of the buffer for optimization
|
||||
// purposes so it doesn't have to rehighlight everything on every update.
|
||||
// Likewise for the search highlighting.
|
||||
type Buffer struct {
|
||||
*EventHandler
|
||||
*SharedBuffer
|
||||
@ -202,6 +204,17 @@ type Buffer struct {
|
||||
// This is hacky. Maybe it would be better to move all the visual x logic
|
||||
// from buffer to display, but it would require rewriting a lot of code.
|
||||
GetVisualX func(loc Loc) int
|
||||
|
||||
// Last search stores the last successful search
|
||||
LastSearch string
|
||||
LastSearchRegex bool
|
||||
// HighlightSearch enables highlighting all instances of the last successful search
|
||||
HighlightSearch bool
|
||||
|
||||
// OverwriteMode indicates that we are in overwrite mode (toggled by
|
||||
// Insert key by default) i.e. that typing a character shall replace the
|
||||
// character under the cursor instead of inserting a character before it.
|
||||
OverwriteMode bool
|
||||
}
|
||||
|
||||
// NewBufferFromFileAtLoc opens a new buffer with a given cursor location
|
||||
@ -225,17 +238,20 @@ func NewBufferFromFileAtLoc(path string, btype BufType, cursorLoc Loc) (*Buffer,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(filename, os.O_WRONLY, 0)
|
||||
readonly := os.IsPermission(err)
|
||||
f.Close()
|
||||
|
||||
fileInfo, serr := os.Stat(filename)
|
||||
if serr != nil && !os.IsNotExist(serr) {
|
||||
if serr != nil && !errors.Is(serr, fs.ErrNotExist) {
|
||||
return nil, serr
|
||||
}
|
||||
if serr == nil && fileInfo.IsDir() {
|
||||
return nil, errors.New("Error: " + filename + " is a directory and cannot be opened")
|
||||
}
|
||||
if serr == nil && !fileInfo.Mode().IsRegular() {
|
||||
return nil, errors.New("Error: " + filename + " is not a regular file and cannot be opened")
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(filename, os.O_WRONLY, 0)
|
||||
readonly := errors.Is(err, fs.ErrPermission)
|
||||
f.Close()
|
||||
|
||||
file, err := os.Open(filename)
|
||||
if err == nil {
|
||||
@ -243,17 +259,21 @@ func NewBufferFromFileAtLoc(path string, btype BufType, cursorLoc Loc) (*Buffer,
|
||||
}
|
||||
|
||||
var buf *Buffer
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
// File does not exist -- create an empty buffer with that name
|
||||
buf = NewBufferFromString("", filename, btype)
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
buf = NewBuffer(file, util.FSize(file), filename, cursorLoc, btype)
|
||||
if buf == nil {
|
||||
return nil, errors.New("could not open file")
|
||||
}
|
||||
}
|
||||
|
||||
if readonly {
|
||||
buf.SetOptionNative("readonly", true)
|
||||
if readonly && prompt != nil {
|
||||
prompt.Message(fmt.Sprintf("Warning: file is readonly - %s will be attempted when saving", config.GlobalSettings["sucmd"].(string)))
|
||||
// buf.SetOptionNative("readonly", true)
|
||||
}
|
||||
|
||||
return buf, nil
|
||||
@ -283,7 +303,10 @@ func NewBufferFromString(text, path string, btype BufType) *Buffer {
|
||||
// Places the cursor at startcursor. If startcursor is -1, -1 places the
|
||||
// cursor at an autodetected location (based on savecursor or :LINE:COL)
|
||||
func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufType) *Buffer {
|
||||
absPath, _ := filepath.Abs(path)
|
||||
absPath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
absPath = path
|
||||
}
|
||||
|
||||
b := new(Buffer)
|
||||
|
||||
@ -306,48 +329,45 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
|
||||
b.AbsPath = absPath
|
||||
b.Path = path
|
||||
|
||||
// this is a little messy since we need to know some settings to read
|
||||
// the file properly, but some settings depend on the filetype, which
|
||||
// we don't know until reading the file. We first read the settings
|
||||
// into a local variable and then use that to determine the encoding,
|
||||
// readonly, and fileformat necessary for reading the file and
|
||||
// assigning the filetype.
|
||||
settings := config.DefaultCommonSettings()
|
||||
b.Settings = config.DefaultCommonSettings()
|
||||
b.LocalSettings = make(map[string]bool)
|
||||
for k, v := range config.GlobalSettings {
|
||||
if _, ok := config.DefaultGlobalOnlySettings[k]; !ok {
|
||||
// make sure setting is not global-only
|
||||
settings[k] = v
|
||||
b.Settings[k] = v
|
||||
}
|
||||
}
|
||||
config.InitLocalSettings(settings, path)
|
||||
b.Settings["readonly"] = settings["readonly"]
|
||||
b.Settings["filetype"] = settings["filetype"]
|
||||
b.Settings["syntax"] = settings["syntax"]
|
||||
config.UpdatePathGlobLocals(b.Settings, absPath)
|
||||
|
||||
enc, err := htmlindex.Get(settings["encoding"].(string))
|
||||
b.encoding, err = htmlindex.Get(b.Settings["encoding"].(string))
|
||||
if err != nil {
|
||||
enc = unicode.UTF8
|
||||
b.encoding = unicode.UTF8
|
||||
b.Settings["encoding"] = "utf-8"
|
||||
}
|
||||
|
||||
hasBackup = b.ApplyBackup(size)
|
||||
var ok bool
|
||||
hasBackup, ok = b.ApplyBackup(size)
|
||||
|
||||
if !ok {
|
||||
return NewBufferFromString("", "", btype)
|
||||
}
|
||||
if !hasBackup {
|
||||
reader := bufio.NewReader(transform.NewReader(r, enc.NewDecoder()))
|
||||
reader := bufio.NewReader(transform.NewReader(r, b.encoding.NewDecoder()))
|
||||
|
||||
var ff FileFormat = FFAuto
|
||||
|
||||
if size == 0 {
|
||||
// for empty files, use the fileformat setting instead of
|
||||
// autodetection
|
||||
switch settings["fileformat"] {
|
||||
switch b.Settings["fileformat"] {
|
||||
case "unix":
|
||||
ff = FFUnix
|
||||
case "dos":
|
||||
ff = FFDos
|
||||
}
|
||||
} else {
|
||||
// in case of autodetection treat as locally set
|
||||
b.LocalSettings["fileformat"] = true
|
||||
}
|
||||
|
||||
b.LineArray = NewLineArray(uint64(size), ff, reader)
|
||||
@ -370,10 +390,10 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
|
||||
}
|
||||
|
||||
b.UpdateRules()
|
||||
// init local settings again now that we know the filetype
|
||||
config.InitLocalSettings(b.Settings, b.Path)
|
||||
// we know the filetype now, so update per-filetype settings
|
||||
config.UpdateFileTypeLocals(b.Settings, b.Settings["filetype"].(string))
|
||||
|
||||
if _, err := os.Stat(filepath.Join(config.ConfigDir, "buffers")); os.IsNotExist(err) {
|
||||
if _, err := os.Stat(filepath.Join(config.ConfigDir, "buffers")); errors.Is(err, fs.ErrNotExist) {
|
||||
os.Mkdir(filepath.Join(config.ConfigDir, "buffers"), os.ModePerm)
|
||||
}
|
||||
|
||||
@ -400,7 +420,7 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
|
||||
}
|
||||
}
|
||||
|
||||
err := config.RunPluginFn("onBufferOpen", luar.New(ulua.L, b))
|
||||
err = config.RunPluginFn("onBufferOpen", luar.New(ulua.L, b))
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
@ -410,6 +430,15 @@ func NewBuffer(r io.Reader, size int64, path string, startcursor Loc, btype BufT
|
||||
return b
|
||||
}
|
||||
|
||||
// CloseOpenBuffers removes all open buffers
|
||||
func CloseOpenBuffers() {
|
||||
for i, buf := range OpenBuffers {
|
||||
buf.Fini()
|
||||
OpenBuffers[i] = nil
|
||||
}
|
||||
OpenBuffers = OpenBuffers[:0]
|
||||
}
|
||||
|
||||
// Close removes this buffer from the list of open buffers
|
||||
func (b *Buffer) Close() {
|
||||
for i, buf := range OpenBuffers {
|
||||
@ -449,7 +478,7 @@ func (b *Buffer) GetName() string {
|
||||
name = b.Path
|
||||
}
|
||||
if b.Settings["basename"].(bool) {
|
||||
return path.Base(name)
|
||||
return filepath.Base(name)
|
||||
}
|
||||
return name
|
||||
}
|
||||
@ -515,7 +544,7 @@ func (b *Buffer) ReOpen() error {
|
||||
}
|
||||
|
||||
reader := bufio.NewReader(transform.NewReader(file, enc.NewDecoder()))
|
||||
data, err := ioutil.ReadAll(reader)
|
||||
data, err := io.ReadAll(reader)
|
||||
txt := string(data)
|
||||
|
||||
if err != nil {
|
||||
@ -525,8 +554,12 @@ func (b *Buffer) ReOpen() error {
|
||||
|
||||
err = b.UpdateModTime()
|
||||
if !b.Settings["fastdirty"].(bool) {
|
||||
if len(data) > LargeFileThreshold {
|
||||
b.Settings["fastdirty"] = true
|
||||
} else {
|
||||
calcHash(b, &b.origHash)
|
||||
}
|
||||
}
|
||||
b.isModified = false
|
||||
b.RelocateCursors()
|
||||
return err
|
||||
@ -539,6 +572,13 @@ func (b *Buffer) RelocateCursors() {
|
||||
}
|
||||
}
|
||||
|
||||
// DeselectCursors removes selection from all cursors
|
||||
func (b *Buffer) DeselectCursors() {
|
||||
for _, c := range b.cursors {
|
||||
c.Deselect(true)
|
||||
}
|
||||
}
|
||||
|
||||
// RuneAt returns the rune at a given location in the buffer
|
||||
func (b *Buffer) RuneAt(loc Loc) rune {
|
||||
line := b.LineBytes(loc.Y)
|
||||
@ -579,6 +619,16 @@ func (b *Buffer) WordAt(loc Loc) []byte {
|
||||
return b.Substr(start, end)
|
||||
}
|
||||
|
||||
// Shared returns if there are other buffers with the same file as this buffer
|
||||
func (b *Buffer) Shared() bool {
|
||||
for _, buf := range OpenBuffers {
|
||||
if buf != b && buf.SharedBuffer == b.SharedBuffer {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Modified returns if this buffer has been modified since
|
||||
// being opened
|
||||
func (b *Buffer) Modified() bool {
|
||||
@ -613,145 +663,97 @@ func (b *Buffer) Size() int {
|
||||
}
|
||||
|
||||
// calcHash calculates md5 hash of all lines in the buffer
|
||||
func calcHash(b *Buffer, out *[md5.Size]byte) error {
|
||||
func calcHash(b *Buffer, out *[md5.Size]byte) {
|
||||
h := md5.New()
|
||||
|
||||
size := 0
|
||||
if len(b.lines) > 0 {
|
||||
n, e := h.Write(b.lines[0].data)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
size += n
|
||||
h.Write(b.lines[0].data)
|
||||
|
||||
for _, l := range b.lines[1:] {
|
||||
n, e = h.Write([]byte{'\n'})
|
||||
if e != nil {
|
||||
return e
|
||||
if b.Endings == FFDos {
|
||||
h.Write([]byte{'\r', '\n'})
|
||||
} else {
|
||||
h.Write([]byte{'\n'})
|
||||
}
|
||||
size += n
|
||||
n, e = h.Write(l.data)
|
||||
if e != nil {
|
||||
return e
|
||||
h.Write(l.data)
|
||||
}
|
||||
size += n
|
||||
}
|
||||
}
|
||||
|
||||
if size > LargeFileThreshold {
|
||||
return ErrFileTooLarge
|
||||
}
|
||||
|
||||
h.Sum((*out)[:0])
|
||||
}
|
||||
|
||||
func parseDefFromFile(f config.RuntimeFile, header *highlight.Header) *highlight.Def {
|
||||
data, err := f.Data()
|
||||
if err != nil {
|
||||
screen.TermMessage("Error loading syntax file " + f.Name() + ": " + err.Error())
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateRules updates the syntax rules and filetype for this buffer
|
||||
// This is called when the colorscheme changes
|
||||
func (b *Buffer) UpdateRules() {
|
||||
if !b.Type.Syntax {
|
||||
return
|
||||
}
|
||||
ft := b.Settings["filetype"].(string)
|
||||
if ft == "off" {
|
||||
return
|
||||
}
|
||||
syntaxFile := ""
|
||||
foundDef := false
|
||||
var header *highlight.Header
|
||||
// search for the syntax file in the user's custom syntax files
|
||||
for _, f := range config.ListRealRuntimeFiles(config.RTSyntax) {
|
||||
data, err := f.Data()
|
||||
if err != nil {
|
||||
screen.TermMessage("Error loading syntax file " + f.Name() + ": " + err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
if header == nil {
|
||||
header, err = highlight.MakeHeaderYaml(data)
|
||||
if err != nil {
|
||||
screen.TermMessage("Error parsing header for syntax file " + f.Name() + ": " + err.Error())
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
file, err := highlight.ParseFile(data)
|
||||
if err != nil {
|
||||
screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
|
||||
continue
|
||||
return nil
|
||||
}
|
||||
|
||||
if ((ft == "unknown" || ft == "") && highlight.MatchFiletype(header.FtDetect, b.Path, b.lines[0].data)) || header.FileType == ft {
|
||||
syndef, err := highlight.ParseDef(file, header)
|
||||
if err != nil {
|
||||
screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
|
||||
continue
|
||||
}
|
||||
b.SyntaxDef = syndef
|
||||
syntaxFile = f.Name()
|
||||
foundDef = true
|
||||
break
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// search in the default syntax files
|
||||
for _, f := range config.ListRuntimeFiles(config.RTSyntaxHeader) {
|
||||
data, err := f.Data()
|
||||
if err != nil {
|
||||
screen.TermMessage("Error loading syntax header file " + f.Name() + ": " + err.Error())
|
||||
continue
|
||||
return syndef
|
||||
}
|
||||
|
||||
header, err = highlight.MakeHeader(data)
|
||||
if err != nil {
|
||||
screen.TermMessage("Error reading syntax header file", f.Name(), err)
|
||||
continue
|
||||
// findRealRuntimeSyntaxDef finds a specific syntax definition
|
||||
// in the user's custom syntax files
|
||||
func findRealRuntimeSyntaxDef(name string, header *highlight.Header) *highlight.Def {
|
||||
for _, f := range config.ListRealRuntimeFiles(config.RTSyntax) {
|
||||
if f.Name() == name {
|
||||
syndef := parseDefFromFile(f, header)
|
||||
if syndef != nil {
|
||||
return syndef
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if ft == "unknown" || ft == "" {
|
||||
if highlight.MatchFiletype(header.FtDetect, b.Path, b.lines[0].data) {
|
||||
syntaxFile = f.Name()
|
||||
break
|
||||
}
|
||||
} else if header.FileType == ft {
|
||||
syntaxFile = f.Name()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if syntaxFile != "" && !foundDef {
|
||||
// we found a syntax file using a syntax header file
|
||||
// findRuntimeSyntaxDef finds a specific syntax definition
|
||||
// in the built-in syntax files
|
||||
func findRuntimeSyntaxDef(name string, header *highlight.Header) *highlight.Def {
|
||||
for _, f := range config.ListRuntimeFiles(config.RTSyntax) {
|
||||
if f.Name() == syntaxFile {
|
||||
data, err := f.Data()
|
||||
if err != nil {
|
||||
screen.TermMessage("Error loading syntax file " + f.Name() + ": " + err.Error())
|
||||
continue
|
||||
if f.Name() == name {
|
||||
syndef := parseDefFromFile(f, header)
|
||||
if syndef != nil {
|
||||
return syndef
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
file, err := highlight.ParseFile(data)
|
||||
if err != nil {
|
||||
screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
|
||||
continue
|
||||
func resolveIncludes(syndef *highlight.Def) {
|
||||
includes := highlight.GetIncludes(syndef)
|
||||
if len(includes) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
syndef, err := highlight.ParseDef(file, header)
|
||||
if err != nil {
|
||||
screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
|
||||
continue
|
||||
}
|
||||
b.SyntaxDef = syndef
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if b.SyntaxDef != nil && highlight.HasIncludes(b.SyntaxDef) {
|
||||
includes := highlight.GetIncludes(b.SyntaxDef)
|
||||
|
||||
var files []*highlight.File
|
||||
for _, f := range config.ListRuntimeFiles(config.RTSyntax) {
|
||||
data, err := f.Data()
|
||||
if err != nil {
|
||||
screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
|
||||
screen.TermMessage("Error loading syntax file " + f.Name() + ": " + err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
header, err := highlight.MakeHeaderYaml(data)
|
||||
if err != nil {
|
||||
screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
|
||||
@ -774,15 +776,193 @@ func (b *Buffer) UpdateRules() {
|
||||
}
|
||||
}
|
||||
|
||||
highlight.ResolveIncludes(b.SyntaxDef, files)
|
||||
highlight.ResolveIncludes(syndef, files)
|
||||
}
|
||||
|
||||
// UpdateRules updates the syntax rules and filetype for this buffer
|
||||
// This is called when the colorscheme changes
|
||||
func (b *Buffer) UpdateRules() {
|
||||
if !b.Type.Syntax {
|
||||
return
|
||||
}
|
||||
ft := b.Settings["filetype"].(string)
|
||||
if ft == "off" {
|
||||
b.ClearMatches()
|
||||
b.SyntaxDef = nil
|
||||
return
|
||||
}
|
||||
|
||||
b.SyntaxDef = nil
|
||||
|
||||
// syntaxFileInfo is an internal helper structure
|
||||
// to store properties of one single syntax file
|
||||
type syntaxFileInfo struct {
|
||||
header *highlight.Header
|
||||
fileName string
|
||||
syntaxDef *highlight.Def
|
||||
}
|
||||
|
||||
fnameMatches := []syntaxFileInfo{}
|
||||
headerMatches := []syntaxFileInfo{}
|
||||
syntaxFile := ""
|
||||
foundDef := false
|
||||
var header *highlight.Header
|
||||
// search for the syntax file in the user's custom syntax files
|
||||
for _, f := range config.ListRealRuntimeFiles(config.RTSyntax) {
|
||||
if f.Name() == "default" {
|
||||
continue
|
||||
}
|
||||
|
||||
data, err := f.Data()
|
||||
if err != nil {
|
||||
screen.TermMessage("Error loading syntax file " + f.Name() + ": " + err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
header, err = highlight.MakeHeaderYaml(data)
|
||||
if err != nil {
|
||||
screen.TermMessage("Error parsing header for syntax file " + f.Name() + ": " + err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
matchedFileType := false
|
||||
matchedFileName := false
|
||||
matchedFileHeader := false
|
||||
|
||||
if ft == "unknown" || ft == "" {
|
||||
if header.MatchFileName(b.Path) {
|
||||
matchedFileName = true
|
||||
}
|
||||
if len(fnameMatches) == 0 && header.MatchFileHeader(b.lines[0].data) {
|
||||
matchedFileHeader = true
|
||||
}
|
||||
} else if header.FileType == ft {
|
||||
matchedFileType = true
|
||||
}
|
||||
|
||||
if matchedFileType || matchedFileName || matchedFileHeader {
|
||||
file, err := highlight.ParseFile(data)
|
||||
if err != nil {
|
||||
screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
syndef, err := highlight.ParseDef(file, header)
|
||||
if err != nil {
|
||||
screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
if matchedFileType {
|
||||
b.SyntaxDef = syndef
|
||||
syntaxFile = f.Name()
|
||||
foundDef = true
|
||||
break
|
||||
}
|
||||
|
||||
if matchedFileName {
|
||||
fnameMatches = append(fnameMatches, syntaxFileInfo{header, f.Name(), syndef})
|
||||
} else if matchedFileHeader {
|
||||
headerMatches = append(headerMatches, syntaxFileInfo{header, f.Name(), syndef})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !foundDef {
|
||||
// search for the syntax file in the built-in syntax files
|
||||
for _, f := range config.ListRuntimeFiles(config.RTSyntaxHeader) {
|
||||
data, err := f.Data()
|
||||
if err != nil {
|
||||
screen.TermMessage("Error loading syntax header file " + f.Name() + ": " + err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
header, err = highlight.MakeHeader(data)
|
||||
if err != nil {
|
||||
screen.TermMessage("Error reading syntax header file", f.Name(), err)
|
||||
continue
|
||||
}
|
||||
|
||||
if ft == "unknown" || ft == "" {
|
||||
if header.MatchFileName(b.Path) {
|
||||
fnameMatches = append(fnameMatches, syntaxFileInfo{header, f.Name(), nil})
|
||||
}
|
||||
if len(fnameMatches) == 0 && header.MatchFileHeader(b.lines[0].data) {
|
||||
headerMatches = append(headerMatches, syntaxFileInfo{header, f.Name(), nil})
|
||||
}
|
||||
} else if header.FileType == ft {
|
||||
syntaxFile = f.Name()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if syntaxFile == "" {
|
||||
matches := fnameMatches
|
||||
if len(matches) == 0 {
|
||||
matches = headerMatches
|
||||
}
|
||||
|
||||
length := len(matches)
|
||||
if length > 0 {
|
||||
signatureMatch := false
|
||||
if length > 1 {
|
||||
// multiple matching syntax files found, try to resolve the ambiguity
|
||||
// using signatures
|
||||
detectlimit := util.IntOpt(b.Settings["detectlimit"])
|
||||
lineCount := len(b.lines)
|
||||
limit := lineCount
|
||||
if detectlimit > 0 && lineCount > detectlimit {
|
||||
limit = detectlimit
|
||||
}
|
||||
|
||||
matchLoop:
|
||||
for _, m := range matches {
|
||||
if m.header.HasFileSignature() {
|
||||
for i := 0; i < limit; i++ {
|
||||
if m.header.MatchFileSignature(b.lines[i].data) {
|
||||
syntaxFile = m.fileName
|
||||
if m.syntaxDef != nil {
|
||||
b.SyntaxDef = m.syntaxDef
|
||||
foundDef = true
|
||||
}
|
||||
header = m.header
|
||||
signatureMatch = true
|
||||
break matchLoop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if length == 1 || !signatureMatch {
|
||||
syntaxFile = matches[0].fileName
|
||||
if matches[0].syntaxDef != nil {
|
||||
b.SyntaxDef = matches[0].syntaxDef
|
||||
foundDef = true
|
||||
}
|
||||
header = matches[0].header
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if syntaxFile != "" && !foundDef {
|
||||
// we found a syntax file using a syntax header file
|
||||
b.SyntaxDef = findRuntimeSyntaxDef(syntaxFile, header)
|
||||
}
|
||||
|
||||
if b.Highlighter == nil || syntaxFile != "" {
|
||||
if b.SyntaxDef != nil {
|
||||
b.Settings["filetype"] = b.SyntaxDef.FileType
|
||||
}
|
||||
} else {
|
||||
b.SyntaxDef = &highlight.EmptyDef
|
||||
// search for the default file in the user's custom syntax files
|
||||
b.SyntaxDef = findRealRuntimeSyntaxDef("default", nil)
|
||||
if b.SyntaxDef == nil {
|
||||
// search for the default file in the built-in syntax files
|
||||
b.SyntaxDef = findRuntimeSyntaxDef("default", nil)
|
||||
}
|
||||
}
|
||||
|
||||
if b.SyntaxDef != nil {
|
||||
resolveIncludes(b.SyntaxDef)
|
||||
}
|
||||
|
||||
if b.SyntaxDef != nil {
|
||||
@ -884,7 +1064,7 @@ func (b *Buffer) MergeCursors() {
|
||||
b.EventHandler.active = b.curCursor
|
||||
}
|
||||
|
||||
// UpdateCursors updates all the cursors indicies
|
||||
// UpdateCursors updates all the cursors indices
|
||||
func (b *Buffer) UpdateCursors() {
|
||||
b.EventHandler.cursors = b.cursors
|
||||
b.EventHandler.active = b.curCursor
|
||||
@ -909,7 +1089,7 @@ func (b *Buffer) ClearCursors() {
|
||||
b.cursors = b.cursors[:1]
|
||||
b.UpdateCursors()
|
||||
b.curCursor = 0
|
||||
b.GetActiveCursor().ResetSelection()
|
||||
b.GetActiveCursor().Deselect(true)
|
||||
}
|
||||
|
||||
// MoveLinesUp moves the range of lines up one row
|
||||
@ -960,34 +1140,14 @@ var BracePairs = [][2]rune{
|
||||
{'[', ']'},
|
||||
}
|
||||
|
||||
// FindMatchingBrace returns the location in the buffer of the matching bracket
|
||||
// It is given a brace type containing the open and closing character, (for example
|
||||
// '{' and '}') as well as the location to match from
|
||||
// TODO: maybe can be more efficient with utf8 package
|
||||
// returns the location of the matching brace
|
||||
// if the boolean returned is true then the original matching brace is one character left
|
||||
// of the starting location
|
||||
func (b *Buffer) FindMatchingBrace(braceType [2]rune, start Loc) (Loc, bool, bool) {
|
||||
curLine := []rune(string(b.LineBytes(start.Y)))
|
||||
startChar := ' '
|
||||
if start.X >= 0 && start.X < len(curLine) {
|
||||
startChar = curLine[start.X]
|
||||
}
|
||||
leftChar := ' '
|
||||
if start.X-1 >= 0 && start.X-1 < len(curLine) {
|
||||
leftChar = curLine[start.X-1]
|
||||
}
|
||||
func (b *Buffer) findMatchingBrace(braceType [2]rune, start Loc, char rune) (Loc, bool) {
|
||||
var i int
|
||||
if startChar == braceType[0] || leftChar == braceType[0] {
|
||||
if char == braceType[0] {
|
||||
for y := start.Y; y < b.LinesNum(); y++ {
|
||||
l := []rune(string(b.LineBytes(y)))
|
||||
xInit := 0
|
||||
if y == start.Y {
|
||||
if startChar == braceType[0] {
|
||||
xInit = start.X
|
||||
} else {
|
||||
xInit = start.X - 1
|
||||
}
|
||||
}
|
||||
for x := xInit; x < len(l); x++ {
|
||||
r := l[x]
|
||||
@ -996,42 +1156,76 @@ func (b *Buffer) FindMatchingBrace(braceType [2]rune, start Loc) (Loc, bool, boo
|
||||
} else if r == braceType[1] {
|
||||
i--
|
||||
if i == 0 {
|
||||
if startChar == braceType[0] {
|
||||
return Loc{x, y}, false, true
|
||||
}
|
||||
return Loc{x, y}, true, true
|
||||
return Loc{x, y}, true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if startChar == braceType[1] || leftChar == braceType[1] {
|
||||
} else if char == braceType[1] {
|
||||
for y := start.Y; y >= 0; y-- {
|
||||
l := []rune(string(b.lines[y].data))
|
||||
xInit := len(l) - 1
|
||||
if y == start.Y {
|
||||
if leftChar == braceType[1] {
|
||||
xInit = start.X - 1
|
||||
} else {
|
||||
xInit = start.X
|
||||
}
|
||||
}
|
||||
for x := xInit; x >= 0; x-- {
|
||||
r := l[x]
|
||||
if r == braceType[0] {
|
||||
if r == braceType[1] {
|
||||
i++
|
||||
} else if r == braceType[0] {
|
||||
i--
|
||||
if i == 0 {
|
||||
if leftChar == braceType[1] {
|
||||
return Loc{x, y}, true, true
|
||||
}
|
||||
return Loc{x, y}, false, true
|
||||
}
|
||||
} else if r == braceType[1] {
|
||||
i++
|
||||
return Loc{x, y}, true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return start, true, false
|
||||
}
|
||||
return start, false
|
||||
}
|
||||
|
||||
// If there is a brace character (for example '{' or ']') at the given start location,
|
||||
// FindMatchingBrace returns the location of the matching brace for it (for example '}'
|
||||
// or '['). The second returned value is true if there was no matching brace found
|
||||
// for given starting location but it was found for the location one character left
|
||||
// of it. The third returned value is true if the matching brace was found at all.
|
||||
func (b *Buffer) FindMatchingBrace(start Loc) (Loc, bool, bool) {
|
||||
// TODO: maybe can be more efficient with utf8 package
|
||||
curLine := []rune(string(b.LineBytes(start.Y)))
|
||||
|
||||
// first try to find matching brace for the given location (it has higher priority)
|
||||
if start.X >= 0 && start.X < len(curLine) {
|
||||
startChar := curLine[start.X]
|
||||
|
||||
for _, bp := range BracePairs {
|
||||
if startChar == bp[0] || startChar == bp[1] {
|
||||
mb, found := b.findMatchingBrace(bp, start, startChar)
|
||||
if found {
|
||||
return mb, false, true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if b.Settings["matchbraceleft"].(bool) {
|
||||
// failed to find matching brace for the given location, so try to find matching
|
||||
// brace for the location one character left of it
|
||||
if start.X-1 >= 0 && start.X-1 < len(curLine) {
|
||||
leftChar := curLine[start.X-1]
|
||||
left := Loc{start.X - 1, start.Y}
|
||||
|
||||
for _, bp := range BracePairs {
|
||||
if leftChar == bp[0] || leftChar == bp[1] {
|
||||
mb, found := b.findMatchingBrace(bp, left, leftChar)
|
||||
if found {
|
||||
return mb, true, true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return start, false, false
|
||||
}
|
||||
|
||||
// Retab changes all tabs to spaces or vice versa
|
||||
@ -1053,7 +1247,11 @@ func (b *Buffer) Retab() {
|
||||
}
|
||||
|
||||
l = bytes.TrimLeft(l, " \t")
|
||||
|
||||
b.Lock()
|
||||
b.lines[i].data = append(ws, l...)
|
||||
b.Unlock()
|
||||
|
||||
b.MarkModified(i, i)
|
||||
dirty = true
|
||||
}
|
||||
@ -1096,7 +1294,7 @@ func (b *Buffer) Write(bytes []byte) (n int, err error) {
|
||||
return len(bytes), nil
|
||||
}
|
||||
|
||||
func (b *Buffer) updateDiffSync() {
|
||||
func (b *Buffer) updateDiff(synchronous bool) {
|
||||
b.diffLock.Lock()
|
||||
defer b.diffLock.Unlock()
|
||||
|
||||
@ -1107,7 +1305,16 @@ func (b *Buffer) updateDiffSync() {
|
||||
}
|
||||
|
||||
differ := dmp.New()
|
||||
baseRunes, bufferRunes, _ := differ.DiffLinesToRunes(string(b.diffBase), string(b.Bytes()))
|
||||
|
||||
if !synchronous {
|
||||
b.Lock()
|
||||
}
|
||||
bytes := b.Bytes()
|
||||
if !synchronous {
|
||||
b.Unlock()
|
||||
}
|
||||
|
||||
baseRunes, bufferRunes, _ := differ.DiffLinesToRunes(string(b.diffBase), string(bytes))
|
||||
diffs := differ.DiffMainRunes(baseRunes, bufferRunes, false)
|
||||
lineN := 0
|
||||
|
||||
@ -1136,13 +1343,9 @@ func (b *Buffer) updateDiffSync() {
|
||||
|
||||
// UpdateDiff computes the diff between the diff base and the buffer content.
|
||||
// The update may be performed synchronously or asynchronously.
|
||||
// UpdateDiff calls the supplied callback when the update is complete.
|
||||
// The argument passed to the callback is set to true if and only if
|
||||
// the update was performed synchronously.
|
||||
// If an asynchronous update is already pending when UpdateDiff is called,
|
||||
// UpdateDiff does not schedule another update, in which case the callback
|
||||
// is not called.
|
||||
func (b *Buffer) UpdateDiff(callback func(bool)) {
|
||||
// UpdateDiff does not schedule another update.
|
||||
func (b *Buffer) UpdateDiff() {
|
||||
if b.updateDiffTimer != nil {
|
||||
return
|
||||
}
|
||||
@ -1153,20 +1356,18 @@ func (b *Buffer) UpdateDiff(callback func(bool)) {
|
||||
}
|
||||
|
||||
if lineCount < 1000 {
|
||||
b.updateDiffSync()
|
||||
callback(true)
|
||||
b.updateDiff(true)
|
||||
} else if lineCount < 30000 {
|
||||
b.updateDiffTimer = time.AfterFunc(500*time.Millisecond, func() {
|
||||
b.updateDiffTimer = nil
|
||||
b.updateDiffSync()
|
||||
callback(false)
|
||||
b.updateDiff(false)
|
||||
screen.Redraw()
|
||||
})
|
||||
} else {
|
||||
// Don't compute diffs for very large files
|
||||
b.diffLock.Lock()
|
||||
b.diff = make(map[int]DiffStatus)
|
||||
b.diffLock.Unlock()
|
||||
callback(true)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1178,9 +1379,7 @@ func (b *Buffer) SetDiffBase(diffBase []byte) {
|
||||
} else {
|
||||
b.diffBaseLineCount = strings.Count(string(diffBase), "\n")
|
||||
}
|
||||
b.UpdateDiff(func(synchronous bool) {
|
||||
screen.Redraw()
|
||||
})
|
||||
b.UpdateDiff()
|
||||
}
|
||||
|
||||
// DiffStatus returns the diff status for a line in the buffer
|
||||
@ -1191,6 +1390,47 @@ func (b *Buffer) DiffStatus(lineN int) DiffStatus {
|
||||
return b.diff[lineN]
|
||||
}
|
||||
|
||||
// FindNextDiffLine returns the line number of the next block of diffs.
|
||||
// If `startLine` is already in a block of diffs, lines in that block are skipped.
|
||||
func (b *Buffer) FindNextDiffLine(startLine int, forward bool) (int, error) {
|
||||
if b.diff == nil {
|
||||
return 0, errors.New("no diff data")
|
||||
}
|
||||
startStatus, ok := b.diff[startLine]
|
||||
if !ok {
|
||||
startStatus = DSUnchanged
|
||||
}
|
||||
curLine := startLine
|
||||
for {
|
||||
curStatus, ok := b.diff[curLine]
|
||||
if !ok {
|
||||
curStatus = DSUnchanged
|
||||
}
|
||||
if curLine < 0 || curLine > b.LinesNum() {
|
||||
return 0, errors.New("no next diff hunk")
|
||||
}
|
||||
if curStatus != startStatus {
|
||||
if startStatus != DSUnchanged && curStatus == DSUnchanged {
|
||||
// Skip over the block of unchanged text
|
||||
startStatus = DSUnchanged
|
||||
} else {
|
||||
return curLine, nil
|
||||
}
|
||||
}
|
||||
if forward {
|
||||
curLine++
|
||||
} else {
|
||||
curLine--
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SearchMatch returns true if the given location is within a match of the last search.
|
||||
// It is used for search highlighting
|
||||
func (b *Buffer) SearchMatch(pos Loc) bool {
|
||||
return b.LineArray.SearchMatch(b, pos)
|
||||
}
|
||||
|
||||
// WriteLog writes a string to the log buffer
|
||||
func WriteLog(s string) {
|
||||
LogBuf.EventHandler.Insert(LogBuf.End(), s)
|
||||
|
@ -20,6 +20,7 @@ type operation struct {
|
||||
|
||||
func init() {
|
||||
ulua.L = lua.NewState()
|
||||
config.InitRuntimeFiles(false)
|
||||
config.InitGlobalSettings()
|
||||
config.GlobalSettings["backup"] = false
|
||||
config.GlobalSettings["fastdirty"] = true
|
||||
|
@ -20,8 +20,14 @@ type Cursor struct {
|
||||
buf *Buffer
|
||||
Loc
|
||||
|
||||
// Last cursor x position
|
||||
// Last visual x position of the cursor. Used in cursor up/down movements
|
||||
// for remembering the original x position when moving to a line that is
|
||||
// shorter than current x position.
|
||||
LastVisualX int
|
||||
// Similar to LastVisualX but takes softwrapping into account, i.e. last
|
||||
// visual x position in a visual (wrapped) line on the screen, which may be
|
||||
// different from the line in the buffer.
|
||||
LastWrappedVisualX int
|
||||
|
||||
// The current selection as a range of character numbers (inclusive)
|
||||
CurSelection [2]Loc
|
||||
@ -30,6 +36,11 @@ type Cursor struct {
|
||||
// to know what the original selection was
|
||||
OrigSelection [2]Loc
|
||||
|
||||
// The line number where a new trailing whitespace has been added
|
||||
// or -1 if there is no new trailing whitespace at this cursor.
|
||||
// This is used for checking if a trailing whitespace should be highlighted
|
||||
NewTrailingWsY int
|
||||
|
||||
// Which cursor index is this (for multiple cursors)
|
||||
Num int
|
||||
}
|
||||
@ -38,6 +49,8 @@ func NewCursor(b *Buffer, l Loc) *Cursor {
|
||||
c := &Cursor{
|
||||
buf: b,
|
||||
Loc: l,
|
||||
|
||||
NewTrailingWsY: -1,
|
||||
}
|
||||
c.StoreVisualX()
|
||||
return c
|
||||
@ -54,8 +67,9 @@ func (c *Cursor) Buf() *Buffer {
|
||||
// Goto puts the cursor at the given cursor's location and gives
|
||||
// the current cursor its selection too
|
||||
func (c *Cursor) Goto(b Cursor) {
|
||||
c.X, c.Y, c.LastVisualX = b.X, b.Y, b.LastVisualX
|
||||
c.X, c.Y = b.X, b.Y
|
||||
c.OrigSelection, c.CurSelection = b.OrigSelection, b.CurSelection
|
||||
c.StoreVisualX()
|
||||
}
|
||||
|
||||
// GotoLoc puts the cursor at the given cursor's location and gives
|
||||
@ -66,8 +80,8 @@ func (c *Cursor) GotoLoc(l Loc) {
|
||||
}
|
||||
|
||||
// GetVisualX returns the x value of the cursor in visual spaces
|
||||
func (c *Cursor) GetVisualX() int {
|
||||
if c.buf.GetVisualX != nil {
|
||||
func (c *Cursor) GetVisualX(wrap bool) int {
|
||||
if wrap && c.buf.GetVisualX != nil {
|
||||
return c.buf.GetVisualX(c.Loc)
|
||||
}
|
||||
|
||||
@ -93,7 +107,7 @@ func (c *Cursor) GetCharPosInLine(b []byte, visualPos int) int {
|
||||
// Start moves the cursor to the start of the line it is on
|
||||
func (c *Cursor) Start() {
|
||||
c.X = 0
|
||||
c.LastVisualX = c.GetVisualX()
|
||||
c.StoreVisualX()
|
||||
}
|
||||
|
||||
// StartOfText moves the cursor to the first non-whitespace rune of
|
||||
@ -124,7 +138,7 @@ func (c *Cursor) IsStartOfText() bool {
|
||||
// End moves the cursor to the end of the line it is on
|
||||
func (c *Cursor) End() {
|
||||
c.X = util.CharacterCount(c.buf.LineBytes(c.Y))
|
||||
c.LastVisualX = c.GetVisualX()
|
||||
c.StoreVisualX()
|
||||
}
|
||||
|
||||
// CopySelection copies the user's selection to either "primary"
|
||||
@ -179,7 +193,7 @@ func (c *Cursor) Deselect(start bool) {
|
||||
if start {
|
||||
c.Loc = c.CurSelection[0]
|
||||
} else {
|
||||
c.Loc = c.CurSelection[1].Move(-1, c.buf)
|
||||
c.Loc = c.CurSelection[1]
|
||||
}
|
||||
c.ResetSelection()
|
||||
c.StoreVisualX()
|
||||
@ -396,13 +410,26 @@ func (c *Cursor) SelectTo(loc Loc) {
|
||||
|
||||
// WordRight moves the cursor one word to the right
|
||||
func (c *Cursor) WordRight() {
|
||||
for util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
c.Right()
|
||||
return
|
||||
}
|
||||
for util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
return
|
||||
}
|
||||
c.Right()
|
||||
}
|
||||
if util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) &&
|
||||
util.IsNonWordChar(c.RuneUnder(c.X+1)) {
|
||||
for util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
return
|
||||
}
|
||||
c.Right()
|
||||
}
|
||||
return
|
||||
}
|
||||
c.Right()
|
||||
for util.IsWordChar(c.RuneUnder(c.X)) {
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
@ -414,6 +441,10 @@ func (c *Cursor) WordRight() {
|
||||
|
||||
// WordLeft moves the cursor one word to the left
|
||||
func (c *Cursor) WordLeft() {
|
||||
if c.X == 0 {
|
||||
c.Left()
|
||||
return
|
||||
}
|
||||
c.Left()
|
||||
for util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
if c.X == 0 {
|
||||
@ -421,6 +452,17 @@ func (c *Cursor) WordLeft() {
|
||||
}
|
||||
c.Left()
|
||||
}
|
||||
if util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) &&
|
||||
util.IsNonWordChar(c.RuneUnder(c.X-1)) {
|
||||
for util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
if c.X == 0 {
|
||||
return
|
||||
}
|
||||
c.Left()
|
||||
}
|
||||
c.Right()
|
||||
return
|
||||
}
|
||||
c.Left()
|
||||
for util.IsWordChar(c.RuneUnder(c.X)) {
|
||||
if c.X == 0 {
|
||||
@ -431,6 +473,132 @@ func (c *Cursor) WordLeft() {
|
||||
c.Right()
|
||||
}
|
||||
|
||||
// SubWordRight moves the cursor one sub-word to the right
|
||||
func (c *Cursor) SubWordRight() {
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
c.Right()
|
||||
return
|
||||
}
|
||||
if util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
for util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
return
|
||||
}
|
||||
c.Right()
|
||||
}
|
||||
return
|
||||
}
|
||||
if util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
for util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
return
|
||||
}
|
||||
c.Right()
|
||||
}
|
||||
return
|
||||
}
|
||||
if util.IsSubwordDelimiter(c.RuneUnder(c.X)) {
|
||||
for util.IsSubwordDelimiter(c.RuneUnder(c.X)) {
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
return
|
||||
}
|
||||
c.Right()
|
||||
}
|
||||
if util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
return
|
||||
}
|
||||
if util.IsUpperLetter(c.RuneUnder(c.X)) &&
|
||||
util.IsUpperLetter(c.RuneUnder(c.X+1)) {
|
||||
for util.IsUpperAlphanumeric(c.RuneUnder(c.X)) {
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
return
|
||||
}
|
||||
c.Right()
|
||||
}
|
||||
if util.IsLowerAlphanumeric(c.RuneUnder(c.X)) {
|
||||
c.Left()
|
||||
}
|
||||
} else {
|
||||
c.Right()
|
||||
for util.IsLowerAlphanumeric(c.RuneUnder(c.X)) {
|
||||
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
|
||||
return
|
||||
}
|
||||
c.Right()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SubWordLeft moves the cursor one sub-word to the left
|
||||
func (c *Cursor) SubWordLeft() {
|
||||
if c.X == 0 {
|
||||
c.Left()
|
||||
return
|
||||
}
|
||||
c.Left()
|
||||
if util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
for util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
if c.X == 0 {
|
||||
return
|
||||
}
|
||||
c.Left()
|
||||
}
|
||||
c.Right()
|
||||
return
|
||||
}
|
||||
if util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
for util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
if c.X == 0 {
|
||||
return
|
||||
}
|
||||
c.Left()
|
||||
}
|
||||
c.Right()
|
||||
return
|
||||
}
|
||||
if util.IsSubwordDelimiter(c.RuneUnder(c.X)) {
|
||||
for util.IsSubwordDelimiter(c.RuneUnder(c.X)) {
|
||||
if c.X == 0 {
|
||||
return
|
||||
}
|
||||
c.Left()
|
||||
}
|
||||
if util.IsWhitespace(c.RuneUnder(c.X)) {
|
||||
c.Right()
|
||||
return
|
||||
}
|
||||
}
|
||||
if c.X == 0 {
|
||||
return
|
||||
}
|
||||
if util.IsUpperLetter(c.RuneUnder(c.X)) &&
|
||||
util.IsUpperLetter(c.RuneUnder(c.X-1)) {
|
||||
for util.IsUpperAlphanumeric(c.RuneUnder(c.X)) {
|
||||
if c.X == 0 {
|
||||
return
|
||||
}
|
||||
c.Left()
|
||||
}
|
||||
if !util.IsUpperAlphanumeric(c.RuneUnder(c.X)) {
|
||||
c.Right()
|
||||
}
|
||||
} else {
|
||||
for util.IsLowerAlphanumeric(c.RuneUnder(c.X)) {
|
||||
if c.X == 0 {
|
||||
return
|
||||
}
|
||||
c.Left()
|
||||
}
|
||||
if !util.IsAlphanumeric(c.RuneUnder(c.X)) {
|
||||
c.Right()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RuneUnder returns the rune under the given x position
|
||||
func (c *Cursor) RuneUnder(x int) rune {
|
||||
line := c.buf.LineBytes(c.Y)
|
||||
@ -454,5 +622,6 @@ func (c *Cursor) RuneUnder(x int) rune {
|
||||
}
|
||||
|
||||
func (c *Cursor) StoreVisualX() {
|
||||
c.LastVisualX = c.GetVisualX()
|
||||
c.LastVisualX = c.GetVisualX(false)
|
||||
c.LastWrappedVisualX = c.GetVisualX(true)
|
||||
}
|
||||
|
@ -104,7 +104,11 @@ func (eh *EventHandler) DoTextEvent(t *TextEvent, useUndo bool) {
|
||||
c.OrigSelection[0] = move(c.OrigSelection[0])
|
||||
c.OrigSelection[1] = move(c.OrigSelection[1])
|
||||
c.Relocate()
|
||||
c.LastVisualX = c.GetVisualX()
|
||||
c.StoreVisualX()
|
||||
}
|
||||
|
||||
if useUndo {
|
||||
eh.updateTrailingWs(t)
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,7 +241,7 @@ func (eh *EventHandler) Execute(t *TextEvent) {
|
||||
}
|
||||
eh.UndoStack.Push(t)
|
||||
|
||||
b, err := config.RunPluginFnBool("onBeforeTextEvent", luar.New(ulua.L, eh.buf), luar.New(ulua.L, t))
|
||||
b, err := config.RunPluginFnBool(nil, "onBeforeTextEvent", luar.New(ulua.L, eh.buf), luar.New(ulua.L, t))
|
||||
if err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
@ -249,11 +253,11 @@ func (eh *EventHandler) Execute(t *TextEvent) {
|
||||
ExecuteTextEvent(t, eh.buf)
|
||||
}
|
||||
|
||||
// Undo the first event in the undo stack
|
||||
func (eh *EventHandler) Undo() {
|
||||
// Undo the first event in the undo stack. Returns false if the stack is empty.
|
||||
func (eh *EventHandler) Undo() bool {
|
||||
t := eh.UndoStack.Peek()
|
||||
if t == nil {
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
startTime := t.Time.UnixNano() / int64(time.Millisecond)
|
||||
@ -262,15 +266,16 @@ func (eh *EventHandler) Undo() {
|
||||
for {
|
||||
t = eh.UndoStack.Peek()
|
||||
if t == nil {
|
||||
return
|
||||
break
|
||||
}
|
||||
|
||||
if t.Time.UnixNano()/int64(time.Millisecond) < endTime {
|
||||
return
|
||||
break
|
||||
}
|
||||
|
||||
eh.UndoOneEvent()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// UndoOneEvent undoes one event
|
||||
@ -286,23 +291,20 @@ func (eh *EventHandler) UndoOneEvent() {
|
||||
eh.UndoTextEvent(t)
|
||||
|
||||
// Set the cursor in the right place
|
||||
teCursor := t.C
|
||||
if teCursor.Num >= 0 && teCursor.Num < len(eh.cursors) {
|
||||
t.C = *eh.cursors[teCursor.Num]
|
||||
eh.cursors[teCursor.Num].Goto(teCursor)
|
||||
} else {
|
||||
teCursor.Num = -1
|
||||
if t.C.Num >= 0 && t.C.Num < len(eh.cursors) {
|
||||
eh.cursors[t.C.Num].Goto(t.C)
|
||||
eh.cursors[t.C.Num].NewTrailingWsY = t.C.NewTrailingWsY
|
||||
}
|
||||
|
||||
// Push it to the redo stack
|
||||
eh.RedoStack.Push(t)
|
||||
}
|
||||
|
||||
// Redo the first event in the redo stack
|
||||
func (eh *EventHandler) Redo() {
|
||||
// Redo the first event in the redo stack. Returns false if the stack is empty.
|
||||
func (eh *EventHandler) Redo() bool {
|
||||
t := eh.RedoStack.Peek()
|
||||
if t == nil {
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
startTime := t.Time.UnixNano() / int64(time.Millisecond)
|
||||
@ -311,15 +313,16 @@ func (eh *EventHandler) Redo() {
|
||||
for {
|
||||
t = eh.RedoStack.Peek()
|
||||
if t == nil {
|
||||
return
|
||||
break
|
||||
}
|
||||
|
||||
if t.Time.UnixNano()/int64(time.Millisecond) > endTime {
|
||||
return
|
||||
break
|
||||
}
|
||||
|
||||
eh.RedoOneEvent()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// RedoOneEvent redoes one event
|
||||
@ -329,12 +332,9 @@ func (eh *EventHandler) RedoOneEvent() {
|
||||
return
|
||||
}
|
||||
|
||||
teCursor := t.C
|
||||
if teCursor.Num >= 0 && teCursor.Num < len(eh.cursors) {
|
||||
t.C = *eh.cursors[teCursor.Num]
|
||||
eh.cursors[teCursor.Num].Goto(teCursor)
|
||||
} else {
|
||||
teCursor.Num = -1
|
||||
if t.C.Num >= 0 && t.C.Num < len(eh.cursors) {
|
||||
eh.cursors[t.C.Num].Goto(t.C)
|
||||
eh.cursors[t.C.Num].NewTrailingWsY = t.C.NewTrailingWsY
|
||||
}
|
||||
|
||||
// Modifies the text event
|
||||
@ -342,3 +342,58 @@ func (eh *EventHandler) RedoOneEvent() {
|
||||
|
||||
eh.UndoStack.Push(t)
|
||||
}
|
||||
|
||||
// updateTrailingWs updates the cursor's trailing whitespace status after a text event
|
||||
func (eh *EventHandler) updateTrailingWs(t *TextEvent) {
|
||||
if len(t.Deltas) != 1 {
|
||||
return
|
||||
}
|
||||
text := t.Deltas[0].Text
|
||||
start := t.Deltas[0].Start
|
||||
end := t.Deltas[0].End
|
||||
|
||||
c := eh.cursors[eh.active]
|
||||
isEol := func(loc Loc) bool {
|
||||
return loc.X == util.CharacterCount(eh.buf.LineBytes(loc.Y))
|
||||
}
|
||||
if t.EventType == TextEventInsert && c.Loc == end && isEol(end) {
|
||||
var addedTrailingWs bool
|
||||
addedAfterWs := false
|
||||
addedWsOnly := false
|
||||
if start.Y == end.Y {
|
||||
addedTrailingWs = util.HasTrailingWhitespace(text)
|
||||
addedWsOnly = util.IsBytesWhitespace(text)
|
||||
addedAfterWs = start.X > 0 && util.IsWhitespace(c.buf.RuneAt(Loc{start.X - 1, start.Y}))
|
||||
} else {
|
||||
lastnl := bytes.LastIndex(text, []byte{'\n'})
|
||||
addedTrailingWs = util.HasTrailingWhitespace(text[lastnl+1:])
|
||||
}
|
||||
|
||||
if addedTrailingWs && !(addedAfterWs && addedWsOnly) {
|
||||
c.NewTrailingWsY = c.Y
|
||||
} else if !addedTrailingWs {
|
||||
c.NewTrailingWsY = -1
|
||||
}
|
||||
} else if t.EventType == TextEventRemove && c.Loc == start && isEol(start) {
|
||||
removedAfterWs := util.HasTrailingWhitespace(eh.buf.LineBytes(start.Y))
|
||||
var removedWsOnly bool
|
||||
if start.Y == end.Y {
|
||||
removedWsOnly = util.IsBytesWhitespace(text)
|
||||
} else {
|
||||
firstnl := bytes.Index(text, []byte{'\n'})
|
||||
removedWsOnly = util.IsBytesWhitespace(text[:firstnl])
|
||||
}
|
||||
|
||||
if removedAfterWs && !removedWsOnly {
|
||||
c.NewTrailingWsY = c.Y
|
||||
} else if !removedAfterWs {
|
||||
c.NewTrailingWsY = -1
|
||||
}
|
||||
} else if c.NewTrailingWsY != -1 && start.Y != end.Y && c.Loc.GreaterThan(start) &&
|
||||
((t.EventType == TextEventInsert && c.Y == c.NewTrailingWsY+(end.Y-start.Y)) ||
|
||||
(t.EventType == TextEventRemove && c.Y == c.NewTrailingWsY-(end.Y-start.Y))) {
|
||||
// The cursor still has its new trailingws
|
||||
// but its line number was shifted by insert or remove of lines above
|
||||
c.NewTrailingWsY = c.Y
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,15 @@ func runeToByteIndex(n int, txt []byte) int {
|
||||
return count
|
||||
}
|
||||
|
||||
// A searchState contains the search match info for a single line
|
||||
type searchState struct {
|
||||
search string
|
||||
useRegex bool
|
||||
ignorecase bool
|
||||
match [][2]int
|
||||
done bool
|
||||
}
|
||||
|
||||
// A Line contains the data in bytes as well as a highlight state, match
|
||||
// and a flag for whether the highlighting needs to be updated
|
||||
type Line struct {
|
||||
@ -39,8 +48,15 @@ type Line struct {
|
||||
|
||||
state highlight.State
|
||||
match highlight.LineMatch
|
||||
rehighlight bool
|
||||
lock sync.Mutex
|
||||
|
||||
// The search states for the line, used for highlighting of search matches,
|
||||
// separately from the syntax highlighting.
|
||||
// A map is used because the line array may be shared between multiple buffers
|
||||
// (multiple instances of the same file opened in different edit panes)
|
||||
// which have distinct searches, so in the general case there are multiple
|
||||
// searches per a line, one search per a Buffer containing this line.
|
||||
search map[*Buffer]*searchState
|
||||
}
|
||||
|
||||
const (
|
||||
@ -58,6 +74,7 @@ type LineArray struct {
|
||||
lines []Line
|
||||
Endings FileFormat
|
||||
initsize uint64
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
// Append efficiently appends lines together
|
||||
@ -99,12 +116,12 @@ func NewLineArray(size uint64, endings FileFormat, reader io.Reader) *LineArray
|
||||
dlen := len(data)
|
||||
if dlen > 1 && data[dlen-2] == '\r' {
|
||||
data = append(data[:dlen-2], '\n')
|
||||
if endings == FFAuto {
|
||||
if la.Endings == FFAuto {
|
||||
la.Endings = FFDos
|
||||
}
|
||||
dlen = len(data)
|
||||
} else if dlen > 0 {
|
||||
if endings == FFAuto {
|
||||
if la.Endings == FFAuto {
|
||||
la.Endings = FFUnix
|
||||
}
|
||||
}
|
||||
@ -133,7 +150,6 @@ func NewLineArray(size uint64, endings FileFormat, reader io.Reader) *LineArray
|
||||
data: data,
|
||||
state: nil,
|
||||
match: nil,
|
||||
rehighlight: false,
|
||||
})
|
||||
}
|
||||
// Last line was read
|
||||
@ -143,7 +159,6 @@ func NewLineArray(size uint64, endings FileFormat, reader io.Reader) *LineArray
|
||||
data: data[:dlen-1],
|
||||
state: nil,
|
||||
match: nil,
|
||||
rehighlight: false,
|
||||
})
|
||||
}
|
||||
n++
|
||||
@ -176,19 +191,20 @@ func (la *LineArray) newlineBelow(y int) {
|
||||
data: []byte{' '},
|
||||
state: nil,
|
||||
match: nil,
|
||||
rehighlight: false,
|
||||
})
|
||||
copy(la.lines[y+2:], la.lines[y+1:])
|
||||
la.lines[y+1] = Line{
|
||||
data: []byte{},
|
||||
state: la.lines[y].state,
|
||||
match: nil,
|
||||
rehighlight: false,
|
||||
}
|
||||
}
|
||||
|
||||
// Inserts a byte array at a given location
|
||||
func (la *LineArray) insert(pos Loc, value []byte) {
|
||||
la.lock.Lock()
|
||||
defer la.lock.Unlock()
|
||||
|
||||
x, y := runeToByteIndex(pos.X, la.lines[pos.Y].data), pos.Y
|
||||
for i := 0; i < len(value); i++ {
|
||||
if value[i] == '\n' || (value[i] == '\r' && i < len(value)-1 && value[i+1] == '\n') {
|
||||
@ -216,24 +232,26 @@ func (la *LineArray) insertByte(pos Loc, value byte) {
|
||||
|
||||
// joinLines joins the two lines a and b
|
||||
func (la *LineArray) joinLines(a, b int) {
|
||||
la.insert(Loc{len(la.lines[a].data), a}, la.lines[b].data)
|
||||
la.lines[a].data = append(la.lines[a].data, la.lines[b].data...)
|
||||
la.deleteLine(b)
|
||||
}
|
||||
|
||||
// split splits a line at a given position
|
||||
func (la *LineArray) split(pos Loc) {
|
||||
la.newlineBelow(pos.Y)
|
||||
la.insert(Loc{0, pos.Y + 1}, la.lines[pos.Y].data[pos.X:])
|
||||
la.lines[pos.Y+1].data = append(la.lines[pos.Y+1].data, la.lines[pos.Y].data[pos.X:]...)
|
||||
la.lines[pos.Y+1].state = la.lines[pos.Y].state
|
||||
la.lines[pos.Y].state = nil
|
||||
la.lines[pos.Y].match = nil
|
||||
la.lines[pos.Y+1].match = nil
|
||||
la.lines[pos.Y].rehighlight = true
|
||||
la.deleteToEnd(Loc{pos.X, pos.Y})
|
||||
}
|
||||
|
||||
// removes from start to end
|
||||
func (la *LineArray) remove(start, end Loc) []byte {
|
||||
la.lock.Lock()
|
||||
defer la.lock.Unlock()
|
||||
|
||||
sub := la.Substr(start, end)
|
||||
startX := runeToByteIndex(start.X, la.lines[start.Y].data)
|
||||
endX := runeToByteIndex(end.X, la.lines[end.Y].data)
|
||||
@ -267,11 +285,6 @@ func (la *LineArray) deleteLines(y1, y2 int) {
|
||||
la.lines = la.lines[:y1+copy(la.lines[y1:], la.lines[y2+1:])]
|
||||
}
|
||||
|
||||
// DeleteByte deletes the byte at a position
|
||||
func (la *LineArray) deleteByte(pos Loc) {
|
||||
la.lines[pos.Y].data = la.lines[pos.Y].data[:pos.X+copy(la.lines[pos.Y].data[pos.X:], la.lines[pos.Y].data[pos.X+1:])]
|
||||
}
|
||||
|
||||
// Substr returns the string representation between two locations
|
||||
func (la *LineArray) Substr(start, end Loc) []byte {
|
||||
startX := runeToByteIndex(start.X, la.lines[start.Y].data)
|
||||
@ -310,11 +323,11 @@ func (la *LineArray) End() Loc {
|
||||
}
|
||||
|
||||
// LineBytes returns line n as an array of bytes
|
||||
func (la *LineArray) LineBytes(n int) []byte {
|
||||
if n >= len(la.lines) || n < 0 {
|
||||
func (la *LineArray) LineBytes(lineN int) []byte {
|
||||
if lineN >= len(la.lines) || lineN < 0 {
|
||||
return []byte{}
|
||||
}
|
||||
return la.lines[n].data
|
||||
return la.lines[lineN].data
|
||||
}
|
||||
|
||||
// State gets the highlight state for the given line number
|
||||
@ -345,14 +358,88 @@ func (la *LineArray) Match(lineN int) highlight.LineMatch {
|
||||
return la.lines[lineN].match
|
||||
}
|
||||
|
||||
func (la *LineArray) Rehighlight(lineN int) bool {
|
||||
la.lines[lineN].lock.Lock()
|
||||
defer la.lines[lineN].lock.Unlock()
|
||||
return la.lines[lineN].rehighlight
|
||||
// Locks the whole LineArray
|
||||
func (la *LineArray) Lock() {
|
||||
la.lock.Lock()
|
||||
}
|
||||
|
||||
func (la *LineArray) SetRehighlight(lineN int, on bool) {
|
||||
la.lines[lineN].lock.Lock()
|
||||
defer la.lines[lineN].lock.Unlock()
|
||||
la.lines[lineN].rehighlight = on
|
||||
// Unlocks the whole LineArray
|
||||
func (la *LineArray) Unlock() {
|
||||
la.lock.Unlock()
|
||||
}
|
||||
|
||||
// SearchMatch returns true if the location `pos` is within a match
|
||||
// of the last search for the buffer `b`.
|
||||
// It is used for efficient highlighting of search matches (separately
|
||||
// from the syntax highlighting).
|
||||
// SearchMatch searches for the matches if it is called first time
|
||||
// for the given line or if the line was modified. Otherwise the
|
||||
// previously found matches are used.
|
||||
//
|
||||
// The buffer `b` needs to be passed because the line array may be shared
|
||||
// between multiple buffers (multiple instances of the same file opened
|
||||
// in different edit panes) which have distinct searches, so SearchMatch
|
||||
// needs to know which search to match against.
|
||||
func (la *LineArray) SearchMatch(b *Buffer, pos Loc) bool {
|
||||
if b.LastSearch == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
lineN := pos.Y
|
||||
if la.lines[lineN].search == nil {
|
||||
la.lines[lineN].search = make(map[*Buffer]*searchState)
|
||||
}
|
||||
s, ok := la.lines[lineN].search[b]
|
||||
if !ok {
|
||||
// Note: here is a small harmless leak: when the buffer `b` is closed,
|
||||
// `s` is not deleted from the map. It means that the buffer
|
||||
// will not be garbage-collected until the line array is garbage-collected,
|
||||
// i.e. until all the buffers sharing this file are closed.
|
||||
s = new(searchState)
|
||||
la.lines[lineN].search[b] = s
|
||||
}
|
||||
if !ok || s.search != b.LastSearch || s.useRegex != b.LastSearchRegex ||
|
||||
s.ignorecase != b.Settings["ignorecase"].(bool) {
|
||||
s.search = b.LastSearch
|
||||
s.useRegex = b.LastSearchRegex
|
||||
s.ignorecase = b.Settings["ignorecase"].(bool)
|
||||
s.done = false
|
||||
}
|
||||
|
||||
if !s.done {
|
||||
s.match = nil
|
||||
start := Loc{0, lineN}
|
||||
end := Loc{util.CharacterCount(la.lines[lineN].data), lineN}
|
||||
for start.X < end.X {
|
||||
m, found, _ := b.FindNext(b.LastSearch, start, end, start, true, b.LastSearchRegex)
|
||||
if !found {
|
||||
break
|
||||
}
|
||||
s.match = append(s.match, [2]int{m[0].X, m[1].X})
|
||||
|
||||
start.X = m[1].X
|
||||
if m[1].X == m[0].X {
|
||||
start.X = m[1].X + 1
|
||||
}
|
||||
}
|
||||
|
||||
s.done = true
|
||||
}
|
||||
|
||||
for _, m := range s.match {
|
||||
if pos.X >= m[0] && pos.X < m[1] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// invalidateSearchMatches marks search matches for the given line as outdated.
|
||||
// It is called when the line is modified.
|
||||
func (la *LineArray) invalidateSearchMatches(lineN int) {
|
||||
if la.lines[lineN].search != nil {
|
||||
for _, s := range la.lines[lineN].search {
|
||||
s.done = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,16 @@ func (l Loc) LessEqual(b Loc) bool {
|
||||
return l == b
|
||||
}
|
||||
|
||||
// Clamp clamps a loc between start and end
|
||||
func (l Loc) Clamp(start, end Loc) Loc {
|
||||
if l.GreaterEqual(end) {
|
||||
return end
|
||||
} else if l.LessThan(start) {
|
||||
return start
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
// The following functions require a buffer to know where newlines are
|
||||
|
||||
// Diff returns the distance between two locations
|
||||
@ -139,10 +149,5 @@ func ByteOffset(pos Loc, buf *Buffer) int {
|
||||
|
||||
// clamps a loc within a buffer
|
||||
func clamp(pos Loc, la *LineArray) Loc {
|
||||
if pos.GreaterEqual(la.End()) {
|
||||
return la.End()
|
||||
} else if pos.LessThan(la.Start()) {
|
||||
return la.Start()
|
||||
}
|
||||
return pos
|
||||
return pos.Clamp(la.Start(), la.End())
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package buffer
|
||||
|
||||
import (
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
)
|
||||
|
||||
type MsgType int
|
||||
@ -82,3 +82,13 @@ func (b *Buffer) ClearMessages(owner string) {
|
||||
func (b *Buffer) ClearAllMessages() {
|
||||
b.Messages = make([]*Message, 0)
|
||||
}
|
||||
|
||||
type Messager interface {
|
||||
Message(msg ...interface{})
|
||||
}
|
||||
|
||||
var prompt Messager
|
||||
|
||||
func SetMessager(m Messager) {
|
||||
prompt = m
|
||||
}
|
||||
|
@ -5,18 +5,19 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
"golang.org/x/text/encoding"
|
||||
"golang.org/x/text/encoding/htmlindex"
|
||||
"golang.org/x/text/transform"
|
||||
)
|
||||
|
||||
@ -24,46 +25,178 @@ import (
|
||||
// because hashing is too slow
|
||||
const LargeFileThreshold = 50000
|
||||
|
||||
// overwriteFile opens the given file for writing, truncating if one exists, and then calls
|
||||
// the supplied function with the file as io.Writer object, also making sure the file is
|
||||
// closed afterwards.
|
||||
func overwriteFile(name string, enc encoding.Encoding, fn func(io.Writer) error, withSudo bool) (err error) {
|
||||
type wrappedFile struct {
|
||||
writeCloser io.WriteCloser
|
||||
withSudo bool
|
||||
screenb bool
|
||||
cmd *exec.Cmd
|
||||
sigChan chan os.Signal
|
||||
}
|
||||
|
||||
type saveResponse struct {
|
||||
size int
|
||||
err error
|
||||
}
|
||||
|
||||
type saveRequest struct {
|
||||
buf *Buffer
|
||||
path string
|
||||
withSudo bool
|
||||
newFile bool
|
||||
saveResponseChan chan saveResponse
|
||||
}
|
||||
|
||||
var saveRequestChan chan saveRequest
|
||||
var backupRequestChan chan *Buffer
|
||||
|
||||
func init() {
|
||||
saveRequestChan = make(chan saveRequest, 10)
|
||||
backupRequestChan = make(chan *Buffer, 10)
|
||||
|
||||
go func() {
|
||||
duration := backupSeconds * float64(time.Second)
|
||||
backupTicker := time.NewTicker(time.Duration(duration))
|
||||
|
||||
for {
|
||||
select {
|
||||
case sr := <-saveRequestChan:
|
||||
size, err := sr.buf.safeWrite(sr.path, sr.withSudo, sr.newFile)
|
||||
sr.saveResponseChan <- saveResponse{size, err}
|
||||
case <-backupTicker.C:
|
||||
for len(backupRequestChan) > 0 {
|
||||
b := <-backupRequestChan
|
||||
bfini := atomic.LoadInt32(&(b.fini)) != 0
|
||||
if !bfini {
|
||||
b.Backup()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func openFile(name string, withSudo bool) (wrappedFile, error) {
|
||||
var err error
|
||||
var writeCloser io.WriteCloser
|
||||
var screenb bool
|
||||
var cmd *exec.Cmd
|
||||
var sigChan chan os.Signal
|
||||
|
||||
if withSudo {
|
||||
cmd := exec.Command(config.GlobalSettings["sucmd"].(string), "dd", "bs=4k", "of="+name)
|
||||
|
||||
if writeCloser, err = cmd.StdinPipe(); err != nil {
|
||||
return
|
||||
cmd = exec.Command(config.GlobalSettings["sucmd"].(string), "dd", "bs=4k", "of="+name)
|
||||
writeCloser, err = cmd.StdinPipe()
|
||||
if err != nil {
|
||||
return wrappedFile{}, err
|
||||
}
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
go func() {
|
||||
<-c
|
||||
cmd.Process.Kill()
|
||||
}()
|
||||
sigChan = make(chan os.Signal, 1)
|
||||
signal.Reset(os.Interrupt)
|
||||
signal.Notify(sigChan, os.Interrupt)
|
||||
|
||||
defer func() {
|
||||
screenb := screen.TempFini()
|
||||
if e := cmd.Run(); e != nil && err == nil {
|
||||
err = e
|
||||
}
|
||||
screenb = screen.TempFini()
|
||||
// need to start the process now, otherwise when we flush the file
|
||||
// contents to its stdin it might hang because the kernel's pipe size
|
||||
// is too small to handle the full file contents all at once
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
screen.TempStart(screenb)
|
||||
}()
|
||||
} else if writeCloser, err = os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644); err != nil {
|
||||
return
|
||||
|
||||
signal.Notify(util.Sigterm, os.Interrupt)
|
||||
signal.Stop(sigChan)
|
||||
|
||||
return wrappedFile{}, err
|
||||
}
|
||||
} else {
|
||||
writeCloser, err = os.OpenFile(name, os.O_WRONLY|os.O_CREATE, util.FileMode)
|
||||
if err != nil {
|
||||
return wrappedFile{}, err
|
||||
}
|
||||
}
|
||||
|
||||
w := bufio.NewWriter(transform.NewWriter(writeCloser, enc.NewEncoder()))
|
||||
err = fn(w)
|
||||
w.Flush()
|
||||
|
||||
if e := writeCloser.Close(); e != nil && err == nil {
|
||||
err = e
|
||||
return wrappedFile{writeCloser, withSudo, screenb, cmd, sigChan}, nil
|
||||
}
|
||||
|
||||
return
|
||||
func (wf wrappedFile) Write(b *Buffer) (int, error) {
|
||||
file := bufio.NewWriter(transform.NewWriter(wf.writeCloser, b.encoding.NewEncoder()))
|
||||
|
||||
b.Lock()
|
||||
defer b.Unlock()
|
||||
|
||||
if len(b.lines) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// end of line
|
||||
var eol []byte
|
||||
if b.Endings == FFDos {
|
||||
eol = []byte{'\r', '\n'}
|
||||
} else {
|
||||
eol = []byte{'\n'}
|
||||
}
|
||||
|
||||
if !wf.withSudo {
|
||||
f := wf.writeCloser.(*os.File)
|
||||
err := f.Truncate(0)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
// write lines
|
||||
size, err := file.Write(b.lines[0].data)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
for _, l := range b.lines[1:] {
|
||||
if _, err = file.Write(eol); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if _, err = file.Write(l.data); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
size += len(eol) + len(l.data)
|
||||
}
|
||||
|
||||
err = file.Flush()
|
||||
if err == nil && !wf.withSudo {
|
||||
// Call Sync() on the file to make sure the content is safely on disk.
|
||||
f := wf.writeCloser.(*os.File)
|
||||
err = f.Sync()
|
||||
}
|
||||
return size, err
|
||||
}
|
||||
|
||||
func (wf wrappedFile) Close() error {
|
||||
err := wf.writeCloser.Close()
|
||||
if wf.withSudo {
|
||||
// wait for dd to finish and restart the screen if we used sudo
|
||||
err := wf.cmd.Wait()
|
||||
screen.TempStart(wf.screenb)
|
||||
|
||||
signal.Notify(util.Sigterm, os.Interrupt)
|
||||
signal.Stop(wf.sigChan)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (b *Buffer) overwriteFile(name string) (int, error) {
|
||||
file, err := openFile(name, false)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
size, err := file.Write(b)
|
||||
|
||||
err2 := file.Close()
|
||||
if err2 != nil && err == nil {
|
||||
err = err2
|
||||
}
|
||||
return size, err
|
||||
}
|
||||
|
||||
// Save saves the buffer to its default path
|
||||
@ -71,9 +204,19 @@ func (b *Buffer) Save() error {
|
||||
return b.SaveAs(b.Path)
|
||||
}
|
||||
|
||||
// AutoSave saves the buffer to its default path
|
||||
func (b *Buffer) AutoSave() error {
|
||||
// Doing full b.Modified() check every time would be costly, due to the hash
|
||||
// calculation. So use just isModified even if fastdirty is not set.
|
||||
if !b.isModified {
|
||||
return nil
|
||||
}
|
||||
return b.saveToFile(b.Path, false, true)
|
||||
}
|
||||
|
||||
// SaveAs saves the buffer to a specified path (filename), creating the file if it does not exist
|
||||
func (b *Buffer) SaveAs(filename string) error {
|
||||
return b.saveToFile(filename, false)
|
||||
return b.saveToFile(filename, false, false)
|
||||
}
|
||||
|
||||
func (b *Buffer) SaveWithSudo() error {
|
||||
@ -81,10 +224,10 @@ func (b *Buffer) SaveWithSudo() error {
|
||||
}
|
||||
|
||||
func (b *Buffer) SaveAsWithSudo(filename string) error {
|
||||
return b.saveToFile(filename, true)
|
||||
return b.saveToFile(filename, true, false)
|
||||
}
|
||||
|
||||
func (b *Buffer) saveToFile(filename string, withSudo bool) error {
|
||||
func (b *Buffer) saveToFile(filename string, withSudo bool, autoSave bool) error {
|
||||
var err error
|
||||
if b.Type.Readonly {
|
||||
return errors.New("Cannot save readonly buffer")
|
||||
@ -96,7 +239,7 @@ func (b *Buffer) saveToFile(filename string, withSudo bool) error {
|
||||
return errors.New("Save with sudo not supported on Windows")
|
||||
}
|
||||
|
||||
if b.Settings["rmtrailingws"].(bool) {
|
||||
if !autoSave && b.Settings["rmtrailingws"].(bool) {
|
||||
for i, l := range b.lines {
|
||||
leftover := util.CharacterCount(bytes.TrimRightFunc(l.data, unicode.IsSpace))
|
||||
|
||||
@ -114,19 +257,35 @@ func (b *Buffer) saveToFile(filename string, withSudo bool) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Update the last time this file was updated after saving
|
||||
defer func() {
|
||||
b.ModTime, _ = util.GetModTime(filename)
|
||||
err = b.Serialize()
|
||||
}()
|
||||
filename, err = util.ReplaceHome(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Removes any tilde and replaces with the absolute path to home
|
||||
absFilename, _ := util.ReplaceHome(filename)
|
||||
newFile := false
|
||||
fileInfo, err := os.Stat(filename)
|
||||
if err != nil {
|
||||
if !errors.Is(err, fs.ErrNotExist) {
|
||||
return err
|
||||
}
|
||||
newFile = true
|
||||
}
|
||||
if err == nil && fileInfo.IsDir() {
|
||||
return errors.New("Error: " + filename + " is a directory and cannot be saved")
|
||||
}
|
||||
if err == nil && !fileInfo.Mode().IsRegular() {
|
||||
return errors.New("Error: " + filename + " is not a regular file and cannot be saved")
|
||||
}
|
||||
|
||||
absFilename, err := filepath.Abs(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get the leading path to the file | "." is returned if there's no leading path provided
|
||||
if dirname := filepath.Dir(absFilename); dirname != "." {
|
||||
// Check if the parent dirs don't exist
|
||||
if _, statErr := os.Stat(dirname); os.IsNotExist(statErr) {
|
||||
if _, statErr := os.Stat(dirname); errors.Is(statErr, fs.ErrNotExist) {
|
||||
// Prompt to make sure they want to create the dirs that are missing
|
||||
if b.Settings["mkparents"].(bool) {
|
||||
// Create all leading dir(s) since they don't exist
|
||||
@ -140,49 +299,22 @@ func (b *Buffer) saveToFile(filename string, withSudo bool) error {
|
||||
}
|
||||
}
|
||||
|
||||
var fileSize int
|
||||
|
||||
enc, err := htmlindex.Get(b.Settings["encoding"].(string))
|
||||
saveResponseChan := make(chan saveResponse)
|
||||
saveRequestChan <- saveRequest{b, absFilename, withSudo, newFile, saveResponseChan}
|
||||
result := <-saveResponseChan
|
||||
err = result.err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if errors.Is(err, util.ErrOverwrite) {
|
||||
screen.TermMessage(err)
|
||||
err = errors.Unwrap(err)
|
||||
|
||||
fwriter := func(file io.Writer) (e error) {
|
||||
if len(b.lines) == 0 {
|
||||
return
|
||||
b.UpdateModTime()
|
||||
}
|
||||
|
||||
// end of line
|
||||
var eol []byte
|
||||
if b.Endings == FFDos {
|
||||
eol = []byte{'\r', '\n'}
|
||||
} else {
|
||||
eol = []byte{'\n'}
|
||||
}
|
||||
|
||||
// write lines
|
||||
if fileSize, e = file.Write(b.lines[0].data); e != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, l := range b.lines[1:] {
|
||||
if _, e = file.Write(eol); e != nil {
|
||||
return
|
||||
}
|
||||
if _, e = file.Write(l.data); e != nil {
|
||||
return
|
||||
}
|
||||
fileSize += len(eol) + len(l.data)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err = overwriteFile(absFilename, enc, fwriter, withSudo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !b.Settings["fastdirty"].(bool) {
|
||||
if fileSize > LargeFileThreshold {
|
||||
if result.size > LargeFileThreshold {
|
||||
// For large files 'fastdirty' needs to be on
|
||||
b.Settings["fastdirty"] = true
|
||||
} else {
|
||||
@ -190,10 +322,70 @@ func (b *Buffer) saveToFile(filename string, withSudo bool) error {
|
||||
}
|
||||
}
|
||||
|
||||
newPath := b.Path != filename
|
||||
b.Path = filename
|
||||
absPath, _ := filepath.Abs(filename)
|
||||
b.AbsPath = absPath
|
||||
b.AbsPath = absFilename
|
||||
b.isModified = false
|
||||
b.UpdateRules()
|
||||
b.UpdateModTime()
|
||||
|
||||
if newPath {
|
||||
// need to update glob-based and filetype-based settings
|
||||
b.ReloadSettings(true)
|
||||
}
|
||||
|
||||
err = b.Serialize()
|
||||
return err
|
||||
}
|
||||
|
||||
// safeWrite writes the buffer to a file in a "safe" way, preventing loss of the
|
||||
// contents of the file if it fails to write the new contents.
|
||||
// This means that the file is not overwritten directly but by writing to the
|
||||
// backup file first.
|
||||
func (b *Buffer) safeWrite(path string, withSudo bool, newFile bool) (int, error) {
|
||||
file, err := openFile(path, withSudo)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if newFile && err != nil {
|
||||
os.Remove(path)
|
||||
}
|
||||
}()
|
||||
|
||||
backupDir := b.backupDir()
|
||||
if _, err := os.Stat(backupDir); err != nil {
|
||||
if !errors.Is(err, fs.ErrNotExist) {
|
||||
return 0, err
|
||||
}
|
||||
if err = os.Mkdir(backupDir, os.ModePerm); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
backupName := util.DetermineEscapePath(backupDir, path)
|
||||
_, err = b.overwriteFile(backupName)
|
||||
if err != nil {
|
||||
os.Remove(backupName)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
b.forceKeepBackup = true
|
||||
size, err := file.Write(b)
|
||||
if err != nil {
|
||||
err = util.OverwriteError{err, backupName}
|
||||
return size, err
|
||||
}
|
||||
b.forceKeepBackup = false
|
||||
|
||||
if !b.keepBackup() {
|
||||
os.Remove(backupName)
|
||||
}
|
||||
|
||||
err2 := file.Close()
|
||||
if err2 != nil && err == nil {
|
||||
err = err2
|
||||
}
|
||||
|
||||
return size, err
|
||||
}
|
||||
|
@ -2,10 +2,56 @@ package buffer
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
)
|
||||
|
||||
// We want "^" and "$" to match only the beginning/end of a line, not the
|
||||
// beginning/end of the search region if it is in the middle of a line.
|
||||
// In that case we use padded regexps to require a rune before or after
|
||||
// the match. (This also affects other empty-string patters like "\\b".)
|
||||
// The following two flags indicate the padding used.
|
||||
const (
|
||||
padStart = 1 << iota
|
||||
padEnd
|
||||
)
|
||||
|
||||
func findLineParams(b *Buffer, start, end Loc, i int, r *regexp.Regexp) ([]byte, int, int, *regexp.Regexp) {
|
||||
l := b.LineBytes(i)
|
||||
charpos := 0
|
||||
padMode := 0
|
||||
|
||||
if i == end.Y {
|
||||
nchars := util.CharacterCount(l)
|
||||
end.X = util.Clamp(end.X, 0, nchars)
|
||||
if end.X < nchars {
|
||||
l = util.SliceStart(l, end.X+1)
|
||||
padMode |= padEnd
|
||||
}
|
||||
}
|
||||
|
||||
if i == start.Y {
|
||||
nchars := util.CharacterCount(l)
|
||||
start.X = util.Clamp(start.X, 0, nchars)
|
||||
if start.X > 0 {
|
||||
charpos = start.X - 1
|
||||
l = util.SliceEnd(l, charpos)
|
||||
padMode |= padStart
|
||||
}
|
||||
}
|
||||
|
||||
if padMode == padStart {
|
||||
r = regexp.MustCompile(".(?:" + r.String() + ")")
|
||||
} else if padMode == padEnd {
|
||||
r = regexp.MustCompile("(?:" + r.String() + ").")
|
||||
} else if padMode == padStart|padEnd {
|
||||
r = regexp.MustCompile(".(?:" + r.String() + ").")
|
||||
}
|
||||
|
||||
return l, charpos, padMode, r
|
||||
}
|
||||
|
||||
func (b *Buffer) findDown(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) {
|
||||
lastcn := util.CharacterCount(b.LineBytes(b.LinesNum() - 1))
|
||||
if start.Y > b.LinesNum()-1 {
|
||||
@ -22,30 +68,19 @@ func (b *Buffer) findDown(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) {
|
||||
}
|
||||
|
||||
for i := start.Y; i <= end.Y; i++ {
|
||||
l := b.LineBytes(i)
|
||||
charpos := 0
|
||||
l, charpos, padMode, rPadded := findLineParams(b, start, end, i, r)
|
||||
|
||||
if i == start.Y && start.Y == end.Y {
|
||||
nchars := util.CharacterCount(l)
|
||||
start.X = util.Clamp(start.X, 0, nchars)
|
||||
end.X = util.Clamp(end.X, 0, nchars)
|
||||
l = util.SliceStart(l, end.X)
|
||||
l = util.SliceEnd(l, start.X)
|
||||
charpos = start.X
|
||||
} else if i == start.Y {
|
||||
nchars := util.CharacterCount(l)
|
||||
start.X = util.Clamp(start.X, 0, nchars)
|
||||
l = util.SliceEnd(l, start.X)
|
||||
charpos = start.X
|
||||
} else if i == end.Y {
|
||||
nchars := util.CharacterCount(l)
|
||||
end.X = util.Clamp(end.X, 0, nchars)
|
||||
l = util.SliceStart(l, end.X)
|
||||
}
|
||||
|
||||
match := r.FindIndex(l)
|
||||
match := rPadded.FindIndex(l)
|
||||
|
||||
if match != nil {
|
||||
if padMode&padStart != 0 {
|
||||
_, size := utf8.DecodeRune(l[match[0]:])
|
||||
match[0] += size
|
||||
}
|
||||
if padMode&padEnd != 0 {
|
||||
_, size := utf8.DecodeLastRune(l[:match[1]])
|
||||
match[1] -= size
|
||||
}
|
||||
start := Loc{charpos + util.RunePos(l, match[0]), i}
|
||||
end := Loc{charpos + util.RunePos(l, match[1]), i}
|
||||
return [2]Loc{start, end}, true
|
||||
@ -70,38 +105,39 @@ func (b *Buffer) findUp(r *regexp.Regexp, start, end Loc) ([2]Loc, bool) {
|
||||
}
|
||||
|
||||
for i := end.Y; i >= start.Y; i-- {
|
||||
l := b.LineBytes(i)
|
||||
charpos := 0
|
||||
charCount := util.CharacterCount(b.LineBytes(i))
|
||||
from := Loc{0, i}.Clamp(start, end)
|
||||
to := Loc{charCount, i}.Clamp(start, end)
|
||||
|
||||
if i == start.Y && start.Y == end.Y {
|
||||
nchars := util.CharacterCount(l)
|
||||
start.X = util.Clamp(start.X, 0, nchars)
|
||||
end.X = util.Clamp(end.X, 0, nchars)
|
||||
l = util.SliceStart(l, end.X)
|
||||
l = util.SliceEnd(l, start.X)
|
||||
charpos = start.X
|
||||
} else if i == start.Y {
|
||||
nchars := util.CharacterCount(l)
|
||||
start.X = util.Clamp(start.X, 0, nchars)
|
||||
l = util.SliceEnd(l, start.X)
|
||||
charpos = start.X
|
||||
} else if i == end.Y {
|
||||
nchars := util.CharacterCount(l)
|
||||
end.X = util.Clamp(end.X, 0, nchars)
|
||||
l = util.SliceStart(l, end.X)
|
||||
}
|
||||
|
||||
match := r.FindIndex(l)
|
||||
|
||||
if match != nil {
|
||||
start := Loc{charpos + util.RunePos(l, match[0]), i}
|
||||
end := Loc{charpos + util.RunePos(l, match[1]), i}
|
||||
return [2]Loc{start, end}, true
|
||||
allMatches := b.findAll(r, from, to)
|
||||
if allMatches != nil {
|
||||
match := allMatches[len(allMatches)-1]
|
||||
return [2]Loc{match[0], match[1]}, true
|
||||
}
|
||||
}
|
||||
return [2]Loc{}, false
|
||||
}
|
||||
|
||||
func (b *Buffer) findAll(r *regexp.Regexp, start, end Loc) [][2]Loc {
|
||||
var matches [][2]Loc
|
||||
loc := start
|
||||
for {
|
||||
match, found := b.findDown(r, loc, end)
|
||||
if !found {
|
||||
break
|
||||
}
|
||||
matches = append(matches, match)
|
||||
if match[0] != match[1] {
|
||||
loc = match[1]
|
||||
} else if match[1] != end {
|
||||
loc = match[1].Move(1, b)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return matches
|
||||
}
|
||||
|
||||
// FindNext finds the next occurrence of a given string in the buffer
|
||||
// It returns the start and end location of the match (if found) and
|
||||
// a boolean indicating if it was found
|
||||
@ -145,49 +181,58 @@ func (b *Buffer) FindNext(s string, start, end, from Loc, down bool, useRegex bo
|
||||
}
|
||||
|
||||
// ReplaceRegex replaces all occurrences of 'search' with 'replace' in the given area
|
||||
// and returns the number of replacements made and the number of runes
|
||||
// and returns the number of replacements made and the number of characters
|
||||
// added or removed on the last line of the range
|
||||
func (b *Buffer) ReplaceRegex(start, end Loc, search *regexp.Regexp, replace []byte) (int, int) {
|
||||
func (b *Buffer) ReplaceRegex(start, end Loc, search *regexp.Regexp, replace []byte, captureGroups bool) (int, int) {
|
||||
if start.GreaterThan(end) {
|
||||
start, end = end, start
|
||||
}
|
||||
|
||||
netrunes := 0
|
||||
|
||||
charsEnd := util.CharacterCount(b.LineBytes(end.Y))
|
||||
found := 0
|
||||
var deltas []Delta
|
||||
for i := start.Y; i <= end.Y; i++ {
|
||||
l := b.lines[i].data
|
||||
charpos := 0
|
||||
|
||||
if start.Y == end.Y && i == start.Y {
|
||||
l = util.SliceStart(l, end.X)
|
||||
l = util.SliceEnd(l, start.X)
|
||||
charpos = start.X
|
||||
} else if i == start.Y {
|
||||
l = util.SliceEnd(l, start.X)
|
||||
charpos = start.X
|
||||
} else if i == end.Y {
|
||||
l = util.SliceStart(l, end.X)
|
||||
for i := start.Y; i <= end.Y; i++ {
|
||||
l := b.LineBytes(i)
|
||||
charCount := util.CharacterCount(l)
|
||||
if (i == start.Y && start.X > 0) || (i == end.Y && end.X < charCount) {
|
||||
// This replacement code works in general, but it creates a separate
|
||||
// modification for each match. We only use it for the first and last
|
||||
// lines, which may use padded regexps
|
||||
|
||||
from := Loc{0, i}.Clamp(start, end)
|
||||
to := Loc{charCount, i}.Clamp(start, end)
|
||||
matches := b.findAll(search, from, to)
|
||||
found += len(matches)
|
||||
|
||||
for j := len(matches) - 1; j >= 0; j-- {
|
||||
// if we counted upwards, the different deltas would interfere
|
||||
match := matches[j]
|
||||
var newText []byte
|
||||
if captureGroups {
|
||||
newText = search.ReplaceAll(b.Substr(match[0], match[1]), replace)
|
||||
} else {
|
||||
newText = replace
|
||||
}
|
||||
newText := search.ReplaceAllFunc(l, func(in []byte) []byte {
|
||||
result := []byte{}
|
||||
for _, submatches := range search.FindAllSubmatchIndex(in, -1) {
|
||||
result = search.Expand(result, replace, in, submatches)
|
||||
deltas = append(deltas, Delta{newText, match[0], match[1]})
|
||||
}
|
||||
} else {
|
||||
newLine := search.ReplaceAllFunc(l, func(in []byte) []byte {
|
||||
found++
|
||||
if i == end.Y {
|
||||
netrunes += util.CharacterCount(result) - util.CharacterCount(in)
|
||||
var result []byte
|
||||
if captureGroups {
|
||||
match := search.FindSubmatchIndex(in)
|
||||
result = search.Expand(result, replace, in, match)
|
||||
} else {
|
||||
result = replace
|
||||
}
|
||||
return result
|
||||
})
|
||||
|
||||
from := Loc{charpos, i}
|
||||
to := Loc{charpos + util.CharacterCount(l), i}
|
||||
|
||||
deltas = append(deltas, Delta{newText, from, to})
|
||||
deltas = append(deltas, Delta{newLine, Loc{0, i}, Loc{charCount, i}})
|
||||
}
|
||||
}
|
||||
|
||||
b.MultipleReplace(deltas)
|
||||
|
||||
return found, netrunes
|
||||
return found, util.CharacterCount(b.LineBytes(end.Y)) - charsEnd
|
||||
}
|
||||
|
@ -1,15 +1,13 @@
|
||||
package buffer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"golang.org/x/text/encoding"
|
||||
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
)
|
||||
@ -31,16 +29,18 @@ func (b *Buffer) Serialize() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
name := filepath.Join(config.ConfigDir, "buffers", util.EscapePath(b.AbsPath))
|
||||
|
||||
return overwriteFile(name, encoding.Nop, func(file io.Writer) error {
|
||||
err := gob.NewEncoder(file).Encode(SerializedBuffer{
|
||||
var buf bytes.Buffer
|
||||
err := gob.NewEncoder(&buf).Encode(SerializedBuffer{
|
||||
b.EventHandler,
|
||||
b.GetActiveCursor().Loc,
|
||||
b.ModTime,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}, false)
|
||||
}
|
||||
|
||||
name := util.DetermineEscapePath(filepath.Join(config.ConfigDir, "buffers"), b.AbsPath)
|
||||
return util.SafeWrite(name, buf.Bytes(), true)
|
||||
}
|
||||
|
||||
// Unserialize loads the buffer info from config.ConfigDir/buffers
|
||||
@ -50,7 +50,7 @@ func (b *Buffer) Unserialize() error {
|
||||
if b.Path == "" {
|
||||
return nil
|
||||
}
|
||||
file, err := os.Open(filepath.Join(config.ConfigDir, "buffers", util.EscapePath(b.AbsPath)))
|
||||
file, err := os.Open(util.DetermineEscapePath(filepath.Join(config.ConfigDir, "buffers"), b.AbsPath))
|
||||
if err == nil {
|
||||
defer file.Close()
|
||||
var buffer SerializedBuffer
|
||||
|
@ -1,26 +1,89 @@
|
||||
package buffer
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"reflect"
|
||||
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
ulua "github.com/zyedidia/micro/v2/internal/lua"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"golang.org/x/text/encoding/htmlindex"
|
||||
"golang.org/x/text/encoding/unicode"
|
||||
luar "layeh.com/gopher-luar"
|
||||
)
|
||||
|
||||
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
|
||||
func (b *Buffer) ReloadSettings(reloadFiletype bool) {
|
||||
settings := config.ParsedSettings()
|
||||
config.UpdatePathGlobLocals(settings, b.AbsPath)
|
||||
|
||||
oldFiletype := b.Settings["filetype"].(string)
|
||||
|
||||
_, local := b.LocalSettings["filetype"]
|
||||
_, volatile := config.VolatileSettings["filetype"]
|
||||
if reloadFiletype && !local && !volatile {
|
||||
// need to update filetype before updating other settings based on it
|
||||
b.Settings["filetype"] = "unknown"
|
||||
if v, ok := settings["filetype"]; ok {
|
||||
b.Settings["filetype"] = v
|
||||
}
|
||||
}
|
||||
|
||||
// update syntax rules, which will also update filetype if needed
|
||||
b.UpdateRules()
|
||||
|
||||
curFiletype := b.Settings["filetype"].(string)
|
||||
if oldFiletype != curFiletype {
|
||||
b.doCallbacks("filetype", oldFiletype, curFiletype)
|
||||
}
|
||||
|
||||
config.UpdateFileTypeLocals(settings, curFiletype)
|
||||
|
||||
for k, v := range config.DefaultCommonSettings() {
|
||||
if k == "filetype" {
|
||||
// prevent recursion
|
||||
continue
|
||||
}
|
||||
if _, ok := config.VolatileSettings[k]; ok {
|
||||
// reload should not override volatile settings
|
||||
continue
|
||||
}
|
||||
if _, ok := b.LocalSettings[k]; ok {
|
||||
// reload should not override local settings
|
||||
continue
|
||||
}
|
||||
if _, ok := settings[k]; ok {
|
||||
b.DoSetOptionNative(k, settings[k])
|
||||
} else {
|
||||
b.DoSetOptionNative(k, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
|
||||
oldValue := b.Settings[option]
|
||||
if reflect.DeepEqual(oldValue, nativeValue) {
|
||||
return
|
||||
}
|
||||
|
||||
b.Settings[option] = nativeValue
|
||||
|
||||
if option == "fastdirty" {
|
||||
if !nativeValue.(bool) {
|
||||
if !b.Modified() {
|
||||
e := calcHash(b, &b.origHash)
|
||||
if e == ErrFileTooLarge {
|
||||
b.Settings["fastdirty"] = false
|
||||
if b.Size() > LargeFileThreshold {
|
||||
b.Settings["fastdirty"] = true
|
||||
} else {
|
||||
if !b.isModified {
|
||||
calcHash(b, &b.origHash)
|
||||
} else {
|
||||
// prevent using an old stale origHash value
|
||||
b.origHash = [md5.Size]byte{}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if option == "statusline" {
|
||||
screen.Redraw()
|
||||
} else if option == "filetype" {
|
||||
b.UpdateRules()
|
||||
b.ReloadSettings(false)
|
||||
} else if option == "fileformat" {
|
||||
switch b.Settings["fileformat"].(string) {
|
||||
case "unix":
|
||||
@ -36,15 +99,53 @@ func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
|
||||
b.UpdateRules()
|
||||
}
|
||||
} else if option == "encoding" {
|
||||
enc, err := htmlindex.Get(b.Settings["encoding"].(string))
|
||||
if err != nil {
|
||||
enc = unicode.UTF8
|
||||
b.Settings["encoding"] = "utf-8"
|
||||
}
|
||||
b.encoding = enc
|
||||
b.isModified = true
|
||||
} else if option == "readonly" && b.Type.Kind == BTDefault.Kind {
|
||||
b.Type.Readonly = nativeValue.(bool)
|
||||
} else if option == "hlsearch" {
|
||||
for _, buf := range OpenBuffers {
|
||||
if b.SharedBuffer == buf.SharedBuffer {
|
||||
buf.HighlightSearch = nativeValue.(bool)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, pl := range config.Plugins {
|
||||
if option == pl.Name {
|
||||
if nativeValue.(bool) {
|
||||
if !pl.Loaded {
|
||||
pl.Load()
|
||||
}
|
||||
_, err := pl.Call("init")
|
||||
if err != nil && err != config.ErrNoSuchFunction {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
} else if !nativeValue.(bool) && pl.Loaded {
|
||||
_, err := pl.Call("deinit")
|
||||
if err != nil && err != config.ErrNoSuchFunction {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if b.OptionCallback != nil {
|
||||
b.OptionCallback(option, nativeValue)
|
||||
b.doCallbacks(option, oldValue, nativeValue)
|
||||
}
|
||||
|
||||
func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error {
|
||||
if err := config.OptionIsValid(option, nativeValue); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.DoSetOptionNative(option, nativeValue)
|
||||
b.LocalSettings[option] = true
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -61,3 +162,15 @@ func (b *Buffer) SetOption(option, value string) error {
|
||||
|
||||
return b.SetOptionNative(option, nativeValue)
|
||||
}
|
||||
|
||||
func (b *Buffer) doCallbacks(option string, oldValue interface{}, newValue interface{}) {
|
||||
if b.OptionCallback != nil {
|
||||
b.OptionCallback(option, newValue)
|
||||
}
|
||||
|
||||
if err := config.RunPluginFn("onBufferOptionChanged",
|
||||
luar.New(ulua.L, b), luar.New(ulua.L, option),
|
||||
luar.New(ulua.L, oldValue), luar.New(ulua.L, newValue)); err != nil {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package clipboard
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/zyedidia/clipboard"
|
||||
"github.com/zyedidia/clipper"
|
||||
)
|
||||
|
||||
type Method int
|
||||
@ -35,12 +35,19 @@ const (
|
||||
PrimaryReg = -2
|
||||
)
|
||||
|
||||
var clipboard clipper.Clipboard
|
||||
|
||||
// Initialize attempts to initialize the clipboard using the given method
|
||||
func Initialize(m Method) error {
|
||||
var err error
|
||||
switch m {
|
||||
case External:
|
||||
err = clipboard.Initialize()
|
||||
clips := make([]clipper.Clipboard, 0, len(clipper.Clipboards)+1)
|
||||
clips = append(clips, &clipper.Custom{
|
||||
Name: "micro-clip",
|
||||
})
|
||||
clips = append(clips, clipper.Clipboards...)
|
||||
clipboard, err = clipper.GetClipboard(clips...)
|
||||
}
|
||||
if err != nil {
|
||||
CurrentMethod = Internal
|
||||
@ -104,9 +111,11 @@ func read(r Register, m Method) (string, error) {
|
||||
case External:
|
||||
switch r {
|
||||
case ClipboardReg:
|
||||
return clipboard.ReadAll("clipboard")
|
||||
b, e := clipboard.ReadAll(clipper.RegClipboard)
|
||||
return string(b), e
|
||||
case PrimaryReg:
|
||||
return clipboard.ReadAll("primary")
|
||||
b, e := clipboard.ReadAll(clipper.RegPrimary)
|
||||
return string(b), e
|
||||
default:
|
||||
return internal.read(r), nil
|
||||
}
|
||||
@ -132,9 +141,9 @@ func write(text string, r Register, m Method) error {
|
||||
case External:
|
||||
switch r {
|
||||
case ClipboardReg:
|
||||
return clipboard.WriteAll(text, "clipboard")
|
||||
return clipboard.WriteAll(clipper.RegClipboard, []byte(text))
|
||||
case PrimaryReg:
|
||||
return clipboard.WriteAll(text, "primary")
|
||||
return clipboard.WriteAll(clipper.RegPrimary, []byte(text))
|
||||
default:
|
||||
internal.write(text, r)
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
)
|
||||
|
||||
type terminalClipboard struct{}
|
||||
|
@ -1,44 +1,49 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var Autosave chan bool
|
||||
var autotime int
|
||||
|
||||
// lock for autosave
|
||||
var autolock sync.Mutex
|
||||
var autotime chan float64
|
||||
|
||||
func init() {
|
||||
Autosave = make(chan bool)
|
||||
autotime = make(chan float64)
|
||||
}
|
||||
|
||||
func SetAutoTime(a int) {
|
||||
autolock.Lock()
|
||||
autotime = a
|
||||
autolock.Unlock()
|
||||
}
|
||||
|
||||
func GetAutoTime() int {
|
||||
autolock.Lock()
|
||||
a := autotime
|
||||
autolock.Unlock()
|
||||
return a
|
||||
func SetAutoTime(a float64) {
|
||||
autotime <- a
|
||||
}
|
||||
|
||||
func StartAutoSave() {
|
||||
go func() {
|
||||
var a float64
|
||||
var t *time.Timer
|
||||
var elapsed <-chan time.Time
|
||||
for {
|
||||
autolock.Lock()
|
||||
a := autotime
|
||||
autolock.Unlock()
|
||||
if a < 1 {
|
||||
break
|
||||
select {
|
||||
case a = <-autotime:
|
||||
if t != nil {
|
||||
t.Stop()
|
||||
for len(elapsed) > 0 {
|
||||
<-elapsed
|
||||
}
|
||||
time.Sleep(time.Duration(a) * time.Second)
|
||||
}
|
||||
if a > 0 {
|
||||
if t != nil {
|
||||
t.Reset(time.Duration(a * float64(time.Second)))
|
||||
} else {
|
||||
t = time.NewTimer(time.Duration(a * float64(time.Second)))
|
||||
elapsed = t.C
|
||||
}
|
||||
}
|
||||
case <-elapsed:
|
||||
if a > 0 {
|
||||
t.Reset(time.Duration(a * float64(time.Second)))
|
||||
Autosave <- true
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
@ -6,13 +6,13 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
)
|
||||
|
||||
// Micro's default style
|
||||
// DefStyle is Micro's default style
|
||||
var DefStyle tcell.Style = tcell.StyleDefault
|
||||
|
||||
// The current colorscheme
|
||||
// Colorscheme is the current colorscheme
|
||||
var Colorscheme map[string]tcell.Style
|
||||
|
||||
// GetColor takes in a syntax group and returns the colorscheme's style for that group
|
||||
@ -52,43 +52,55 @@ func InitColorscheme() error {
|
||||
Colorscheme = make(map[string]tcell.Style)
|
||||
DefStyle = tcell.StyleDefault
|
||||
|
||||
return LoadDefaultColorscheme()
|
||||
c, err := LoadDefaultColorscheme()
|
||||
if err == nil {
|
||||
Colorscheme = c
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// LoadDefaultColorscheme loads the default colorscheme from $(ConfigDir)/colorschemes
|
||||
func LoadDefaultColorscheme() error {
|
||||
return LoadColorscheme(GlobalSettings["colorscheme"].(string))
|
||||
func LoadDefaultColorscheme() (map[string]tcell.Style, error) {
|
||||
var parsedColorschemes []string
|
||||
return LoadColorscheme(GlobalSettings["colorscheme"].(string), &parsedColorschemes)
|
||||
}
|
||||
|
||||
// LoadColorscheme loads the given colorscheme from a directory
|
||||
func LoadColorscheme(colorschemeName string) error {
|
||||
func LoadColorscheme(colorschemeName string, parsedColorschemes *[]string) (map[string]tcell.Style, error) {
|
||||
c := make(map[string]tcell.Style)
|
||||
file := FindRuntimeFile(RTColorscheme, colorschemeName)
|
||||
if file == nil {
|
||||
return errors.New(colorschemeName + " is not a valid colorscheme")
|
||||
return c, errors.New(colorschemeName + " is not a valid colorscheme")
|
||||
}
|
||||
if data, err := file.Data(); err != nil {
|
||||
return errors.New("Error loading colorscheme: " + err.Error())
|
||||
return c, errors.New("Error loading colorscheme: " + err.Error())
|
||||
} else {
|
||||
Colorscheme, err = ParseColorscheme(string(data))
|
||||
var err error
|
||||
c, err = ParseColorscheme(file.Name(), string(data), parsedColorschemes)
|
||||
if err != nil {
|
||||
return err
|
||||
return c, err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// ParseColorscheme parses the text definition for a colorscheme and returns the corresponding object
|
||||
// Colorschemes are made up of color-link statements linking a color group to a list of colors
|
||||
// For example, color-link keyword (blue,red) makes all keywords have a blue foreground and
|
||||
// red background
|
||||
func ParseColorscheme(text string) (map[string]tcell.Style, error) {
|
||||
func ParseColorscheme(name string, text string, parsedColorschemes *[]string) (map[string]tcell.Style, error) {
|
||||
var err error
|
||||
parser := regexp.MustCompile(`color-link\s+(\S*)\s+"(.*)"`)
|
||||
|
||||
colorParser := regexp.MustCompile(`color-link\s+(\S*)\s+"(.*)"`)
|
||||
includeParser := regexp.MustCompile(`include\s+"(.*)"`)
|
||||
lines := strings.Split(text, "\n")
|
||||
|
||||
c := make(map[string]tcell.Style)
|
||||
|
||||
if parsedColorschemes != nil {
|
||||
*parsedColorschemes = append(*parsedColorschemes, name)
|
||||
}
|
||||
|
||||
lineLoop:
|
||||
for _, line := range lines {
|
||||
if strings.TrimSpace(line) == "" ||
|
||||
strings.TrimSpace(line)[0] == '#' {
|
||||
@ -96,7 +108,30 @@ func ParseColorscheme(text string) (map[string]tcell.Style, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
matches := parser.FindSubmatch([]byte(line))
|
||||
matches := includeParser.FindSubmatch([]byte(line))
|
||||
if len(matches) == 2 {
|
||||
// support includes only in case parsedColorschemes are given
|
||||
if parsedColorschemes != nil {
|
||||
include := string(matches[1])
|
||||
for _, name := range *parsedColorschemes {
|
||||
// check for circular includes...
|
||||
if name == include {
|
||||
// ...and prevent them
|
||||
continue lineLoop
|
||||
}
|
||||
}
|
||||
includeScheme, err := LoadColorscheme(include, parsedColorschemes)
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
for k, v := range includeScheme {
|
||||
c[k] = v
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
matches = colorParser.FindSubmatch([]byte(line))
|
||||
if len(matches) == 3 {
|
||||
link := string(matches[1])
|
||||
colors := string(matches[2])
|
||||
@ -131,15 +166,22 @@ func StringToStyle(str string) tcell.Style {
|
||||
bg = strings.TrimSpace(bg)
|
||||
|
||||
var fgColor, bgColor tcell.Color
|
||||
if fg == "" {
|
||||
var ok bool
|
||||
if fg == "" || fg == "default" {
|
||||
fgColor, _, _ = DefStyle.Decompose()
|
||||
} else {
|
||||
fgColor = StringToColor(fg)
|
||||
fgColor, ok = StringToColor(fg)
|
||||
if !ok {
|
||||
fgColor, _, _ = DefStyle.Decompose()
|
||||
}
|
||||
if bg == "" {
|
||||
}
|
||||
if bg == "" || bg == "default" {
|
||||
_, bgColor, _ = DefStyle.Decompose()
|
||||
} else {
|
||||
bgColor = StringToColor(bg)
|
||||
bgColor, ok = StringToColor(bg)
|
||||
if !ok {
|
||||
_, bgColor, _ = DefStyle.Decompose()
|
||||
}
|
||||
}
|
||||
|
||||
style := DefStyle.Foreground(fgColor).Background(bgColor)
|
||||
@ -160,49 +202,52 @@ func StringToStyle(str string) tcell.Style {
|
||||
|
||||
// StringToColor returns a tcell color from a string representation of a color
|
||||
// We accept either bright... or light... to mean the brighter version of a color
|
||||
func StringToColor(str string) tcell.Color {
|
||||
func StringToColor(str string) (tcell.Color, bool) {
|
||||
switch str {
|
||||
case "black":
|
||||
return tcell.ColorBlack
|
||||
return tcell.ColorBlack, true
|
||||
case "red":
|
||||
return tcell.ColorMaroon
|
||||
return tcell.ColorMaroon, true
|
||||
case "green":
|
||||
return tcell.ColorGreen
|
||||
return tcell.ColorGreen, true
|
||||
case "yellow":
|
||||
return tcell.ColorOlive
|
||||
return tcell.ColorOlive, true
|
||||
case "blue":
|
||||
return tcell.ColorNavy
|
||||
return tcell.ColorNavy, true
|
||||
case "magenta":
|
||||
return tcell.ColorPurple
|
||||
return tcell.ColorPurple, true
|
||||
case "cyan":
|
||||
return tcell.ColorTeal
|
||||
return tcell.ColorTeal, true
|
||||
case "white":
|
||||
return tcell.ColorSilver
|
||||
return tcell.ColorSilver, true
|
||||
case "brightblack", "lightblack":
|
||||
return tcell.ColorGray
|
||||
return tcell.ColorGray, true
|
||||
case "brightred", "lightred":
|
||||
return tcell.ColorRed
|
||||
return tcell.ColorRed, true
|
||||
case "brightgreen", "lightgreen":
|
||||
return tcell.ColorLime
|
||||
return tcell.ColorLime, true
|
||||
case "brightyellow", "lightyellow":
|
||||
return tcell.ColorYellow
|
||||
return tcell.ColorYellow, true
|
||||
case "brightblue", "lightblue":
|
||||
return tcell.ColorBlue
|
||||
return tcell.ColorBlue, true
|
||||
case "brightmagenta", "lightmagenta":
|
||||
return tcell.ColorFuchsia
|
||||
return tcell.ColorFuchsia, true
|
||||
case "brightcyan", "lightcyan":
|
||||
return tcell.ColorAqua
|
||||
return tcell.ColorAqua, true
|
||||
case "brightwhite", "lightwhite":
|
||||
return tcell.ColorWhite
|
||||
return tcell.ColorWhite, true
|
||||
case "default":
|
||||
return tcell.ColorDefault
|
||||
return tcell.ColorDefault, true
|
||||
default:
|
||||
// Check if this is a 256 color
|
||||
if num, err := strconv.Atoi(str); err == nil {
|
||||
return GetColor256(num)
|
||||
return GetColor256(num), true
|
||||
}
|
||||
// Probably a truecolor hex value
|
||||
return tcell.GetColor(str)
|
||||
// Check if this is a truecolor hex value
|
||||
if len(str) == 7 && str[0] == '#' {
|
||||
return tcell.GetColor(str), true
|
||||
}
|
||||
return tcell.ColorDefault, false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,8 @@ package config
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
)
|
||||
|
||||
func TestSimpleStringToStyle(t *testing.T) {
|
||||
@ -65,7 +65,7 @@ color-link constant "#AE81FF,#282828"
|
||||
color-link constant.string "#E6DB74,#282828"
|
||||
color-link constant.string.char "#BDE6AD,#282828"`
|
||||
|
||||
c, err := ParseColorscheme(testColorscheme)
|
||||
c, err := ParseColorscheme("testColorscheme", testColorscheme, nil)
|
||||
assert.Nil(t, err)
|
||||
|
||||
fg, bg, _ := c["comment"].Decompose()
|
||||
|
@ -28,7 +28,7 @@ func LoadAllPlugins() error {
|
||||
func RunPluginFn(fn string, args ...lua.LValue) error {
|
||||
var reterr error
|
||||
for _, p := range Plugins {
|
||||
if !p.IsEnabled() {
|
||||
if !p.IsLoaded() {
|
||||
continue
|
||||
}
|
||||
_, err := p.Call(fn, args...)
|
||||
@ -42,11 +42,11 @@ func RunPluginFn(fn string, args ...lua.LValue) error {
|
||||
// RunPluginFnBool runs a function in all plugins and returns
|
||||
// false if any one of them returned false
|
||||
// also returns an error if any of the plugins had an error
|
||||
func RunPluginFnBool(fn string, args ...lua.LValue) (bool, error) {
|
||||
func RunPluginFnBool(settings map[string]interface{}, fn string, args ...lua.LValue) (bool, error) {
|
||||
var reterr error
|
||||
retbool := true
|
||||
for _, p := range Plugins {
|
||||
if !p.IsEnabled() {
|
||||
if !p.IsLoaded() || (settings != nil && settings[p.Name] == false) {
|
||||
continue
|
||||
}
|
||||
val, err := p.Call(fn, args...)
|
||||
@ -74,8 +74,8 @@ type Plugin struct {
|
||||
Default bool // pre-installed plugin
|
||||
}
|
||||
|
||||
// IsEnabled returns if a plugin is enabled
|
||||
func (p *Plugin) IsEnabled() bool {
|
||||
// IsLoaded returns if a plugin is enabled
|
||||
func (p *Plugin) IsLoaded() bool {
|
||||
if v, ok := GlobalSettings[p.Name]; ok {
|
||||
return v.(bool) && p.Loaded
|
||||
}
|
||||
@ -101,7 +101,7 @@ func (p *Plugin) Load() error {
|
||||
}
|
||||
}
|
||||
p.Loaded = true
|
||||
RegisterGlobalOption(p.Name, true)
|
||||
RegisterCommonOption(p.Name, true)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ func (p *Plugin) Call(fn string, args ...lua.LValue) (lua.LValue, error) {
|
||||
func FindPlugin(name string) *Plugin {
|
||||
var pl *Plugin
|
||||
for _, p := range Plugins {
|
||||
if !p.IsEnabled() {
|
||||
if !p.IsLoaded() {
|
||||
continue
|
||||
}
|
||||
if p.Name == name {
|
||||
@ -143,15 +143,3 @@ func FindPlugin(name string) *Plugin {
|
||||
}
|
||||
return pl
|
||||
}
|
||||
|
||||
// FindAnyPlugin does not require the plugin to be enabled
|
||||
func FindAnyPlugin(name string) *Plugin {
|
||||
var pl *Plugin
|
||||
for _, p := range Plugins {
|
||||
if p.Name == name {
|
||||
pl = p
|
||||
break
|
||||
}
|
||||
}
|
||||
return pl
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -14,8 +13,8 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/blang/semver"
|
||||
"github.com/micro-editor/json5"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
"github.com/zyedidia/json5"
|
||||
ulua "github.com/zyedidia/micro/v2/internal/lua"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
)
|
||||
@ -363,7 +362,7 @@ func GetInstalledVersions(withCore bool) PluginVersions {
|
||||
}
|
||||
|
||||
for _, p := range Plugins {
|
||||
if !p.IsEnabled() {
|
||||
if !p.IsLoaded() {
|
||||
continue
|
||||
}
|
||||
version := GetInstalledPluginVersion(p.Name)
|
||||
@ -396,7 +395,7 @@ func (pv *PluginVersion) DownloadAndInstall(out io.Writer) error {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -572,7 +571,7 @@ func (pv PluginVersions) install(out io.Writer) {
|
||||
// UninstallPlugin deletes the plugin folder of the given plugin
|
||||
func UninstallPlugin(out io.Writer, name string) {
|
||||
for _, p := range Plugins {
|
||||
if !p.IsEnabled() {
|
||||
if !p.IsLoaded() {
|
||||
continue
|
||||
}
|
||||
if p.Name == name {
|
||||
@ -605,7 +604,7 @@ func UpdatePlugins(out io.Writer, plugins []string) {
|
||||
// if no plugins are specified, update all installed plugins.
|
||||
if len(plugins) == 0 {
|
||||
for _, p := range Plugins {
|
||||
if !p.IsEnabled() || p.Default {
|
||||
if !p.IsLoaded() || p.Default {
|
||||
continue
|
||||
}
|
||||
plugins = append(plugins, p.Name)
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/blang/semver"
|
||||
|
||||
"github.com/zyedidia/json5"
|
||||
"github.com/micro-editor/json5"
|
||||
)
|
||||
|
||||
func TestDependencyResolving(t *testing.T) {
|
||||
|
@ -2,13 +2,13 @@ package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
rt "github.com/zyedidia/micro/v2/runtime"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -38,6 +38,10 @@ var allFiles [][]RuntimeFile
|
||||
var realFiles [][]RuntimeFile
|
||||
|
||||
func init() {
|
||||
initRuntimeVars()
|
||||
}
|
||||
|
||||
func initRuntimeVars() {
|
||||
allFiles = make([][]RuntimeFile, NumTypes)
|
||||
realFiles = make([][]RuntimeFile, NumTypes)
|
||||
}
|
||||
@ -56,12 +60,6 @@ type realFile string
|
||||
// some asset file
|
||||
type assetFile string
|
||||
|
||||
// some file on filesystem but with a different name
|
||||
type namedFile struct {
|
||||
realFile
|
||||
name string
|
||||
}
|
||||
|
||||
// a file with the data stored in memory
|
||||
type memoryFile struct {
|
||||
name string
|
||||
@ -81,20 +79,16 @@ func (rf realFile) Name() string {
|
||||
}
|
||||
|
||||
func (rf realFile) Data() ([]byte, error) {
|
||||
return ioutil.ReadFile(string(rf))
|
||||
return os.ReadFile(string(rf))
|
||||
}
|
||||
|
||||
func (af assetFile) Name() string {
|
||||
fn := path.Base(string(af))
|
||||
return fn[:len(fn)-len(path.Ext(fn))]
|
||||
fn := filepath.Base(string(af))
|
||||
return fn[:len(fn)-len(filepath.Ext(fn))]
|
||||
}
|
||||
|
||||
func (af assetFile) Data() ([]byte, error) {
|
||||
return Asset(string(af))
|
||||
}
|
||||
|
||||
func (nf namedFile) Name() string {
|
||||
return nf.name
|
||||
return rt.Asset(string(af))
|
||||
}
|
||||
|
||||
// AddRuntimeFile registers a file for the given filetype
|
||||
@ -111,7 +105,7 @@ func AddRealRuntimeFile(fileType RTFiletype, file RuntimeFile) {
|
||||
// AddRuntimeFilesFromDirectory registers each file from the given directory for
|
||||
// the filetype which matches the file-pattern
|
||||
func AddRuntimeFilesFromDirectory(fileType RTFiletype, directory, pattern string) {
|
||||
files, _ := ioutil.ReadDir(directory)
|
||||
files, _ := os.ReadDir(directory)
|
||||
for _, f := range files {
|
||||
if ok, _ := filepath.Match(pattern, f.Name()); !f.IsDir() && ok {
|
||||
fullPath := filepath.Join(directory, f.Name())
|
||||
@ -123,13 +117,21 @@ func AddRuntimeFilesFromDirectory(fileType RTFiletype, directory, pattern string
|
||||
// AddRuntimeFilesFromAssets registers each file from the given asset-directory for
|
||||
// the filetype which matches the file-pattern
|
||||
func AddRuntimeFilesFromAssets(fileType RTFiletype, directory, pattern string) {
|
||||
files, err := AssetDir(directory)
|
||||
files, err := rt.AssetDir(directory)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
assetLoop:
|
||||
for _, f := range files {
|
||||
if ok, _ := path.Match(pattern, f); ok {
|
||||
AddRuntimeFile(fileType, assetFile(path.Join(directory, f)))
|
||||
if ok, _ := filepath.Match(pattern, f); ok {
|
||||
af := assetFile(filepath.Join(directory, f))
|
||||
for _, rf := range realFiles[fileType] {
|
||||
if af.Name() == rf.Name() {
|
||||
continue assetLoop
|
||||
}
|
||||
}
|
||||
AddRuntimeFile(fileType, af)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -156,19 +158,30 @@ func ListRealRuntimeFiles(fileType RTFiletype) []RuntimeFile {
|
||||
return realFiles[fileType]
|
||||
}
|
||||
|
||||
// InitRuntimeFiles initializes all assets file and the config directory
|
||||
func InitRuntimeFiles() {
|
||||
// InitRuntimeFiles initializes all assets files and the config directory.
|
||||
// If `user` is false, InitRuntimeFiles ignores the config directory and
|
||||
// initializes asset files only.
|
||||
func InitRuntimeFiles(user bool) {
|
||||
add := func(fileType RTFiletype, dir, pattern string) {
|
||||
if user {
|
||||
AddRuntimeFilesFromDirectory(fileType, filepath.Join(ConfigDir, dir), pattern)
|
||||
AddRuntimeFilesFromAssets(fileType, path.Join("runtime", dir), pattern)
|
||||
}
|
||||
AddRuntimeFilesFromAssets(fileType, filepath.Join("runtime", dir), pattern)
|
||||
}
|
||||
|
||||
initRuntimeVars()
|
||||
|
||||
add(RTColorscheme, "colorschemes", "*.micro")
|
||||
add(RTSyntax, "syntax", "*.yaml")
|
||||
add(RTSyntaxHeader, "syntax", "*.hdr")
|
||||
add(RTHelp, "help", "*.md")
|
||||
}
|
||||
|
||||
// InitPlugins initializes the plugins
|
||||
func InitPlugins() {
|
||||
Plugins = Plugins[:0]
|
||||
initlua := filepath.Join(ConfigDir, "init.lua")
|
||||
|
||||
if _, err := os.Stat(initlua); !os.IsNotExist(err) {
|
||||
p := new(Plugin)
|
||||
p.Name = "initlua"
|
||||
@ -179,13 +192,14 @@ func InitRuntimeFiles() {
|
||||
|
||||
// Search ConfigDir for plugin-scripts
|
||||
plugdir := filepath.Join(ConfigDir, "plug")
|
||||
files, _ := ioutil.ReadDir(plugdir)
|
||||
files, _ := os.ReadDir(plugdir)
|
||||
|
||||
isID := regexp.MustCompile(`^[_A-Za-z0-9]+$`).MatchString
|
||||
|
||||
for _, d := range files {
|
||||
if d.IsDir() {
|
||||
srcs, _ := ioutil.ReadDir(filepath.Join(plugdir, d.Name()))
|
||||
plugpath := filepath.Join(plugdir, d.Name())
|
||||
if stat, err := os.Stat(plugpath); err == nil && stat.IsDir() {
|
||||
srcs, _ := os.ReadDir(plugpath)
|
||||
p := new(Plugin)
|
||||
p.Name = d.Name()
|
||||
p.DirName = d.Name()
|
||||
@ -193,7 +207,7 @@ func InitRuntimeFiles() {
|
||||
if strings.HasSuffix(f.Name(), ".lua") {
|
||||
p.Srcs = append(p.Srcs, realFile(filepath.Join(plugdir, d.Name(), f.Name())))
|
||||
} else if strings.HasSuffix(f.Name(), ".json") {
|
||||
data, err := ioutil.ReadFile(filepath.Join(plugdir, d.Name(), f.Name()))
|
||||
data, err := os.ReadFile(filepath.Join(plugdir, d.Name(), f.Name()))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@ -214,9 +228,17 @@ func InitRuntimeFiles() {
|
||||
}
|
||||
|
||||
plugdir = filepath.Join("runtime", "plugins")
|
||||
if files, err := AssetDir(plugdir); err == nil {
|
||||
if files, err := rt.AssetDir(plugdir); err == nil {
|
||||
outer:
|
||||
for _, d := range files {
|
||||
if srcs, err := AssetDir(filepath.Join(plugdir, d)); err == nil {
|
||||
for _, p := range Plugins {
|
||||
if p.Name == d {
|
||||
log.Println(p.Name, "built-in plugin overridden by user-defined one")
|
||||
continue outer
|
||||
}
|
||||
}
|
||||
|
||||
if srcs, err := rt.AssetDir(filepath.Join(plugdir, d)); err == nil {
|
||||
p := new(Plugin)
|
||||
p.Name = d
|
||||
p.DirName = d
|
||||
@ -225,7 +247,7 @@ func InitRuntimeFiles() {
|
||||
if strings.HasSuffix(f, ".lua") {
|
||||
p.Srcs = append(p.Srcs, assetFile(filepath.Join(plugdir, d, f)))
|
||||
} else if strings.HasSuffix(f, ".json") {
|
||||
data, err := Asset(filepath.Join(plugdir, d, f))
|
||||
data, err := rt.Asset(filepath.Join(plugdir, d, f))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@ -277,7 +299,7 @@ func PluginAddRuntimeFile(plugin string, filetype RTFiletype, filePath string) e
|
||||
if _, err := os.Stat(fullpath); err == nil {
|
||||
AddRealRuntimeFile(filetype, realFile(fullpath))
|
||||
} else {
|
||||
fullpath = path.Join("runtime", "plugins", pldir, filePath)
|
||||
fullpath = filepath.Join("runtime", "plugins", pldir, filePath)
|
||||
AddRuntimeFile(filetype, assetFile(fullpath))
|
||||
}
|
||||
return nil
|
||||
@ -294,7 +316,7 @@ func PluginAddRuntimeFilesFromDirectory(plugin string, filetype RTFiletype, dire
|
||||
if _, err := os.Stat(fullpath); err == nil {
|
||||
AddRuntimeFilesFromDirectory(filetype, fullpath, pattern)
|
||||
} else {
|
||||
fullpath = path.Join("runtime", "plugins", pldir, directory)
|
||||
fullpath = filepath.Join("runtime", "plugins", pldir, directory)
|
||||
AddRuntimeFilesFromAssets(filetype, fullpath, pattern)
|
||||
}
|
||||
return nil
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
InitRuntimeFiles()
|
||||
InitRuntimeFiles(false)
|
||||
}
|
||||
|
||||
func TestAddFile(t *testing.T) {
|
||||
|
File diff suppressed because one or more lines are too long
@ -4,21 +4,140 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/micro-editor/json5"
|
||||
"github.com/zyedidia/glob"
|
||||
"github.com/zyedidia/json5"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
"golang.org/x/text/encoding/htmlindex"
|
||||
)
|
||||
|
||||
type optionValidator func(string, interface{}) error
|
||||
|
||||
// a list of settings that need option validators
|
||||
var optionValidators = map[string]optionValidator{
|
||||
"autosave": validateNonNegativeValue,
|
||||
"clipboard": validateChoice,
|
||||
"colorcolumn": validateNonNegativeValue,
|
||||
"colorscheme": validateColorscheme,
|
||||
"detectlimit": validateNonNegativeValue,
|
||||
"encoding": validateEncoding,
|
||||
"fileformat": validateChoice,
|
||||
"helpsplit": validateChoice,
|
||||
"matchbracestyle": validateChoice,
|
||||
"multiopen": validateChoice,
|
||||
"pageoverlap": validateNonNegativeValue,
|
||||
"reload": validateChoice,
|
||||
"scrollmargin": validateNonNegativeValue,
|
||||
"scrollspeed": validateNonNegativeValue,
|
||||
"tabsize": validatePositiveValue,
|
||||
"truecolor": validateChoice,
|
||||
}
|
||||
|
||||
// a list of settings with pre-defined choices
|
||||
var OptionChoices = map[string][]string{
|
||||
"clipboard": {"internal", "external", "terminal"},
|
||||
"fileformat": {"unix", "dos"},
|
||||
"helpsplit": {"hsplit", "vsplit"},
|
||||
"matchbracestyle": {"underline", "highlight"},
|
||||
"multiopen": {"tab", "hsplit", "vsplit"},
|
||||
"reload": {"prompt", "auto", "disabled"},
|
||||
"truecolor": {"auto", "on", "off"},
|
||||
}
|
||||
|
||||
// a list of settings that can be globally and locally modified and their
|
||||
// default values
|
||||
var defaultCommonSettings = map[string]interface{}{
|
||||
"autoindent": true,
|
||||
"autosu": false,
|
||||
"backup": true,
|
||||
"backupdir": "",
|
||||
"basename": false,
|
||||
"colorcolumn": float64(0),
|
||||
"cursorline": true,
|
||||
"detectlimit": float64(100),
|
||||
"diffgutter": false,
|
||||
"encoding": "utf-8",
|
||||
"eofnewline": true,
|
||||
"fastdirty": false,
|
||||
"fileformat": defaultFileFormat(),
|
||||
"filetype": "unknown",
|
||||
"hlsearch": false,
|
||||
"hltaberrors": false,
|
||||
"hltrailingws": false,
|
||||
"ignorecase": true,
|
||||
"incsearch": true,
|
||||
"indentchar": " ",
|
||||
"keepautoindent": false,
|
||||
"matchbrace": true,
|
||||
"matchbraceleft": true,
|
||||
"matchbracestyle": "underline",
|
||||
"mkparents": false,
|
||||
"pageoverlap": float64(2),
|
||||
"permbackup": false,
|
||||
"readonly": false,
|
||||
"relativeruler": false,
|
||||
"reload": "prompt",
|
||||
"rmtrailingws": false,
|
||||
"ruler": true,
|
||||
"savecursor": false,
|
||||
"saveundo": false,
|
||||
"scrollbar": false,
|
||||
"scrollmargin": float64(3),
|
||||
"scrollspeed": float64(2),
|
||||
"smartpaste": true,
|
||||
"softwrap": false,
|
||||
"splitbottom": true,
|
||||
"splitright": true,
|
||||
"statusformatl": "$(filename) $(modified)$(overwrite)($(line),$(col)) $(status.paste)| ft:$(opt:filetype) | $(opt:fileformat) | $(opt:encoding)",
|
||||
"statusformatr": "$(bind:ToggleKeyMenu): bindings, $(bind:ToggleHelp): help",
|
||||
"statusline": true,
|
||||
"syntax": true,
|
||||
"tabmovement": false,
|
||||
"tabsize": float64(4),
|
||||
"tabstospaces": false,
|
||||
"truecolor": "auto",
|
||||
"useprimary": true,
|
||||
"wordwrap": false,
|
||||
}
|
||||
|
||||
// a list of settings that should only be globally modified and their
|
||||
// default values
|
||||
var DefaultGlobalOnlySettings = map[string]interface{}{
|
||||
"autosave": float64(0),
|
||||
"clipboard": "external",
|
||||
"colorscheme": "default",
|
||||
"divchars": "|-",
|
||||
"divreverse": true,
|
||||
"fakecursor": false,
|
||||
"helpsplit": "hsplit",
|
||||
"infobar": true,
|
||||
"keymenu": false,
|
||||
"mouse": true,
|
||||
"multiopen": "tab",
|
||||
"parsecursor": false,
|
||||
"paste": false,
|
||||
"pluginchannels": []string{"https://raw.githubusercontent.com/micro-editor/plugin-channel/master/channel.json"},
|
||||
"pluginrepos": []string{},
|
||||
"savehistory": true,
|
||||
"scrollbarchar": "|",
|
||||
"sucmd": "sudo",
|
||||
"tabhighlight": false,
|
||||
"tabreverse": true,
|
||||
"xterm": false,
|
||||
}
|
||||
|
||||
// a list of settings that should never be globally modified
|
||||
var LocalSettings = []string{
|
||||
"filetype",
|
||||
"readonly",
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidOption = errors.New("Invalid option")
|
||||
ErrInvalidValue = errors.New("Invalid value")
|
||||
@ -33,30 +152,83 @@ var (
|
||||
// ModifiedSettings is a map of settings which should be written to disk
|
||||
// because they have been modified by the user in this session
|
||||
ModifiedSettings map[string]bool
|
||||
|
||||
// VolatileSettings is a map of settings which should not be written to disk
|
||||
// because they have been temporarily set for this session only
|
||||
VolatileSettings map[string]bool
|
||||
)
|
||||
|
||||
func writeFile(name string, txt []byte) error {
|
||||
return util.SafeWrite(name, txt, false)
|
||||
}
|
||||
|
||||
func init() {
|
||||
ModifiedSettings = make(map[string]bool)
|
||||
parsedSettings = make(map[string]interface{})
|
||||
VolatileSettings = make(map[string]bool)
|
||||
}
|
||||
|
||||
// Options with validators
|
||||
var optionValidators = map[string]optionValidator{
|
||||
"autosave": validateNonNegativeValue,
|
||||
"clipboard": validateClipboard,
|
||||
"tabsize": validatePositiveValue,
|
||||
"scrollmargin": validateNonNegativeValue,
|
||||
"scrollspeed": validateNonNegativeValue,
|
||||
"colorscheme": validateColorscheme,
|
||||
"colorcolumn": validateNonNegativeValue,
|
||||
"fileformat": validateLineEnding,
|
||||
"encoding": validateEncoding,
|
||||
func validateParsedSettings() error {
|
||||
var err error
|
||||
defaults := DefaultAllSettings()
|
||||
for k, v := range parsedSettings {
|
||||
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
|
||||
if strings.HasPrefix(k, "ft:") {
|
||||
for k1, v1 := range v.(map[string]interface{}) {
|
||||
if _, ok := defaults[k1]; ok {
|
||||
if e := verifySetting(k1, v1, defaults[k1]); e != nil {
|
||||
err = e
|
||||
parsedSettings[k].(map[string]interface{})[k1] = defaults[k1]
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if _, e := glob.Compile(k); e != nil {
|
||||
err = errors.New("Error with glob setting " + k + ": " + e.Error())
|
||||
delete(parsedSettings, k)
|
||||
continue
|
||||
}
|
||||
for k1, v1 := range v.(map[string]interface{}) {
|
||||
if _, ok := defaults[k1]; ok {
|
||||
if e := verifySetting(k1, v1, defaults[k1]); e != nil {
|
||||
err = e
|
||||
parsedSettings[k].(map[string]interface{})[k1] = defaults[k1]
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if k == "autosave" {
|
||||
// if autosave is a boolean convert it to float
|
||||
s, ok := v.(bool)
|
||||
if ok {
|
||||
if s {
|
||||
parsedSettings["autosave"] = 8.0
|
||||
} else {
|
||||
parsedSettings["autosave"] = 0.0
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
if _, ok := defaults[k]; ok {
|
||||
if e := verifySetting(k, v, defaults[k]); e != nil {
|
||||
err = e
|
||||
parsedSettings[k] = defaults[k]
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func ReadSettings() error {
|
||||
parsedSettings = make(map[string]interface{})
|
||||
filename := filepath.Join(ConfigDir, "settings.json")
|
||||
if _, e := os.Stat(filename); e == nil {
|
||||
input, err := ioutil.ReadFile(filename)
|
||||
input, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
settingsParseError = true
|
||||
return errors.New("Error reading settings.json file: " + err.Error())
|
||||
@ -68,89 +240,91 @@ func ReadSettings() error {
|
||||
settingsParseError = true
|
||||
return errors.New("Error reading settings.json: " + err.Error())
|
||||
}
|
||||
|
||||
// check if autosave is a boolean and convert it to float if so
|
||||
if v, ok := parsedSettings["autosave"]; ok {
|
||||
s, ok := v.(bool)
|
||||
if ok {
|
||||
if s {
|
||||
parsedSettings["autosave"] = 8.0
|
||||
} else {
|
||||
parsedSettings["autosave"] = 0.0
|
||||
}
|
||||
}
|
||||
err = validateParsedSettings()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func verifySetting(option string, value reflect.Type, def reflect.Type) bool {
|
||||
func ParsedSettings() map[string]interface{} {
|
||||
s := make(map[string]interface{})
|
||||
for k, v := range parsedSettings {
|
||||
s[k] = v
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func verifySetting(option string, value interface{}, def interface{}) error {
|
||||
var interfaceArr []interface{}
|
||||
valType := reflect.TypeOf(value)
|
||||
defType := reflect.TypeOf(def)
|
||||
assignable := false
|
||||
|
||||
switch option {
|
||||
case "pluginrepos", "pluginchannels":
|
||||
return value.AssignableTo(reflect.TypeOf(interfaceArr))
|
||||
assignable = valType.AssignableTo(reflect.TypeOf(interfaceArr))
|
||||
default:
|
||||
return def.AssignableTo(value)
|
||||
assignable = defType.AssignableTo(valType)
|
||||
}
|
||||
if !assignable {
|
||||
return fmt.Errorf("Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", option, valType, def, defType)
|
||||
}
|
||||
|
||||
if err := OptionIsValid(option, value); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitGlobalSettings initializes the options map and sets all options to their default values
|
||||
// Must be called after ReadSettings
|
||||
func InitGlobalSettings() error {
|
||||
var err error
|
||||
GlobalSettings = DefaultGlobalSettings()
|
||||
GlobalSettings = DefaultAllSettings()
|
||||
|
||||
for k, v := range parsedSettings {
|
||||
if !strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
|
||||
if _, ok := GlobalSettings[k]; ok && !verifySetting(k, reflect.TypeOf(v), reflect.TypeOf(GlobalSettings[k])) {
|
||||
err = fmt.Errorf("Global Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", k, reflect.TypeOf(v), GlobalSettings[k], reflect.TypeOf(GlobalSettings[k]))
|
||||
continue
|
||||
}
|
||||
|
||||
GlobalSettings[k] = v
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// InitLocalSettings scans the json in settings.json and sets the options locally based
|
||||
// on whether the filetype or path matches ft or glob local settings
|
||||
// UpdatePathGlobLocals scans the already parsed settings and sets the options locally
|
||||
// based on whether the path matches a glob
|
||||
// Must be called after ReadSettings
|
||||
func InitLocalSettings(settings map[string]interface{}, path string) error {
|
||||
var parseError error
|
||||
func UpdatePathGlobLocals(settings map[string]interface{}, path string) {
|
||||
for k, v := range parsedSettings {
|
||||
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
|
||||
if strings.HasPrefix(k, "ft:") {
|
||||
if settings["filetype"].(string) == k[3:] {
|
||||
for k1, v1 := range v.(map[string]interface{}) {
|
||||
if _, ok := settings[k1]; ok && !verifySetting(k1, reflect.TypeOf(v1), reflect.TypeOf(settings[k1])) {
|
||||
parseError = fmt.Errorf("Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", k, reflect.TypeOf(v1), settings[k1], reflect.TypeOf(settings[k1]))
|
||||
continue
|
||||
}
|
||||
settings[k1] = v1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
g, err := glob.Compile(k)
|
||||
if err != nil {
|
||||
parseError = errors.New("Error with glob setting " + k + ": " + err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") && !strings.HasPrefix(k, "ft:") {
|
||||
g, _ := glob.Compile(k)
|
||||
if g.MatchString(path) {
|
||||
for k1, v1 := range v.(map[string]interface{}) {
|
||||
if _, ok := settings[k1]; ok && !verifySetting(k1, reflect.TypeOf(v1), reflect.TypeOf(settings[k1])) {
|
||||
parseError = fmt.Errorf("Error: setting '%s' has incorrect type (%s), using default value: %v (%s)", k, reflect.TypeOf(v1), settings[k1], reflect.TypeOf(settings[k1]))
|
||||
continue
|
||||
}
|
||||
settings[k1] = v1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return parseError
|
||||
|
||||
// UpdateFileTypeLocals scans the already parsed settings and sets the options locally
|
||||
// based on whether the filetype matches to "ft:"
|
||||
// Must be called after ReadSettings
|
||||
func UpdateFileTypeLocals(settings map[string]interface{}, filetype string) {
|
||||
for k, v := range parsedSettings {
|
||||
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") && strings.HasPrefix(k, "ft:") {
|
||||
if filetype == k[3:] {
|
||||
for k1, v1 := range v.(map[string]interface{}) {
|
||||
if k1 != "filetype" {
|
||||
settings[k1] = v1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WriteSettings writes the settings to the specified filename as JSON
|
||||
@ -165,13 +339,14 @@ func WriteSettings(filename string) error {
|
||||
|
||||
var err error
|
||||
if _, e := os.Stat(ConfigDir); e == nil {
|
||||
defaults := DefaultGlobalSettings()
|
||||
defaults := DefaultAllSettings()
|
||||
|
||||
// remove any options froms parsedSettings that have since been marked as default
|
||||
for k, v := range parsedSettings {
|
||||
if !strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
|
||||
cur, okcur := GlobalSettings[k]
|
||||
if def, ok := defaults[k]; ok && okcur && reflect.DeepEqual(cur, def) {
|
||||
_, vol := VolatileSettings[k]
|
||||
if def, ok := defaults[k]; ok && okcur && !vol && reflect.DeepEqual(cur, def) {
|
||||
delete(parsedSettings, k)
|
||||
}
|
||||
}
|
||||
@ -187,7 +362,8 @@ func WriteSettings(filename string) error {
|
||||
}
|
||||
|
||||
txt, _ := json.MarshalIndent(parsedSettings, "", " ")
|
||||
err = ioutil.WriteFile(filename, append(txt, '\n'), 0644)
|
||||
txt = append(txt, '\n')
|
||||
err = writeFile(filename, txt)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@ -199,7 +375,7 @@ func OverwriteSettings(filename string) error {
|
||||
|
||||
var err error
|
||||
if _, e := os.Stat(ConfigDir); e == nil {
|
||||
defaults := DefaultGlobalSettings()
|
||||
defaults := DefaultAllSettings()
|
||||
for k, v := range GlobalSettings {
|
||||
if def, ok := defaults[k]; !ok || !reflect.DeepEqual(v, def) {
|
||||
if _, wr := ModifiedSettings[k]; wr {
|
||||
@ -208,26 +384,16 @@ func OverwriteSettings(filename string) error {
|
||||
}
|
||||
}
|
||||
|
||||
txt, _ := json.MarshalIndent(settings, "", " ")
|
||||
err = ioutil.WriteFile(filename, append(txt, '\n'), 0644)
|
||||
txt, _ := json.MarshalIndent(parsedSettings, "", " ")
|
||||
txt = append(txt, '\n')
|
||||
err = writeFile(filename, txt)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// RegisterCommonOptionPlug creates a new option (called pl.name). This is meant to be called by plugins to add options.
|
||||
func RegisterCommonOptionPlug(pl string, name string, defaultvalue interface{}) error {
|
||||
name = pl + "." + name
|
||||
if _, ok := GlobalSettings[name]; !ok {
|
||||
defaultCommonSettings[name] = defaultvalue
|
||||
GlobalSettings[name] = defaultvalue
|
||||
err := WriteSettings(filepath.Join(ConfigDir, "settings.json"))
|
||||
if err != nil {
|
||||
return errors.New("Error writing settings.json file: " + err.Error())
|
||||
}
|
||||
} else {
|
||||
defaultCommonSettings[name] = defaultvalue
|
||||
}
|
||||
return nil
|
||||
return RegisterCommonOption(pl+"."+name, defaultvalue)
|
||||
}
|
||||
|
||||
// RegisterGlobalOptionPlug creates a new global-only option (named pl.name)
|
||||
@ -235,18 +401,21 @@ func RegisterGlobalOptionPlug(pl string, name string, defaultvalue interface{})
|
||||
return RegisterGlobalOption(pl+"."+name, defaultvalue)
|
||||
}
|
||||
|
||||
// RegisterCommonOption creates a new option
|
||||
func RegisterCommonOption(name string, defaultvalue interface{}) error {
|
||||
if _, ok := GlobalSettings[name]; !ok {
|
||||
GlobalSettings[name] = defaultvalue
|
||||
}
|
||||
defaultCommonSettings[name] = defaultvalue
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterGlobalOption creates a new global-only option
|
||||
func RegisterGlobalOption(name string, defaultvalue interface{}) error {
|
||||
if v, ok := GlobalSettings[name]; !ok {
|
||||
DefaultGlobalOnlySettings[name] = defaultvalue
|
||||
if _, ok := GlobalSettings[name]; !ok {
|
||||
GlobalSettings[name] = defaultvalue
|
||||
err := WriteSettings(filepath.Join(ConfigDir, "settings.json"))
|
||||
if err != nil {
|
||||
return errors.New("Error writing settings.json file: " + err.Error())
|
||||
}
|
||||
} else {
|
||||
DefaultGlobalOnlySettings[name] = v
|
||||
}
|
||||
DefaultGlobalOnlySettings[name] = defaultvalue
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -255,49 +424,11 @@ func GetGlobalOption(name string) interface{} {
|
||||
return GlobalSettings[name]
|
||||
}
|
||||
|
||||
var defaultCommonSettings = map[string]interface{}{
|
||||
"autoindent": true,
|
||||
"autosu": false,
|
||||
"backup": true,
|
||||
"backupdir": "",
|
||||
"basename": false,
|
||||
"colorcolumn": float64(0),
|
||||
"cursorline": true,
|
||||
"diffgutter": false,
|
||||
"encoding": "utf-8",
|
||||
"eofnewline": true,
|
||||
"fastdirty": false,
|
||||
"fileformat": "unix",
|
||||
"filetype": "unknown",
|
||||
"incsearch": true,
|
||||
"ignorecase": true,
|
||||
"indentchar": " ",
|
||||
"keepautoindent": false,
|
||||
"matchbrace": true,
|
||||
"mkparents": false,
|
||||
"permbackup": false,
|
||||
"readonly": false,
|
||||
"rmtrailingws": false,
|
||||
"ruler": true,
|
||||
"relativeruler": false,
|
||||
"savecursor": false,
|
||||
"saveundo": false,
|
||||
"scrollbar": false,
|
||||
"scrollmargin": float64(3),
|
||||
"scrollspeed": float64(2),
|
||||
"smartpaste": true,
|
||||
"softwrap": false,
|
||||
"splitbottom": true,
|
||||
"splitright": true,
|
||||
"statusformatl": "$(filename) $(modified)($(line),$(col)) $(status.paste)| ft:$(opt:filetype) | $(opt:fileformat) | $(opt:encoding)",
|
||||
"statusformatr": "$(bind:ToggleKeyMenu): bindings, $(bind:ToggleHelp): help",
|
||||
"statusline": true,
|
||||
"syntax": true,
|
||||
"tabmovement": false,
|
||||
"tabsize": float64(4),
|
||||
"tabstospaces": false,
|
||||
"useprimary": true,
|
||||
"wordwrap": false,
|
||||
func defaultFileFormat() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
return "dos"
|
||||
}
|
||||
return "unix"
|
||||
}
|
||||
|
||||
func GetInfoBarOffset() int {
|
||||
@ -311,8 +442,8 @@ func GetInfoBarOffset() int {
|
||||
return offset
|
||||
}
|
||||
|
||||
// DefaultCommonSettings returns the default global settings for micro
|
||||
// Note that colorscheme is a global only option
|
||||
// DefaultCommonSettings returns a map of all common buffer settings
|
||||
// and their default values
|
||||
func DefaultCommonSettings() map[string]interface{} {
|
||||
commonsettings := make(map[string]interface{})
|
||||
for k, v := range defaultCommonSettings {
|
||||
@ -321,47 +452,8 @@ func DefaultCommonSettings() map[string]interface{} {
|
||||
return commonsettings
|
||||
}
|
||||
|
||||
// a list of settings that should only be globally modified and their
|
||||
// default values
|
||||
var DefaultGlobalOnlySettings = map[string]interface{}{
|
||||
"autosave": float64(0),
|
||||
"clipboard": "external",
|
||||
"colorscheme": "default",
|
||||
"divchars": "|-",
|
||||
"divreverse": true,
|
||||
"infobar": true,
|
||||
"keymenu": false,
|
||||
"mouse": true,
|
||||
"parsecursor": false,
|
||||
"paste": false,
|
||||
"savehistory": true,
|
||||
"sucmd": "sudo",
|
||||
"pluginchannels": []string{"https://raw.githubusercontent.com/micro-editor/plugin-channel/master/channel.json"},
|
||||
"pluginrepos": []string{},
|
||||
"xterm": false,
|
||||
}
|
||||
|
||||
// a list of settings that should never be globally modified
|
||||
var LocalSettings = []string{
|
||||
"filetype",
|
||||
"readonly",
|
||||
}
|
||||
|
||||
// DefaultGlobalSettings returns the default global settings for micro
|
||||
// Note that colorscheme is a global only option
|
||||
func DefaultGlobalSettings() map[string]interface{} {
|
||||
globalsettings := make(map[string]interface{})
|
||||
for k, v := range defaultCommonSettings {
|
||||
globalsettings[k] = v
|
||||
}
|
||||
for k, v := range DefaultGlobalOnlySettings {
|
||||
globalsettings[k] = v
|
||||
}
|
||||
return globalsettings
|
||||
}
|
||||
|
||||
// DefaultAllSettings returns a map of all settings and their
|
||||
// default values (both common and global settings)
|
||||
// DefaultAllSettings returns a map of all common buffer & global-only settings
|
||||
// and their default values
|
||||
func DefaultAllSettings() map[string]interface{} {
|
||||
allsettings := make(map[string]interface{})
|
||||
for k, v := range defaultCommonSettings {
|
||||
@ -386,18 +478,15 @@ func GetNativeValue(option string, realValue interface{}, value string) (interfa
|
||||
} else if kind == reflect.String {
|
||||
native = value
|
||||
} else if kind == reflect.Float64 {
|
||||
i, err := strconv.Atoi(value)
|
||||
f, err := strconv.ParseFloat(value, 64)
|
||||
if err != nil {
|
||||
return nil, ErrInvalidValue
|
||||
}
|
||||
native = float64(i)
|
||||
native = f
|
||||
} else {
|
||||
return nil, ErrInvalidValue
|
||||
}
|
||||
|
||||
if err := OptionIsValid(option, native); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return native, nil
|
||||
}
|
||||
|
||||
@ -413,13 +502,13 @@ func OptionIsValid(option string, value interface{}) error {
|
||||
// Option validators
|
||||
|
||||
func validatePositiveValue(option string, value interface{}) error {
|
||||
tabsize, ok := value.(float64)
|
||||
nativeValue, ok := value.(float64)
|
||||
|
||||
if !ok {
|
||||
return errors.New("Expected numeric type for " + option)
|
||||
}
|
||||
|
||||
if tabsize < 1 {
|
||||
if nativeValue < 1 {
|
||||
return errors.New(option + " must be greater than 0")
|
||||
}
|
||||
|
||||
@ -440,6 +529,26 @@ func validateNonNegativeValue(option string, value interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateChoice(option string, value interface{}) error {
|
||||
if choices, ok := OptionChoices[option]; ok {
|
||||
val, ok := value.(string)
|
||||
if !ok {
|
||||
return errors.New("Expected string type for " + option)
|
||||
}
|
||||
|
||||
for _, v := range choices {
|
||||
if val == v {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
choicesStr := strings.Join(choices, ", ")
|
||||
return errors.New(option + " must be one of: " + choicesStr)
|
||||
}
|
||||
|
||||
return errors.New("Option has no pre-defined choices")
|
||||
}
|
||||
|
||||
func validateColorscheme(option string, value interface{}) error {
|
||||
colorscheme, ok := value.(string)
|
||||
|
||||
@ -454,36 +563,6 @@ func validateColorscheme(option string, value interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateClipboard(option string, value interface{}) error {
|
||||
val, ok := value.(string)
|
||||
|
||||
if !ok {
|
||||
return errors.New("Expected string type for clipboard")
|
||||
}
|
||||
|
||||
switch val {
|
||||
case "internal", "external", "terminal":
|
||||
default:
|
||||
return errors.New(option + " must be 'internal', 'external', or 'terminal'")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateLineEnding(option string, value interface{}) error {
|
||||
endingType, ok := value.(string)
|
||||
|
||||
if !ok {
|
||||
return errors.New("Expected string type for file format")
|
||||
}
|
||||
|
||||
if endingType != "unix" && endingType != "dos" {
|
||||
return errors.New("File format must be either 'unix' or 'dos'")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateEncoding(option string, value interface{}) error {
|
||||
_, err := htmlindex.Get(value.(string))
|
||||
return err
|
||||
|
@ -4,15 +4,14 @@ import (
|
||||
"strconv"
|
||||
|
||||
runewidth "github.com/mattn/go-runewidth"
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
"github.com/zyedidia/micro/v2/internal/buffer"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
)
|
||||
|
||||
// The BufWindow provides a way of displaying a certain section
|
||||
// of a buffer
|
||||
// The BufWindow provides a way of displaying a certain section of a buffer.
|
||||
type BufWindow struct {
|
||||
*View
|
||||
|
||||
@ -44,6 +43,7 @@ func NewBufWindow(x, y, width, height int, buf *buffer.Buffer) *BufWindow {
|
||||
return w
|
||||
}
|
||||
|
||||
// SetBuffer sets this window's buffer.
|
||||
func (w *BufWindow) SetBuffer(b *buffer.Buffer) {
|
||||
w.Buf = b
|
||||
b.OptionCallback = func(option string, nativeValue interface{}) {
|
||||
@ -53,11 +53,19 @@ func (w *BufWindow) SetBuffer(b *buffer.Buffer) {
|
||||
} else {
|
||||
w.StartLine.Row = 0
|
||||
}
|
||||
w.Relocate()
|
||||
|
||||
for _, c := range w.Buf.GetCursors() {
|
||||
c.LastVisualX = c.GetVisualX()
|
||||
}
|
||||
|
||||
if option == "softwrap" || option == "wordwrap" {
|
||||
w.Relocate()
|
||||
for _, c := range w.Buf.GetCursors() {
|
||||
c.LastWrappedVisualX = c.GetVisualX(true)
|
||||
}
|
||||
}
|
||||
|
||||
if option == "diffgutter" || option == "ruler" || option == "scrollbar" ||
|
||||
option == "statusline" {
|
||||
w.updateDisplayInfo()
|
||||
w.Relocate()
|
||||
}
|
||||
}
|
||||
b.GetVisualX = func(loc buffer.Loc) int {
|
||||
@ -65,31 +73,30 @@ func (w *BufWindow) SetBuffer(b *buffer.Buffer) {
|
||||
}
|
||||
}
|
||||
|
||||
// GetView gets the view.
|
||||
func (w *BufWindow) GetView() *View {
|
||||
return w.View
|
||||
}
|
||||
|
||||
// GetView sets the view.
|
||||
func (w *BufWindow) SetView(view *View) {
|
||||
w.View = view
|
||||
}
|
||||
|
||||
// Resize resizes this window.
|
||||
func (w *BufWindow) Resize(width, height int) {
|
||||
w.Width, w.Height = width, height
|
||||
w.updateDisplayInfo()
|
||||
|
||||
w.Relocate()
|
||||
|
||||
if w.Buf.Settings["softwrap"].(bool) {
|
||||
for _, c := range w.Buf.GetCursors() {
|
||||
c.LastVisualX = c.GetVisualX()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SetActive marks the window as active.
|
||||
func (w *BufWindow) SetActive(b bool) {
|
||||
w.active = b
|
||||
}
|
||||
|
||||
// IsActive returns true if this window is active.
|
||||
func (w *BufWindow) IsActive() bool {
|
||||
return w.active
|
||||
}
|
||||
@ -128,6 +135,11 @@ func (w *BufWindow) updateDisplayInfo() {
|
||||
w.bufHeight--
|
||||
}
|
||||
|
||||
scrollbarWidth := 0
|
||||
if w.Buf.Settings["scrollbar"].(bool) && w.Buf.LinesNum() > w.Height && w.Width > 0 {
|
||||
scrollbarWidth = 1
|
||||
}
|
||||
|
||||
w.hasMessage = len(b.Messages) > 0
|
||||
|
||||
// We need to know the string length of the largest line number
|
||||
@ -145,9 +157,17 @@ func (w *BufWindow) updateDisplayInfo() {
|
||||
w.gutterOffset += w.maxLineNumLength + 1
|
||||
}
|
||||
|
||||
w.bufWidth = w.Width - w.gutterOffset
|
||||
if w.Buf.Settings["scrollbar"].(bool) && w.Buf.LinesNum() > w.Height {
|
||||
w.bufWidth--
|
||||
if w.gutterOffset > w.Width-scrollbarWidth {
|
||||
w.gutterOffset = w.Width - scrollbarWidth
|
||||
}
|
||||
|
||||
prevBufWidth := w.bufWidth
|
||||
w.bufWidth = w.Width - w.gutterOffset - scrollbarWidth
|
||||
|
||||
if w.bufWidth != prevBufWidth && w.Buf.Settings["softwrap"].(bool) {
|
||||
for _, c := range w.Buf.GetCursors() {
|
||||
c.LastWrappedVisualX = c.GetVisualX(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,7 +234,7 @@ func (w *BufWindow) Relocate() bool {
|
||||
w.StartLine = c
|
||||
ret = true
|
||||
}
|
||||
if c.GreaterThan(w.Scroll(w.StartLine, height-1-scrollmargin)) && c.LessThan(w.Scroll(bEnd, -scrollmargin+1)) {
|
||||
if c.GreaterThan(w.Scroll(w.StartLine, height-1-scrollmargin)) && c.LessEqual(w.Scroll(bEnd, -scrollmargin)) {
|
||||
w.StartLine = w.Scroll(c, -height+1+scrollmargin)
|
||||
ret = true
|
||||
} else if c.GreaterThan(w.Scroll(bEnd, -scrollmargin)) && c.GreaterThan(w.Scroll(w.StartLine, height-1)) {
|
||||
@ -224,7 +244,7 @@ func (w *BufWindow) Relocate() bool {
|
||||
|
||||
// horizontal relocation (scrolling)
|
||||
if !b.Settings["softwrap"].(bool) {
|
||||
cx := activeC.GetVisualX()
|
||||
cx := activeC.GetVisualX(false)
|
||||
rw := runewidth.RuneWidth(activeC.RuneUnder(activeC.X))
|
||||
if rw == 0 {
|
||||
rw = 1 // tab or newline
|
||||
@ -234,8 +254,8 @@ func (w *BufWindow) Relocate() bool {
|
||||
w.StartCol = cx
|
||||
ret = true
|
||||
}
|
||||
if cx+w.gutterOffset+rw > w.StartCol+w.Width {
|
||||
w.StartCol = cx - w.Width + w.gutterOffset + rw
|
||||
if cx+rw > w.StartCol+w.bufWidth {
|
||||
w.StartCol = cx - w.bufWidth + rw
|
||||
ret = true
|
||||
}
|
||||
}
|
||||
@ -268,13 +288,17 @@ func (w *BufWindow) drawGutter(vloc *buffer.Loc, bloc *buffer.Loc) {
|
||||
break
|
||||
}
|
||||
}
|
||||
screen.SetContent(w.X+vloc.X, w.Y+vloc.Y, char, nil, s)
|
||||
vloc.X++
|
||||
for i := 0; i < 2 && vloc.X < w.gutterOffset; i++ {
|
||||
screen.SetContent(w.X+vloc.X, w.Y+vloc.Y, char, nil, s)
|
||||
vloc.X++
|
||||
}
|
||||
}
|
||||
|
||||
func (w *BufWindow) drawDiffGutter(backgroundStyle tcell.Style, softwrapped bool, vloc *buffer.Loc, bloc *buffer.Loc) {
|
||||
if vloc.X >= w.gutterOffset {
|
||||
return
|
||||
}
|
||||
|
||||
symbol := ' '
|
||||
styleName := ""
|
||||
|
||||
@ -310,27 +334,29 @@ func (w *BufWindow) drawLineNum(lineNumStyle tcell.Style, softwrapped bool, vloc
|
||||
} else {
|
||||
lineInt = bloc.Y - cursorLine
|
||||
}
|
||||
lineNum := strconv.Itoa(util.Abs(lineInt))
|
||||
lineNum := []rune(strconv.Itoa(util.Abs(lineInt)))
|
||||
|
||||
// Write the spaces before the line number if necessary
|
||||
for i := 0; i < w.maxLineNumLength-len(lineNum); i++ {
|
||||
for i := 0; i < w.maxLineNumLength-len(lineNum) && vloc.X < w.gutterOffset; i++ {
|
||||
screen.SetContent(w.X+vloc.X, w.Y+vloc.Y, ' ', nil, lineNumStyle)
|
||||
vloc.X++
|
||||
}
|
||||
// Write the actual line number
|
||||
for _, ch := range lineNum {
|
||||
if softwrapped {
|
||||
for i := 0; i < len(lineNum) && vloc.X < w.gutterOffset; i++ {
|
||||
if softwrapped || (w.bufWidth == 0 && w.Buf.Settings["softwrap"] == true) {
|
||||
screen.SetContent(w.X+vloc.X, w.Y+vloc.Y, ' ', nil, lineNumStyle)
|
||||
} else {
|
||||
screen.SetContent(w.X+vloc.X, w.Y+vloc.Y, ch, nil, lineNumStyle)
|
||||
screen.SetContent(w.X+vloc.X, w.Y+vloc.Y, lineNum[i], nil, lineNumStyle)
|
||||
}
|
||||
vloc.X++
|
||||
}
|
||||
|
||||
// Write the extra space
|
||||
if vloc.X < w.gutterOffset {
|
||||
screen.SetContent(w.X+vloc.X, w.Y+vloc.Y, ' ', nil, lineNumStyle)
|
||||
vloc.X++
|
||||
}
|
||||
}
|
||||
|
||||
// getStyle returns the highlight style for the given character position
|
||||
// If there is no change to the current highlight style it just returns that
|
||||
@ -364,18 +390,7 @@ func (w *BufWindow) displayBuffer() {
|
||||
|
||||
if b.ModifiedThisFrame {
|
||||
if b.Settings["diffgutter"].(bool) {
|
||||
b.UpdateDiff(func(synchronous bool) {
|
||||
// If the diff was updated asynchronously, the outer call to
|
||||
// displayBuffer might already be completed and we need to
|
||||
// schedule a redraw in order to display the new diff.
|
||||
// Note that this cannot lead to an infinite recursion
|
||||
// because the modifications were cleared above so there won't
|
||||
// be another call to UpdateDiff when displayBuffer is called
|
||||
// during the redraw.
|
||||
if !synchronous {
|
||||
screen.Redraw()
|
||||
}
|
||||
})
|
||||
b.UpdateDiff()
|
||||
}
|
||||
b.ModifiedThisFrame = false
|
||||
}
|
||||
@ -383,26 +398,20 @@ func (w *BufWindow) displayBuffer() {
|
||||
var matchingBraces []buffer.Loc
|
||||
// bracePairs is defined in buffer.go
|
||||
if b.Settings["matchbrace"].(bool) {
|
||||
for _, bp := range buffer.BracePairs {
|
||||
for _, c := range b.GetCursors() {
|
||||
if c.HasSelection() {
|
||||
continue
|
||||
}
|
||||
curX := c.X
|
||||
curLoc := c.Loc
|
||||
|
||||
r := c.RuneUnder(curX)
|
||||
rl := c.RuneUnder(curX - 1)
|
||||
if r == bp[0] || r == bp[1] || rl == bp[0] || rl == bp[1] {
|
||||
mb, left, found := b.FindMatchingBrace(bp, curLoc)
|
||||
mb, left, found := b.FindMatchingBrace(c.Loc)
|
||||
if found {
|
||||
matchingBraces = append(matchingBraces, mb)
|
||||
if !left {
|
||||
matchingBraces = append(matchingBraces, curLoc)
|
||||
if b.Settings["matchbracestyle"].(string) != "highlight" {
|
||||
matchingBraces = append(matchingBraces, c.Loc)
|
||||
}
|
||||
} else {
|
||||
matchingBraces = append(matchingBraces, curLoc.Move(-1, b))
|
||||
}
|
||||
}
|
||||
matchingBraces = append(matchingBraces, c.Loc.Move(-1, b))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -446,7 +455,7 @@ func (w *BufWindow) displayBuffer() {
|
||||
|
||||
currentLine := false
|
||||
for _, c := range cursors {
|
||||
if bloc.Y == c.Y && w.active {
|
||||
if !c.HasSelection() && bloc.Y == c.Y && w.active {
|
||||
currentLine = true
|
||||
break
|
||||
}
|
||||
@ -473,6 +482,12 @@ func (w *BufWindow) displayBuffer() {
|
||||
vloc.X = w.gutterOffset
|
||||
}
|
||||
|
||||
bline := b.LineBytes(bloc.Y)
|
||||
blineLen := util.CharacterCount(bline)
|
||||
|
||||
leadingwsEnd := len(util.GetLeadingWhitespace(bline))
|
||||
trailingwsStart := blineLen - util.CharacterCount(util.GetTrailingWhitespace(bline))
|
||||
|
||||
line, nColsBeforeStart, bslice, startStyle := w.getStartInfo(w.StartCol, bloc.Y)
|
||||
if startStyle != nil {
|
||||
curStyle = *startStyle
|
||||
@ -482,13 +497,51 @@ func (w *BufWindow) displayBuffer() {
|
||||
draw := func(r rune, combc []rune, style tcell.Style, highlight bool, showcursor bool) {
|
||||
if nColsBeforeStart <= 0 && vloc.Y >= 0 {
|
||||
if highlight {
|
||||
if w.Buf.HighlightSearch && w.Buf.SearchMatch(bloc) {
|
||||
style = config.DefStyle.Reverse(true)
|
||||
if s, ok := config.Colorscheme["hlsearch"]; ok {
|
||||
style = s
|
||||
}
|
||||
}
|
||||
|
||||
_, origBg, _ := style.Decompose()
|
||||
_, defBg, _ := config.DefStyle.Decompose()
|
||||
|
||||
// syntax highlighting with non-default background takes precedence
|
||||
// syntax or hlsearch highlighting with non-default background takes precedence
|
||||
// over cursor-line and color-column
|
||||
dontOverrideBackground := origBg != defBg
|
||||
|
||||
if b.Settings["hltaberrors"].(bool) {
|
||||
if s, ok := config.Colorscheme["tab-error"]; ok {
|
||||
isTab := (r == '\t') || (r == ' ' && !showcursor)
|
||||
if (b.Settings["tabstospaces"].(bool) && isTab) ||
|
||||
(!b.Settings["tabstospaces"].(bool) && bloc.X < leadingwsEnd && r == ' ' && !isTab) {
|
||||
fg, _, _ := s.Decompose()
|
||||
style = style.Background(fg)
|
||||
dontOverrideBackground = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if b.Settings["hltrailingws"].(bool) {
|
||||
if s, ok := config.Colorscheme["trailingws"]; ok {
|
||||
if bloc.X >= trailingwsStart && bloc.X < blineLen {
|
||||
hl := true
|
||||
for _, c := range cursors {
|
||||
if c.NewTrailingWsY == bloc.Y {
|
||||
hl = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if hl {
|
||||
fg, _, _ := s.Decompose()
|
||||
style = style.Background(fg)
|
||||
dontOverrideBackground = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, c := range cursors {
|
||||
if c.HasSelection() &&
|
||||
(bloc.GreaterEqual(c.CurSelection[0]) && bloc.LessThan(c.CurSelection[1]) ||
|
||||
@ -541,10 +594,18 @@ func (w *BufWindow) displayBuffer() {
|
||||
|
||||
for _, mb := range matchingBraces {
|
||||
if mb.X == bloc.X && mb.Y == bloc.Y {
|
||||
if b.Settings["matchbracestyle"].(string) == "highlight" {
|
||||
if s, ok := config.Colorscheme["match-brace"]; ok {
|
||||
style = s
|
||||
} else {
|
||||
style = style.Reverse(true)
|
||||
}
|
||||
} else {
|
||||
style = style.Underline(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
screen.SetContent(w.X+vloc.X, w.Y+vloc.Y, r, combc, style)
|
||||
|
||||
@ -564,6 +625,8 @@ func (w *BufWindow) displayBuffer() {
|
||||
|
||||
wrap := func() {
|
||||
vloc.X = 0
|
||||
|
||||
if vloc.Y >= 0 {
|
||||
if w.hasMessage {
|
||||
w.drawGutter(&vloc, &bloc)
|
||||
}
|
||||
@ -575,6 +638,9 @@ func (w *BufWindow) displayBuffer() {
|
||||
if b.Settings["ruler"].(bool) {
|
||||
w.drawLineNum(lineNumStyle, true, &vloc, &bloc)
|
||||
}
|
||||
} else {
|
||||
vloc.X = w.gutterOffset
|
||||
}
|
||||
}
|
||||
|
||||
type glyph struct {
|
||||
@ -593,7 +659,7 @@ func (w *BufWindow) displayBuffer() {
|
||||
wordwidth := 0
|
||||
|
||||
totalwidth := w.StartCol - nColsBeforeStart
|
||||
for len(line) > 0 {
|
||||
for len(line) > 0 && vloc.X < maxWidth {
|
||||
r, combc, size := util.DecodeCharacter(line)
|
||||
line = line[size:]
|
||||
|
||||
@ -751,8 +817,14 @@ func (w *BufWindow) displayScrollBar() {
|
||||
scrollBarStyle = style
|
||||
}
|
||||
|
||||
scrollBarChar := config.GetGlobalOption("scrollbarchar").(string)
|
||||
if util.CharacterCountInString(scrollBarChar) != 1 {
|
||||
scrollBarChar = "|"
|
||||
}
|
||||
scrollBarRune := []rune(scrollBarChar)
|
||||
|
||||
for y := barstart; y < util.Min(barstart+barsize, w.Y+w.bufHeight); y++ {
|
||||
screen.SetContent(scrollX, y, '|', nil, scrollBarStyle)
|
||||
screen.SetContent(scrollX, y, scrollBarRune[0], nil, scrollBarStyle)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ package display
|
||||
|
||||
import (
|
||||
runewidth "github.com/mattn/go-runewidth"
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
"github.com/zyedidia/micro/v2/internal/buffer"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/info"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
)
|
||||
|
||||
type InfoWindow struct {
|
||||
@ -260,7 +260,9 @@ func (i *InfoWindow) Display() {
|
||||
done := false
|
||||
|
||||
statusLineStyle := config.DefStyle.Reverse(true)
|
||||
if style, ok := config.Colorscheme["statusline"]; ok {
|
||||
if style, ok := config.Colorscheme["statusline.suggestions"]; ok {
|
||||
statusLineStyle = style
|
||||
} else if style, ok := config.Colorscheme["statusline"]; ok {
|
||||
statusLineStyle = style
|
||||
}
|
||||
keymenuOffset := 0
|
||||
|
@ -30,6 +30,28 @@ func (s SLoc) GreaterThan(b SLoc) bool {
|
||||
return s.Line == b.Line && s.Row > b.Row
|
||||
}
|
||||
|
||||
// LessEqual returns true if s is less than or equal to b
|
||||
func (s SLoc) LessEqual(b SLoc) bool {
|
||||
if s.Line < b.Line {
|
||||
return true
|
||||
}
|
||||
if s.Line == b.Line && s.Row < b.Row {
|
||||
return true
|
||||
}
|
||||
return s == b
|
||||
}
|
||||
|
||||
// GreaterEqual returns true if s is bigger than or equal to b
|
||||
func (s SLoc) GreaterEqual(b SLoc) bool {
|
||||
if s.Line > b.Line {
|
||||
return true
|
||||
}
|
||||
if s.Line == b.Line && s.Row > b.Row {
|
||||
return true
|
||||
}
|
||||
return s == b
|
||||
}
|
||||
|
||||
// VLoc represents a location in the buffer as a visual location in the
|
||||
// linewrapped buffer.
|
||||
type VLoc struct {
|
||||
@ -269,13 +291,7 @@ func (w *BufWindow) diff(s1, s2 SLoc) int {
|
||||
// within the buffer boundaries.
|
||||
func (w *BufWindow) Scroll(s SLoc, n int) SLoc {
|
||||
if !w.Buf.Settings["softwrap"].(bool) {
|
||||
s.Line += n
|
||||
if s.Line < 0 {
|
||||
s.Line = 0
|
||||
}
|
||||
if s.Line > w.Buf.LinesNum()-1 {
|
||||
s.Line = w.Buf.LinesNum() - 1
|
||||
}
|
||||
s.Line = util.Clamp(s.Line+n, 0, w.Buf.LinesNum()-1)
|
||||
return s
|
||||
}
|
||||
return w.scroll(s, n)
|
||||
|
@ -47,6 +47,18 @@ var statusInfo = map[string]func(*buffer.Buffer) string{
|
||||
}
|
||||
return ""
|
||||
},
|
||||
"overwrite": func(b *buffer.Buffer) string {
|
||||
if b.OverwriteMode && !b.Type.Readonly {
|
||||
return "[ovwr] "
|
||||
}
|
||||
return ""
|
||||
},
|
||||
"lines": func(b *buffer.Buffer) string {
|
||||
return strconv.Itoa(b.LinesNum())
|
||||
},
|
||||
"percentage": func(b *buffer.Buffer) string {
|
||||
return strconv.Itoa((b.GetActiveCursor().Y + 1) * 100 / b.LinesNum())
|
||||
},
|
||||
}
|
||||
|
||||
func SetStatusInfoFnLua(fn string) {
|
||||
@ -60,7 +72,7 @@ func SetStatusInfoFnLua(fn string) {
|
||||
return
|
||||
}
|
||||
statusInfo[fn] = func(b *buffer.Buffer) string {
|
||||
if pl == nil || !pl.IsEnabled() {
|
||||
if pl == nil || !pl.IsLoaded() {
|
||||
return ""
|
||||
}
|
||||
val, err := pl.Call(plFn, luar.New(ulua.L, b))
|
||||
@ -104,7 +116,9 @@ func (s *StatusLine) Display() {
|
||||
// autocomplete suggestions (for the buffer, not for the infowindow)
|
||||
if b.HasSuggestions && len(b.Suggestions) > 1 {
|
||||
statusLineStyle := config.DefStyle.Reverse(true)
|
||||
if style, ok := config.Colorscheme["statusline"]; ok {
|
||||
if style, ok := config.Colorscheme["statusline.suggestions"]; ok {
|
||||
statusLineStyle = style
|
||||
} else if style, ok := config.Colorscheme["statusline"]; ok {
|
||||
statusLineStyle = style
|
||||
}
|
||||
x := 0
|
||||
@ -161,9 +175,17 @@ func (s *StatusLine) Display() {
|
||||
rightText = formatParser.ReplaceAllFunc(rightText, formatter)
|
||||
|
||||
statusLineStyle := config.DefStyle.Reverse(true)
|
||||
if s.win.IsActive() {
|
||||
if style, ok := config.Colorscheme["statusline"]; ok {
|
||||
statusLineStyle = style
|
||||
}
|
||||
} else {
|
||||
if style, ok := config.Colorscheme["statusline.inactive"]; ok {
|
||||
statusLineStyle = style
|
||||
} else if style, ok := config.Colorscheme["statusline"]; ok {
|
||||
statusLineStyle = style
|
||||
}
|
||||
}
|
||||
|
||||
leftLen := util.StringWidth(leftText, util.CharacterCount(leftText), 1)
|
||||
rightLen := util.StringWidth(rightText, util.CharacterCount(rightText), 1)
|
||||
|
@ -2,6 +2,7 @@ package display
|
||||
|
||||
import (
|
||||
runewidth "github.com/mattn/go-runewidth"
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
"github.com/zyedidia/micro/v2/internal/buffer"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
@ -94,7 +95,14 @@ func (w *TabWindow) Display() {
|
||||
x := -w.hscroll
|
||||
done := false
|
||||
|
||||
tabBarStyle := config.DefStyle.Reverse(true)
|
||||
globalTabReverse := config.GetGlobalOption("tabreverse").(bool)
|
||||
globalTabHighlight := config.GetGlobalOption("tabhighlight").(bool)
|
||||
|
||||
// xor of reverse and tab highlight to get tab character (as in filename and surrounding characters) reverse state
|
||||
tabCharHighlight := (globalTabReverse || globalTabHighlight) && !(globalTabReverse && globalTabHighlight)
|
||||
|
||||
reverseStyles := func(reverse bool) (tcell.Style, tcell.Style) {
|
||||
tabBarStyle := config.DefStyle.Reverse(reverse)
|
||||
if style, ok := config.Colorscheme["tabbar"]; ok {
|
||||
tabBarStyle = style
|
||||
}
|
||||
@ -102,8 +110,12 @@ func (w *TabWindow) Display() {
|
||||
if style, ok := config.Colorscheme["tabbar.active"]; ok {
|
||||
tabBarActiveStyle = style
|
||||
}
|
||||
return tabBarStyle, tabBarActiveStyle
|
||||
}
|
||||
|
||||
draw := func(r rune, n int, active bool, reversed bool) {
|
||||
tabBarStyle, tabBarActiveStyle := reverseStyles(reversed)
|
||||
|
||||
draw := func(r rune, n int, active bool) {
|
||||
style := tabBarStyle
|
||||
if active {
|
||||
style = tabBarActiveStyle
|
||||
@ -131,28 +143,33 @@ func (w *TabWindow) Display() {
|
||||
|
||||
for i, n := range w.Names {
|
||||
if i == w.active {
|
||||
draw('[', 1, true)
|
||||
draw('[', 1, true, tabCharHighlight)
|
||||
} else {
|
||||
draw(' ', 1, false)
|
||||
draw(' ', 1, false, tabCharHighlight)
|
||||
}
|
||||
|
||||
for _, c := range n {
|
||||
draw(c, 1, i == w.active)
|
||||
draw(c, 1, i == w.active, tabCharHighlight)
|
||||
}
|
||||
|
||||
if i == len(w.Names)-1 {
|
||||
done = true
|
||||
}
|
||||
|
||||
if i == w.active {
|
||||
draw(']', 1, true)
|
||||
draw(' ', 2, true)
|
||||
draw(']', 1, true, tabCharHighlight)
|
||||
draw(' ', 2, true, globalTabReverse)
|
||||
} else {
|
||||
draw(' ', 3, false)
|
||||
draw(' ', 1, false, tabCharHighlight)
|
||||
draw(' ', 2, false, globalTabReverse)
|
||||
}
|
||||
|
||||
if x >= w.Width {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if x < w.Width {
|
||||
draw(' ', w.Width-x, false)
|
||||
draw(' ', w.Width-x, false, globalTabReverse)
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package display
|
||||
|
||||
import (
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
"github.com/micro-editor/terminal"
|
||||
"github.com/zyedidia/micro/v2/internal/buffer"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/micro/v2/internal/shell"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
"github.com/zyedidia/terminal"
|
||||
)
|
||||
|
||||
type TermWindow struct {
|
||||
@ -110,6 +110,8 @@ func (w *TermWindow) Display() {
|
||||
}
|
||||
if w.State.CursorVisible() && w.active {
|
||||
curx, cury := w.State.Cursor()
|
||||
if curx < w.Width && cury < w.Height {
|
||||
screen.ShowCursor(curx+w.X, cury+w.Y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,17 @@
|
||||
package info
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"errors"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
)
|
||||
|
||||
// LoadHistory attempts to load user history from configDir/buffers/history
|
||||
@ -15,24 +21,23 @@ func (i *InfoBuf) LoadHistory() {
|
||||
if config.GetGlobalOption("savehistory").(bool) {
|
||||
file, err := os.Open(filepath.Join(config.ConfigDir, "buffers", "history"))
|
||||
var decodedMap map[string][]string
|
||||
if err == nil {
|
||||
defer file.Close()
|
||||
decoder := gob.NewDecoder(file)
|
||||
err = decoder.Decode(&decodedMap)
|
||||
|
||||
if err != nil {
|
||||
if !errors.Is(err, fs.ErrNotExist) {
|
||||
i.Error("Error loading history: ", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
err = gob.NewDecoder(file).Decode(&decodedMap)
|
||||
if err != nil {
|
||||
i.Error("Error decoding history: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
if decodedMap != nil {
|
||||
i.History = decodedMap
|
||||
} else {
|
||||
i.History = make(map[string][]string)
|
||||
}
|
||||
} else {
|
||||
i.History = make(map[string][]string)
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,16 +52,18 @@ func (i *InfoBuf) SaveHistory() {
|
||||
}
|
||||
}
|
||||
|
||||
file, err := os.Create(filepath.Join(config.ConfigDir, "buffers", "history"))
|
||||
if err == nil {
|
||||
defer file.Close()
|
||||
encoder := gob.NewEncoder(file)
|
||||
|
||||
err = encoder.Encode(i.History)
|
||||
var buf bytes.Buffer
|
||||
err := gob.NewEncoder(&buf).Encode(i.History)
|
||||
if err != nil {
|
||||
i.Error("Error saving history:", err)
|
||||
screen.TermMessage("Error encoding history: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
filename := filepath.Join(config.ConfigDir, "buffers", "history")
|
||||
err = util.SafeWrite(filename, buf.Bytes(), true)
|
||||
if err != nil {
|
||||
screen.TermMessage("Error saving history: ", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -102,3 +109,51 @@ func (i *InfoBuf) DownHistory(history []string) {
|
||||
i.Buffer.GetActiveCursor().GotoLoc(i.End())
|
||||
}
|
||||
}
|
||||
|
||||
// SearchUpHistory fetches the previous item in the history
|
||||
// beginning with the text in the infobuffer before cursor
|
||||
func (i *InfoBuf) SearchUpHistory(history []string) {
|
||||
if i.HistoryNum > 0 && i.HasPrompt && !i.HasYN {
|
||||
i.searchHistory(history, false)
|
||||
}
|
||||
}
|
||||
|
||||
// SearchDownHistory fetches the next item in the history
|
||||
// beginning with the text in the infobuffer before cursor
|
||||
func (i *InfoBuf) SearchDownHistory(history []string) {
|
||||
if i.HistoryNum < len(history)-1 && i.HasPrompt && !i.HasYN {
|
||||
i.searchHistory(history, true)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *InfoBuf) searchHistory(history []string, down bool) {
|
||||
line := string(i.LineBytes(0))
|
||||
c := i.Buffer.GetActiveCursor()
|
||||
|
||||
if !i.HistorySearch || !strings.HasPrefix(line, i.HistorySearchPrefix) {
|
||||
i.HistorySearch = true
|
||||
i.HistorySearchPrefix = util.SliceStartStr(line, c.X)
|
||||
}
|
||||
|
||||
found := -1
|
||||
if down {
|
||||
for j := i.HistoryNum + 1; j < len(history); j++ {
|
||||
if strings.HasPrefix(history[j], i.HistorySearchPrefix) {
|
||||
found = j
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for j := i.HistoryNum - 1; j >= 0; j-- {
|
||||
if strings.HasPrefix(history[j], i.HistorySearchPrefix) {
|
||||
found = j
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if found != -1 {
|
||||
i.HistoryNum = found
|
||||
i.Replace(i.Start(), i.End(), history[found])
|
||||
c.GotoLoc(i.End())
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
// The InfoBuf displays messages and other info at the bottom of the screen.
|
||||
// It is respresented as a buffer and a message with a style.
|
||||
// It is represented as a buffer and a message with a style.
|
||||
type InfoBuf struct {
|
||||
*buffer.Buffer
|
||||
|
||||
@ -25,6 +25,10 @@ type InfoBuf struct {
|
||||
// It's a map of history type -> history array
|
||||
History map[string][]string
|
||||
HistoryNum int
|
||||
// HistorySearch indicates whether we are searching for history items
|
||||
// beginning with HistorySearchPrefix
|
||||
HistorySearch bool
|
||||
HistorySearchPrefix string
|
||||
|
||||
// Is the current message a message from the gutter
|
||||
HasGutter bool
|
||||
@ -102,6 +106,7 @@ func (i *InfoBuf) Prompt(prompt string, msg string, ptype string, eventcb func(s
|
||||
i.History[ptype] = append(i.History[ptype], "")
|
||||
}
|
||||
i.HistoryNum = len(i.History[ptype]) - 1
|
||||
i.HistorySearch = false
|
||||
|
||||
i.PromptType = ptype
|
||||
i.Msg = prompt
|
||||
@ -138,13 +143,12 @@ func (i *InfoBuf) DonePrompt(canceled bool) {
|
||||
if i.PromptCallback != nil {
|
||||
if canceled {
|
||||
i.Replace(i.Start(), i.End(), "")
|
||||
i.PromptCallback("", true)
|
||||
h := i.History[i.PromptType]
|
||||
i.History[i.PromptType] = h[:len(h)-1]
|
||||
i.PromptCallback("", true)
|
||||
} else {
|
||||
resp := string(i.LineBytes(0))
|
||||
i.Replace(i.Start(), i.End(), "")
|
||||
i.PromptCallback(resp, false)
|
||||
h := i.History[i.PromptType]
|
||||
h[len(h)-1] = resp
|
||||
|
||||
@ -155,6 +159,8 @@ func (i *InfoBuf) DonePrompt(canceled bool) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
i.PromptCallback(resp, false)
|
||||
}
|
||||
// i.PromptCallback = nil
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ import (
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
@ -27,7 +26,6 @@ import (
|
||||
)
|
||||
|
||||
var L *lua.LState
|
||||
var Lock sync.Mutex
|
||||
|
||||
// LoadFile loads a lua file
|
||||
func LoadFile(module string, file string, data []byte) error {
|
||||
@ -127,6 +125,7 @@ func importIo() *lua.LTable {
|
||||
L.SetField(pkg, "MultiWriter", luar.New(L, io.MultiWriter))
|
||||
L.SetField(pkg, "NewSectionReader", luar.New(L, io.NewSectionReader))
|
||||
L.SetField(pkg, "Pipe", luar.New(L, io.Pipe))
|
||||
L.SetField(pkg, "ReadAll", luar.New(L, io.ReadAll))
|
||||
L.SetField(pkg, "ReadAtLeast", luar.New(L, io.ReadAtLeast))
|
||||
L.SetField(pkg, "ReadFull", luar.New(L, io.ReadFull))
|
||||
L.SetField(pkg, "TeeReader", luar.New(L, io.TeeReader))
|
||||
@ -372,13 +371,15 @@ func importOs() *lua.LTable {
|
||||
L.SetField(pkg, "PathListSeparator", luar.New(L, os.PathListSeparator))
|
||||
L.SetField(pkg, "PathSeparator", luar.New(L, os.PathSeparator))
|
||||
L.SetField(pkg, "Pipe", luar.New(L, os.Pipe))
|
||||
L.SetField(pkg, "ReadDir", luar.New(L, os.ReadDir))
|
||||
L.SetField(pkg, "ReadFile", luar.New(L, os.ReadFile))
|
||||
L.SetField(pkg, "Readlink", luar.New(L, os.Readlink))
|
||||
L.SetField(pkg, "Remove", luar.New(L, os.Remove))
|
||||
L.SetField(pkg, "RemoveAll", luar.New(L, os.RemoveAll))
|
||||
L.SetField(pkg, "Rename", luar.New(L, os.Rename))
|
||||
L.SetField(pkg, "SEEK_CUR", luar.New(L, os.SEEK_CUR))
|
||||
L.SetField(pkg, "SEEK_END", luar.New(L, os.SEEK_END))
|
||||
L.SetField(pkg, "SEEK_SET", luar.New(L, os.SEEK_SET))
|
||||
L.SetField(pkg, "SEEK_CUR", luar.New(L, io.SeekCurrent))
|
||||
L.SetField(pkg, "SEEK_END", luar.New(L, io.SeekEnd))
|
||||
L.SetField(pkg, "SEEK_SET", luar.New(L, io.SeekStart))
|
||||
L.SetField(pkg, "SameFile", luar.New(L, os.SameFile))
|
||||
L.SetField(pkg, "Setenv", luar.New(L, os.Setenv))
|
||||
L.SetField(pkg, "StartProcess", luar.New(L, os.StartProcess))
|
||||
@ -390,6 +391,7 @@ func importOs() *lua.LTable {
|
||||
L.SetField(pkg, "TempDir", luar.New(L, os.TempDir))
|
||||
L.SetField(pkg, "Truncate", luar.New(L, os.Truncate))
|
||||
L.SetField(pkg, "UserHomeDir", luar.New(L, os.UserHomeDir))
|
||||
L.SetField(pkg, "WriteFile", luar.New(L, os.WriteFile))
|
||||
|
||||
return pkg
|
||||
}
|
||||
@ -425,7 +427,6 @@ func importPath() *lua.LTable {
|
||||
func importFilePath() *lua.LTable {
|
||||
pkg := L.NewTable()
|
||||
|
||||
L.SetField(pkg, "Join", luar.New(L, filepath.Join))
|
||||
L.SetField(pkg, "Abs", luar.New(L, filepath.Abs))
|
||||
L.SetField(pkg, "Base", luar.New(L, filepath.Base))
|
||||
L.SetField(pkg, "Clean", luar.New(L, filepath.Clean))
|
||||
@ -523,21 +524,16 @@ func importErrors() *lua.LTable {
|
||||
func importTime() *lua.LTable {
|
||||
pkg := L.NewTable()
|
||||
|
||||
L.SetField(pkg, "After", luar.New(L, time.After))
|
||||
L.SetField(pkg, "Sleep", luar.New(L, time.Sleep))
|
||||
L.SetField(pkg, "Tick", luar.New(L, time.Tick))
|
||||
L.SetField(pkg, "Since", luar.New(L, time.Since))
|
||||
L.SetField(pkg, "FixedZone", luar.New(L, time.FixedZone))
|
||||
L.SetField(pkg, "LoadLocation", luar.New(L, time.LoadLocation))
|
||||
L.SetField(pkg, "NewTicker", luar.New(L, time.NewTicker))
|
||||
L.SetField(pkg, "Date", luar.New(L, time.Date))
|
||||
L.SetField(pkg, "Now", luar.New(L, time.Now))
|
||||
L.SetField(pkg, "Parse", luar.New(L, time.Parse))
|
||||
L.SetField(pkg, "ParseDuration", luar.New(L, time.ParseDuration))
|
||||
L.SetField(pkg, "ParseInLocation", luar.New(L, time.ParseInLocation))
|
||||
L.SetField(pkg, "Unix", luar.New(L, time.Unix))
|
||||
L.SetField(pkg, "AfterFunc", luar.New(L, time.AfterFunc))
|
||||
L.SetField(pkg, "NewTimer", luar.New(L, time.NewTimer))
|
||||
L.SetField(pkg, "Nanosecond", luar.New(L, time.Nanosecond))
|
||||
L.SetField(pkg, "Microsecond", luar.New(L, time.Microsecond))
|
||||
L.SetField(pkg, "Millisecond", luar.New(L, time.Millisecond))
|
||||
@ -545,6 +541,15 @@ func importTime() *lua.LTable {
|
||||
L.SetField(pkg, "Minute", luar.New(L, time.Minute))
|
||||
L.SetField(pkg, "Hour", luar.New(L, time.Hour))
|
||||
|
||||
// TODO: these raw Go timer APIs don't provide any synchronization
|
||||
// with micro. Stop exposing them to lua once plugins switch to using
|
||||
// the safer micro.After() interface instead. See issue #3209
|
||||
L.SetField(pkg, "After", luar.New(L, time.After))
|
||||
L.SetField(pkg, "AfterFunc", luar.New(L, time.AfterFunc))
|
||||
L.SetField(pkg, "NewTicker", luar.New(L, time.NewTicker))
|
||||
L.SetField(pkg, "NewTimer", luar.New(L, time.NewTimer))
|
||||
L.SetField(pkg, "Tick", luar.New(L, time.Tick))
|
||||
|
||||
return pkg
|
||||
}
|
||||
|
||||
|
@ -6,9 +6,9 @@ import (
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/micro-editor/tcell/v2"
|
||||
"github.com/zyedidia/micro/v2/internal/config"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
"github.com/zyedidia/tcell/v2"
|
||||
)
|
||||
|
||||
// Screen is the tcell screen we use to draw to the terminal
|
||||
@ -22,6 +22,10 @@ var Screen tcell.Screen
|
||||
// Events is the channel of tcell events
|
||||
var Events chan (tcell.Event)
|
||||
|
||||
// RestartCallback is called when the screen is restarted after it was
|
||||
// temporarily shut down
|
||||
var RestartCallback func()
|
||||
|
||||
// The lock is necessary since the screen is polled on a separate thread
|
||||
var lock sync.Mutex
|
||||
|
||||
@ -29,6 +33,12 @@ var lock sync.Mutex
|
||||
// written to even if no event user event has occurred
|
||||
var drawChan chan bool
|
||||
|
||||
// rawSeq is the list of raw escape sequences that are bound to some actions
|
||||
// via keybindings and thus should be parsed by tcell. We need to register
|
||||
// them in tcell every time we reinitialize the screen, so we need to remember
|
||||
// them in a list
|
||||
var rawSeq = make([]string, 0)
|
||||
|
||||
// Lock locks the screen lock
|
||||
func Lock() {
|
||||
lock.Lock()
|
||||
@ -79,6 +89,10 @@ func ShowFakeCursor(x, y int) {
|
||||
lastCursor.style = style
|
||||
}
|
||||
|
||||
func UseFake() bool {
|
||||
return util.FakeCursor || config.GetGlobalOption("fakecursor").(bool)
|
||||
}
|
||||
|
||||
// ShowFakeCursorMulti is the same as ShowFakeCursor except it does not
|
||||
// reset previous locations of the cursor
|
||||
// Fake cursors are also necessary to display multiple cursors
|
||||
@ -91,7 +105,7 @@ func ShowFakeCursorMulti(x, y int) {
|
||||
// if enabled or using the terminal cursor otherwise
|
||||
// By default only the windows console will use a fake cursor
|
||||
func ShowCursor(x, y int) {
|
||||
if util.FakeCursor {
|
||||
if UseFake() {
|
||||
ShowFakeCursor(x, y)
|
||||
} else {
|
||||
Screen.ShowCursor(x, y)
|
||||
@ -106,13 +120,41 @@ func SetContent(x, y int, mainc rune, combc []rune, style tcell.Style) {
|
||||
}
|
||||
|
||||
Screen.SetContent(x, y, mainc, combc, style)
|
||||
if util.FakeCursor && lastCursor.x == x && lastCursor.y == y {
|
||||
if UseFake() && lastCursor.x == x && lastCursor.y == y {
|
||||
lastCursor.r = mainc
|
||||
lastCursor.style = style
|
||||
lastCursor.combc = combc
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterRawSeq registers a raw escape sequence that should be parsed by tcell
|
||||
func RegisterRawSeq(r string) {
|
||||
for _, seq := range rawSeq {
|
||||
if seq == r {
|
||||
return
|
||||
}
|
||||
}
|
||||
rawSeq = append(rawSeq, r)
|
||||
|
||||
if Screen != nil {
|
||||
Screen.RegisterRawSeq(r)
|
||||
}
|
||||
}
|
||||
|
||||
// UnregisterRawSeq unregisters a raw escape sequence that should be parsed by tcell
|
||||
func UnregisterRawSeq(r string) {
|
||||
for i, seq := range rawSeq {
|
||||
if seq == r {
|
||||
rawSeq[i] = rawSeq[len(rawSeq)-1]
|
||||
rawSeq = rawSeq[:len(rawSeq)-1]
|
||||
}
|
||||
}
|
||||
|
||||
if Screen != nil {
|
||||
Screen.UnregisterRawSeq(r)
|
||||
}
|
||||
}
|
||||
|
||||
// TempFini shuts the screen down temporarily
|
||||
func TempFini() bool {
|
||||
screenWasNil := Screen == nil
|
||||
@ -130,6 +172,10 @@ func TempStart(screenWasNil bool) {
|
||||
if !screenWasNil {
|
||||
Init()
|
||||
Unlock()
|
||||
|
||||
if RestartCallback != nil {
|
||||
RestartCallback()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,10 +184,13 @@ func Init() error {
|
||||
drawChan = make(chan bool, 8)
|
||||
|
||||
// Should we enable true color?
|
||||
truecolor := os.Getenv("MICRO_TRUECOLOR") == "1"
|
||||
|
||||
if !truecolor {
|
||||
truecolor := config.GetGlobalOption("truecolor").(string)
|
||||
if truecolor == "on" || (truecolor == "auto" && os.Getenv("MICRO_TRUECOLOR") == "1") {
|
||||
os.Setenv("TCELL_TRUECOLOR", "enable")
|
||||
} else if truecolor == "off" {
|
||||
os.Setenv("TCELL_TRUECOLOR", "disable")
|
||||
} else {
|
||||
// For "auto", tcell already autodetects truecolor by default
|
||||
}
|
||||
|
||||
var oldTerm string
|
||||
@ -183,6 +232,10 @@ func Init() error {
|
||||
Screen.EnableMouse()
|
||||
}
|
||||
|
||||
for _, r := range rawSeq {
|
||||
Screen.RegisterRawSeq(r)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,10 @@ func JobSpawn(cmdName string, cmdArgs []string, onStdout, onStderr, onExit func(
|
||||
go func() {
|
||||
// Run the process in the background and create the onExit callback
|
||||
proc.Run()
|
||||
if onExit != nil {
|
||||
jobFunc := JobFunction{onExit, outbuf.String(), userargs}
|
||||
Jobs <- jobFunc
|
||||
}
|
||||
}()
|
||||
|
||||
return &Job{proc, stdin}
|
||||
|
@ -8,10 +8,10 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"strings"
|
||||
|
||||
shellquote "github.com/kballard/go-shellquote"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/micro/v2/internal/util"
|
||||
)
|
||||
|
||||
// ExecCommand executes a command using exec
|
||||
@ -59,16 +59,11 @@ func RunBackgroundShell(input string) (func() string, error) {
|
||||
inputCmd := args[0]
|
||||
return func() string {
|
||||
output, err := RunCommand(input)
|
||||
totalLines := strings.Split(output, "\n")
|
||||
|
||||
str := output
|
||||
if len(totalLines) < 3 {
|
||||
if err == nil {
|
||||
str = fmt.Sprint(inputCmd, " exited without error")
|
||||
} else {
|
||||
if err != nil {
|
||||
str = fmt.Sprint(inputCmd, " exited with error: ", err, ": ", output)
|
||||
}
|
||||
}
|
||||
return str
|
||||
}, nil
|
||||
}
|
||||
@ -101,28 +96,30 @@ func RunInteractiveShell(input string, wait bool, getOutput bool) (string, error
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
// This is a trap for Ctrl-C so that it doesn't kill micro
|
||||
// Instead we trap Ctrl-C to kill the program we're running
|
||||
// micro is killed if the signal is ignored only on Windows, so it is
|
||||
// received
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Reset(os.Interrupt)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
go func() {
|
||||
for range c {
|
||||
cmd.Process.Kill()
|
||||
}
|
||||
}()
|
||||
|
||||
cmd.Start()
|
||||
err = cmd.Start()
|
||||
if err == nil {
|
||||
err = cmd.Wait()
|
||||
|
||||
output := outputBytes.String()
|
||||
|
||||
if wait {
|
||||
// This is just so we don't return right away and let the user press enter to return
|
||||
screen.TermMessage("")
|
||||
}
|
||||
} else {
|
||||
screen.TermMessage(err)
|
||||
}
|
||||
|
||||
output := outputBytes.String()
|
||||
|
||||
// Start the screen back up
|
||||
screen.TempStart(screenb)
|
||||
|
||||
signal.Notify(util.Sigterm, os.Interrupt)
|
||||
signal.Stop(c)
|
||||
|
||||
return output, err
|
||||
}
|
||||
|
||||
|
@ -5,9 +5,9 @@ import (
|
||||
"os/exec"
|
||||
"strconv"
|
||||
|
||||
"github.com/micro-editor/terminal"
|
||||
"github.com/zyedidia/micro/v2/internal/buffer"
|
||||
"github.com/zyedidia/micro/v2/internal/screen"
|
||||
"github.com/zyedidia/terminal"
|
||||
)
|
||||
|
||||
type TermType int
|
||||
@ -78,8 +78,9 @@ func (t *Terminal) Start(execCmd []string, getOutput bool, wait bool, callback f
|
||||
t.output = nil
|
||||
if getOutput {
|
||||
t.output = bytes.NewBuffer([]byte{})
|
||||
cmd.Stdout = t.output
|
||||
}
|
||||
Term, _, err := terminal.Start(&t.State, cmd, t.output)
|
||||
Term, _, err := terminal.Start(&t.State, cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -128,7 +129,13 @@ func (t *Terminal) Close() {
|
||||
// call the lua function that the user has given as a callback
|
||||
if t.getOutput {
|
||||
if t.callback != nil {
|
||||
t.callback(t.output.String())
|
||||
Jobs <- JobFunction{
|
||||
Function: func(out string, args []interface{}) {
|
||||
t.callback(out)
|
||||
},
|
||||
Output: t.output.String(),
|
||||
Args: nil,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,9 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
@ -15,6 +18,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/blang/semver"
|
||||
runewidth "github.com/mattn/go-runewidth"
|
||||
@ -25,7 +29,7 @@ var (
|
||||
|
||||
// Version is the version number or commit hash
|
||||
Version = "0.0.0-unknown"
|
||||
// Semantic version
|
||||
// SemVersion is the Semantic version
|
||||
SemVersion semver.Version
|
||||
// CommitHash is the commit this version was built on
|
||||
CommitHash = "Unknown"
|
||||
@ -39,8 +43,46 @@ var (
|
||||
|
||||
// Stdout is a buffer that is written to stdout when micro closes
|
||||
Stdout *bytes.Buffer
|
||||
// Sigterm is a channel where micro exits when written
|
||||
Sigterm chan os.Signal
|
||||
|
||||
// To be used for fails on (over-)write with safe writes
|
||||
ErrOverwrite = OverwriteError{}
|
||||
)
|
||||
|
||||
// To be used for file writes before umask is applied
|
||||
const FileMode os.FileMode = 0666
|
||||
|
||||
const OverwriteFailMsg = `An error occurred while writing to the file:
|
||||
|
||||
%s
|
||||
|
||||
The file may be corrupted now. The good news is that it has been
|
||||
successfully backed up. Next time you open this file with Micro,
|
||||
Micro will ask if you want to recover it from the backup.
|
||||
|
||||
The backup path is:
|
||||
|
||||
%s`
|
||||
|
||||
// OverwriteError is a custom error to add additional information
|
||||
type OverwriteError struct {
|
||||
What error
|
||||
BackupName string
|
||||
}
|
||||
|
||||
func (e OverwriteError) Error() string {
|
||||
return fmt.Sprintf(OverwriteFailMsg, e.What, e.BackupName)
|
||||
}
|
||||
|
||||
func (e OverwriteError) Is(target error) bool {
|
||||
return target == ErrOverwrite
|
||||
}
|
||||
|
||||
func (e OverwriteError) Unwrap() error {
|
||||
return e.What
|
||||
}
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
SemVersion, err = semver.Make(Version)
|
||||
@ -216,10 +258,56 @@ func FSize(f *os.File) int64 {
|
||||
return fi.Size()
|
||||
}
|
||||
|
||||
// IsWordChar returns whether or not the string is a 'word character'
|
||||
// Word characters are defined as numbers, letters, or '_'
|
||||
// IsWordChar returns whether or not a rune is a 'word character'
|
||||
// Word characters are defined as numbers, letters or sub-word delimiters
|
||||
func IsWordChar(r rune) bool {
|
||||
return unicode.IsLetter(r) || unicode.IsNumber(r) || r == '_'
|
||||
return IsAlphanumeric(r) || IsSubwordDelimiter(r)
|
||||
}
|
||||
|
||||
// IsNonWordChar returns whether or not a rune is not a 'word character'
|
||||
// Non word characters are defined as all characters not being numbers, letters or sub-word delimiters
|
||||
// See IsWordChar()
|
||||
func IsNonWordChar(r rune) bool {
|
||||
return !IsWordChar(r)
|
||||
}
|
||||
|
||||
// IsSubwordDelimiter returns whether or not a rune is a 'sub-word delimiter character'
|
||||
// i.e. is considered a part of the word and is used as a delimiter between sub-words of the word.
|
||||
// For now the only sub-word delimiter character is '_'.
|
||||
func IsSubwordDelimiter(r rune) bool {
|
||||
return r == '_'
|
||||
}
|
||||
|
||||
// IsAlphanumeric returns whether or not a rune is an 'alphanumeric character'
|
||||
// Alphanumeric characters are defined as numbers or letters
|
||||
func IsAlphanumeric(r rune) bool {
|
||||
return unicode.IsLetter(r) || unicode.IsNumber(r)
|
||||
}
|
||||
|
||||
// IsUpperAlphanumeric returns whether or not a rune is an 'upper alphanumeric character'
|
||||
// Upper alphanumeric characters are defined as numbers or upper-case letters
|
||||
func IsUpperAlphanumeric(r rune) bool {
|
||||
return IsUpperLetter(r) || unicode.IsNumber(r)
|
||||
}
|
||||
|
||||
// IsLowerAlphanumeric returns whether or not a rune is a 'lower alphanumeric character'
|
||||
// Lower alphanumeric characters are defined as numbers or lower-case letters
|
||||
func IsLowerAlphanumeric(r rune) bool {
|
||||
return IsLowerLetter(r) || unicode.IsNumber(r)
|
||||
}
|
||||
|
||||
// IsUpperLetter returns whether or not a rune is an 'upper letter character'
|
||||
// Upper letter characters are defined as upper-case letters
|
||||
func IsUpperLetter(r rune) bool {
|
||||
// unicode.IsUpper() returns true for letters only
|
||||
return unicode.IsUpper(r)
|
||||
}
|
||||
|
||||
// IsLowerLetter returns whether or not a rune is a 'lower letter character'
|
||||
// Lower letter characters are defined as lower-case letters
|
||||
func IsLowerLetter(r rune) bool {
|
||||
// unicode.IsLower() returns true for letters only
|
||||
return unicode.IsLower(r)
|
||||
}
|
||||
|
||||
// Spaces returns a string with n spaces
|
||||
@ -270,6 +358,28 @@ func RunePos(b []byte, i int) int {
|
||||
return CharacterCount(b[:i])
|
||||
}
|
||||
|
||||
// IndexAnyUnquoted returns the first position in s of a character from chars.
|
||||
// Escaped (with backslash) and quoted (with single or double quotes) characters
|
||||
// are ignored. Returns -1 if not successful
|
||||
func IndexAnyUnquoted(s, chars string) int {
|
||||
var e bool
|
||||
var q rune
|
||||
for i, r := range s {
|
||||
if e {
|
||||
e = false
|
||||
} else if (q == 0 || q == '"') && r == '\\' {
|
||||
e = true
|
||||
} else if r == q {
|
||||
q = 0
|
||||
} else if q == 0 && (r == '\'' || r == '"') {
|
||||
q = r
|
||||
} else if q == 0 && strings.IndexRune(chars, r) >= 0 {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// MakeRelative will attempt to make a relative path between path and base
|
||||
func MakeRelative(path, base string) (string, error) {
|
||||
if len(path) > 0 {
|
||||
@ -314,7 +424,7 @@ func ReplaceHome(path string) (string, error) {
|
||||
// This is used for opening files like util.go:10:5 to specify a line and column
|
||||
// Special cases like Windows Absolute path (C:\myfile.txt:10:5) are handled correctly.
|
||||
func GetPathAndCursorPosition(path string) (string, []string) {
|
||||
re := regexp.MustCompile(`([\s\S]+?)(?::(\d+))(?::(\d+))?`)
|
||||
re := regexp.MustCompile(`([\s\S]+?)(?::(\d+))(?::(\d+))?$`)
|
||||
match := re.FindStringSubmatch(path)
|
||||
// no lines/columns were specified in the path, return just the path with no cursor location
|
||||
if len(match) == 0 {
|
||||
@ -336,8 +446,17 @@ func GetModTime(path string) (time.Time, error) {
|
||||
return info.ModTime(), nil
|
||||
}
|
||||
|
||||
// EscapePath replaces every path separator in a given path with a %
|
||||
func EscapePath(path string) string {
|
||||
func AppendBackupSuffix(path string) string {
|
||||
return path + ".micro-backup"
|
||||
}
|
||||
|
||||
// EscapePathUrl encodes the path in URL query form
|
||||
func EscapePathUrl(path string) string {
|
||||
return url.QueryEscape(filepath.ToSlash(path))
|
||||
}
|
||||
|
||||
// EscapePathLegacy replaces every path separator in a given path with a %
|
||||
func EscapePathLegacy(path string) string {
|
||||
path = filepath.ToSlash(path)
|
||||
if runtime.GOOS == "windows" {
|
||||
// ':' is not valid in a path name on Windows but is ok on Unix
|
||||
@ -346,6 +465,24 @@ func EscapePath(path string) string {
|
||||
return strings.ReplaceAll(path, "/", "%")
|
||||
}
|
||||
|
||||
// DetermineEscapePath escapes a path, determining whether it should be escaped
|
||||
// using URL encoding (preferred, since it encodes unambiguously) or
|
||||
// legacy encoding with '%' (for backward compatibility, if the legacy-escaped
|
||||
// path exists in the given directory).
|
||||
func DetermineEscapePath(dir string, path string) string {
|
||||
url := filepath.Join(dir, EscapePathUrl(path))
|
||||
if _, err := os.Stat(url); err == nil {
|
||||
return url
|
||||
}
|
||||
|
||||
legacy := filepath.Join(dir, EscapePathLegacy(path))
|
||||
if _, err := os.Stat(legacy); err == nil {
|
||||
return legacy
|
||||
}
|
||||
|
||||
return url
|
||||
}
|
||||
|
||||
// GetLeadingWhitespace returns the leading whitespace of the given byte array
|
||||
func GetLeadingWhitespace(b []byte) []byte {
|
||||
ws := []byte{}
|
||||
@ -362,6 +499,28 @@ func GetLeadingWhitespace(b []byte) []byte {
|
||||
return ws
|
||||
}
|
||||
|
||||
// GetTrailingWhitespace returns the trailing whitespace of the given byte array
|
||||
func GetTrailingWhitespace(b []byte) []byte {
|
||||
ws := []byte{}
|
||||
for len(b) > 0 {
|
||||
r, size := utf8.DecodeLastRune(b)
|
||||
if IsWhitespace(r) {
|
||||
ws = append([]byte(string(r)), ws...)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
b = b[:len(b)-size]
|
||||
}
|
||||
return ws
|
||||
}
|
||||
|
||||
// HasTrailingWhitespace returns true if the given byte array ends with a whitespace
|
||||
func HasTrailingWhitespace(b []byte) bool {
|
||||
r, _ := utf8.DecodeLastRune(b)
|
||||
return IsWhitespace(r)
|
||||
}
|
||||
|
||||
// IntOpt turns a float64 setting to an int
|
||||
func IntOpt(opt interface{}) int {
|
||||
return int(opt.(float64))
|
||||
@ -421,16 +580,9 @@ func Clamp(val, min, max int) int {
|
||||
return val
|
||||
}
|
||||
|
||||
func IsNonAlphaNumeric(c rune) bool {
|
||||
return !unicode.IsLetter(c) && !unicode.IsNumber(c) && c != '_'
|
||||
}
|
||||
|
||||
// IsAutocomplete returns whether a character should begin an autocompletion.
|
||||
func IsAutocomplete(c rune) bool {
|
||||
return c == '.' || !IsNonAlphaNumeric(c)
|
||||
}
|
||||
|
||||
func ParseSpecial(s string) string {
|
||||
return strings.ReplaceAll(s, "\\t", "\t")
|
||||
return c == '.' || IsWordChar(c)
|
||||
}
|
||||
|
||||
// String converts a byte array to a string (for lua plugins)
|
||||
@ -490,3 +642,90 @@ func Unzip(src, dest string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// HttpRequest returns a new http.Client for making custom requests (for lua plugins)
|
||||
func HttpRequest(method string, url string, headers []string) (resp *http.Response, err error) {
|
||||
client := http.Client{}
|
||||
req, err := http.NewRequest(method, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := 0; i < len(headers); i += 2 {
|
||||
req.Header.Add(headers[i], headers[i+1])
|
||||
}
|
||||
return client.Do(req)
|
||||
}
|
||||
|
||||
// SafeWrite writes bytes to a file in a "safe" way, preventing loss of the
|
||||
// contents of the file if it fails to write the new contents.
|
||||
// This means that the file is not overwritten directly but by writing to a
|
||||
// temporary file first.
|
||||
//
|
||||
// If rename is true, write is performed atomically, by renaming the temporary
|
||||
// file to the target file after the data is successfully written to the
|
||||
// temporary file. This guarantees that the file will not remain in a corrupted
|
||||
// state, but it also has limitations, e.g. the file should not be a symlink
|
||||
// (otherwise SafeWrite silently replaces this symlink with a regular file),
|
||||
// the file creation date in Linux is not preserved (since the file inode
|
||||
// changes) etc. Use SafeWrite with rename=true for files that are only created
|
||||
// and used by micro for its own needs and are not supposed to be used directly
|
||||
// by the user.
|
||||
//
|
||||
// If rename is false, write is performed by overwriting the target file after
|
||||
// the data is successfully written to the temporary file.
|
||||
// This means that the target file may remain corrupted if overwrite fails,
|
||||
// but in such case the temporary file is preserved as a backup so the file
|
||||
// can be recovered later. So it is less convenient than atomic write but more
|
||||
// universal. Use SafeWrite with rename=false for files that may be managed
|
||||
// directly by the user, like settings.json and bindings.json.
|
||||
func SafeWrite(path string, bytes []byte, rename bool) error {
|
||||
var err error
|
||||
if _, err = os.Stat(path); err != nil {
|
||||
if !errors.Is(err, fs.ErrNotExist) {
|
||||
return err
|
||||
}
|
||||
// Force rename for new files!
|
||||
rename = true
|
||||
}
|
||||
|
||||
var file *os.File
|
||||
if !rename {
|
||||
file, err = os.OpenFile(path, os.O_WRONLY|os.O_CREATE, FileMode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
}
|
||||
|
||||
tmp := AppendBackupSuffix(path)
|
||||
err = os.WriteFile(tmp, bytes, FileMode)
|
||||
if err != nil {
|
||||
os.Remove(tmp)
|
||||
return err
|
||||
}
|
||||
|
||||
if rename {
|
||||
err = os.Rename(tmp, path)
|
||||
} else {
|
||||
err = file.Truncate(0)
|
||||
if err == nil {
|
||||
_, err = file.Write(bytes)
|
||||
}
|
||||
if err == nil {
|
||||
err = file.Sync()
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
if rename {
|
||||
os.Remove(tmp)
|
||||
} else {
|
||||
err = OverwriteError{err, tmp}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if !rename {
|
||||
os.Remove(tmp)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -185,6 +185,10 @@ func (n *Node) hResizeSplit(i int, size int) bool {
|
||||
|
||||
// ResizeSplit resizes a certain split to a given size
|
||||
func (n *Node) ResizeSplit(size int) bool {
|
||||
// TODO: `size < 0` does not work for some reason
|
||||
if size <= 0 {
|
||||
return false
|
||||
}
|
||||
if len(n.parent.children) <= 1 {
|
||||
// cannot resize a lone node
|
||||
return false
|
||||
@ -201,7 +205,7 @@ func (n *Node) ResizeSplit(size int) bool {
|
||||
return n.parent.hResizeSplit(ind, size)
|
||||
}
|
||||
|
||||
// Resize sets this node's size and resizes all children accordlingly
|
||||
// Resize sets this node's size and resizes all children accordingly
|
||||
func (n *Node) Resize(w, h int) {
|
||||
n.W, n.H = w, h
|
||||
|
||||
@ -435,11 +439,12 @@ func (n *Node) VSplit(right bool) uint64 {
|
||||
}
|
||||
|
||||
// unsplits the child of a split
|
||||
func (n *Node) unsplit(i int, h bool) {
|
||||
func (n *Node) unsplit(i int) {
|
||||
copy(n.children[i:], n.children[i+1:])
|
||||
n.children[len(n.children)-1] = nil
|
||||
n.children = n.children[:len(n.children)-1]
|
||||
|
||||
h := n.Kind == STVert
|
||||
nonrs, numr := n.getResizeInfo(h)
|
||||
if numr == 0 {
|
||||
// This means that this was the last child
|
||||
@ -466,18 +471,62 @@ func (n *Node) Unsplit() bool {
|
||||
ind = i
|
||||
}
|
||||
}
|
||||
if n.parent.Kind == STVert {
|
||||
n.parent.unsplit(ind, true)
|
||||
} else {
|
||||
n.parent.unsplit(ind, false)
|
||||
}
|
||||
|
||||
n.parent.unsplit(ind)
|
||||
if n.parent.IsLeaf() {
|
||||
return n.parent.Unsplit()
|
||||
}
|
||||
|
||||
n.parent.flatten()
|
||||
return true
|
||||
}
|
||||
|
||||
// flattens the tree by removing unnecessary intermediate parents that have only one child
|
||||
// and handles the side effect of it
|
||||
func (n *Node) flatten() {
|
||||
if n.parent == nil || len(n.children) != 1 {
|
||||
return
|
||||
}
|
||||
|
||||
ind := 0
|
||||
for i, c := range n.parent.children {
|
||||
if c.id == n.id {
|
||||
ind = i
|
||||
}
|
||||
}
|
||||
|
||||
// Replace current node with its child node to remove chained parent
|
||||
successor := n.children[0]
|
||||
n.parent.children[ind] = successor
|
||||
successor.parent = n.parent
|
||||
|
||||
// Maintain the tree in a consistent state: any child node's kind (horiz vs vert)
|
||||
// should be the opposite of its parent's kind.
|
||||
if successor.IsLeaf() {
|
||||
successor.Kind = n.Kind
|
||||
} else {
|
||||
// If the successor node has children, that means it is a chained parent as well.
|
||||
// Therefore it can be replaced by its own children.
|
||||
origsize := len(n.parent.children)
|
||||
|
||||
// Let's say we have 5 children and want to replace [2] with its children [a] [b] [c]
|
||||
// [0] [1] [2] [3] [4] --> [0] [1] [a] [b] [c] [3] [4]
|
||||
// insertcount will be `3 - 1 = 2` in this case
|
||||
insertcount := len(successor.children) - 1
|
||||
|
||||
n.parent.children = append(n.parent.children, make([]*Node, insertcount)...)
|
||||
copy(n.parent.children[ind+insertcount+1:], n.parent.children[ind+1:origsize])
|
||||
copy(n.parent.children[ind:], successor.children)
|
||||
|
||||
for i := 0; i < len(successor.children); i++ {
|
||||
n.parent.children[ind+i].parent = n.parent
|
||||
}
|
||||
}
|
||||
|
||||
// Update propW and propH since the parent of the children has been updated,
|
||||
// so the children have new siblings
|
||||
n.parent.markSizes()
|
||||
}
|
||||
|
||||
// String returns the string form of the node and all children (used for debugging)
|
||||
func (n *Node) String() string {
|
||||
var strf func(n *Node, ident int) string
|
||||
|
@ -1,18 +0,0 @@
|
||||
package highlight
|
||||
|
||||
import "regexp"
|
||||
|
||||
// MatchFiletype will use the list of syntax definitions provided and the filename and first line of the file
|
||||
// to determine the filetype of the file
|
||||
// It will return the corresponding syntax definition for the filetype
|
||||
func MatchFiletype(ftdetect [2]*regexp.Regexp, filename string, firstLine []byte) bool {
|
||||
if ftdetect[0] != nil && ftdetect[0].MatchString(filename) {
|
||||
return true
|
||||
}
|
||||
|
||||
if ftdetect[1] != nil {
|
||||
return ftdetect[1].Match(firstLine)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
@ -51,24 +51,9 @@ func runePos(p int, str []byte) int {
|
||||
return CharacterCount(str[:p])
|
||||
}
|
||||
|
||||
func combineLineMatch(src, dst LineMatch) LineMatch {
|
||||
for k, v := range src {
|
||||
if g, ok := dst[k]; ok {
|
||||
if g == 0 {
|
||||
dst[k] = v
|
||||
}
|
||||
} else {
|
||||
dst[k] = v
|
||||
}
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
||||
// A State represents the region at the end of a line
|
||||
type State *region
|
||||
|
||||
var EmptyDef = Def{nil, &rules{}}
|
||||
|
||||
// LineStates is an interface for a buffer-like object which can also store the states and matches for every line
|
||||
type LineStates interface {
|
||||
LineBytes(n int) []byte
|
||||
@ -76,6 +61,8 @@ type LineStates interface {
|
||||
State(lineN int) State
|
||||
SetState(lineN int, s State)
|
||||
SetMatch(lineN int, m LineMatch)
|
||||
Lock()
|
||||
Unlock()
|
||||
}
|
||||
|
||||
// A Highlighter contains the information needed to highlight a string
|
||||
@ -95,19 +82,7 @@ func NewHighlighter(def *Def) *Highlighter {
|
||||
// color's group (represented as one byte)
|
||||
type LineMatch map[int]Group
|
||||
|
||||
func findIndex(regex *regexp.Regexp, skip *regexp.Regexp, str []byte, canMatchStart, canMatchEnd bool) []int {
|
||||
regexStr := regex.String()
|
||||
if strings.Contains(regexStr, "^") {
|
||||
if !canMatchStart {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if strings.Contains(regexStr, "$") {
|
||||
if !canMatchEnd {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func findIndex(regex *regexp.Regexp, skip *regexp.Regexp, str []byte) []int {
|
||||
var strbytes []byte
|
||||
if skip != nil {
|
||||
strbytes = skip.ReplaceAllFunc(str, func(match []byte) []byte {
|
||||
@ -126,18 +101,7 @@ func findIndex(regex *regexp.Regexp, skip *regexp.Regexp, str []byte, canMatchSt
|
||||
return []int{runePos(match[0], str), runePos(match[1], str)}
|
||||
}
|
||||
|
||||
func findAllIndex(regex *regexp.Regexp, str []byte, canMatchStart, canMatchEnd bool) [][]int {
|
||||
regexStr := regex.String()
|
||||
if strings.Contains(regexStr, "^") {
|
||||
if !canMatchStart {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if strings.Contains(regexStr, "$") {
|
||||
if !canMatchEnd {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
func findAllIndex(regex *regexp.Regexp, str []byte) [][]int {
|
||||
matches := regex.FindAllIndex(str, -1)
|
||||
for i, m := range matches {
|
||||
matches[i][0] = runePos(m[0], str)
|
||||
@ -156,40 +120,20 @@ func (h *Highlighter) highlightRegion(highlights LineMatch, start int, canMatchE
|
||||
}
|
||||
}
|
||||
|
||||
loc := findIndex(curRegion.end, curRegion.skip, line, start == 0, canMatchEnd)
|
||||
if loc != nil {
|
||||
if !statesOnly {
|
||||
highlights[start+loc[0]] = curRegion.limitGroup
|
||||
}
|
||||
if curRegion.parent == nil {
|
||||
if !statesOnly {
|
||||
highlights[start+loc[1]] = 0
|
||||
h.highlightRegion(highlights, start, false, lineNum, sliceEnd(line, loc[0]), curRegion, statesOnly)
|
||||
}
|
||||
h.highlightEmptyRegion(highlights, start+loc[1], canMatchEnd, lineNum, sliceStart(line, loc[1]), statesOnly)
|
||||
return highlights
|
||||
}
|
||||
if !statesOnly {
|
||||
highlights[start+loc[1]] = curRegion.parent.group
|
||||
h.highlightRegion(highlights, start, false, lineNum, sliceEnd(line, loc[0]), curRegion, statesOnly)
|
||||
}
|
||||
h.highlightRegion(highlights, start+loc[1], canMatchEnd, lineNum, sliceStart(line, loc[1]), curRegion.parent, statesOnly)
|
||||
return highlights
|
||||
}
|
||||
|
||||
if lineLen == 0 {
|
||||
if canMatchEnd {
|
||||
h.lastRegion = curRegion
|
||||
}
|
||||
|
||||
return highlights
|
||||
}
|
||||
|
||||
firstLoc := []int{lineLen, 0}
|
||||
|
||||
var firstRegion *region
|
||||
firstLoc := []int{lineLen, 0}
|
||||
searchNesting := true
|
||||
endLoc := findIndex(curRegion.end, curRegion.skip, line)
|
||||
if endLoc != nil {
|
||||
if start == endLoc[0] {
|
||||
searchNesting = false
|
||||
} else {
|
||||
firstLoc = endLoc
|
||||
}
|
||||
}
|
||||
if searchNesting {
|
||||
for _, r := range curRegion.rules.regions {
|
||||
loc := findIndex(r.start, nil, line, start == 0, canMatchEnd)
|
||||
loc := findIndex(r.start, r.skip, line)
|
||||
if loc != nil {
|
||||
if loc[0] < firstLoc[0] {
|
||||
firstLoc = loc
|
||||
@ -197,11 +141,12 @@ func (h *Highlighter) highlightRegion(highlights LineMatch, start int, canMatchE
|
||||
}
|
||||
}
|
||||
}
|
||||
if firstLoc[0] != lineLen {
|
||||
}
|
||||
if firstRegion != nil && firstLoc[0] != lineLen {
|
||||
if !statesOnly {
|
||||
highlights[start+firstLoc[0]] = firstRegion.limitGroup
|
||||
}
|
||||
h.highlightRegion(highlights, start, false, lineNum, sliceEnd(line, firstLoc[0]), curRegion, statesOnly)
|
||||
h.highlightEmptyRegion(highlights, start+firstLoc[1], canMatchEnd, lineNum, sliceStart(line, firstLoc[1]), statesOnly)
|
||||
h.highlightRegion(highlights, start+firstLoc[1], canMatchEnd, lineNum, sliceStart(line, firstLoc[1]), firstRegion, statesOnly)
|
||||
return highlights
|
||||
}
|
||||
@ -212,14 +157,20 @@ func (h *Highlighter) highlightRegion(highlights LineMatch, start int, canMatchE
|
||||
fullHighlights[i] = curRegion.group
|
||||
}
|
||||
|
||||
if searchNesting {
|
||||
for _, p := range curRegion.rules.patterns {
|
||||
matches := findAllIndex(p.regex, line, start == 0, canMatchEnd)
|
||||
if curRegion.group == curRegion.limitGroup || p.group == curRegion.limitGroup {
|
||||
matches := findAllIndex(p.regex, line)
|
||||
for _, m := range matches {
|
||||
if (endLoc == nil) || (m[0] < endLoc[0]) {
|
||||
for i := m[0]; i < m[1]; i++ {
|
||||
fullHighlights[i] = p.group
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for i, h := range fullHighlights {
|
||||
if i == 0 || h != fullHighlights[i-1] {
|
||||
highlights[start+i] = h
|
||||
@ -227,6 +178,25 @@ func (h *Highlighter) highlightRegion(highlights LineMatch, start int, canMatchE
|
||||
}
|
||||
}
|
||||
|
||||
loc := endLoc
|
||||
if loc != nil {
|
||||
if !statesOnly {
|
||||
highlights[start+loc[0]] = curRegion.limitGroup
|
||||
}
|
||||
if curRegion.parent == nil {
|
||||
if !statesOnly {
|
||||
highlights[start+loc[1]] = 0
|
||||
}
|
||||
h.highlightEmptyRegion(highlights, start+loc[1], canMatchEnd, lineNum, sliceStart(line, loc[1]), statesOnly)
|
||||
return highlights
|
||||
}
|
||||
if !statesOnly {
|
||||
highlights[start+loc[1]] = curRegion.parent.group
|
||||
}
|
||||
h.highlightRegion(highlights, start+loc[1], canMatchEnd, lineNum, sliceStart(line, loc[1]), curRegion.parent, statesOnly)
|
||||
return highlights
|
||||
}
|
||||
|
||||
if canMatchEnd {
|
||||
h.lastRegion = curRegion
|
||||
}
|
||||
@ -243,10 +213,10 @@ func (h *Highlighter) highlightEmptyRegion(highlights LineMatch, start int, canM
|
||||
return highlights
|
||||
}
|
||||
|
||||
firstLoc := []int{lineLen, 0}
|
||||
var firstRegion *region
|
||||
firstLoc := []int{lineLen, 0}
|
||||
for _, r := range h.Def.rules.regions {
|
||||
loc := findIndex(r.start, nil, line, start == 0, canMatchEnd)
|
||||
loc := findIndex(r.start, r.skip, line)
|
||||
if loc != nil {
|
||||
if loc[0] < firstLoc[0] {
|
||||
firstLoc = loc
|
||||
@ -254,7 +224,7 @@ func (h *Highlighter) highlightEmptyRegion(highlights LineMatch, start int, canM
|
||||
}
|
||||
}
|
||||
}
|
||||
if firstLoc[0] != lineLen {
|
||||
if firstRegion != nil && firstLoc[0] != lineLen {
|
||||
if !statesOnly {
|
||||
highlights[start+firstLoc[0]] = firstRegion.limitGroup
|
||||
}
|
||||
@ -273,7 +243,7 @@ func (h *Highlighter) highlightEmptyRegion(highlights LineMatch, start int, canM
|
||||
|
||||
fullHighlights := make([]Group, len(line))
|
||||
for _, p := range h.Def.rules.patterns {
|
||||
matches := findAllIndex(p.regex, line, start == 0, canMatchEnd)
|
||||
matches := findAllIndex(p.regex, line)
|
||||
for _, m := range matches {
|
||||
for i := m[0]; i < m[1]; i++ {
|
||||
fullHighlights[i] = p.group
|
||||
@ -319,7 +289,13 @@ func (h *Highlighter) HighlightString(input string) []LineMatch {
|
||||
|
||||
// HighlightStates correctly sets all states for the buffer
|
||||
func (h *Highlighter) HighlightStates(input LineStates) {
|
||||
for i := 0; i < input.LinesNum(); i++ {
|
||||
for i := 0; ; i++ {
|
||||
input.Lock()
|
||||
if i >= input.LinesNum() {
|
||||
input.Unlock()
|
||||
break
|
||||
}
|
||||
|
||||
line := input.LineBytes(i)
|
||||
// highlights := make(LineMatch)
|
||||
|
||||
@ -332,6 +308,7 @@ func (h *Highlighter) HighlightStates(input LineStates) {
|
||||
curState := h.lastRegion
|
||||
|
||||
input.SetState(i, curState)
|
||||
input.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
@ -340,7 +317,9 @@ func (h *Highlighter) HighlightStates(input LineStates) {
|
||||
// This assumes that all the states are set correctly
|
||||
func (h *Highlighter) HighlightMatches(input LineStates, startline, endline int) {
|
||||
for i := startline; i <= endline; i++ {
|
||||
input.Lock()
|
||||
if i >= input.LinesNum() {
|
||||
input.Unlock()
|
||||
break
|
||||
}
|
||||
|
||||
@ -355,6 +334,7 @@ func (h *Highlighter) HighlightMatches(input LineStates, startline, endline int)
|
||||
}
|
||||
|
||||
input.SetMatch(i, match)
|
||||
input.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
@ -366,9 +346,19 @@ func (h *Highlighter) ReHighlightStates(input LineStates, startline int) int {
|
||||
|
||||
h.lastRegion = nil
|
||||
if startline > 0 {
|
||||
input.Lock()
|
||||
if startline-1 < input.LinesNum() {
|
||||
h.lastRegion = input.State(startline - 1)
|
||||
}
|
||||
for i := startline; i < input.LinesNum(); i++ {
|
||||
input.Unlock()
|
||||
}
|
||||
for i := startline; ; i++ {
|
||||
input.Lock()
|
||||
if i >= input.LinesNum() {
|
||||
input.Unlock()
|
||||
break
|
||||
}
|
||||
|
||||
line := input.LineBytes(i)
|
||||
// highlights := make(LineMatch)
|
||||
|
||||
@ -382,6 +372,7 @@ func (h *Highlighter) ReHighlightStates(input LineStates, startline int) int {
|
||||
lastState := input.State(i)
|
||||
|
||||
input.SetState(i, curState)
|
||||
input.Unlock()
|
||||
|
||||
if curState == lastState {
|
||||
return i
|
||||
@ -393,6 +384,9 @@ func (h *Highlighter) ReHighlightStates(input LineStates, startline int) int {
|
||||
|
||||
// ReHighlightLine will rehighlight the state and match for a single line
|
||||
func (h *Highlighter) ReHighlightLine(input LineStates, lineN int) {
|
||||
input.Lock()
|
||||
defer input.Unlock()
|
||||
|
||||
line := input.LineBytes(lineN)
|
||||
highlights := make(LineMatch)
|
||||
|
||||
|
@ -33,26 +33,27 @@ func (g Group) String() string {
|
||||
// Then it has the rules which define how to highlight the file
|
||||
type Def struct {
|
||||
*Header
|
||||
|
||||
rules *rules
|
||||
}
|
||||
|
||||
type Header struct {
|
||||
FileType string
|
||||
FtDetect [2]*regexp.Regexp
|
||||
FileNameRegex *regexp.Regexp
|
||||
HeaderRegex *regexp.Regexp
|
||||
SignatureRegex *regexp.Regexp
|
||||
}
|
||||
|
||||
type HeaderYaml struct {
|
||||
FileType string `yaml:"filetype"`
|
||||
Detect struct {
|
||||
FNameRgx string `yaml:"filename"`
|
||||
HeaderRgx string `yaml:"header"`
|
||||
FNameRegexStr string `yaml:"filename"`
|
||||
HeaderRegexStr string `yaml:"header"`
|
||||
SignatureRegexStr string `yaml:"signature"`
|
||||
} `yaml:"detect"`
|
||||
}
|
||||
|
||||
type File struct {
|
||||
FileType string
|
||||
|
||||
yamlSrc map[interface{}]interface{}
|
||||
}
|
||||
|
||||
@ -97,20 +98,24 @@ func init() {
|
||||
// A yaml file might take ~400us to parse while a header file only takes ~20us
|
||||
func MakeHeader(data []byte) (*Header, error) {
|
||||
lines := bytes.Split(data, []byte{'\n'})
|
||||
if len(lines) < 3 {
|
||||
if len(lines) < 4 {
|
||||
return nil, errors.New("Header file has incorrect format")
|
||||
}
|
||||
header := new(Header)
|
||||
var err error
|
||||
header.FileType = string(lines[0])
|
||||
fnameRgx := string(lines[1])
|
||||
headerRgx := string(lines[2])
|
||||
fnameRegexStr := string(lines[1])
|
||||
headerRegexStr := string(lines[2])
|
||||
signatureRegexStr := string(lines[3])
|
||||
|
||||
if fnameRgx != "" {
|
||||
header.FtDetect[0], err = regexp.Compile(fnameRgx)
|
||||
if fnameRegexStr != "" {
|
||||
header.FileNameRegex, err = regexp.Compile(fnameRegexStr)
|
||||
}
|
||||
if headerRgx != "" {
|
||||
header.FtDetect[1], err = regexp.Compile(headerRgx)
|
||||
if err == nil && headerRegexStr != "" {
|
||||
header.HeaderRegex, err = regexp.Compile(headerRegexStr)
|
||||
}
|
||||
if err == nil && signatureRegexStr != "" {
|
||||
header.SignatureRegex, err = regexp.Compile(signatureRegexStr)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@ -132,11 +137,14 @@ func MakeHeaderYaml(data []byte) (*Header, error) {
|
||||
header := new(Header)
|
||||
header.FileType = hdrYaml.FileType
|
||||
|
||||
if hdrYaml.Detect.FNameRgx != "" {
|
||||
header.FtDetect[0], err = regexp.Compile(hdrYaml.Detect.FNameRgx)
|
||||
if hdrYaml.Detect.FNameRegexStr != "" {
|
||||
header.FileNameRegex, err = regexp.Compile(hdrYaml.Detect.FNameRegexStr)
|
||||
}
|
||||
if hdrYaml.Detect.HeaderRgx != "" {
|
||||
header.FtDetect[1], err = regexp.Compile(hdrYaml.Detect.HeaderRgx)
|
||||
if err == nil && hdrYaml.Detect.HeaderRegexStr != "" {
|
||||
header.HeaderRegex, err = regexp.Compile(hdrYaml.Detect.HeaderRegexStr)
|
||||
}
|
||||
if err == nil && hdrYaml.Detect.SignatureRegexStr != "" {
|
||||
header.SignatureRegex, err = regexp.Compile(hdrYaml.Detect.SignatureRegexStr)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@ -146,6 +154,37 @@ func MakeHeaderYaml(data []byte) (*Header, error) {
|
||||
return header, nil
|
||||
}
|
||||
|
||||
// MatchFileName will check the given file name with the stored regex
|
||||
func (header *Header) MatchFileName(filename string) bool {
|
||||
if header.FileNameRegex != nil {
|
||||
return header.FileNameRegex.MatchString(filename)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (header *Header) MatchFileHeader(firstLine []byte) bool {
|
||||
if header.HeaderRegex != nil {
|
||||
return header.HeaderRegex.Match(firstLine)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// HasFileSignature checks the presence of a stored signature
|
||||
func (header *Header) HasFileSignature() bool {
|
||||
return header.SignatureRegex != nil
|
||||
}
|
||||
|
||||
// MatchFileSignature will check the given line with the stored regex
|
||||
func (header *Header) MatchFileSignature(line []byte) bool {
|
||||
if header.SignatureRegex != nil {
|
||||
return header.SignatureRegex.Match(line)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func ParseFile(input []byte) (f *File, err error) {
|
||||
// This is just so if we have an error, we can exit cleanly and return the parse error to the user
|
||||
defer func() {
|
||||
@ -170,11 +209,19 @@ func ParseFile(input []byte) (f *File, err error) {
|
||||
if k == "filetype" {
|
||||
filetype := v.(string)
|
||||
|
||||
if filetype == "" {
|
||||
return nil, errors.New("empty filetype")
|
||||
}
|
||||
|
||||
f.FileType = filetype
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if f.FileType == "" {
|
||||
return nil, errors.New("missing filetype")
|
||||
}
|
||||
|
||||
return f, err
|
||||
}
|
||||
|
||||
@ -191,12 +238,12 @@ func ParseDef(f *File, header *Header) (s *Def, err error) {
|
||||
}
|
||||
}()
|
||||
|
||||
rules := f.yamlSrc
|
||||
src := f.yamlSrc
|
||||
|
||||
s = new(Def)
|
||||
s.Header = header
|
||||
|
||||
for k, v := range rules {
|
||||
for k, v := range src {
|
||||
if k == "rules" {
|
||||
inputRules := v.([]interface{})
|
||||
|
||||
@ -209,6 +256,11 @@ func ParseDef(f *File, header *Header) (s *Def, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
if s.rules == nil {
|
||||
// allow empty rules
|
||||
s.rules = &rules{}
|
||||
}
|
||||
|
||||
return s, err
|
||||
}
|
||||
|
||||
@ -303,6 +355,10 @@ func parseRules(input []interface{}, curRegion *region) (ru *rules, err error) {
|
||||
|
||||
switch object := val.(type) {
|
||||
case string:
|
||||
if object == "" {
|
||||
return nil, fmt.Errorf("Empty rule %s", k)
|
||||
}
|
||||
|
||||
if k == "include" {
|
||||
ru.includes = append(ru.includes, object)
|
||||
} else {
|
||||
@ -356,30 +412,56 @@ func parseRegion(group string, regionInfo map[interface{}]interface{}, prevRegio
|
||||
r.group = groupNum
|
||||
r.parent = prevRegion
|
||||
|
||||
r.start, err = regexp.Compile(regionInfo["start"].(string))
|
||||
// start is mandatory
|
||||
if start, ok := regionInfo["start"]; ok {
|
||||
start := start.(string)
|
||||
if start == "" {
|
||||
return nil, fmt.Errorf("Empty start in %s", group)
|
||||
}
|
||||
|
||||
r.start, err = regexp.Compile(start)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("Missing start in %s", group)
|
||||
}
|
||||
|
||||
r.end, err = regexp.Compile(regionInfo["end"].(string))
|
||||
// end is mandatory
|
||||
if end, ok := regionInfo["end"]; ok {
|
||||
end := end.(string)
|
||||
if end == "" {
|
||||
return nil, fmt.Errorf("Empty end in %s", group)
|
||||
}
|
||||
|
||||
r.end, err = regexp.Compile(end)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("Missing end in %s", group)
|
||||
}
|
||||
|
||||
// skip is optional
|
||||
if _, ok := regionInfo["skip"]; ok {
|
||||
r.skip, err = regexp.Compile(regionInfo["skip"].(string))
|
||||
if skip, ok := regionInfo["skip"]; ok {
|
||||
skip := skip.(string)
|
||||
if skip == "" {
|
||||
return nil, fmt.Errorf("Empty skip in %s", group)
|
||||
}
|
||||
|
||||
r.skip, err = regexp.Compile(skip)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// limit-color is optional
|
||||
if _, ok := regionInfo["limit-group"]; ok {
|
||||
groupStr := regionInfo["limit-group"].(string)
|
||||
if groupStr, ok := regionInfo["limit-group"]; ok {
|
||||
groupStr := groupStr.(string)
|
||||
if groupStr == "" {
|
||||
return nil, fmt.Errorf("Empty limit-group in %s", group)
|
||||
}
|
||||
|
||||
if _, ok := Groups[groupStr]; !ok {
|
||||
numGroups++
|
||||
Groups[groupStr] = numGroups
|
||||
@ -394,11 +476,18 @@ func parseRegion(group string, regionInfo map[interface{}]interface{}, prevRegio
|
||||
r.limitGroup = r.group
|
||||
}
|
||||
|
||||
r.rules, err = parseRules(regionInfo["rules"].([]interface{}), r)
|
||||
|
||||
// rules are optional
|
||||
if rules, ok := regionInfo["rules"]; ok {
|
||||
r.rules, err = parseRules(rules.([]interface{}), r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if r.rules == nil {
|
||||
// allow empty rules
|
||||
r.rules = &rules{}
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ color-link special "#A6E22E,#1D1F21"
|
||||
color-link underlined "#D33682,#1D1F21"
|
||||
color-link error "bold #FF4444,#1D1F21"
|
||||
color-link todo "bold #FF8844,#1D1F21"
|
||||
color-link hlsearch "#000000,#B4EC85"
|
||||
color-link statusline "#1D1F21,#C5C8C6"
|
||||
color-link tabbar "#1D1F21,#C5C8C6"
|
||||
color-link indent-char "#505050,#1D1F21"
|
||||
@ -27,3 +28,6 @@ color-link color-column "#2D2F31"
|
||||
#No extended types (bool in C, etc.)
|
||||
#color-link type.extended "default"
|
||||
#Plain brackets
|
||||
color-link match-brace "#1D1F21,#62B1FE"
|
||||
color-link tab-error "#D75F5F"
|
||||
color-link trailingws "#D75F5F"
|
||||
|
@ -12,6 +12,7 @@ color-link special "167,231"
|
||||
color-link error "231, 160"
|
||||
color-link underlined "underline 241,231"
|
||||
color-link todo "246,231"
|
||||
color-link hlsearch "231,136"
|
||||
color-link statusline "241,254"
|
||||
color-link tabbar "241,254"
|
||||
color-link diff-added "34"
|
||||
@ -25,3 +26,6 @@ color-link color-column "254"
|
||||
#No extended types (bool in C, &c.) and plain brackets
|
||||
color-link type.extended "241,231"
|
||||
color-link symbol.brackets "241,231"
|
||||
color-link match-brace "231,28"
|
||||
color-link tab-error "210"
|
||||
color-link trailingws "210"
|
||||
|
@ -26,6 +26,7 @@ color-link special "magenta"
|
||||
color-link ignore "default"
|
||||
color-link error "bold ,brightred"
|
||||
color-link todo "underline black,brightyellow"
|
||||
color-link hlsearch "white,darkgreen"
|
||||
color-link indent-char ",brightgreen"
|
||||
color-link line-number "green"
|
||||
color-link line-number.scrollbar "green"
|
||||
@ -41,3 +42,6 @@ color-link gutter-warning "red"
|
||||
color-link color-column "cyan"
|
||||
color-link underlined.url "underline blue, white"
|
||||
color-link divider "blue"
|
||||
color-link match-brace "black,cyan"
|
||||
color-link tab-error "brightred"
|
||||
color-link trailingws "brightred"
|
||||
|
@ -21,6 +21,7 @@ color-link special "#b57edc"
|
||||
color-link ignore "default"
|
||||
color-link error "bold ,#e34234"
|
||||
color-link todo "bold underline #888888,#f26522"
|
||||
color-link hlsearch "#b7b7b7,#32593d"
|
||||
color-link indent-char ",#bdecb6"
|
||||
color-link line-number "#bdecb6,#36393e"
|
||||
color-link line-number.scrollbar "#3eb489"
|
||||
@ -37,3 +38,6 @@ color-link color-column "#f26522"
|
||||
color-link constant.bool "bold #55ffff"
|
||||
color-link constant.bool.true "bold #85ff85"
|
||||
color-link constant.bool.false "bold #ff8585"
|
||||
color-link match-brace "#1e2124,#55ffff"
|
||||
color-link tab-error "#d75f5f"
|
||||
color-link trailingws "#d75f5f"
|
||||
|
@ -12,6 +12,7 @@ color-link special "#CC8242,#242424"
|
||||
color-link underlined "#D33682,#242424"
|
||||
color-link error "bold #CB4B16,#242424"
|
||||
color-link todo "bold #D33682,#242424"
|
||||
color-link hlsearch "#CCCCCC,#32593D"
|
||||
color-link statusline "#242424,#CCCCCC"
|
||||
color-link tabbar "#242424,#CCCCCC"
|
||||
color-link indent-char "#4F4F4F,#242424"
|
||||
@ -28,3 +29,6 @@ color-link color-column "#2C2C2C"
|
||||
color-link type.extended "default"
|
||||
#color-link symbol.brackets "default"
|
||||
color-link symbol.tag "#AE81FF,#242424"
|
||||
color-link match-brace "#242424,#7A9EC2"
|
||||
color-link tab-error "#D75F5F"
|
||||
color-link trailingws "#D75F5F"
|
||||
|
@ -1,30 +1 @@
|
||||
color-link default "#F8F8F2,#282828"
|
||||
color-link comment "#75715E,#282828"
|
||||
color-link identifier "#66D9EF,#282828"
|
||||
color-link constant "#AE81FF,#282828"
|
||||
color-link constant.string "#E6DB74,#282828"
|
||||
color-link constant.string.char "#BDE6AD,#282828"
|
||||
color-link statement "#F92672,#282828"
|
||||
color-link symbol.operator "#F92671,#282828"
|
||||
color-link preproc "#CB4B16,#282828"
|
||||
color-link type "#66D9EF,#282828"
|
||||
color-link special "#A6E22E,#282828"
|
||||
color-link underlined "#D33682,#282828"
|
||||
color-link error "bold #CB4B16,#282828"
|
||||
color-link todo "bold #D33682,#282828"
|
||||
color-link statusline "#282828,#F8F8F2"
|
||||
color-link tabbar "#282828,#F8F8F2"
|
||||
color-link indent-char "#505050,#282828"
|
||||
color-link line-number "#AAAAAA,#323232"
|
||||
color-link current-line-number "#AAAAAA,#282828"
|
||||
color-link diff-added "#00AF00"
|
||||
color-link diff-modified "#FFAF00"
|
||||
color-link diff-deleted "#D70000"
|
||||
color-link gutter-error "#CB4B16,#282828"
|
||||
color-link gutter-warning "#E6DB74,#282828"
|
||||
color-link cursor-line "#323232"
|
||||
color-link color-column "#323232"
|
||||
#No extended types; Plain brackets.
|
||||
color-link type.extended "default"
|
||||
#color-link symbol.brackets "default"
|
||||
color-link symbol.tag "#AE81FF,#282828"
|
||||
include "monokai"
|
||||
|
@ -24,6 +24,8 @@ color-link underlined "#FF79C6"
|
||||
color-link error "bold #FF5555"
|
||||
color-link todo "bold #FF79C6"
|
||||
|
||||
color-link hlsearch "#282A36,#50FA7B"
|
||||
|
||||
color-link diff-added "#50FA7B"
|
||||
color-link diff-modified "#FFB86C"
|
||||
color-link diff-deleted "#FF5555"
|
||||
@ -41,3 +43,7 @@ color-link cursor-line "#44475A,#F8F8F2"
|
||||
color-link color-column "#44475A"
|
||||
color-link type.extended "default"
|
||||
|
||||
color-link match-brace "#282A36,#FF79C6"
|
||||
|
||||
color-link tab-error "#D75F5F"
|
||||
color-link trailingws "#D75F5F"
|
||||
|
@ -15,6 +15,7 @@ color-link divider "#001e28,#d0d0d0"
|
||||
color-link error "#cb4b16,#001e28"
|
||||
color-link gutter-error "#cb4b16,#001e28"
|
||||
color-link gutter-warning "#fce94f,#001e28"
|
||||
color-link hlsearch "#ffffff,#005028"
|
||||
color-link identifier "#00c8a0,#001e28"
|
||||
color-link identifier.class "#00c8a0,#001e28"
|
||||
color-link indent-char "#a0a0a0,#001e28"
|
||||
@ -32,3 +33,6 @@ color-link type "bold #3cc83c,#001e28"
|
||||
color-link type.keyword "bold #5aaae6,#001e28"
|
||||
color-link type.extended "#ffffff,#001e28"
|
||||
color-link underlined "#608b4e,#001e28"
|
||||
color-link match-brace "#001e28,#5aaae6"
|
||||
color-link tab-error "#d75f5f"
|
||||
color-link trailingws "#d75f5f"
|
||||
|
@ -15,6 +15,7 @@ color-link divider "#f0f0f0,#004080"
|
||||
color-link error "#500000,#f0f0f0"
|
||||
color-link gutter-error "#500000,#f0f0f0"
|
||||
color-link gutter-warning "#dcc800,#f0f0f0"
|
||||
color-link hlsearch "#000000,#b8d8e8"
|
||||
color-link identifier "bold #0078a0,#f0f0f0"
|
||||
color-link identifier.class "bold #0078a0,#f0f0f0"
|
||||
color-link indent-char "#404040,#f0f0f0"
|
||||
@ -32,3 +33,6 @@ color-link type "bold #004080,#f0f0f0"
|
||||
color-link type.keyword "bold #780050,#f0f0f0"
|
||||
color-link type.extended "#000000,#f0f0f0"
|
||||
color-link underlined "#3f7f5f,#f0f0f0"
|
||||
color-link match-brace "#f0f0f0,#780050"
|
||||
color-link tab-error "#ff8787"
|
||||
color-link trailingws "#ff8787"
|
||||
|
@ -15,6 +15,7 @@ color-link divider "#2d0023,#d0d0d0"
|
||||
color-link error "#cb4b16,#2d0023"
|
||||
color-link gutter-error "#cb4b16,#2d0023"
|
||||
color-link gutter-warning "#fce94f,#2d0023"
|
||||
color-link hlsearch "#ffffff,#005028"
|
||||
color-link identifier "#00c8a0,#2d0023"
|
||||
color-link identifier.class "#00c8a0,#2d0023"
|
||||
color-link indent-char "#a0a0a0,#2d0023"
|
||||
@ -32,3 +33,6 @@ color-link type "bold #3cc83c,#2d0023"
|
||||
color-link type.keyword "bold #5aaae6,#2d0023"
|
||||
color-link type.extended "#ffffff,#2d0023"
|
||||
color-link underlined "#886484,#2d0023"
|
||||
color-link match-brace "#2d0023,#5aaae6"
|
||||
color-link tab-error "#d75f5f"
|
||||
color-link trailingws "#d75f5f"
|
||||
|
@ -12,6 +12,7 @@ color-link type "blue"
|
||||
color-link type.extended "default"
|
||||
color-link error "red"
|
||||
color-link todo "bold cyan"
|
||||
color-link hlsearch "black,brightcyan"
|
||||
color-link indent-char "bold black"
|
||||
color-link line-number ""
|
||||
color-link current-line-number ""
|
||||
@ -23,3 +24,6 @@ color-link diff-modified "yellow"
|
||||
color-link diff-deleted "red"
|
||||
color-link gutter-error ",red"
|
||||
color-link gutter-warning "red"
|
||||
color-link match-brace "black,cyan"
|
||||
color-link tab-error "brightred"
|
||||
color-link trailingws "brightred"
|
||||
|
@ -11,6 +11,7 @@ color-link special "#D26937,#0C1014"
|
||||
color-link underlined "#EDB443,#0C1014"
|
||||
color-link error "bold #C23127,#0C1014"
|
||||
color-link todo "bold #888CA6,#0C1014"
|
||||
color-link hlsearch "#091F2E,#EDB443"
|
||||
color-link statusline "#091F2E,#599CAB"
|
||||
color-link indent-char "#505050,#0C1014"
|
||||
color-link line-number "#245361,#11151C"
|
||||
@ -23,3 +24,6 @@ color-link gutter-warning "#EDB443,#11151C"
|
||||
color-link cursor-line "#091F2E"
|
||||
color-link color-column "#11151C"
|
||||
color-link symbol "#99D1CE,#0C1014"
|
||||
color-link match-brace "#0C1014,#D26937"
|
||||
color-link tab-error "#D75F5F"
|
||||
color-link trailingws "#D75F5F"
|
||||
|
@ -9,8 +9,10 @@ color-link statement "#fb4934,#282828"
|
||||
color-link preproc "#fb4934,235"
|
||||
color-link type "#fb4934,#282828"
|
||||
color-link special "#d79921,#282828"
|
||||
color-link underlined "underline #282828"
|
||||
color-link underlined "underline #458588,#282828"
|
||||
color-link error "#9d0006,#282828"
|
||||
color-link todo "bold #ebdbb2,#282828"
|
||||
color-link hlsearch "#282828,#fabd2f"
|
||||
color-link diff-added "#00AF00"
|
||||
color-link diff-modified "#FFAF00"
|
||||
color-link diff-deleted "#D70000"
|
||||
@ -22,3 +24,6 @@ color-link cursor-line "#3c3836"
|
||||
color-link color-column "#79740e"
|
||||
color-link statusline "#ebdbb2,#665c54"
|
||||
color-link tabbar "#ebdbb2,#665c54"
|
||||
color-link match-brace "#282828,#d3869b"
|
||||
color-link tab-error "#d75f5f"
|
||||
color-link trailingws "#d75f5f"
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user