Skip to content

Commit

Permalink
Update 1.2!
Browse files Browse the repository at this point in the history
  • Loading branch information
azhinu committed Aug 18, 2021
1 parent f89dd6a commit d0805df
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 64 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

## 1.2.0 - 8/18/21
* Removed menu items
* Changed -*- construction to syntax=
* Added ability to use "source." grammar name
* Changed package name
## 1.1.0 - 5/1/15
* Added to readme

Expand Down
21 changes: 3 additions & 18 deletions LICENSE.md
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.
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,31 @@
This is an Atom editor package to let the author of a source file add a comment to force the file to use a certain grammar (aka "mode" in EMACS) and show the appropriate syntax highlighting. This is needed on files with no extensions or files that start with one language but then are mostly another language (like react view files).

### Installation

Enter the terminal command `apm install grammar-mode` or use the `+ Install` button in the settings tab (`ctrl-,`) and search for grammar-mode.
Enter the terminal command `apm install azhinu-grammar-mode` or use the `+ Install` button in the settings tab (`ctrl-,`) and search for azhinu-grammar-mode.

### Usage

Add a string with this format anywhere in the file, usually in a comment. `EXTENSION` should be a typical source file extension for the type of file that uses the grammar you want your file to use. The period at the beginning is optional and nothing is case-sensitive.
Extension check grammar tag on file open.

```
-*- grammar-ext: EXTENSION -*-
syntax=EXTENSION
Examples ...
# -*- grammar-ext: .coffee -*-
// -*- grammar-ext: js -*-
```
#syntax=coffee
// syntax=js
or
syntax=grammar.name
### Checking manually
Examples ...
#syntax=source.yaml
// syntax=source.
```

Normally the `grammar-ext` comment is detected and the syntax highlighting set when the file is loaded. If you add a comment and want to see the results immediately then you need to issue a command to check all the loaded files. This is done with the `grammar-mode:check-all` command which is bound by default to `ctrl-shift-alt-M`.

### License
### License

Grammar-mode is copyright Mark Hahn with the MIT license.
2 changes: 0 additions & 2 deletions keymaps/grammar-mode.cson

This file was deleted.

40 changes: 20 additions & 20 deletions lib/grammar-mode.coffee
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 -*-
11 changes: 0 additions & 11 deletions menus/grammar-mode.cson

This file was deleted.

26 changes: 22 additions & 4 deletions package.json
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"
}

0 comments on commit d0805df

Please sign in to comment.