micro icon indicating copy to clipboard operation
micro copied to clipboard

Feature request: inline options

Open 1buran opened this issue 1 year ago • 4 comments

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     

1buran avatar May 01 '24 09:05 1buran

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

JoeKar avatar May 01 '24 10:05 JoeKar

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)

1buran avatar May 01 '24 11:05 1buran

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.

glupi-borna avatar May 01 '24 19:05 glupi-borna

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.

1buran avatar May 01 '24 19:05 1buran