1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 10:17:59 +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) { onSubmit: function onSubmit(command) {
contexts.withContext({ file: "[Command Line]", line: 1 },
function () {
io.withSavedValues(["readHeredoc"], function () { io.withSavedValues(["readHeredoc"], function () {
this.readHeredoc = commandline.readHeredoc; this.readHeredoc = commandline.readHeredoc;
contexts.withSavedValues(["context"], function () {
this.context = { file: "[Command Line]", line: 1 };
commands.repeat = command; commands.repeat = command;
dactyl.execute(command); dactyl.execute(command);
}); });

View File

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

View File

@@ -270,6 +270,12 @@ var Contexts = Module("contexts", {
get default() (contexts.context && contexts.context.group || contexts.user)[name], get default() (contexts.context && contexts.context.group || contexts.user)[name],
completer: function (context) completion.group(context) 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) { Context: modules.Script = function Context(file, group, args) {

View File

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

View File

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