Description
When I magit diff my ~/.emacs
file, there is no syntax highlighting. I'm trying to find out the right way to make it have syntax highlighting. I know that emacs knows what language my file is, and I was thinking that maybe magit-delta
could pass the --default-language
argument to its delta
subprocess.
Here's what I think I know:
magit-delta
is built upongit-delta
is built uponbat
is built uponsyntect
syntect
allows the user to modify its understanding of languages using.sublime-syntax
yaml files- part of this format is
file_extensions
- part of this format is
bat
lets you put.sublime-syntax
files in~/.config/bat/syntaxes/
bat
lets you use--syntax-map "<extension>:<syntax>"
in the CLI and in~/.config/bat/config
git-delta
does not supportbat
's syntax map (open issue), but it does have a--default-syntax
CLI option anddelta.default-language
git config option (discussion)- emacs determines the major mode for a file based on filename with
auto-mode-alist
, based on file contents withmagic-mode-alist
/magic-fallback-mode-alist
, based on shebang withinterpreter-mode-alist
, or by themajor-mode
variable set using file-local variables, dir-locals, or any user elisp code.- snippet of
auto-mode-alist
:("\\.ya?ml\\'" . yaml-ts-mode) ("\\.rs\\'" . rust-ts-mode) ("\\.py[iw]?\\'" . python-ts-mode) ("\\.lua\\'" . lua-ts-mode) ("\\.json\\'" . json-ts-mode) ("\\.js\\'" . js-ts-mode)
- snippet of
Determining the value for --default-language
might not be doable in an elegant way. The problem is that the language string format is human readable and case sensitive, so a mapping from major-mode to bat-language-string is unlikely to be a simple regex replace and will probably require some amount of human maintenance effort.
Using --default-syntax
would also not help if git-delta
's detected syntax is different from what you want, but it would help when git-delta
doesn't detect any syntax, like with .emacs
.
One way to solve both of these problems would be to modify the file extensions given to git-delta
. auto-mode-alist
tells you at least one valid file extension for a major mode, which git-delta
is likely to recognize. Creating symbolic links is ... doable in theory. Symbolic links have been possible without elevated privileges on windows for some time, but in my experience magit is effectively useless on windows anyways. I imagine that this blocking filesystem operation would not take terribly long, but still this feels like a hack.