Merge pull request #1192 from ajaxorg/tmSnippets
Add support for TextMate snippets
This commit is contained in:
commit
dd5c9954db
64 changed files with 9881 additions and 215 deletions
|
|
@ -120,20 +120,21 @@ env.editor.commands.addCommands([{
|
|||
editor.gotoLine(line);
|
||||
},
|
||||
readOnly: true
|
||||
}/*, {
|
||||
name: "find",
|
||||
bindKey: {win: "Ctrl-F", mac: "Command-F"},
|
||||
}, {
|
||||
name: "snippet",
|
||||
bindKey: {win: "Alt-C", mac: "Command-Alt-C"},
|
||||
exec: function(editor, needle) {
|
||||
if (typeof needle == "object") {
|
||||
var arg = this.name + " " + editor.getCopyText();
|
||||
editor.cmdLine.setValue(arg, 1);
|
||||
editor.cmdLine.setValue("snippet ", 1);
|
||||
editor.cmdLine.focus();
|
||||
return;
|
||||
}
|
||||
editor.find(needle);
|
||||
var s = SnippetManager.getSnippetByName(needle, editor);
|
||||
if (s)
|
||||
SnippetManager.insertSnippet(editor, s.content);
|
||||
},
|
||||
readOnly: true
|
||||
}*/, {
|
||||
}, {
|
||||
name: "focusCommandLine",
|
||||
bindKey: "shift-esc",
|
||||
exec: function(editor, needle) { editor.cmdLine.focus(); },
|
||||
|
|
@ -460,4 +461,47 @@ event.addListener(container, "drop", function(e) {
|
|||
var StatusBar = require("./statusbar").StatusBar;
|
||||
new StatusBar(env.editor, cmdLine.container);
|
||||
|
||||
require("ace/placeholder").PlaceHolder;
|
||||
|
||||
var SnippetManager = require("ace/snippets").SnippetManager
|
||||
var jsSnippets = require("ace/snippets/javascript");
|
||||
window.SnippetManager = SnippetManager
|
||||
saveSnippets()
|
||||
|
||||
function saveSnippets() {
|
||||
jsSnippets.snippets = SnippetManager.parseSnippetFile(jsSnippets.snippetText);
|
||||
SnippetManager.snipp
|
||||
SnippetManager.register(jsSnippets.snippets, "javascript")
|
||||
}
|
||||
|
||||
env.editSnippets = function() {
|
||||
var sp = env.split;
|
||||
if (sp.getSplits() == 2) {
|
||||
sp.setSplits(1);
|
||||
return;
|
||||
}
|
||||
sp.setSplits(1);
|
||||
sp.setSplits(2);
|
||||
sp.setOrientation(sp.BESIDE);
|
||||
var editor = sp.$editors[1]
|
||||
if (!env.snippetSession) {
|
||||
var file = jsSnippets.snippetText;
|
||||
env.snippetSession = doclist.initDoc(file, "", {});
|
||||
env.snippetSession.setMode("ace/mode/tmsnippet");
|
||||
env.snippetSession.setUseSoftTabs(false);
|
||||
}
|
||||
editor.on("blur", function() {
|
||||
jsSnippets.snippetText = editor.getValue();
|
||||
saveSnippets();
|
||||
})
|
||||
editor.setSession(env.snippetSession, 1);
|
||||
editor.focus();
|
||||
}
|
||||
|
||||
ace.commands.bindKey("Tab", function(editor) {
|
||||
var success = SnippetManager.expandWithTab(editor);
|
||||
if (!success)
|
||||
editor.execCommand("indent");
|
||||
})
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ function initDoc(file, path, doc) {
|
|||
var mode = modelist.getModeFromPath(path);
|
||||
session.modeName = mode.name;
|
||||
session.setMode(mode.mode);
|
||||
return session;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,26 @@
|
|||
$$------------------------------------
|
||||
tabTrigger: t
|
||||
name: Heading 3
|
||||
scope: language
|
||||
content: -----------------------------
|
||||
\begin{${1:documnet}}
|
||||
${2:$TM_SELECTED_TEXT:some latex}
|
||||
${3:$TM_SELECTED_TEXT/a/b/c}
|
||||
${4:${TM_SELECTED_TEXT/(.)/\\u$1/g:7}}
|
||||
\end{$1}
|
||||
$0\\$$
|
||||
$$------------------------------------
|
||||
tabTrigger: ^3
|
||||
name: Heading 3
|
||||
scope: language
|
||||
content: -----------------------------
|
||||
|
||||
${TM_CURRENT_LINE/./^/g}
|
||||
$$------------------------------------
|
||||
# Function
|
||||
snippet fun
|
||||
function ${1?:function_name}(${2:argument}) {
|
||||
${3:// body...}
|
||||
}
|
||||
# Anonymous Function
|
||||
regex /((=)\s*|(:)\s*|(\()|\b)/f/(\))?/
|
||||
name f
|
||||
function${M1?: ${1:functionName}}($2) {
|
||||
${0:$TM_SELECTED_TEXT}
|
||||
}${M2?;}${M3?,}${M4?)}
|
||||
# Immediate function
|
||||
trigger \(?f\(
|
||||
endTrigger \)?
|
||||
snippet f(
|
||||
(function(${1}) {
|
||||
${0:${TM_SELECTED_TEXT:/* code */}}
|
||||
}(${1}));
|
||||
# if
|
||||
snippet if
|
||||
if (${1:true}) {
|
||||
${0}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ var modesByName = {
|
|||
tex: ["Tex" , "tex"],
|
||||
text: ["Text" , "txt"],
|
||||
textile: ["Textile" , "textile"],
|
||||
tm_snippet: ["tmSnippet" , "tmSnippet"],
|
||||
tmsnippet: ["tmSnippet" , "tmSnippet"],
|
||||
toml: ["toml" , "toml"],
|
||||
typescript: ["Typescript" , "typescript|ts|str"],
|
||||
vbscript: ["VBScript" , "vbs"],
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
{
|
||||
"main": "./demo.js",
|
||||
"mappings": {
|
||||
"ace": "../.."
|
||||
},
|
||||
"config": {
|
||||
"github.com/sourcemint/bundler-js/0/-meta/config/0": {
|
||||
"adapter": "github.com/sourcemint/sdk-requirejs/0",
|
||||
"resources": [
|
||||
"./icons/*",
|
||||
"./logo.png",
|
||||
"./styles.css"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue