1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 20:07:59 +01:00

couldn't resist, had to add support for auto-sourcing ~/.vimperator/plugin/ before we release 0.5

This commit is contained in:
Martin Stubenschrott
2007-08-01 02:51:37 +00:00
parent 0d8140cedc
commit 983600cb7a
6 changed files with 113 additions and 52 deletions

View File

@@ -1,6 +1,7 @@
<pre> <pre>
2007-07-02: 2007-07-02:
* version 0.5 * version 0.5
* files in ~/.vimperator/plugin/ are auto-sourced
* :winopen support (multiple windows still very very experimental) * :winopen support (multiple windows still very very experimental)
* 'activate' option implemented * 'activate' option implemented
* search enginges which use POST instead of GET work now * search enginges which use POST instead of GET work now

View File

@@ -913,7 +913,13 @@ function Commands() //{{{
{ {
usage: ["so[urce][!] {file}"], usage: ["so[urce][!] {file}"],
short_help: "Read Ex commands from {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 &lt; gt</code> " +
"and put javascript code within a:<br/><code class=\"code\">" +
"js &lt;&lt;EOF<br/>hello = function() {<br/>&nbsp;&nbsp;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/>&nbsp;&nbsp;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/>" + "~ is supported as a shortcut for the $HOME directory.<br/>" +
"If <code class=\"command\">!</code> is specified, errors are not printed.", "If <code class=\"command\">!</code> is specified, errors are not printed.",
completer: function(filter) { return get_file_completions(filter); } completer: function(filter) { return get_file_completions(filter); }
@@ -1117,6 +1123,7 @@ function execute_command(count, cmd, special, args, modifiers) //{{{
{ {
if (!cmd) if (!cmd)
return; return;
if (!modifiers) if (!modifiers)
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'] * and returns an array ['www.google.com/search?q=bla', 'www.osnews.com']
*/ */
//function stringToURLs(str)
String.prototype.toURLArray = function() String.prototype.toURLArray = function()
{ {
var urls = this.split(/\s*\,\s+/); var urls = this.split(/\s*\,\s+/);

View File

@@ -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 */ /* This is now also used as part of the url completion, so the substrings shouldn't be cleared for that case */
if (!arguments[1]) if (!arguments[1])
g_substrings = []; g_substrings = [];
var match = filter.match(/^(.*[\/\\])(.*?)$/); var match = filter.match(/^(.*[\/\\])(.*?)$/);
var dir; var dir;

View File

@@ -107,6 +107,10 @@ fieldset.paypal {
color: #106326; color: #106326;
} }
.code {
color: #108826;
}
.shorthelp { .shorthelp {
font-weight: bold; font-weight: bold;
} }

View File

@@ -27,46 +27,46 @@ the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/ }}} ***** END LICENSE BLOCK *****/
// XXX: move somehere else! // XXX: move somehere else!
function multiliner(line, prev_match, heredoc) //{{{ // function multiliner(line, prev_match, heredoc) //{{{
{ // {
var end = true; // var end = true;
var match = tokenize_ex(line, prev_match[4]); // var match = tokenize_ex(line, prev_match[4]);
if (prev_match[3] === undefined) prev_match[3] = ''; // if (prev_match[3] === undefined) prev_match[3] = '';
if (match[4] === null) // if (match[4] === null)
{ // {
vimperator.focusContent(); // vimperator.focusContent();
execute_command.apply(this, match); // execute_command.apply(this, match);
} // }
else // else
{ // {
if (match[4] === false) // if (match[4] === false)
{ // {
prev_match[3] = prev_match[3].replace(new RegExp('<<\s*' + prev_match[4]), heredoc.replace(/\n$/, '')); // 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 // vimperator.focusContent(); // also sets comp_tab_index to -1
execute_command.apply(this, prev_match); // execute_command.apply(this, prev_match);
prev_match = new Array(5); // prev_match = new Array(5);
prev_match[3] = ''; // prev_match[3] = '';
heredoc = ''; // heredoc = '';
} // }
else // else
{ // {
end = false; // end = false;
if (!prev_match[3]) // if (!prev_match[3])
{ // {
prev_match[0] = match[0]; // prev_match[0] = match[0];
prev_match[1] = match[1]; // prev_match[1] = match[1];
prev_match[2] = match[2]; // prev_match[2] = match[2];
prev_match[3] = match[3]; // prev_match[3] = match[3];
prev_match[4] = match[4]; // prev_match[4] = match[4];
} // }
else // else
{ // {
heredoc += match[3] + '\n'; // heredoc += match[3] + '\n';
} // }
} // }
} // }
return [prev_match, heredoc, end]; // return [prev_match, heredoc, end];
} //}}} // } //}}}
/* /*
* This class is used for prompting of user input and echoing of messages * This class is used for prompting of user input and echoing of messages

View File

@@ -277,7 +277,7 @@ const vimperator = (function() //{{{
var postdata = typeof urls[0] == "string" ? null : urls[0][1]; var postdata = typeof urls[0] == "string" ? null : urls[0][1];
var whichwindow = window; var whichwindow = window;
// decide where to load the first tab // decide where to load the first url
switch (where) switch (where)
{ {
case vimperator.CURRENT_TAB: 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) source: function(filename, silent)
{ {
if (!filename) if (!filename)
return; return;
// TODO: move this to a seperate function
// convert "~" to HOME on Windows // convert "~" to HOME on Windows
if (navigator.platform == "Win32") if (navigator.platform == "Win32")
{ {
@@ -488,13 +491,45 @@ const vimperator = (function() //{{{
var s = fd.read(); var s = fd.read();
fd.close(); fd.close();
// TODO: simplify and get rid of multiliner (look at "javascript" in commands.js) // handle pure javascript files special
var prev_match = new Array(5); if (filename.search("\.js$") != -1)
var heredoc = ''; eval(s);
var end = false; else
s.split('\n').forEach(function(line) { {
[prev_match, heredoc, end] = multiliner(line, prev_match, heredoc); 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) catch (e)
{ {
@@ -577,8 +612,22 @@ const vimperator = (function() //{{{
// Finally, read a ~/.vimperatorrc // Finally, read a ~/.vimperatorrc
// Make sourcing asynchronous, otherwise commands that open new tabs won't work // Make sourcing asynchronous, otherwise commands that open new tabs won't work
setTimeout(function() { setTimeout(function() {
vimperator.source("~/.vimperatorrc", true); vimperator.source("~/.vimperatorrc", false);
vimperator.log("~/.vimperatorrc sourced", 1); 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); }, 50);
vimperator.log("Vimperator fully initialized", 1); vimperator.log("Vimperator fully initialized", 1);