Skip to content

Commit

Permalink
Update modeline regexes with github-linguist/linguist#5271
Browse files Browse the repository at this point in the history
  • Loading branch information
Alhadis committed Mar 12, 2021
1 parent c6026e8 commit 0759f88
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- Icons of symlinked projects that aren't Git repositories
- [[`#841`][]]: `requirements.txt` showing [Binder][] icon instead of PyPi's
- [[`github/linguist#5271`][]]: Inaccuracies related to modeline matching

[`github/linguist#5271`]: https://github.com/github/linguist/pull/5271
[`#841`]: https://github.com/file-icons/atom/issues/841
[Binder]: https://mybinder.org/

Expand Down
4 changes: 2 additions & 2 deletions lib/service/strategies/modeline-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class ModelineStrategy extends HeaderStrategy {
return null;

// Emacs
let tokens = data.match(/-\*-(?:(?:(?!mode\s*:)[^:;]+:[^:;]+;)*\s*mode\s*:)?\s*([\w+-]+)\s*(?:;[^:;]+:[^:;]+?)*;?\s*-\*-/i);
let tokens = data.match(/-\*-(?:[ \t]*(?=[^:;\s]+[ \t]*-\*-)|(?:.*?[ \t;]|(?<=-\*-))[ \t]*mode[ \t]*:[ \t]*)([^:;\s]+)(?=[ \t;]|(?<![-*])-\*-).*?-\*-/i);
if(tokens && "fundamental" !== tokens[1])
return IconTables.matchLanguage(tokens[1]) || null;

// Vim
tokens = data.match(/(?:(?:\s|^)vi(?:m[<=>]?\d+|m)?|[\t ]ex)(?=:(?=\s*set?\s[^\n:]+:)|:(?!\s*set?\s))(?:(?:\s|\s*:\s*)\w*(?:\s*=(?:[^\n\\\s]|\\.)*)?)*[\s:](?:filetype|ft|syntax)\s*=(\w+)(?=\s|:|$)/i);
tokens = data.match(/(?:(?:^|[ \t])(?:vi|Vi(?=m))(?:m[<=>]?[0-9]+|m)?|[ \t]ex)(?=:(?=[ \t]*set?[ \t][^\r\n:]+:)|:(?![ \t]*set?[ \t]))(?:(?:[ \t]*:[ \t]*|[ \t])\w*(?:[ \t]*=(?:[^\\\s]|\\.)*)?)*[ \t:](?:filetype|ft|syntax)[ \t]*=(\w+)(?=$|\s|:)/i);
if(tokens)
return IconTables.matchLanguage(tokens[1]) || null;

Expand Down

0 comments on commit 0759f88

Please sign in to comment.