Commit Graph

3451 Commits

Author SHA1 Message Date
Neko Box Coder
115e560ee2 Fixing regression introduced by #3310 with missing word boundary (#3891) 2025-10-19 13:13:30 +02:00
Jöran Karl
284942dffd Merge pull request #3806 from JoeKar/fix/backup-path
backup+util: Prevent too long backup file names with hashing + resolve file
2025-10-19 12:46:17 +02:00
Jöran Karl
bab39079b3 save: Remove a possible written backup in case the path has changed 2025-10-18 21:07:07 +02:00
Jöran Karl
02611f4ad2 backup: Keep path of stored & hashed backup files in a own $hash.path file
Since full escaped backup paths can become longer than the maximum filename size
and hashed filenames cannot be restored it is helpful to have a lookup file for
the user to resolve the hashed path.
2025-10-18 21:07:06 +02:00
Jöran Karl
1ce2202d9a util: Convert suffix added with AppendBackupSuffix() to simple constant 2025-10-18 21:06:47 +02:00
Jöran Karl
78d2c617ed util: Hash the path in DetermineEscapePath()
...in case the escaped path exceeds the file name length limit
2025-10-18 21:05:56 +02:00
Mikko
815ca0b6d8 fix c++ highlighting for binary literal with digit separator and suffix (#3870) 2025-10-11 21:59:02 +02:00
Jöran Karl
ec8bb7c11d Merge pull request #3866 from niten94/hide-sudo-prompt-win
- Disable sudo save prompt on Windows
- Add micro.exe to .gitignore
2025-09-21 14:33:23 +02:00
niten94
dcdddc191b Add micro.exe to .gitignore 2025-09-21 00:30:16 +08:00
niten94
85b4b2b788 Disable sudo save prompt on Windows
Display message stating that saving with sudo is unsupported on Windows,
immediately without a prompt when permission is denied.
2025-09-21 00:30:07 +08:00
Jöran Karl
ad24089e4e README: Use v2 for the Go Report Card (#3835) 2025-09-09 20:28:13 +02:00
Neko Box Coder
ed970eede3 Reordering triple quotes string to be evaluated first for groovy syntax (#3858) 2025-09-07 11:40:13 +02:00
Neko Box Coder
4d95f5f121 Adding comment for typescript (#3857) 2025-09-07 11:37:11 +02:00
Jöran Karl
45342bb0f1 Merge pull request #3760 from Neko-Box-Coder/MoreCharOptions
Adding indenttabchar, indentspacechar and spacechar options
2025-09-06 18:53:09 +02:00
Neko Box Coder
1ef6459846 Adding showchars option 2025-09-06 16:48:01 +01:00
Neko Box Coder
532c315f79 Simplifying draw to be less nested 2025-09-06 16:46:50 +01:00
Neko Box Coder
7b01fe4f56 Splitting draw out to getRuneStyle in bufwindow, removing @ for wide rune in bufwindow 2025-09-06 16:42:40 +01:00
cutelisp
0b9c7c0c4a Add toggle & togglelocal command (#3783) 2025-09-05 20:56:02 +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
ZRZ
bbea2a3f28 Fix highlighting for auto in C++ (#3836) 2025-09-02 19:46:35 +02:00
Jöran Karl
b37fa2e34d Merge pull request #3846 from JoeKar/revert/syntax-rules
syntax: Revert removal of `rules: []`
2025-09-02 19:28:06 +02:00
Mikko
4b2f8aa828 make arduino filetype detection less aggressive (#3848) 2025-09-01 20:46:10 +02:00
Jöran Karl
52f629cee7 syntax: Fix invalid escape of ' in php 2025-08-31 18:58:15 +02:00
Jöran Karl
d9245d9659 syntax: Add the empty rules: [] to the files currently "missing" them 2025-08-31 18:53:45 +02:00
Jöran Karl
3fd2fe3cc7 Revert "doc: syntax: Add hint about incompatibilities to previous versions"
This reverts commit 02e69dddbe.
2025-08-31 13:53:34 +02:00
Jöran Karl
0277516eef Revert "syntax: Remove empty rules in regions"
This reverts commit a9b513a28a.
2025-08-31 13:47:53 +02:00
deepdring
b8057f28c6 refactor: use a more modern writing style to simplify code (#3834)
Signed-off-by: deepdring <deepdrink@icloud.com>
2025-08-26 02:00:51 +02:00
Dmytro Maluka
094b02da4c plugin installer: Remove extra spaces in log messages 2025-08-20 22:19:47 +02:00
Dmytro Maluka
7a252f4986 Merge pull request #3810 from Neko-Box-Coder/ShowBuiltinPlugins
Adding the ability to differentiate builtin plugins when listing
2025-08-20 22:05:07 +02:00
Mikko
6b15bf3b19 fix shell highlighting for variables with leading underscore (#3833) 2025-08-20 20:51:34 +02:00
Jöran Karl
421da6752e Merge pull request #3812 from dmaluka/update-manpage
Update man page + change `[FILE]:LINE:COL` to `FILE[:LINE:COL]` in `micro -help`
2025-08-19 17:36:41 +02:00
Dmytro Maluka
c7d65d113a man page: Remove empty lines
As pointed out by @niten94, empty lines in the man page are not just
unnecessary but also cause extra empty lines to be displayed with
alternative `man` implementations, e.g. `mandoc`. To test on Debian,
for example, mandoc's implementation is named `mman` and included in the
`mandoc` package.
2025-08-19 01:57:18 +02:00
Dmytro Maluka
2b5eb3eca2 man page: Improve formatting
Display option names in bold text and argument placeholders in italic
text, as recommended in `man man`.
2025-08-19 01:56:31 +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
remisalmon
86a9fac7ef Fix variable expansion regex in fish syntax (#3830) 2025-08-16 13:30:47 +02:00
Jöran Karl
1dbb058773 Merge pull request #3814 from JoeKar/fix/sudo-save
save: Use `dd` with the `notrunc` & `fsync` and postpone truncation
2025-08-12 19:37:16 +02:00
Aleksey Sakovets
bce573b6c9 Add syntax highlighting for meson build system (#3236)
* Add syntax highlighting for meson build system

It is basically a port of upstream syntax highlighting for vim,
but a bit less noisy (e.g numbers are not colored).

* meson.yaml: fix meson_options.txt detection

* meson.yaml: remove empty rules

* meson.yaml: add highlighting for operators and brackets

* meson.yaml: rearrange the keywords to be in alphabetical order

* meson.yaml: add highlighting for numbers
2025-08-12 19:36:09 +02:00
Dmytro Maluka
774a6d8036 Merge pull request #3822 from dmaluka/fix-spurious-backups
Fix spurious backups of unmodified files
2025-08-11 22:30:25 +02:00
Neko Box Coder
177f4d5b01 Updating remove plugin message to specify plugin name 2025-08-09 10:58:16 +01:00
Jöran Karl
165a5a4896 save: Use dd with the notrunc & fsync option
Using notrunc  will stop the overall truncation of the target file done by sudo.
We need to do this because dd, like other coreutils, already truncates the file
on open(). In case we can't store the backup file afterwards we would end up in
a truncated file for which the user has no write permission by default.
Instead we use a second call of `dd` to perform the necessary truncation
on the command line.
With the fsync option we force the dd process to synchronize the written file
to the underlying device.
2025-08-06 20:13:36 +02:00
Dmytro Maluka
0a9fa4f2ea Always use temporary file when writing backup
When writing a backup file, we should write it atomically (i.e. use a
temporary file + rename) in all cases, not only when replacing an
existing backup. Just like we do in util.SafeWrite(). Otherwise, if
micro crashes while writing this backup, even if that doesn't result
in corrupting an existing good backup, it still results in creating
an undesired backup with invalid contents.
2025-08-03 18:41:34 +02:00
Dmytro Maluka
a862c9709e Unify backup write logic
Use the same backup write helper function for both periodic
background backups and for temporary backups in safeWrite().

Besides just removing code duplication, this brings the advantages
of both together:

- Temporary backups in safeWrite() now use the same atomic mechanism
  when replacing an already existing backup. So that if micro crashes
  in the middle of writing the backup in safeWrite(), this corrupted
  backup will not overwrite a previous good backup.

- Better error handling for periodic backups.
2025-08-03 18:37:00 +02:00
Dmytro Maluka
04b878bc2d Ignore the backup option when removing backup
When we need to remove existing backup for whatever reason (e.g. because
we've just successfully saved the file), we should do that regardless of
whether backups are enabled or not, since a backup may exist regardless
(it could have been created before the `backup` option got disabled).
2025-08-03 16:32:25 +02:00
Dmytro Maluka
e127f08251 On panic, backup modified buffers only 2025-08-03 16:32:11 +02:00
Dmytro Maluka
7aa495fd3f Remove backup when buffer becomes unmodified
We should cancel previously requested periodic backup (and remove this
backup if it has already been created) not only when saving or closing
the buffer but also in other cases when the buffer's state changes from
modified to unmodified, i.e. when the user undoes all unsaved changes.

Otherwise, if micro terminates abnormally before the buffer is closed,
this backup will not get removed (so next time micro will suggest the
user to recover this file), even though all changes to this file were
successfully saved.
2025-08-03 16:17:53 +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
Dmytro Maluka
e84d44d451 Move backup & save related stuff from Buffer to SharedBuffer
Various methods of Buffer should be rather methods of SharedBuffer. This
commit doesn't move all of them to SharedBuffer yet, only those that
need to be moved to SharedBuffer in order to be able to request creating
or removing backups in other SharedBuffer methods.
2025-08-03 14:53:29 +02:00
Dmytro Maluka
f938f62e31 Make isModified reflect actual modified/unmodified state of buffer
Instead of calculating the hash of the buffer every time Modified() is
called, do that every time b.isModified is updated (i.e. every time the
buffer is modified) and set b.isModified value accordingly.

This change means that the hash will be recalculated every time the user
types or deletes a character. But that is what already happens anyway,
since inserting or deleting characters triggers redrawing the display,
in particular redrawing the status line, which triggers Modified() in
order to show the up-to-date modified/unmodified status in the status
line. And with this change, we will be able to check this status
more than once during a single "handle event & redraw" cycle, while
still recalculating the hash only once.
2025-08-03 14:48:26 +02:00
Dmytro Maluka
4ade5cdf24 Make calcHash() a method of SharedBuffer
This will make it easier to use calcHash() in other SharedBuffer
methods.
2025-08-03 14:47:27 +02:00