curlpipe / ox

An independent Rust text editor that runs in your terminal!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add modeline magic for file type etc.

mjf opened this issue · comments

At least for file types you should provide modeline magic:

$ cat script
#! /bin/sh

echo "Hello, world!"
exit 0

# ox: ft=sh

Not everyone likes to add file extension to determine the file type! Therefor modeline magic can help to force it.
Also the #! ... shebang can be split to get the interpreter name (i.e. sh). You can also add some sort
of aliases for it. For example (for syntax etc. for some "shell" and "c"):

(
    filetypes: {
        "shell": {
            files: [".bash*", ".profile"],
            extensions: [".sh", ".bash", ".dash", ".sh.inc"],
            interpreters: ["sh", "bash", "dash"],
            modeline: {
                keywords: ["filetype", "ft"],
                values: ["shell", "sh"],
            },
        },
        "c": {
            files: ["~/dev/c/**"],
            extensions: [".c", ".h", ".cpp"],
            interpreters: ["tcc"],
            modeline: {
                keywords: ["filetype", "ft"],
                values: ["c", "c++"],
            },
        },
    },
)

Where the files, extensions, interpreters and modeline are "or-ed" (any of them can match). Just an idea... May be related to #76.

commented

I'll look into this