Created
June 29, 2016 01:22
-
-
Save humanfactors/064b17afde7e44231b6766e1d3aa19d0 to your computer and use it in GitHub Desktop.
Nvatom modifications
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
fs = require 'fs-plus' | |
path = require 'path' | |
{CompositeDisposable} = require 'atom' | |
Utility = require './utility' | |
module.exports = | |
class Interlink | |
constructor: -> | |
Interlink.loadGrammarSync() | |
@subscriptions = new CompositeDisposable | |
@subscriptions.add atom.commands.add 'atom-workspace', 'nvatom:openInterlink': => Interlink.openInterlink() | |
@subscriptions.add atom.workspace.observeTextEditors (editor) -> | |
if Utility.isNote(editor.getPath()) | |
editor.setGrammar(atom.grammars.grammarForScopeName('text.md')) | |
destroy: -> | |
@subscriptions.dispose() | |
@loadGrammarSync: -> | |
unless atom.grammars.grammarForScopeName('text.md') | |
grammarPath = path.join(atom.packages.resolvePackagePath('language-markdown'), 'grammars', 'language-markdown.json') | |
atom.grammars.loadGrammarSync(grammarPath) | |
@openInterlink: -> | |
editor = atom.workspace.getActiveTextEditor() | |
return unless editor? | |
return unless Utility.isNote(editor.getPath()) | |
noteTitle = Interlink.getInterlinkUnderCursor(editor) | |
return unless noteTitle? | |
return unless noteTitle.length | |
notePath = Utility.getNotePath(noteTitle) | |
unless fs.existsSync(notePath) | |
fs.writeFileSync(notePath, '') | |
atom.workspace.open(notePath) | |
@getInterlinkUnderCursor: (editor) -> | |
cursorPosition = editor.getCursorBufferPosition() | |
token = editor.tokenForBufferPosition(cursorPosition) | |
return unless token | |
return unless token.value | |
return unless token.scopes.indexOf('markup.underline.link.interlink.md') > -1 | |
interlink = Utility.trim(token.value) | |
return unless interlink.length | |
return interlink | |
# Second part | |
'name': 'nvAtom' | |
'scopeName': 'text.md.nvatom' | |
'patterns': [ | |
{ | |
'include': 'text.md' | |
} | |
{ | |
'match': '(?<!\\[)(\\[\\[)([^\\[\\]\|]+)(\\]\\])(?!\\])' | |
'name': 'interlink' | |
'captures': | |
'1': | |
'name': 'punctuation.definition.begin.md' | |
'2': | |
'name': 'markup.underline.link.interlink.md' | |
'3': | |
'name': 'punctuation.definition.begin.md' | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment