pygments / pygments.rb

💎 Ruby wrapper for Pygments syntax highlighter
MIT License
572 stars 141 forks source link

Emacs Lisp files are highlighted with the Scheme lexer on Github #134

Closed wasamasa closed 10 years ago

wasamasa commented 10 years ago

This Reddit post reminded me of a Github issue that highlights Emacs Lisp code incorrectly when escaped quote glyphs are involved which can be seen here for example. I've investigated into it and found out Github uses linguist which uses this library which again wraps pygments.

To experiment I've created problematic.el from the sample code:

((eq char ?\")
 (setq token-type 'string)
 (while (and continue (search-forward "\"" reg-end t))
   (if (looking-back "\\\\+\"" reg-beg t)
       (setq continue (= (mod (- (point) (match-beginning 0)) 2) 0))
     (setq continue nil))))

Specifying the Scheme lexer exactly recreates the rendering seen on the linked Github snippet. Here's the correctly highlighted snippet with the Emacs Lisp lexer:

((eq char ?\")
 (setq token-type 'string)
 (while (and continue (search-forward "\"" reg-end t))
   (if (looking-back "\\\\+\"" reg-beg t)
       (setq continue (= (mod (- (point) (match-beginning 0)) 2) 0))
     (setq continue nil))))

Is this behaviour the fault of pygments.rb? The pygmentize script autodetects the lexer correctly. If this is rather the fault of linguist, I'll repost the issue on their bug tracker.

wasamasa commented 10 years ago

Hmm, looks like it's rather linguist's fault. I'll leave this open for now until either option is confirmed.