forked from mark-hahn/grammar-mode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
azhinu
committed
Aug 18, 2021
1 parent
f89dd6a
commit d0805df
Showing
7 changed files
with
65 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,7 @@ | ||
Copyright (c) 2014 Mark Hahn | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
# -*- mode: Plain Text -*- | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
|
||
SubAtom = require 'sub-atom' | ||
|
||
module.exports = | ||
|
||
activate: -> | ||
activate: -> | ||
@subs = new SubAtom() | ||
@editorsWaitingForGrammar = [] | ||
|
||
@subs.add atom.workspace.observeTextEditors (editor) => | ||
editor.scan /-\*-\s*gramm[ae]r-ext:\s*\.?(\S+)\s*-\*-/i, (scanRes) => | ||
regex = /\ssyntax\=(\S+)\s*$/ | ||
@subs.add atom.workspace.observeTextEditors (editor) => | ||
editor.scan regex, (scanRes) => | ||
@editorsWaitingForGrammar.push [editor, scanRes.match[1].toLowerCase()] | ||
@chkAndStartTimeout() | ||
@chkAndStartTimeout() | ||
scanRes.stop() | ||
|
||
@subs.add atom.grammars.onDidAddGrammar (=> @chkAndStartTimeout()) | ||
|
||
@subs.add atom.commands.add 'atom-workspace', 'grammar-mode:check-all': => | ||
for editor in atom.workspace.getTextEditors() | ||
editor.scan /-\*-\s*gramm[ae]r-ext:\s*\.?(\S+)\s*-\*-/i, (scanRes) => | ||
@editorsWaitingForGrammar.push [editor, scanRes.match[1].toLowerCase()] | ||
scanRes.stop() | ||
@chkGrammars 'timedOut' | ||
|
||
chkAndStartTimeout: -> | ||
@chkGrammars() | ||
if @timeout then clearTimeout @timeout | ||
@timeout = setTimeout (=> @chkGrammars 'timedOut'), 2000 | ||
@timeout = setTimeout (=> @chkGrammars 'timedOut'), 1000 | ||
|
||
chkGrammars: (timedOut) -> | ||
if @timeout then clearTimeout @timeout | ||
for editorAndExt, editorIdx in @editorsWaitingForGrammar | ||
[editor, ext] = editorAndExt | ||
grammar = atom.grammars.selectGrammar 'x.' + ext | ||
regex = /source\./ | ||
if ext.search(regex) == 0 | ||
grammar = atom.grammars.grammarForScopeName(ext) | ||
console.log "Contains source" | ||
console.log ext | ||
else | ||
grammar = atom.grammars.selectGrammar 'x.' + ext | ||
console.log "Does not Contains source" | ||
console.log ext | ||
|
||
if grammar.name isnt 'Null Grammar' | ||
console.log 'setting mode', path: editor.getPath(), ext: ext, grammar: grammar.name | ||
setTimeout (-> editor.setGrammar grammar), 50 | ||
setTimeout (-> editor.setGrammar grammar), 10 | ||
@editorsWaitingForGrammar.splice editorIdx, 1 | ||
else if timedOut | ||
# @editorsWaitingForGrammar.splice editorIdx, 1 | ||
console.log 'Grammer not found for extension "' + ext + '" ' + | ||
'in file ' + editor.getPath() | ||
@editorsWaitingForGrammar.splice editorIdx, 1 | ||
|
||
deactivate: -> | ||
@subs.dispose() | ||
|
||
# -*- mode: CoffeeScript -*- |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,32 @@ | ||
{ | ||
"name": "grammar-mode", | ||
"name": "azhinu-grammar-mode", | ||
"main": "./lib/grammar-mode", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Force the grammar highlighting (\"mode\" in EMACS) of a file with a comment", | ||
"repository": "https://github.com/mark-hahn/grammar-mode", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/azhinu/grammar-mode.git" | ||
}, | ||
"license": "MIT", | ||
"engines": { | ||
"atom": ">0.180.0" | ||
}, | ||
"dependencies": { | ||
"sub-atom": "^1.0.0" | ||
} | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/azhinu/grammar-mode/issues" | ||
}, | ||
"homepage": "https://github.com/azhinu/grammar-mode#readme", | ||
"directories": { | ||
"lib": "lib" | ||
}, | ||
"devDependencies": {}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"atom-package" | ||
], | ||
"author": "Azhinu" | ||
} |