micro icon indicating copy to clipboard operation
micro copied to clipboard

either automatic default extension, or automatic syntax

Open evanescente-ondine opened this issue 3 years ago • 5 comments

Hi, I wondered if it was possible to have micro either add a default extension to all file text it creates, say .md, so by default it gets to highlight or more or less display) markdown hints ? to get some form of rich text in a termlinal... something awfully difficult, even in 2022. Pfff... Either that or could micro open all text files with that syntax mode, unless it sees more specific extensions (or ANY extension since my text files usually have none) ?

thanks for your help

evanescente-ondine avatar Feb 13 '22 02:02 evanescente-ondine

You can enable Markdown syntax for any file ending in *.txt by adding this to ~/.config/micro/settings.json:

    "*.txt": {
        "filetype": "markdown"
    },

But I don't know how to do this for files without an extension. Not surprisingly using "*" overrides all the internal filetypes and "*." only works for files ending in ".".

I'm not sure Micro if can determine a file type based its contents the way file(1) does.

Sorry for the non-answer, but maybe someone else can chime in with a solution.

zoomosis avatar Feb 13 '22 03:02 zoomosis

yours is a fine one, but only if Micro can get to put a default extension after the filename I submitted if it doesn't see a .something .

evanescente-ondine avatar Feb 13 '22 04:02 evanescente-ondine

Based on my experiments (not looking at the code), there seems to be a hacky way to achieve a default syntax highlighting:

  1. Copy all the syntax files you want micro to use (even the built-in ones) to ~/.config/micro/syntax/
  2. Create the desired syntax file in that directory (or just duplicate the one you want)
  3. Set its first line to filetype: unknown
  4. Remove the whole detect: part from it
  5. Rename the file to something that is sorted below all the others (e.g. zzz.yaml). Note that case is important and lowercase comes after uppercase.

This should work based on my tests.

arash-rohani avatar Jun 14 '22 05:06 arash-rohani

You can also just specify ft:unknown instead of a glob like *.txt in the settings.json:

{
    "ft:unknown": {
        "filetype": "markdown"
    }
}

zyedidia avatar Jun 14 '22 12:06 zyedidia

@zyedidia I tried it right now and it will replace all the filetypes with markdown even if the extension (or header) is not unknown. I'm on the latest release version (from pacman). Does it actually work like that on the master branch? Because I don't think replacing all the filetypes with markdown is what the OP wanted. He just wanted all the unknown filetypes to show markdown syntax highlighting. My solution actually does work that way. It just shows unknown as the filetype. But the syntax highlighting works for everything else too.

arash-rohani avatar Jun 14 '22 15:06 arash-rohani