271 Commits

Author SHA1 Message Date
Jöran Karl
ab8c242044 gofmt after renaming the URL 2026-01-21 20:29:57 +01:00
Jöran Karl
4ead0e453b Change zyedidia/micro to micro-editor/micro 2026-01-21 20:29:55 +01:00
Andy Kluger
331c43ebb5 Replace never-assigned var filename with literal empty strings 2025-12-03 15:10:36 -05:00
Andy Kluger
70d9b64301 LoadInput: reduce variable scope (input, err)
Move input and err variable declarations to their usage point.
2025-12-02 14:59:45 -05:00
Andy Kluger
4debd29ccf Make the buffer creation when (no file args, terminal stdin) explicitly distinct
. . . but functionally equivalent.
2025-12-01 13:26:19 -05:00
Andy Kluger
c80e5cd97f Only set buffer type to stdout when no file args are passed
Fixes #2600
2025-12-01 13:15:28 -05:00
Jöran Karl
1ce2202d9a util: Convert suffix added with AppendBackupSuffix() to simple constant 2025-10-18 21:06:47 +02:00
Luca Stefani
e9f241af71 micro: Handle +/regex search from args (#3767)
This is a feature found in vim and commonly used
by Linux kernel test robots to give context about
warnings and/or failures.

e.g. vim +/imem_size +623 drivers/net/ipa/ipa_mem.c

The order in which the commands appear in the args
determines in which order the "goto line:column"
and search will be executed.
2025-09-05 20:53:37 +02:00
Dmytro Maluka
20ebca9be4 Update man page
Align it with `micro -help`.
2025-08-19 01:55:57 +02:00
Dmytro Maluka
f735ff04b4 Improve micro -help output 2025-08-16 16:29:16 +02:00
Dmytro Maluka
e127f08251 On panic, backup modified buffers only 2025-08-03 16:32:11 +02:00
Dmytro Maluka
2c010afbe4 Fix races between removing backups and creating periodic backups
Micro's logic for periodic backup creation is racy and may cause
spurious backups of unmodified buffers, at least for the following
reasons:

1. When a buffer is closed, its backup is removed by the main goroutine,
   without any synchronization with the backup/save goroutine which
   creates periodic backups in the background.

   A part of the problem here is that the main goroutine removes the
   backup before setting b.fini to true, not after it, so the
   backup/save goroutine may start creating a new backup even after it
   has been removed by the main goroutine. But even if we move the
   b.RemoveBackup() call after setting b.fini, it will not solve the
   problem, since the backup/save goroutine may have already started
   creating a new periodic backup just before b.fini was set to true.

2. When a buffer is successfully saved and thus its backup is removed,
   if there was a periodic backup for this buffer requested by the main
   goroutine but not saved by the backup/save goroutine yet (i.e. this
   request is still pending in backupRequestChan), micro doesn't cancel
   this pending request, so a backup is unexpectedly saved a couple of
   seconds after the file itself was saved.

   Although usually this erroneous backup is removed later, when the
   buffer is closed. But if micro terminates abnormally and the buffer
   is not properly closed, this backup is not removed. Also if this
   issue occurs in combination with the race issue #1 described above,
   this backup may not be successfully removed either.

So, to fix these issues:

1. Do the backup removal in the backup/save goroutine (at requests from
   the main goroutine), not directly in the main goroutine.

2. Make the communication between these goroutines fully synchronous:

2a. Instead of using the buffered channel backupRequestChan as a storage
    for pending requests for periodic backups, let the backup/save
    goroutine itself store this information, in the requestesBackups
    map. Then, backupRequestChan can be made non-buffered.

2b. Make saveRequestChan a non-buffered channel as well. (There was no
    point in making it buffered in the first place, actually.) Once both
    channels are non-buffered, the backup/save goroutine receives both
    backup and save requests from the main goroutine in exactly the same
    order as the main goroutine sends them, so we can guarantee that
    saving the buffer will cancel the previous pending backup request
    for this buffer.
2025-08-03 16:17:03 +02:00
cutelisp
3a7705a090 Enhance GetNativeValue 2025-07-11 11:21:40 +02:00
Dmytro Maluka
e923640b37 Move loading colorschemes after initializing plugins
Micro "allows" plugins to register colorschemes via
config.AddRuntimeFile(). However, that has never really worked, since
InitColorscheme() is called earlier than plugins init() or even
preinit() callbacks are called.

To work around that, plugins that use it (e.g. nord-tc [1]) are using a
tricky hack: call config.AddRuntimeFile() not in init() or preinit() but
directly in Lua's global scope, so that it is called earlier, when the
plugin's Lua code is loaded. This hack is not guaranteed to work, and
works by chance. Furthermore, it only works when starting micro, and
doesn't work after the `reload` command. (The reason it doesn't work is
that PluginAddRuntimeFile() calls FindPlugin() which calls IsLoaded()
which returns false, since, well, the plugin is not loaded, it is only
being loaded. And the reason why it works when starting micro is that
in that case IsLoaded() confusingly returns true, since
GlobalSettings[p.Name] has not been set yet.)

