micro
micro copied to clipboard
Micro do not save file and reopen old file
Linux desktop Zorin Pro 16.3
Micro is not saving file and when opening the same file, after closing and reopening it with micro give the msg
The file on disk has changed. Reload file (y,n,esc)
Closing micro, starting vim, deleting a line with vim for testing...cat file to verify
Micro is loading the old file again (from WHERE ???) deleting a line with micro, saving the file C-s, C-q restart micro file IS NOT updated (Did a check by using vim).
Package from Zorin distribution. Did install a snap version, same result.
Standard installation at ~/.config/micro
Apparently it is happening with the configuration files (in this case bindings.json)
NO automatic saving
A line can usually be added again in bindings.json
because a key binding is being tried to be set in a plugin when micro is opened. I think you were trying to delete a line so that nothing would happen when pressing a key, but the action can be set as None
so that nothing would happen.
For example, the file would be like this when setting the action of Alt-/
as None
:
{
"Alt-/": "None",
"Ctrl-F2": "command:toggleBookmark",
"CtrlShift-F2": "command:clearBookmarks",
"F2": "command:nextBookmark",
"Shift-F2": "command:prevBookmark"
}
Micro writes bindings.json
before opening anything. So you start micro. Micro starts plugins. Plugins register bindings. Micro rewrites bindings.json
. Micro finishes initialization and starts to open file you wanted to open. It looks to already overwritten bindings.json
...
You can even delete the line. Open any file but not bindings.json
. Close micro. Open bindings.json
via vim and see that it was rewritten
The file on disk has changed. Reload file (y,n,esc)
is partially solved by https://github.com/zyedidia/micro/pull/3009 but IIUC only for settings.json
Sorry. I stand my ground.
Start with a small bindings built with vim
Here;
{ "Alt-/": "lua:comment.comment", "Ctrl-F2": "command:toggleBookmark" }
:wq!
cat .config/micro/bindings.json shows the file (4 lines) as before.
micro .config/micro/bindings.json
Got msg The file on disk has changed. Reload file (y,n,esc)
Did not reply. Did a cat on another terminal for .config/micro/bindings.json and the file has ALREADY BEEN CHANGED by starting micro. It is.
$ cat .config/micro/bindings.json { "Alt-/": "lua:comment.comment", "Ctrl-F2": "command:toggleBookmark", "CtrlShift-F2": "command:clearBookmarks", "F2": "command:nextBookmark", "F5": "lua:wc.wordCount", "Shift-F2": "command:prevBookmark" }
Reply n to micro; Exit micro
micro .config/micro/bindings.json
Got the OLD file !!!
From WHERE ? So ?
Easy to reproduce.
Got the OLD file !!! From WHERE ? So ?
Because micro at start regenerates that file!
It doesn't open old
version. It generates it each time you run micro. You can open ANY file with micro and it will regenerate the bindings file
Sorry you are wrong. THERE IS NO reason fro micro to reinstate configuration lines suppressed by user with the user file at .config/micro/bindings.json
They are user bindings NOT system bindings.
On top micro is adding old user bindings (suppressed by me...).
They are the bindings set by plugins.
You don't believe me. Just disable your bookmark plugin Ctrl+e
and then type> set bookmark off
after it you can again edit your file to:
{
"Alt-/": "lua:comment.comment",
"Ctrl-F2": "command:toggleBookmark"
}
Micro won't add the lines that was configured by bookmark plugin
The bindings for bookmarks were set BY ME NOT by the plugin for a start.
From bookmarks plugin page...
How to use:
While editing, press the default key (F11) to set a bookmark at the current line. You can also use the command toggle_bookmark from the (Ctrl+E) prompt Press the default key (F10) to loop through all the bookmarks You can also use the command next_bookmark from the (Ctrl+E) prompt To remove a bookmark, press the default key again while the cursor is on the bookmarked line
The bindings for bookmarks were set BY ME NOT by the plugin for a start.
https://github.com/haqk/micro-bookmark/blob/baca5fdd6a6475c3b8f9b1bb08192044ffcfff81/bookmark.lua#L401-L405
The plugin tells me something different...
You were right and it is a strange design for configuration files. I did a check within the bookmark plugin before reading your last msg.
config.TryBindKey("Ctrl-F2", "command:toggleBookmark", false)
config.TryBindKey("CtrlShift-F2", "command:clearBookmarks", false)
config.TryBindKey("F2", "command:nextBookmark", false)
config.TryBindKey("Shift-F2", "command:prevBookmark", false)
In fact I did not know the bindings..and took the same I was using with Sublime-Text...I was convinced I did it.
It can be confusing. If you start like this
micro .config/micro/bindings.json
micro load the old bindings.json (modified using vim) and after loading plugins (and adjusting bindings.json) tell you file has been changed...
If you start like this
micro and after opening .config/micro/bindings.json no msg of course.
Thanks anyway.
it is a strange design for configuration files.
Yes, it is. If I was @zyedidia I would design it differently.
But we can't just change it now, since we need to preserve compatibility with existing plugins and so on, so...
Anyway, @niten94 has already mentioned the solution for preventing a plugin from forcing its default binding for a key when there is no user-defined binding: bind this key to None
.
But we can't just change it now, since we need to preserve compatibility with existing plugins and so on, so...
As a partial workaround we can (can we?) not to rewrite bindings.json
if nothing differs so if bindings weren't changed by plugin, user at least won't see annoying "file is changed"...
As a partial workaround we can (can we?) not to rewrite bindings.json if nothing differs so if bindings weren't changed by plugin, user at least won't see annoying "file is changed"...
Isn't that how it already works? (Unless the last argument to TryBindKey
is true, which I also mentioned in #2647, but that's not a very common case.)
Yeah, you are right it is a last argument of TryBindKey
in one of my test plugins
Yes a solution is to bind some keys to None if you do want plugins to populate keys definition (or to change plugins yourself...). I was using vi (yep..), vim, neovim, emacs, Sublime-Text, gedit, kate NOT a single editor or plugin's editor is changing configuration files during start. Plugins are offering sometime default key not anything else. You can of course replace the default. At least emacs has a discovery help..C-h k to discover if a key sequence is used and vim/neovim have plugin(s) to do it.
Currently we have `
At least emacs has a discovery help..C-h k to discover if a key sequence is used and vim/neovim have plugin(s) to do it.
Now we have showkey
command that do the same