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

Add contexts.withContext.

--HG--
branch : groups
This commit is contained in:
Kris Maglione
2011-02-07 23:51:29 -05:00
parent 76dee44cb9
commit 51a9fc8dea
5 changed files with 14 additions and 13 deletions

View File

@@ -424,10 +424,10 @@ var CommandExMode = Class("CommandExMode", CommandMode, {
},
onSubmit: function onSubmit(command) {
contexts.withContext({ file: "[Command Line]", line: 1 },
function () {
io.withSavedValues(["readHeredoc"], function () {
this.readHeredoc = commandline.readHeredoc;
contexts.withSavedValues(["context"], function () {
this.context = { file: "[Command Line]", line: 1 };
commands.repeat = command;
dactyl.execute(command);
});

View File

@@ -635,10 +635,8 @@ var Commands = Module("commands", {
* command string.
*/
execute: function (string, tokens, silent, args, context) {
contexts.withSavedValues(["context"], function () {
context = update({}, context || this.context || { file: "[Command Line]", line: 1 });
this.context = context;
contexts.withContext(context || this.context || { file: "[Command Line]", line: 1 },
function (context) {
io.withSavedValues(["readHeredoc"], function () {
this.readHeredoc = function (end) {
let res = [];

View File

@@ -270,6 +270,12 @@ var Contexts = Module("contexts", {
get default() (contexts.context && contexts.context.group || contexts.user)[name],
completer: function (context) completion.group(context)
}),
withContext: function withContext(defaults, callback, self)
this.withSavedValues(["context"], function () {
this.context = defaults && update({}, defaults);
return callback.call(self, this.context);
})
}, {
Context: modules.Script = function Context(file, group, args) {

View File

@@ -90,8 +90,6 @@ var MOW = Module("mow", {
* @param {string} highlightGroup
*/
echo: function echo(data, highlightGroup, silent) {
this.document;
util.dump(String(this.widget), String(this.window), String(this.document));
let body = this.document.body;
this.widgets.message = null;

View File

@@ -150,8 +150,7 @@ var IO = Module("io", {
params = params || {};
let time = Date.now();
return contexts.withSavedValues(["context"], function _source() {
contexts.context = null;
return contexts.withContext(null, function () {
try {
var file = util.getFile(filename) || io.File(filename);