mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 00:17:58 +01:00
couldn't resist, had to add support for auto-sourcing ~/.vimperator/plugin/ before we release 0.5
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<pre>
|
||||
2007-07-02:
|
||||
* version 0.5
|
||||
* files in ~/.vimperator/plugin/ are auto-sourced
|
||||
* :winopen support (multiple windows still very very experimental)
|
||||
* 'activate' option implemented
|
||||
* search enginges which use POST instead of GET work now
|
||||
|
||||
@@ -913,7 +913,13 @@ function Commands() //{{{
|
||||
{
|
||||
usage: ["so[urce][!] {file}"],
|
||||
short_help: "Read Ex commands from {file}",
|
||||
help: "The .vimperatorrc file in your home directory is always sourced at start up.<br/>" +
|
||||
help: "You can either source files which mostly contain Ex commands like <code class=\"command\">map < gt</code> " +
|
||||
"and put javascript code within a:<br/><code class=\"code\">" +
|
||||
"js <<EOF<br/>hello = function() {<br/> alert(\"Hello world\");<br/>}<br/>EOF<br/></code> section.<br/>" +
|
||||
"Or you can alternatively source a file which ends in .js, these files are automatically sourced as pure javascript files.<br/>" +
|
||||
"NOTE: In both cases you must add functions to the global window object like shown above, functions written as:<br/>" +
|
||||
"<code class=\"code\">function hello2() {<br/> alert(\"Hello world\");<br/>}<br/></code>are only available within the scope of the script. <br/><br/>" +
|
||||
"The .vimperatorrc file in your home directory and any files in ~/.vimperator/plugin/ are always sourced at startup.<br/>" +
|
||||
"~ is supported as a shortcut for the $HOME directory.<br/>" +
|
||||
"If <code class=\"command\">!</code> is specified, errors are not printed.",
|
||||
completer: function(filter) { return get_file_completions(filter); }
|
||||
@@ -1117,6 +1123,7 @@ function execute_command(count, cmd, special, args, modifiers) //{{{
|
||||
{
|
||||
if (!cmd)
|
||||
return;
|
||||
|
||||
if (!modifiers)
|
||||
modifiers = {};
|
||||
|
||||
@@ -1201,10 +1208,9 @@ function execute(string)
|
||||
}
|
||||
|
||||
|
||||
/* takes a string like 'google bla| www.osnews.com'
|
||||
/* takes a string like 'google bla, www.osnews.com'
|
||||
* and returns an array ['www.google.com/search?q=bla', 'www.osnews.com']
|
||||
*/
|
||||
//function stringToURLs(str)
|
||||
String.prototype.toURLArray = function()
|
||||
{
|
||||
var urls = this.split(/\s*\,\s+/);
|
||||
|
||||
@@ -245,6 +245,7 @@ function get_file_completions(filter) //{{{
|
||||
/* This is now also used as part of the url completion, so the substrings shouldn't be cleared for that case */
|
||||
if (!arguments[1])
|
||||
g_substrings = [];
|
||||
|
||||
var match = filter.match(/^(.*[\/\\])(.*?)$/);
|
||||
var dir;
|
||||
|
||||
|
||||
@@ -107,6 +107,10 @@ fieldset.paypal {
|
||||
color: #106326;
|
||||
}
|
||||
|
||||
.code {
|
||||
color: #108826;
|
||||
}
|
||||
|
||||
.shorthelp {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
@@ -27,46 +27,46 @@ the terms of any one of the MPL, the GPL or the LGPL.
|
||||
}}} ***** END LICENSE BLOCK *****/
|
||||
|
||||
// XXX: move somehere else!
|
||||
function multiliner(line, prev_match, heredoc) //{{{
|
||||
{
|
||||
var end = true;
|
||||
var match = tokenize_ex(line, prev_match[4]);
|
||||
if (prev_match[3] === undefined) prev_match[3] = '';
|
||||
if (match[4] === null)
|
||||
{
|
||||
vimperator.focusContent();
|
||||
execute_command.apply(this, match);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (match[4] === false)
|
||||
{
|
||||
prev_match[3] = prev_match[3].replace(new RegExp('<<\s*' + prev_match[4]), heredoc.replace(/\n$/, ''));
|
||||
vimperator.focusContent(); // also sets comp_tab_index to -1
|
||||
execute_command.apply(this, prev_match);
|
||||
prev_match = new Array(5);
|
||||
prev_match[3] = '';
|
||||
heredoc = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
end = false;
|
||||
if (!prev_match[3])
|
||||
{
|
||||
prev_match[0] = match[0];
|
||||
prev_match[1] = match[1];
|
||||
prev_match[2] = match[2];
|
||||
prev_match[3] = match[3];
|
||||
prev_match[4] = match[4];
|
||||
}
|
||||
else
|
||||
{
|
||||
heredoc += match[3] + '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
return [prev_match, heredoc, end];
|
||||
} //}}}
|
||||
// function multiliner(line, prev_match, heredoc) //{{{
|
||||
// {
|
||||
// var end = true;
|
||||
// var match = tokenize_ex(line, prev_match[4]);
|
||||
// if (prev_match[3] === undefined) prev_match[3] = '';
|
||||
// if (match[4] === null)
|
||||
// {
|
||||
// vimperator.focusContent();
|
||||
// execute_command.apply(this, match);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (match[4] === false)
|
||||
// {
|
||||
// prev_match[3] = prev_match[3].replace(new RegExp('<<\s*' + prev_match[4]), heredoc.replace(/\n$/, ''));
|
||||
// vimperator.focusContent(); // also sets comp_tab_index to -1
|
||||
// execute_command.apply(this, prev_match);
|
||||
// prev_match = new Array(5);
|
||||
// prev_match[3] = '';
|
||||
// heredoc = '';
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// end = false;
|
||||
// if (!prev_match[3])
|
||||
// {
|
||||
// prev_match[0] = match[0];
|
||||
// prev_match[1] = match[1];
|
||||
// prev_match[2] = match[2];
|
||||
// prev_match[3] = match[3];
|
||||
// prev_match[4] = match[4];
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// heredoc += match[3] + '\n';
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return [prev_match, heredoc, end];
|
||||
// } //}}}
|
||||
|
||||
/*
|
||||
* This class is used for prompting of user input and echoing of messages
|
||||
|
||||
@@ -277,7 +277,7 @@ const vimperator = (function() //{{{
|
||||
var postdata = typeof urls[0] == "string" ? null : urls[0][1];
|
||||
var whichwindow = window;
|
||||
|
||||
// decide where to load the first tab
|
||||
// decide where to load the first url
|
||||
switch (where)
|
||||
{
|
||||
case vimperator.CURRENT_TAB:
|
||||
@@ -454,11 +454,14 @@ const vimperator = (function() //{{{
|
||||
}
|
||||
},
|
||||
|
||||
// files which end in .js are sourced as pure javascript files,
|
||||
// no need (actually forbidden) to add: js <<EOF ... EOF around those files
|
||||
source: function(filename, silent)
|
||||
{
|
||||
if (!filename)
|
||||
return;
|
||||
|
||||
// TODO: move this to a seperate function
|
||||
// convert "~" to HOME on Windows
|
||||
if (navigator.platform == "Win32")
|
||||
{
|
||||
@@ -488,13 +491,45 @@ const vimperator = (function() //{{{
|
||||
var s = fd.read();
|
||||
fd.close();
|
||||
|
||||
// TODO: simplify and get rid of multiliner (look at "javascript" in commands.js)
|
||||
var prev_match = new Array(5);
|
||||
var heredoc = '';
|
||||
var end = false;
|
||||
s.split('\n').forEach(function(line) {
|
||||
[prev_match, heredoc, end] = multiliner(line, prev_match, heredoc);
|
||||
});
|
||||
// handle pure javascript files special
|
||||
if (filename.search("\.js$") != -1)
|
||||
eval(s);
|
||||
else
|
||||
{
|
||||
var heredoc = "";
|
||||
var heredocEnd = null; // the string which ends the heredoc
|
||||
s.split("\n").forEach(function(line) {
|
||||
if (heredocEnd) // we already are in a heredoc
|
||||
{
|
||||
if (line.search(heredocEnd) != -1)
|
||||
{
|
||||
eval(heredoc);
|
||||
heredoc = "";
|
||||
heredocEnd = null;
|
||||
}
|
||||
else
|
||||
heredoc += line + "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
// check for a heredoc
|
||||
var [count, cmd, special, args] = tokenize_ex(line);
|
||||
var command = vimperator.commands.get(cmd);
|
||||
if (command && command.name == "javascript")
|
||||
{
|
||||
var matches = args.match(/(.*)<<\s*([^\s]+)$/);
|
||||
if (matches && matches[2])
|
||||
{
|
||||
heredocEnd = new RegExp("^" + matches[2] + "$", "m");
|
||||
if(matches[1])
|
||||
heredoc = matches[1] + "\n";
|
||||
}
|
||||
}
|
||||
else // execute a normal vimperator command
|
||||
execute_command(count, cmd, special, args);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
@@ -577,8 +612,22 @@ const vimperator = (function() //{{{
|
||||
// Finally, read a ~/.vimperatorrc
|
||||
// Make sourcing asynchronous, otherwise commands that open new tabs won't work
|
||||
setTimeout(function() {
|
||||
vimperator.source("~/.vimperatorrc", true);
|
||||
vimperator.source("~/.vimperatorrc", false);
|
||||
vimperator.log("~/.vimperatorrc sourced", 1);
|
||||
|
||||
// also source plugins in ~/.vimperator/plugin/
|
||||
var entries = [];
|
||||
try {
|
||||
var fd = fopen("~/.vimperator/plugin", "<");
|
||||
var entries = fd.read();
|
||||
fd.close();
|
||||
entries.forEach(function(file) {
|
||||
if (!file.isDirectory())
|
||||
vimperator.source(file.path, false);
|
||||
});
|
||||
} catch(e) {
|
||||
// thrown if directory does not exist
|
||||
}
|
||||
}, 50);
|
||||
|
||||
vimperator.log("Vimperator fully initialized", 1);
|
||||
|
||||
Reference in New Issue
Block a user