zyedidia / micro

A modern and intuitive terminal-based text editor
https://micro-editor.github.io
MIT License
24.39k stars 1.16k forks source link

Feature request: inline options #3278

Open 1buran opened 2 months ago

1buran commented 2 months ago

It would be great to have support of inline options e.g. using setlocal command in comment will apply it in current buffer at first file opening:

// this is a normal comment line, but the next one is an inline command: 
// setlocal tabsize 2

or, if it would be easier implemented, something like emacs .dir-locals.el: special file with custom options for current dir and its decendants or type of files e.g. file with name .micro.yaml:

filetype: json 

detect:
    filename: "\\.json$"
    header: "^\\{$"

options: 
    - tabsize: 2     
JoeKar commented 2 months ago

Is the approach of Global and local settings not sufficient? The same works for whole directories too. :wink:

1buran commented 2 months ago

Is the approach of Global and local settings not sufficient? The same works for whole directories too. 😉

hmm.. I didn't get it at the first reading of docs..

Does it work for all options? For example is it allowed to do something like this? settings.json:

{
    "lsp.autocompleteDetails": true,
    "lsp.formatOnSave": false,
    "lsp.server": "go=gopls,php=intelephense --stdio",
    "/home/user/projects/name/huge.php": {
        "lsp.server": ""
    }
}

(disable lsp for one file)

glupi-borna commented 2 months ago

Note that what is actually matched against the "/home/user/projects/name/huge.php" key in your settings is the relative path to the file, as opposed to the absolute path. In this specific case, if you were in the "/home/user/projects/name" folder and typed micro huge.php at the command line, micro would open, but your settings would not be applied. Instead, you can supply the full path (micro /home/user/projects/name/huge.php), and then your settings would be applied.

If your settings were instead (off the top of my head):

{
    "lsp.autocompleteDetails": true,
    "lsp.formatOnSave": false,
    "lsp.server": "go=gopls,php=intelephense --stdio",
    "*/huge.php": {
        "lsp.server": ""
    }
}

Then any file named huge.php would have the lsp.server setting set to "".

On the topic of inline options being specified inside of files, you could totally make a plugin that does this.

1buran commented 2 months ago

Note that what is actually matched against the "/home/user/projects/name/huge.php" key in your settings is the relative path to the file, as opposed to the absolute path. In this specific case, if you were in the "/home/user/projects/name" folder and typed micro huge.php at the command line, micro would open, but your settings would not be applied. Instead, you can supply the full path (micro /home/user/projects/name/huge.php), and then your settings would be applied.

If your settings were instead (off the top of my head):

{
    "lsp.autocompleteDetails": true,
    "lsp.formatOnSave": false,
    "lsp.server": "go=gopls,php=intelephense --stdio",
    "*/huge.php": {
        "lsp.server": ""
    }
}

Then any file named huge.php would have the lsp.server setting set to "".

Thank you! Yeah, you are right: i faced with this weird issue - sometime the local settings were not applied, with your hints about paths puzzle is solved. I'll test this with more generic path (like you proposed).

On the topic of inline options being specified inside of files, you could totally make a plugin that does this.

hm... that's interesting, I'm not really familiar with Lua, but I really like the micro-editor, want to switch to it completely from emacs. But I'm used to using dired, magit and other emacs stuff, maybe this will encourage me to learn Lua and create plugins that will cover the lack of such functionality.