Skip to content

Commit

Permalink
vimp
Browse files Browse the repository at this point in the history
  • Loading branch information
eagletmt committed Jan 28, 2011
1 parent df2ebd7 commit 0886724
Show file tree
Hide file tree
Showing 18 changed files with 828 additions and 300 deletions.
4 changes: 2 additions & 2 deletions dot.vimperator/plugin/_libly.js
Expand Up @@ -15,7 +15,7 @@ var PLUGIN_INFO =
<version>0.1.33</version>
<minVersion>2.3pre</minVersion>
<maxVersion>2.3</maxVersion>
<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/_libly.js</updateURL>
<updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/_libly.js</updateURL>
<detail><![CDATA[
== Objects ==
- liberator.plugins.libly.$U
Expand Down Expand Up @@ -146,7 +146,7 @@ Request(url, headers, options):
BASIC認証時のパスワード
postBody:
POSTメソッドにより送信するbody
addEventLister(name, func):
addEventListener(name, func):
イベントリスナを登録する。
name:
'onSuccess':
Expand Down
224 changes: 224 additions & 0 deletions dot.vimperator/plugin/bracket-pair.js
@@ -0,0 +1,224 @@
// vim: set sw=4 ts=4 et fdm=marker:
var INFO = //{{{
<plugin name="liberator-overlay-ext" version="0.0.1"
href="http://github.com/caisui/vimperator/blob/master/plugin/bracket-pair.js"
summary="bracket pair"
xmlns="http://vimperator.org/namespaces/liberator">
<author href="http://d.hatena.ne.jp/caisui">caisui</author>
<license href="http://www.opensource.org/licenses/bsd-license.php">New BSD License</license>
<project name="Vimperator" minVersion="2.0"/>
<item>
<description>
括弧の対応先をハイライトします。
</description>
</item>
<item>
<spec>関数</spec>
<description>
<dl>
<dt>jumpToMatchItem</dt>
<dd>対応括弧にジャンプ</dd>
<dt>show_highlight</dt>
<dd>対応括弧をハイライトします</dd>
</dl>
</description>
</item>
<item>
<spec>{"c_<C-5>"}</spec>
<tags>{"c_<C-5>"}</tags>
<description>
対応括弧へジャンプします
</description>
</item>
<item>
<tags> g:show_cursor_bracket </tags>
<spec> let g:show_cursor_bracket </spec>
<description>
true で 括弧の両方がハイライトされます。
</description>
</item>
</plugin>
; //}}}
(function (self) {
const close2open = {
")": "(",
"}": "{",
"]": "[",
};
const matchTargets = /[(){}\[\]"']/;
const re_highlight = /^(js|javascript|echo|ec)/;

function getMatchPairMain(expression, index) {
const chars = "(){}\\[\\]\\\"'";
const re = new RegExp(<>([{chars}])(\s*)([^{chars}]*)</>, "g");
const reStr1 = /((?:[^"\\]|\\.)*)(")/gy;
const reStr2 = /((?:[^'\\]|\\.)*)(')/gy;

let m;
let stack = [];
let isString = false;
while (m = re.exec(expression)) {
switch (m[1]) {
case "(":
case "{":
case "[":
stack.push({c: m[1], index: m.index});
if (m.index == index) {
index= expression.length;
stack[stack.length - 1].goal = true;
}
break;
case ")":
case "}":
case "]":
if (stack.length == 0) {
return {index: 0, valid: false};
} else {
let b = stack.pop();
if (b.goal) {
return {index: m.index, valid: b.c == close2open[m[1]]};
} else if (m.index == index) {
return {index: b.index, valid: b.c == close2open[m[1]]};
}
}
break;
case '"':
case "'": {
let re1 = m[1] == '"' ? reStr1 :reStr2;

re1.lastIndex = m.index + 1;
let m1 = re1.exec(expression);
if (!m1) return null;

if (index == m.index) {
return {index: re1.lastIndex - 1, valid: true};
} else if (index == re1.lastIndex - 1) {
return {index: m1.index - 1, valid: true};
}
re.lastIndex = re1.lastIndex;
} break;
}
if (re.lastIndex > index) break;
}
}

function event_keyup(evt) {
const inputField = commandline._commandWidget.inputField;
const editor = inputField.editor;
const selectionController = editor.selectionController;
const aFind = selectionController.getSelection(Ci.nsISelectionController.SELECTION_FIND);
const aSpell = selectionController.getSelection(Ci.nsISelectionController.SELECTION_SPELLCHECK);

aFind.removeAllRanges();
aSpell.removeAllRanges();

let i = inputField.selectionEnd - 1;
let c = inputField.value.substr(i, 1);

if (matchTargets.test(c)) {
let ret, aType;
ret = searchOpenBracket(inputField.value, i);

if (!ret) return;
let doc = editor.document;
let range = doc.createRange();
let elem = editor.rootElement.childNodes[0];

range.setStart(elem, ret.index);
range.setEnd(elem, ret.index + 1);
aFind.addRange(range);

range = doc.createRange();
range.setStart(elem, i);
range.setEnd(elem, i + 1);
aFind.addRange(range);

if (!ret.valid) {
let range = doc.createRange();
if (ret.index > i) [i, ret.index] = [ret.index, i];
range.setStart(elem, ret.index);
range.setEnd(elem, i);

aSpell.addRange(range);
}
}
}

self.core = {
getMatchPair: function _getMatchPair(inputField) {
let i = inputField.selectionEnd - 1;
let c = inputField.value.substr(i, 1);
if (!matchTargets.test(c)) return [];

return [getMatchPairMain(inputField.value, i), i, c];
},
jumpToMatchItem: function jumpToMatchItem(inputField) {
let [inf] = this.getMatchPair(inputField);
if (inf) {
if (inputField.selectionStart == inputField.selectionEnd) {
inputField.selectionEnd = inputField.selectionStart = inf.index + 1;
} else {
//todo: 選択範囲がある場合は、selectionStart を起点に選択範囲を更新できるようにする
inputField.selectionEnd = inputField.selectionStart = inf.index + 1;
}
}
},
highlight: function highlight(inputField) {
let [inf, i, c] = this.getMatchPair(inputField);

let editor = inputField.editor;
let selectionController = editor.selectionController;
let aFind = selectionController.getSelection(Ci.nsISelectionController.SELECTION_FIND);
let aSpell = selectionController.getSelection(Ci.nsISelectionController.SELECTION_SPELLCHECK);

aFind.removeAllRanges();
aSpell.removeAllRanges();

if (!inf) return;


let doc = editor.document;
let range = doc.createRange();
let text = editor.rootElement.childNodes[0];

range.setStart(text, inf.index);
range.setEnd(text, inf.index + 1);
aFind.addRange(range);

if (liberator.globalVariables.show_cursor_bracket) {
range = doc.createRange();
range.setStart(text, i);
range.setEnd(text, i + 1);
aFind.addRange(range);
}

if (!inf.valid) {
let range = doc.createRange();
if (inf.index > i) [i, inf.index] = [inf.index, i];
range.setStart(text, inf.index);
range.setEnd(text, i);

aSpell.addRange(range);
}
}
};
self.jumpToMatchItem = function() {
this.core.jumpToMatchItem(Editor.getEditor());
};
self.show_highlight = function() {
this.core.highlight(Editor.getEditor());
};

let(inputField = commandline._commandWidget.inputField) {
const cache_key = "@cache-bracket-pair";
const eventName = "keyup";
userContext[cache_key] && inputField.removeEventListener(eventName, userContext[cache_key], false);
userContext[cache_key] = function() {
let text = Editor.getEditor().value;
if (re_highlight.test(text))
self.show_highlight();
}
inputField.addEventListener("keyup", userContext[cache_key], false);
}
mappings.addUserMap([modes.COMMAND_LINE], ["<C-5>"], "", function() self.jumpToMatchItem());
})(this);
2 changes: 1 addition & 1 deletion dot.vimperator/plugin/copy.js
Expand Up @@ -121,7 +121,7 @@ var PLUGIN_INFO =
<description lang="ja">テンプレートから文字列のコピーを可能にします(CopyURL+みたいなもの)</description>
<minVersion>2.0pre</minVersion>
<maxVersion>2.0pre</maxVersion>
<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/copy.js</updateURL>
<updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/copy.js</updateURL>
<author mail="teramako@gmail.com" homepage="http://vimperator.g.hatena.ne.jp/teramako/">teramako</author>
<license>MPL 1.1/GPL 2.0/LGPL 2.1</license>
<version>0.7.5</version>
Expand Down
14 changes: 7 additions & 7 deletions dot.vimperator/plugin/feedSomeKeys_3.js
Expand Up @@ -39,11 +39,11 @@ let PLUGIN_INFO =
<name lang="ja">feedSomeKeys 3</name>
<description>feed some defined key events into the Web content</description>
<description lang="ja">キーイベントをWebコンテンツ側に送る</description>
<version>1.8.1</version>
<version>1.8.3</version>
<author mail="anekos@snca.net" homepage="http://d.hatena.ne.jp/nokturnalmortum/">anekos</author>
<license>new BSD License (Please read the source code comments of this plugin)</license>
<license lang="ja">修正BSDライセンス (ソースコードのコメントを参照してください)</license>
<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/feedSomeKeys_3.js</updateURL>
<updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/feedSomeKeys_3.js</updateURL>
<minVersion>2.3</minVersion>
<maxVersion>2.3</maxVersion>
<require type="plugin">_libly.js</require>
Expand Down Expand Up @@ -79,7 +79,7 @@ lazy fmaps -u='http://code.google.com/p/vimperator-labs/issues/detail' u
// }}}
// INFO {{{
let INFO = <>
<plugin name="feedSomeKeys" version="1.8.1"
<plugin name="feedSomeKeys" version="1.8.3"
href="http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/feedSomeKeys_3.js"
summary="Feed some defined key events into the Web content"
lang="en-US"
Expand Down Expand Up @@ -181,9 +181,9 @@ let INFO = <>
:lazy fmaps -u='http://code.google.com/p/vimperator-labs/issues/detail' u
</ex></code>
</plugin>
<plugin name="feedSomeKeys" version="1.8.1"
<plugin name="feedSomeKeys" version="1.8.3"
href="http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/feedSomeKeys_3.js"
summary="Feed some defined key events into the Web content"
summary="Web コンテンツに直接キーイベントを送ります。"
lang="ja"
xmlns="http://vimperator.org/namespaces/liberator">
<author email="anekos@snca.net">anekos</author>
Expand Down Expand Up @@ -354,7 +354,7 @@ let INFO = <>

function getFrames () {
function bodyCheck (content)
(content.document.body.localName.toLowerCase() === 'body');
(content.document && content.document.body && content.document.body.localName.toLowerCase() === 'body');

function get (content)
(bodyCheck(content) && result.push(content), Array.slice(content.frames).forEach(get));
Expand Down Expand Up @@ -514,7 +514,7 @@ let INFO = <>
if (map.matchingUrls && !uniq[map.matchingUrls])
];
if (currentURL) {
result.unshift([util.escapeRegex(buffer.URL), 'Current URL']);
result.unshift(['^' + util.escapeRegex(buffer.URL), 'Current URL']);
result.unshift([util.escapeRegex(content.document.domain), 'Current domain']);
}
return result;
Expand Down
4 changes: 2 additions & 2 deletions dot.vimperator/plugin/loginManager.js
Expand Up @@ -7,7 +7,7 @@ var PLUGIN_INFO =
<version>0.0.4</version>
<minVersion>2.0pre</minVersion>
<maxVersion>2.2pre</maxVersion>
<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/loginManger.js</updateURL>
<updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/loginManger.js</updateURL>
<license>public domain</license>
<detail><![CDATA[

Expand Down Expand Up @@ -80,7 +80,7 @@ var services = {
passwordField: "password",
},
twitter: {
HOST: ["http://twitter.com", "https://twitter.com"],
HOST: ["https://twitter.com", "http://twitter.com"],
LOGIN: "/sessions",
LOGOUT: "/sessions/destroy",
usernameField: "session[username_or_email]",
Expand Down
2 changes: 1 addition & 1 deletion dot.vimperator/plugin/multi_requester.js
Expand Up @@ -15,7 +15,7 @@ var PLUGIN_INFO =
<license>MIT</license>
<minVersion>2.0pre</minVersion>
<maxVersion>2.3</maxVersion>
<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/multi_requester.js</updateURL>
<updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/multi_requester.js</updateURL>
<detail><![CDATA[
== Needs Library ==
- _libly.js(ver.0.1.19)
Expand Down
5 changes: 2 additions & 3 deletions dot.vimperator/plugin/pixiv.js
Expand Up @@ -110,7 +110,7 @@ liberator.plugins.pixiv = (function() {
},
true); // }}}

commands.addUserCommand('pixivUserBookmark', '[un]bookmark this user', // {{{
commands.addUserCommand(['pixivUserBookmark'], '[un]bookmark this user', // {{{
function(args) {
let id = content.document.getElementById('rpc_u_id');
if (id) {
Expand All @@ -133,7 +133,7 @@ liberator.plugins.pixiv = (function() {
}
}, { bang: true, argCount: '0' }, true); // }}}

commands.addUserCommand('pixivViewBookmark', 'view pixiv bookmark', // {{{
commands.addUserCommand(['pixivViewBookmark'], 'view pixiv bookmark', // {{{
function() {
if (!/http:\/\/www\.pixiv\.net\/member_illust\.php\?.*illust_id=(\d+)/.test(buffer.URI)) {
liberator.echo('not pixiv illust page');
Expand Down Expand Up @@ -163,7 +163,6 @@ liberator.plugins.pixiv = (function() {

liberator.echo(xml);
});
req.get();
}, { argCount: '0' }, true); // }}}

hints.addMode( // hint mode for tombloo {{{
Expand Down
12 changes: 9 additions & 3 deletions dot.vimperator/plugin/refcontrol.js
Expand Up @@ -7,7 +7,7 @@ var PLUGIN_INFO =
<author homepage="http://d.hatena.ne.jp/pekepekesamurai/">pekepeke</author>
<minVersion>2.0pre</minVersion>
<maxVersion>2.0pre</maxVersion>
<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/refcontrol.js</updateURL>
<updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/refcontrol.js</updateURL>
<detail><![CDATA[
== コマンド ==
:togglerefcontrol:
Expand Down Expand Up @@ -98,8 +98,9 @@ RefControl.prototype = {
panel.setAttribute('class', 'statusbarpanel-iconic');
panel.setAttribute('src', self.isEnable ? ENABLE_ICON : DISABLE_ICON);
panel.addEventListener('click', function(e) { self.isEnable = !self.isEnable; }, false);
document.getElementById('status-bar').insertBefore(
panel, document.getElementById('security-button').nextSibling);
document.getElementById('status-bar').appendChild(panel);
//document.getElementById('status-bar').insertBefore(
// panel, document.getElementById('security-button').nextSibling);
return panel;
},
get isEnable() _isEnable,
Expand Down Expand Up @@ -159,6 +160,11 @@ commands.addUserCommand(['addref'], 'add referrer control setting', function(arg
commands.addUserCommand(['togglerefcontrol'], 'toggle referrer control on/off',
function() {
manager.isEnable = !manager.isEnable;
if (manager.isEnable) {
liberator.echo('refcontrol enabled');
} else {
liberator.echo('refcontrol disabled');
}
}, {}
);

Expand Down

0 comments on commit 0886724

Please sign in to comment.