-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
33 lines (27 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"use strict";
const VIM_MODELINE = /(?:(?:^|[ \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;
const {CompositeDisposable, Disposable} = require("atom");
module.exports = {
disposables: null,
activate(){
this.disposables && this.disposables.dispose();
this.disposables = new CompositeDisposable(
new Disposable(() => this.disposables = null),
atom.packages.onDidActivateInitialPackages(() => {
atom.workspace.observeTextEditors(this.updateHelpGrammar.bind(this));
})
);
},
deactivate(){
if(this.disposables){
this.disposables.dispose();
}
},
updateHelpGrammar(editor){
if(!atom.workspace.isTextEditor(editor))
return; // Not even a real editor
const path = editor.getPath();
if(/\.txt$/i.test(path) && VIM_MODELINE.test(editor.getText()) && "help" === RegExp.lastParen)
editor.setGrammar(atom.grammars.grammarForScopeName("text.vim-help"));
},
};