Commit graph

3029 commits

Author SHA1 Message Date
Dmytro Maluka
fade304667 infopane: HandleEvent: refactor y/n prompt handling 2024-04-25 00:13:37 +02:00
Dmytro Maluka
5b3737fb2a infopane: HandleEvent: reset key sequence when handling y/n prompt
Fix the following buggy behavior:

1. bind "<n><a>" to the Paste action in the command bar
2. open a split pane, type some text and press Ctrl-q to close it
3. answer "n" to the "Save changes before closing?" prompt
4. press Ctrl-e to open the command prompt and press "a"

-> result: instead of inserting the "a" letter, clipboard is pasted.
2024-04-25 00:05:27 +02:00
Dmytro Maluka
36bf3f6619 DoKeyEvent: document return value
The return value of DoKeyEvent() has a dual meaning, which makes the
code not obvious and confusing. So at least document it.
2024-04-24 23:21:28 +02:00
Dmytro Maluka
8c7f63ac15 infopane: DoKeyEvent: ignore action return value
It is not really defined what is the meaning of this return value.
Currently this value is always true. And even if this value actually
meant something (for example, the result of the last executed action
in the chain), we should not use this value in HandleEvent(). The key
event handling logic should behave the same regardless of whether the
action triggered by this key succeeded or not.
2024-04-24 22:51:27 +02:00
Dmytro Maluka
18f3e1bf89
Merge pull request #3245 from dmaluka/onsetactive-fix
Fix issues with `onSetActive` callback
2024-04-23 21:28:03 +02:00
Dmytro Maluka
e48575f349
Add onBufPaneOpen error checking (#3246)
If onBufPaneOpen callback execution fails (e.g. due to a Lua runtime
error), report this error to the user, like we do for all other Lua
callbacks, rather than silently continue working as if nothing
happened.
2024-04-23 21:23:25 +02:00
Dmytro Maluka
eec068a4fc
help/colors: syntax: document default.yaml (#3262) 2024-04-23 21:21:51 +02:00
Dmytro Maluka
5510317942
Relocate buffer view when reloading file (#3250)
After reloading a file that has been externally modified, the buffer
view may become invalid: the displayed subset of lines of the file may
no longer exist, since the file may have been truncated. So relocate the
buffer view in this case.

In particular, this fixes crashes caused by out of bounds accesses to
the line array by displayBuffer() trying to display no longer existing
lines.
2024-04-21 22:49:01 +02:00
Dmytro Maluka
169a9a65fa
Merge pull request #3259 from dmaluka/default-syntax-followup
Follow-ups after adding `default.yaml` support
2024-04-21 22:48:33 +02:00
Jöran Karl
c3052b491f
parser: Check and prompt for empty patterns and region properties (fix crash) (#3256)
* parser: Precise error message for missing `start` & `end` in region

* parser: Check and prompt for empty patterns and region properties

* syntax: Remove empty identifier pattern from log definition
2024-04-21 20:13:28 +02:00
Dmytro Maluka
b929c61228 help/colors: syntax: document that nested includes are not supported 2024-04-21 15:41:49 +02:00
Dmytro Maluka
08c516c730 UpdateRules: optimize out HasIncludes() usage 2024-04-21 15:14:21 +02:00
Dmytro Maluka
1bddc8d03e UpdateRules: move include logic to a helper function 2024-04-21 15:13:03 +02:00
Jöran Karl
f9cad2e448
action: Fix the duplication of the unknown filetype (#3258) 2024-04-19 06:01:27 +02:00
Dmytro Maluka
3aed20fde9 UpdateRules: correct the comments
The "runtime" term is ambiguous: it refers to both built-in and user's
custom ("real runtime") files.
2024-04-19 00:10:58 +02:00
Dmytro Maluka
a436dae587 UpdateRules: allow includes in default.yaml 2024-04-18 23:29:33 +02:00
Dmytro Maluka
5610d01e08 UpdateRules: fix set filetype unknown
Fix `set filetype unknown` not working as expected in the following
scenario:

1. open foo.txt (no filetype detected) -> ft is `unknown`, highlighted
   with default.yaml, as expected

2. `set filetype go` -> ft is `go`, highlighted with go.yaml as expected

3. `set filetype unknown` -> ft is still `go`, still highlighted with
   go.yaml (whereas expected behavior is: ft is `unknown`, highlighted
   with default.yaml)

Fix that by always updating b.SyntaxDef value, not reusing the old one.

This also makes the code simpler and easier to understand.
2024-04-18 22:39:16 +02:00
Jöran Karl
0806addbd7
Merge pull request #2933 from JoeKar/feature/default-syntax
syntax: Provide default.yaml as fallback definition
2024-04-18 19:38:35 +02:00
Jöran Karl
6cd39efddc buffer: Refactor UpdateRules() by creating further helper functions
- `findRealRuntimeSyntaxDef()`
- `findRuntimeSyntaxDef()`

This will reduce the length of this function again and thus improves the
readability.
2024-04-18 18:33:00 +02:00
Jöran Karl
089160a7e4 buffer: Refactor UpdateRules() by creating parseDefFromFile()
This will reduce the length of this function and thus improves the
readability.
2024-04-18 18:29:52 +02:00
Jöran Karl
ed993a4021 buffer: Precise comment about searching in the internal runtime files 2024-04-18 18:20:11 +02:00
Jöran Karl
4cafa601b5 syntax: Optimize the patterns and remove the comment region 2024-04-18 18:20:11 +02:00
Jöran Karl
87ee41ab27 buffer: Don't process the default syntax in the user's custom file lookup
It needs to be processed earliest in the moment no match could be determined.
2024-04-18 18:20:08 +02:00
Kevin Klement
8d8bc58f91
Update html.yaml by adding support for dialog tags (#3255)
Another relatively new tag but commonly used
2024-04-18 14:36:19 +02:00
Jöran Karl
6ffabd626f buffer: Let the user override the default.yaml 2024-04-17 18:10:15 +02:00
Jöran Karl
2c53d1fcab test: Perform DoEvent() as long as normal or draw events are present
This is necessary since DoEvent() isn't called in a loop like in the main
application, but as one-shot only and a async draw event can lead to ignore
the explicit injected events.
Additional checks have been added to check the presence of the expected buffers.
2024-04-14 16:55:59 +02:00
Jöran Karl
f265179def buffer: Correct error message in case of failed read 2024-04-14 16:55:59 +02:00
Jöran Karl
390794213e syntax: Provide default.yaml as fallback definition 2024-04-14 16:55:59 +02:00
Jöran Karl
430da61314 highlighter: Remove EmptyDef since it's superseeded by a nil check of SyntaxDef 2024-04-14 16:55:59 +02:00
matthias314
f386b29e16
add public keyword to Julia syntax file (#3247) 2024-04-13 14:47:42 +02:00
Dmytro Maluka
4283881591 onSetActive doc: move it
Cosmetic change: move onSetActive description to keep it together with
other callbacks that are associated with bufpane, not with buffer.
2024-04-12 02:33:16 +02:00
Dmytro Maluka
186817d0c4 onSetPane doc: s/panel/bufpane/
It is pane, not panel. Also, let's call it bufpane here, like we do in
other callbacks' descriptions.
2024-04-12 02:30:56 +02:00
Dmytro Maluka
2a1790d15a Don't call onSetActive for an already active pane
Currently onSetActive is called when the user clicks with the mouse on
a pane even if this pane is already active. We should avoid calling it
in this case.

Implementation detail: like with tabs in the previous commit, we cannot
check if the pane is already active just by checking the index passed
to the Tab's SetActive() (since the index may not change while the pane
itself changes), we need to check state of the pane itself. So we move
the onSetActive invocation from the Tab's SetActive() to the BufPane's
SetActive().
2024-04-12 02:21:03 +02:00
Dmytro Maluka
c6dc5a4b1f Call onSetActive when switching to another tab
We should call the onSetActive callback not only when switching to
another bufpane within the same tab but also when switching to another
tab.

Note on implementation details:

- In SetActive() we need to check if the tab is not already active, to
  avoid calling onSetActive for an already active bufpane.

- We cannot check that just by checking if the tab index passed to
  SetActive() is different from the current active tab index, since this
  index may remain the same even if the tab itself is different (in the
  case of removing a tab from the tablist). So we need to check the tab
  itself, not just the tab index. So we introduce the isActive field,
  to track the tab's active state in the Tab structure itself.
2024-04-12 02:07:29 +02:00
Jöran Karl
426aa9bb8b
command: Prevent re-writing settings in case of local option (#3178)
* command: Prevent re-writing settings in case of local option

* command: Refactor SetGlobalOptionNative()

Co-authored-by: Dmitry Maluka <dmitrymaluka@gmail.com>

---------

Co-authored-by: Dmitry Maluka <dmitrymaluka@gmail.com>
2024-04-11 18:35:13 +02:00
Dmytro Maluka
acb0d763df
ReHighlightStates: sanity-check startline value (#3237)
Check if startline value is valid before passing it to input.State(),
to prevent a theoretically possible race when the number of lines
changes in the meantime, causing an out of bounds access.

Actually this race cannot happen: ReHighlightStates() is only called
from the main goroutine, and the line array is modified, again, only by
the main goroutine. So for now this change is rather cosmetic: it is
just to make the highligher API implementation self-sufficiently safe
without assumptions about which goroutines are using which API functions
and how.
2024-04-09 00:31:01 +02:00
lvyaoting
d1d38d1ed7
chore: fix some typos (#3239)
Signed-off-by: lvyaoting <lvyaoting@outlook.com>
2024-04-08 12:04:38 +02:00
Jöran Karl
467c71dbb8
Merge pull request #3224 from JoeKar/fix/line-synchronization
buffer: Add proper lock mechanism to lock the full `LineArray` instead of single lines
2024-04-06 00:09:17 +02:00
Jöran Karl
a3ca054371 buffer: Uncomment InitRuntimeFiles(false) in the buffer_test.go
...since we fixed the race between the syntax highlighting and the buffer
editing.
2024-04-05 14:24:59 +02:00
Jöran Karl
b6dcbfa846 highlighter: Fix race between the async highlighter and the main routine
This is achieved by the usage of the new `LineArray` locking machanism,
which prevents the interruption in the moment of modifications like insertion
or removal of lines.

Co-authored-by: Dmytro Maluka <dmitrymaluka@gmail.com>
2024-04-05 14:24:39 +02:00
Jöran Karl
6e71e37568 buffer: Rename LineBytes parameter to "lineN" to fit to the rest 2024-04-05 14:24:39 +02:00
Jöran Karl
dd7134a762 buffer: Remove superfluous rehighlight from LineArray
...which isn't used so far and probably handled better in a different way.
2024-04-05 14:24:39 +02:00
Jöran Karl
2830c4878e buffer: Lock the LineArray in case of modifications and export this lock 2024-04-05 14:24:06 +02:00
Jöran Karl
53d56d032c buffer: Remove unneeded recursion of insert()
This is necessary as a preparation to introduce a lock for the whole LineArray.
The modification can then be done without trying to lock the same lock twice.

Co-authored-by: Dmytro Maluka <dmitrymaluka@gmail.com>
2024-04-05 14:19:37 +02:00
Jöran Karl
c493e14eb4
Merge pull request #3220 from dmaluka/tests-rtfiles-fix
Don't initialize plugins and user settings in tests
2024-04-05 11:24:40 +02:00
Dmytro Maluka
69dc54b407 Temporarily don't initialize runtime files in buffer test
Adding InitRuntimeFiles() to buffer_test.go has changed the behavior
of this test: now it tests not just buffer editing per se, but also
how well buffer editing works together with syntax highlighting (since
InitRuntimeFiles() loads syntax files, and many of the test buffers
match the json header pattern in the json.yaml syntax file, so they are
"highlighted" as json). This revealed long existing races between
buffer editing and syntax highlighting.

Until we fix those races, temporarily disable InitRuntimeFiles() in this
test.
2024-04-03 04:37:44 +02:00
Dmytro Maluka
c5d32f625b Ignore user-defined runtime files in buffer test and rtfiles test
When initializing runtime files (syntax files etc) in tests, initialize
built-in runtime files only, to ensure that the tests are not affected
by whatever is in ~/.config/micro/ on the test machine.

micro_test.go already ensures that, by using its own temporary directory
as an (empty) config directory. So we only need to fix buffer_test.go
and rtfiles_test.go. In those tests, don't repeat the same dance with
a temporary directory, instead just ignore the config directory.
2024-04-03 03:44:15 +02:00
Dmytro Maluka
baca0e5cb2 Add param to InitRuntimeFiles() to init built-in files only 2024-04-03 03:41:06 +02:00
Dmytro Maluka
d67ce731ed Don't initialize plugins in buffer test and rtfiles test
Adding InitPlugins() to tests has caused noisy error logs when running
the buffer_test.go test (although the test result is still PASS):

2024/03/23 15:14:30 Plugin does not exist: autoclose at autoclose : &{autoclose autoclose <nil> [runtime/plugins/autoclose/autoclose.lua] false true}
2024/03/23 15:14:30 Plugin does not exist: comment at comment : &{comment comment <nil> [runtime/plugins/comment/comment.lua] false true}
2024/03/23 15:14:30 Plugin does not exist: diff at diff : &{diff diff <nil> [runtime/plugins/diff/diff.lua] false true}
2024/03/23 15:14:30 Plugin does not exist: ftoptions at ftoptions : &{ftoptions ftoptions <nil> [runtime/plugins/ftoptions/ftoptions.lua] false true}
...

These errors are caused simply by the fact that plugins are initialized
but not loaded. Adding config.LoadAllPlugins() to buffer_test.go "fixes"
this problem.

However, at the moment it doesn't seem a good idea to load plugins in
buffer_test.go, since buffer_test.go doesn't properly initialize Lua. It
only does ulua.L = lua.NewState() but doesn't do the other stuff that
init() in cmd/micro/initlua.go does. As a result, plugins will not be
able to do anything correctly.

So in order to initialize Lua correctly we need to be inside cmd/micro/,
so we cannot do it in buffer_test.go or any other tests except
micro_test.go.
2024-04-03 03:04:42 +02:00
Dmytro Maluka
828871acdf
Improve crontab filetype detection (#3222)
Support crontab filetype detection in the case crontab is opened via
sudoedit. Also apparently this fixes crontab filetype detection when
it is opened normally via `crontab -e` but in MacOS.

Fixes #3172
2024-04-01 19:50:42 +02:00