mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-29 07:45:46 +01:00
Add experimental :mksyntax command.
This commit is contained in:
@@ -568,6 +568,143 @@ lookup:
|
|||||||
completer: function (context) completion.file(context, true)
|
completer: function (context) completion.file(context, true)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
commands.add(["mks[yntax]"],
|
||||||
|
"Generate a Vim syntax file",
|
||||||
|
function (args) {
|
||||||
|
let runtime = util.OS.isWindows ? "~/vimfiles/" : "~/.vim/";
|
||||||
|
let file = io.File(runtime + "syntax/" + config.name + ".vim");
|
||||||
|
if (args.length)
|
||||||
|
file = io.File(args[0]);
|
||||||
|
|
||||||
|
if (file.exists() && file.isDirectory() || args[0] && /\/$/.test(args[0]))
|
||||||
|
file.append(config.name + ".vim");
|
||||||
|
dactyl.assert(!file.exists() || args.bang, "File exists");
|
||||||
|
|
||||||
|
let template = <![CDATA[
|
||||||
|
" Vim syntax file
|
||||||
|
" Language: Pentadactyl configuration file
|
||||||
|
" Maintainer: Doug Kearns <dougkearns@gmail.com>
|
||||||
|
|
||||||
|
" TODO: make this <name> specific - shared dactyl config?
|
||||||
|
|
||||||
|
if exists("b:current_syntax")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
let s:cpo_save = &cpo
|
||||||
|
set cpo&vim
|
||||||
|
|
||||||
|
syn include @javascriptTop syntax/javascript.vim
|
||||||
|
unlet b:current_syntax
|
||||||
|
|
||||||
|
syn include @cssTop syntax/css.vim
|
||||||
|
unlet b:current_syntax
|
||||||
|
|
||||||
|
syn match <name>CommandStart "\%(^\s*:\=\)\@<=" nextgroup=<name>Command,<name>AutoCmd
|
||||||
|
|
||||||
|
<commands>
|
||||||
|
|
||||||
|
syn match <name>Command "!" contained
|
||||||
|
|
||||||
|
syn keyword <name>AutoCmd au[tocmd] contained nextgroup=<name>AutoEventList skipwhite
|
||||||
|
|
||||||
|
<autocommands>
|
||||||
|
\ contained
|
||||||
|
|
||||||
|
syn match <name>AutoEventList "\(\a\+,\)*\a\+" contained contains=<name>AutoEvent
|
||||||
|
|
||||||
|
syn region <name>Set matchgroup=<name>Command start="\%(^\s*:\=\)\@<=\<\%(setl\%[ocal]\|setg\%[lobal]\|set\=\)\=\>"
|
||||||
|
\ end="$" keepend oneline contains=<name>Option,<name>String
|
||||||
|
|
||||||
|
<options>
|
||||||
|
|
||||||
|
<toggleoptions>
|
||||||
|
execute 'syn match <name>Option "\<\%(no\|inv\)\=\%(' .
|
||||||
|
\ join(s:toggleOptions, '\|') .
|
||||||
|
\ '\)\>!\=" contained nextgroup=<name>SetMod'
|
||||||
|
|
||||||
|
syn match <name>SetMod "\%(\<[a-z_]\+\)\@<=&" contained
|
||||||
|
|
||||||
|
syn region <name>JavaScript start="\%(^\s*\%(javascript\|js\)\s\+\)\@<=" end="$" contains=@javascriptTop keepend oneline
|
||||||
|
syn region <name>JavaScript matchgroup=<name>JavaScriptDelimiter
|
||||||
|
\ start="\%(^\s*\%(javascript\|js\)\s\+\)\@<=<<\s*\z(\h\w*\)"hs=s+2 end="^\z1$" contains=@javascriptTop fold
|
||||||
|
|
||||||
|
let s:cssRegionStart = '\%(^\s*sty\%[le]!\=\s\+\%(-\%(n\|name\)\%(\s\+\|=\)\S\+\s\+\)\=[^-]\S\+\s\+\)\@<='
|
||||||
|
execute 'syn region <name>Css start="' . s:cssRegionStart . '" end="$" contains=@cssTop keepend oneline'
|
||||||
|
execute 'syn region <name>Css matchgroup=<name>CssDelimiter'
|
||||||
|
\ 'start="' . s:cssRegionStart . '<<\s*\z(\h\w*\)"hs=s+2 end="^\z1$" contains=@cssTop fold'
|
||||||
|
|
||||||
|
syn match <name>Notation "<[0-9A-Za-z-]\+>"
|
||||||
|
|
||||||
|
syn match <name>Comment +".*$+ contains=<name>Todo,@Spell
|
||||||
|
syn keyword <name>Todo FIXME NOTE TODO XXX contained
|
||||||
|
|
||||||
|
syn region <name>String start="\z(["']\)" end="\z1" skip="\\\\\|\\\z1" oneline
|
||||||
|
|
||||||
|
syn match <name>LineComment +^\s*".*$+ contains=<name>Todo,@Spell
|
||||||
|
|
||||||
|
" NOTE: match vim.vim highlighting group names
|
||||||
|
hi def link <name>AutoCmd <name>Command
|
||||||
|
hi def link <name>AutoEvent Type
|
||||||
|
hi def link <name>Command Statement
|
||||||
|
hi def link <name>Comment Comment
|
||||||
|
hi def link <name>JavaScriptDelimiter Delimiter
|
||||||
|
hi def link <name>CssDelimiter Delimiter
|
||||||
|
hi def link <name>Notation Special
|
||||||
|
hi def link <name>LineComment Comment
|
||||||
|
hi def link <name>Option PreProc
|
||||||
|
hi def link <name>SetMod <name>Option
|
||||||
|
hi def link <name>String String
|
||||||
|
hi def link <name>Todo Todo
|
||||||
|
|
||||||
|
let b:current_syntax = "<name>"
|
||||||
|
|
||||||
|
let &cpo = s:cpo_save
|
||||||
|
unlet s:cpo_save
|
||||||
|
|
||||||
|
" vim: tw=130 et ts=4 sw=4:
|
||||||
|
]]>;
|
||||||
|
|
||||||
|
const WIDTH = 80;
|
||||||
|
function wrap(prefix, items, sep) {
|
||||||
|
sep = sep || " ";
|
||||||
|
let width = 0;
|
||||||
|
let lines = [];
|
||||||
|
lines.__defineGetter__("last", function () this[this.length - 1]);
|
||||||
|
|
||||||
|
for (let item in (isArray(items) ? array.iterValues : iter)(items)) {
|
||||||
|
if (item.length > width && (!lines.length || lines.last.length)) {
|
||||||
|
lines.push([prefix]);
|
||||||
|
width = WIDTH - prefix.length;
|
||||||
|
prefix = " \\ ";
|
||||||
|
}
|
||||||
|
width -= item.length + sep.length;
|
||||||
|
lines.last.push(item, sep);
|
||||||
|
}
|
||||||
|
lines.last.pop();
|
||||||
|
return lines.map(function (l) l.join("")).join("\n").replace(/\s+\n/gm, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
file.write(commands.replaceTokens(String(template), {
|
||||||
|
name: config.name,
|
||||||
|
autocommands: wrap("syn keyword " + config.name + "AutoEvent ",
|
||||||
|
keys(config.autocommands)),
|
||||||
|
commands: wrap("syn keyword " + config.name + "Command ",
|
||||||
|
array(c.specs for (c in commands)).flatten()),
|
||||||
|
options: wrap("syn keyword " + config.name + "Option ",
|
||||||
|
array(o.names for (o in options) if (o.type != "boolean")).flatten()),
|
||||||
|
toggleoptions: wrap("let s:toggleOptions = [",
|
||||||
|
array(o.realNames for (o in options) if (o.type == "boolean"))
|
||||||
|
.flatten().map(String.quote),
|
||||||
|
", ") + "]"
|
||||||
|
}));
|
||||||
|
}, {
|
||||||
|
argCount: "?",
|
||||||
|
bang: true,
|
||||||
|
completer: function (context) completion.file(context, true),
|
||||||
|
literal: 1
|
||||||
|
});
|
||||||
|
|
||||||
commands.add(["runt[ime]"],
|
commands.add(["runt[ime]"],
|
||||||
"Source the specified file from each directory in 'runtimepath'",
|
"Source the specified file from each directory in 'runtimepath'",
|
||||||
function (args) { io.sourceFromRuntimePath(args, args.bang); },
|
function (args) { io.sourceFromRuntimePath(args, args.bang); },
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ const Option = Class("Option", {
|
|||||||
init: function (names, description, type, defaultValue, extraInfo) {
|
init: function (names, description, type, defaultValue, extraInfo) {
|
||||||
this.name = names[0];
|
this.name = names[0];
|
||||||
this.names = names;
|
this.names = names;
|
||||||
|
this.realNames = names;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
|
||||||
|
|||||||
@@ -287,6 +287,7 @@ This file contains a list of all available commands, mappings and options.
|
|||||||
<dt><ex>:messages</ex></dt> <dd>Display previously given messages</dd>
|
<dt><ex>:messages</ex></dt> <dd>Display previously given messages</dd>
|
||||||
<dt><ex>:messclear</ex></dt> <dd>Clear the message history</dd>
|
<dt><ex>:messclear</ex></dt> <dd>Clear the message history</dd>
|
||||||
<dt><ex>:mk&dactyl.name;rc</ex></dt> <dd>Write current key mappings and changed options to the config file</dd>
|
<dt><ex>:mk&dactyl.name;rc</ex></dt> <dd>Write current key mappings and changed options to the config file</dd>
|
||||||
|
<dt><ex>:mksyntax</ex></dt> <dd>Generate a Vim syntax file</dd>
|
||||||
<dt><ex>:nmap</ex></dt> <dd>Map a key sequence in Normal mode</dd>
|
<dt><ex>:nmap</ex></dt> <dd>Map a key sequence in Normal mode</dd>
|
||||||
<dt><ex>:nmapclear</ex></dt> <dd>Remove all mappings in Normal mode</dd>
|
<dt><ex>:nmapclear</ex></dt> <dd>Remove all mappings in Normal mode</dd>
|
||||||
<dt><ex>:nnoremap</ex></dt> <dd>Map a key sequence without remapping keys in Normal mode</dd>
|
<dt><ex>:nnoremap</ex></dt> <dd>Map a key sequence without remapping keys in Normal mode</dd>
|
||||||
|
|||||||
@@ -45,6 +45,20 @@
|
|||||||
</description>
|
</description>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
|
<item>
|
||||||
|
<tags>:mks :mksyntax</tags>
|
||||||
|
<spec>:mks<oa>yntax</oa><oa>!</oa> <oa>path</oa></spec>
|
||||||
|
<description>
|
||||||
|
<p>
|
||||||
|
Generate a Vim syntax file. If <oa>path</oa> is not given, the local
|
||||||
|
Vim runtime path is guessed. If <oa>path</oa> is a directory, the
|
||||||
|
file <str delim="">&dactyl.name;.vim</str> in that directory is
|
||||||
|
used. An existing file will never be overwritten unless
|
||||||
|
<oa>bang</oa> is given.
|
||||||
|
</p>
|
||||||
|
</description>
|
||||||
|
</item>
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<tags><![CDATA[<C-l> CTRL-L :redr :redraw]]></tags>
|
<tags><![CDATA[<C-l> CTRL-L :redr :redraw]]></tags>
|
||||||
<strut/>
|
<strut/>
|
||||||
|
|||||||
@@ -54,6 +54,7 @@
|
|||||||
consistent interactive help facility (improvements include
|
consistent interactive help facility (improvements include
|
||||||
listing keys for modes other than Normal, filtering the output
|
listing keys for modes other than Normal, filtering the output
|
||||||
and linking to source locations).
|
and linking to source locations).
|
||||||
|
* Added :mksyntax command.
|
||||||
* IMPORTANT option changes:
|
* IMPORTANT option changes:
|
||||||
- 'cdpath' and 'runtimepath' no longer treat ",,"
|
- 'cdpath' and 'runtimepath' no longer treat ",,"
|
||||||
specially. Use "." instead.
|
specially. Use "." instead.
|
||||||
|
|||||||
Reference in New Issue
Block a user