Bat: feature request: detect filetype based on vim/emacs comments

Created on 31 May 2018  路  7Comments  路  Source: sharkdp/bat

Vim and Emacs can detect the file type base on comments placed at the top of the file.

For emacs:

# -*- mode: ruby -*-

For vim:

# vi: set ft=ruby :

This is useful for vagrant configuration files which are written in Ruby but are named Vagrantfile for example.

question

All 7 comments

Thank you for the feedback. bat (or rather syntect) can do the same, but it has to be specified in the respective syntax file. The C.sublime-syntax file, for example, has this header (see first_line_match):

name: C
file_extensions:
  - c
  - h
first_line_match: "-[*]-( Mode:)? C -[*]-"
scope: source.c

which bat correctly detects:

image

Unfortunately, only a few syntax definitions include this feature. The Ruby syntax includes this:

first_line_match: ^#!\s*/.*\bj?ruby\b

which means that it only detects shebangs:
image

However, note that Vagrantfile is correctly detected and displayed with Ruby syntax highlighting:
image

Actually, I guess correct highlighting of files such as Vagrantfile is only supported on master and not in the latest release. It has been integrated in syntect with my pull request here: https://github.com/trishume/syntect/pull/163.

Ah awesome! I'll wait for next release then. I'll look at syntect to ask if it's worth adding support for -*- mode: ruby -*-. Thanks for the answer!

I'll look at syntect to ask if it's worth adding support for -- mode: ruby --.

This would have to be done here: https://github.com/sublimehq/Packages

New release is out.

Just updated, and I can now see my Vagrantfiles with colors \o/
Thanks for this nice crate!

Thank you for the feedback!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

scalp42 picture scalp42  路  3Comments

tomgoren picture tomgoren  路  3Comments

lilyball picture lilyball  路  3Comments

rien333 picture rien333  路  3Comments

issmirnov picture issmirnov  路  3Comments