So move InitColorscheme() call after calling plugins init/preinit/
postinit callbacks, to let plugins successfully register colorschemes
in any of those callbacks instead of using the aforementioned hack.

[1] https://github.com/KiranWells/micro-nord-tc-colors
2025-06-24 22:24:47 +02:00
Dmytro Maluka
eadc402ae0 Import paths: fix non-alphabetic order
Make gofmt happy about that.
2025-03-24 23:01:48 +01:00
Jöran Karl
79ce93fb7d backup: Clear the requested backup upon completion notification
Now the main go routine takes care of the backup synchronization.
2025-02-28 18:57:53 +01:00
Jöran Karl
8c883c6210 backup: Rearrange and extend BackupMsg 2025-02-28 18:57:53 +01:00
Jöran Karl
c4dcef3e66 micro: Provide recovery of settings.json & bindings.json 2025-02-28 18:57:53 +01:00
Jöran Karl
e15bb88270 micro: Generalize exit behavior 2025-02-28 18:57:53 +01:00
Jöran Karl
6e8daa117a ioutil: Remove deprecated functions where possible 2025-02-28 18:57:53 +01:00
Jöran Karl
6600430e88 import: Use micro-editor/tcell (legacy) instead of zyedidia/tcell (#3593) 2025-01-04 15:55:46 +01:00
Jöran Karl
8b31dc79bf config: Rework autosave to be rearmed upon change 2024-08-18 22:28:49 +02:00
Jöran Karl
4170df89eb config: Use float64 within the autosave processing 2024-08-18 21:10:37 +02:00
Jöran Karl
4663927098 config: Refactor parsed option handling
Validate the parsed options directly after read and inform about errors.
2024-08-18 21:10:37 +02:00
Dmytro Maluka
1f71667616 Fix termpane not closing automatically after terminal job finished (#3386)
Fix regression caused by the fix 0de16334d3 ("micro: Don't forward
nil events into the sub event handler"): even if the terminal was
started with `wait` set to false, it is not closed immediately after
it finished its job, instead it shows "Press enter to close".

The reason is that since the commit b68461cf72 ("Terminal plugin
callback support") the termpane code has been (slightly hackily) relying
on nil events as notifications to close the terminal after it finished
its job. So fix this by introducing a separate CloseTerms() function
for notifying termpanes about that, decoupled from HandleEvent() which
is for tcell events only.
2024-07-15 09:35:50 +02:00
niten94
26ae1b95cc Move sigterm channel to internal/util 2024-06-17 18:08:18 +08:00
Dmytro Maluka
b70f0eb113 Add onAnyEvent callback (#3244)
Implement a radical approach to improving abilities of plugins to detect
and handle various changes of micro's state: add onAnyEvent callback
which is called, literally, after any event. A plugin can use this
callback to compare a state after the previous event and after the
current event, and thus is able to catch various events that cannot be
detected using other callbacks.

Some examples of such events:

- change of current working directory
- switching cursor focus between a bufpane and the command bar
- change of message text in the status bar
2024-05-14 18:01:15 +02:00
Dmytro Maluka
baca0e5cb2 Add param to InitRuntimeFiles() to init built-in files only 2024-04-03 03:41:06 +02:00
Jöran Karl
a57d29ada9 command: Fix reload command to correctly initialize and reload all runtime files (#3062)
* rtfiles: Initialize all-/realFiles and Plugins in InitRuntimeFiles

* command: Reload plugins at ReloadCmd too

* command: Don't reload plugins in case of ReloadConfig()

* rtfiles: Split InitRuntimeFiles() into one func for assets and one for plugins

* rtfiles: Remove the unnecessary init function

With this modification the InitRuntimeFiles() and InitPlugins() (if needed)
must be called first, otherwise uninitialized runtime file variables are most
likely.
2024-03-22 20:47:30 +01:00
Dmytro Maluka
9ab9f8bc1c Forward resize event to both TabList and InfoBar (#3179)
InfoBar should really receive the resize event, to know the window width
in order to do horizontal scrolling of the command line when it doesn't
fit in the screen. Although currently it doesn't scroll the command line
at all (see issue #2527) and just ignores the resize event, but we
should fix that anyway, so let's forward the resize event to it.
2024-03-21 21:40:22 +01:00
Suhaas Joshi
16e38b988c cmd: Fix typo in the plugin line of "micro --help" (#2594)
fixes #2582
2024-03-17 16:48:41 +01:00
Jöran Karl
4a53419c62 option: Don't apply rmtrailingws in case of timed autosave (#2850) 2024-03-15 18:46:51 +01:00
Dmytro Maluka
cb903f414c Remove unused autosave channel leftover (#3024)
config.Autosave channel is used instead.
2024-03-14 04:58:45 +01:00
Dmytro Maluka
0a69cc68dc Merge pull request #3023 from dmaluka/timerchan
Rework lua timers and remove lua.Lock
2024-03-14 04:58:19 +01:00
Dmytro Maluka
1d1b363fa7 Remove lua.Lock
Exposing locking primitives to lua plugins is tricky and may lead to
deadlocks. Instead, if possible, it's better to ensure all the needed
synchonization in micro itself, without leaving this burden to lua code.

Since we've added micro.After() timer API and removed exposing Go timers
directly to lua, now we (probably?) have no cases of lua code possibly
running asynchronously without micro controlling when it is running. So
now we can remove lua.Lock.

This means breaking compatibility, but, until recently lua.Lock wasn't
workable at all (see #2945), which suggests that it has never been
really used by anyone. So it should be safe to remove it.
2024-03-14 04:53:56 +01:00
Dmytro Maluka
9089e9ec83 Add micro's own lua timer function micro.After()
Directly using Go's time.AfterFunc() from lua is tricky. First, it
requires the lua timer callback to explicitly lock ulua.Lock to prevent
races. Second, it requires the lua timer callback to explicitly redraw
the screen if the callback changes the screen contents (see #2923).

So instead provide micro's own timer API which ensures both
synchronization and redrawing on its own, instead of leaving this burden
to lua code. In fact, its implementation runs the lua timer callback in
the main micro's goroutine (i.e. from micro's perspective it is
synchronous, not asynchronous), so both redrawing and synchronization
are ensured automatically.

Fixes #2923
2024-03-14 04:52:59 +01:00
Dmytro Maluka
c24604d1ab Fix overwriting persistent non-default settings with temporary default settings (#3010)
Passing options via micro -option=value in the command line should only
temporarily override the option value for the current micro session,
not change it permanently in settings.json. But currently it wrongly
writes it to settings.json in the case when the value passed via command
line is the default value of this option, while the current permanent
setting in settings.json is a non-default value.

Fixes #3005
2024-03-14 04:43:40 +01:00
Jöran Karl
321322af31 micro: DoEvent: Don't forward the resize event into the InfoBar (#3035) 2024-03-12 18:49:24 +01:00
Jöran Karl
0de16334d3 micro: Don't forward nil events into the sub event handler (#2992) 2024-03-12 18:35:33 +01:00
Zachary Yedidia
9da6af91c8 Handle SIGABRT properly 2023-10-20 08:51:17 +02:00
Zachary Yedidia
5739daffc8 Exit application if input terminal has closed
Bump tcell to get access to event error information, and to propagate
input EOF errors as event errors.

Fixes #2569
Fixes #2148
2023-03-20 16:17:43 -04:00
Dmitry Maluka
e31f5ed26e Add -profile flag for CPU profiling (#2715)
There is already a commented-out code in main() for enabling CPU
profiling of micro, which is often useful. Adjust it to allow enabling
it just by providing -profile flag on the command line, without
modifying and recompiling the code.
2023-01-29 18:10:57 -08:00
Zachary Yedidia
810133d5a8 Use shell job for terminal callback
Fixes #2529
2022-08-19 15:46:01 -07:00
Zachary Yedidia
3d6b0c6dd6 Ensure screen cannot draw during a term prompt
Fixes #2528
2022-08-16 22:07:41 -07:00
Zachary Yedidia
c315a91fc6 Allow aborting while opening a file with backup
Also fixes an issue where the abort prompt consumes interrupt signals.

Fixes #2151
2021-08-02 21:05:22 -04:00
Zachary Yedidia
0b0c99f1f5 Warn for readonly instead of setting option
Fixes #2106
2021-05-19 14:58:00 -04:00
Zachary Yedidia
0851499130 Handle SIGHUP properly
Fixes #2085

Not the nicest solution but it will do for now.
2021-04-20 21:27:59 -04:00
Zachary Yedidia
4c21808c6c Remove clipboard error message 2020-12-16 21:35:07 -05:00
Zachary Yedidia
a424a0dca1 Fix autosave not running by default 2020-10-08 23:33:34 -04:00
Sourya Vatsyayan
fc3dd9a62f Fix quality issues (#1856)
* Add .deepsource.toml

* Remove unnecessary comparison with bool

* Remove unnecessary use of slice

* Replace multiple `append`s with one

* Remove unnecessary wrapping of function call

* Fix check for empty string

* Simplify error creation with `fmt.Errorf`

* Fix defers before error check

Signed-off-by: sourya_deepsource <sourya@deepsource.io>

* Remove untrappable `os.Kill` signal

Signed-off-by: sourya_deepsource <sourya@deepsource.io>

* Remove empty else branch

Signed-off-by: sourya_deepsource <sourya@deepsource.io>

* Add missing error check

Signed-off-by: sourya_deepsource <sourya@deepsource.io>

* Merge variable declaration and assignment

Signed-off-by: sourya_deepsource <sourya@deepsource.io>

* Remove unnecessary `nil` check

Signed-off-by: sourya_deepsource <sourya@deepsource.io>

* Revert changes to generated files

Signed-off-by: sourya_deepsource <sourya@deepsource.io>

* Remove .deepsource.toml

Signed-off-by: sourya_deepsource <sourya@deepsource.io>

Co-authored-by: DeepSource Bot <bot@deepsource.io>
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2020-09-16 00:08:01 -04:00