]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/io.jsm
Import 1.0b7.1 supporting Firefox up to 8.*
[dactyl.git] / common / modules / io.jsm
index a6487a99ea99d18ecd88928349a378180cafc0db..63ac6061921a35d2d88c12a13d1f65c7712c458b 100644 (file)
@@ -105,7 +105,7 @@ var IO = Module("io", {
          * found it is sourced. Only the first file found (per specified path) is
          * sourced unless *all* is specified, then all found files are sourced.
          *
-         * @param {string[]} paths An array of relative paths to source.
+         * @param {[string]} paths An array of relative paths to source.
          * @param {boolean} all Whether all found files should be sourced.
          */
         sourceFromRuntimePath: function sourceFromRuntimePath(paths, all) {
@@ -116,7 +116,7 @@ var IO = Module("io", {
 
         outer:
             for (let dir in values(dirs)) {
-                for (let [,path] in Iterator(paths)) {
+                for (let [, path] in Iterator(paths)) {
                     let file = dir.child(path);
 
                     dactyl.echomsg(_("io.searchingFor", file.path.quote()), 3);
@@ -202,13 +202,13 @@ var IO = Module("io", {
                         this._scriptNames.push(file.path);
 
                     dactyl.echomsg(_("io.sourcingEnd", filename.quote()), 2);
+                    dactyl.log(_("dactyl.sourced", filename), 3);
 
-                    dactyl.log("Sourced: " + filename, 3);
                     return context;
                 }
                 catch (e) {
                     dactyl.reportError(e);
-                    let message = "Sourcing file: " + (e.echoerr || file.path + ": " + e);
+                    let message = _("io.sourcingError", e.echoerr || (file ? file.path : filename) + ": " + e);
                     if (!params.silent)
                         dactyl.echoerr(message);
                 }
@@ -216,7 +216,7 @@ var IO = Module("io", {
                     defineModule.loadLog.push("done sourcing " + filename + ": " + (Date.now() - time) + "ms");
                 }
             }, this);
-        },
+        }
     }),
 
     // TODO: there seems to be no way, short of a new component, to change
@@ -354,7 +354,7 @@ var IO = Module("io", {
      */
     listJar: function listJar(file, path) {
         file = util.getFile(file);
-        if (file) {
+        if (file && file.exists() && file.isFile() && file.isReadable()) {
             // let jar = services.zipReader.getZip(file); Crashes.
             let jar = services.ZipReader(file);
             try {
@@ -366,7 +366,8 @@ var IO = Module("io", {
                         yield entry;
             }
             finally {
-                jar.close();
+                if (jar)
+                    jar.close();
             }
         }
     },
@@ -422,7 +423,7 @@ var IO = Module("io", {
      * Runs an external program.
      *
      * @param {File|string} program The program to run.
-     * @param {string[]} args An array of arguments to pass to *program*.
+     * @param {[string]} args An array of arguments to pass to *program*.
      */
     run: function (program, args, blocking) {
         args = args || [];
@@ -569,7 +570,6 @@ var IO = Module("io", {
 
                 // go directly to an absolute path or look for a relative path
                 // match in 'cdpath'
-                // TODO: handle ../ and ./ paths
                 if (File.isAbsolutePath(arg)) {
                     io.cwd = arg;
                     dactyl.echomsg(io.cwd.path);
@@ -610,7 +610,7 @@ var IO = Module("io", {
                 dactyl.assert(!file.exists() || args.bang, _("io.exists", file.path.quote()));
 
                 // TODO: Use a set/specifiable list here:
-                let lines = [cmd.serialize().map(commands.commandToString, cmd) for (cmd in commands.iterator(true)) if (cmd.serialize)];
+                let lines = [cmd.serialize().map(commands.commandToString, cmd) for (cmd in commands.iterator()) if (cmd.serialize)];
                 lines = array.flatten(lines);
 
                 lines.unshift('"' + config.version + "\n");
@@ -620,8 +620,8 @@ var IO = Module("io", {
                     file.write(lines.join("\n"));
                 }
                 catch (e) {
-                    dactyl.echoerr(_("io.notWriteable"), file.path.quote());
-                    dactyl.log("Could not write to " + file.path + ": " + e.message); // XXX
+                    dactyl.echoerr(_("io.notWriteable", file.path.quote()));
+                    dactyl.log(_("error.notWriteable", file.path, e.message)); // XXX
                 }
             }, {
                 argCount: "*", // FIXME: should be "?" but kludged for proper error message
@@ -639,7 +639,7 @@ var IO = Module("io", {
 
                 if (file.exists() && file.isDirectory() || args[0] && /\/$/.test(args[0]))
                     file.append(config.name + ".vim");
-                dactyl.assert(!file.exists() || args.bang, "File exists");
+                dactyl.assert(!file.exists() || args.bang, _("io.exists"));
 
                 let template = util.compileMacro(<![CDATA[
 " Vim syntax file
@@ -699,22 +699,20 @@ execute 'syn region <name>Css matchgroup=<name>CssDelimiter'
 
 syn match <name>Notation "<[0-9A-Za-z-]\+>"
 
-syn match   <name>Comment +".*$+ contains=<name>Todo,@Spell
 syn keyword <name>Todo FIXME NOTE TODO XXX contained
 
 syn region <name>String start="\z(["']\)" end="\z1" skip="\\\\\|\\\z1" oneline
 
-syn match <name>LineComment +^\s*".*$+ contains=<name>Todo,@Spell
+syn match <name>Comment +^\s*".*$+ contains=<name>Todo,@Spell
 
 " NOTE: match vim.vim highlighting group names
 hi def link <name>AutoCmd               <name>Command
 hi def link <name>AutoEvent             Type
 hi def link <name>Command               Statement
-hi def link <name>Comment               Comment
 hi def link <name>JavaScriptDelimiter   Delimiter
 hi def link <name>CssDelimiter          Delimiter
 hi def link <name>Notation              Special
-hi def link <name>LineComment           Comment
+hi def link <name>Comment               Comment
 hi def link <name>Option                PreProc
 hi def link <name>SetMod                <name>Option
 hi def link <name>String                String
@@ -782,14 +780,18 @@ unlet s:cpo_save
         commands.add(["scrip[tnames]"],
             "List all sourced script names",
             function () {
-                modules.commandline.commandOutput(
-                    template.tabular(["<SNR>", "Filename"], ["text-align: right; padding-right: 1em;"],
-                        ([i + 1, file] for ([i, file] in Iterator(io._scriptNames)))));  // TODO: add colon and remove column titles for pedantic Vim compatibility?
+                if (!io._scriptNames.length)
+                    dactyl.echomsg(_("command.scriptnames.none"));
+                else
+                    modules.commandline.commandOutput(
+                        template.tabular(["<SNR>", "Filename"], ["text-align: right; padding-right: 1em;"],
+                            ([i + 1, file] for ([i, file] in Iterator(io._scriptNames)))));
+
             },
             { argCount: "0" });
 
         commands.add(["so[urce]"],
-            "Read Ex commands from a file",
+            "Read Ex commands, JavaScript or CSS from a file",
             function (args) {
                 if (args.length > 1)
                     dactyl.echoerr(_("io.oneFileAllowed"));
@@ -819,7 +821,7 @@ unlet s:cpo_save
                 if (modules.options["banghist"]) {
                     // replaceable bang and no previous command?
                     dactyl.assert(!/((^|[^\\])(\\\\)*)!/.test(arg) || io._lastRunCommand,
-                        "E34: No previous command");
+                        _("command.run.noPrevious"));
 
                     arg = arg.replace(/(\\)*!/g,
                         function (m) /^\\(\\\\)*!$/.test(m) ? m.replace("\\!", "!") : m.replace("!", io._lastRunCommand)
@@ -830,14 +832,14 @@ unlet s:cpo_save
 
                 let result = io.system(arg);
                 if (result.returnValue != 0)
-                    result.output += "\nshell returned " + result.returnValue;
+                    result.output += "\n" + _("io.shellReturn", result.returnValue);
 
-                modules.commandline.command = "!" + arg;
+                modules.commandline.command = args.commandName.replace("run", "$& ") + arg;
                 modules.commandline.commandOutput(<span highlight="CmdOutput">{result.output}</span>);
 
                 modules.autocommands.trigger("ShellCmdPost", {});
             }, {
-                argCount: "?", // TODO: "1" - probably not worth supporting weird Vim edge cases. The dream is dead. --djk
+                argCount: "?",
                 bang: true,
                 // This is abominably slow.
                 // completer: function (context) completion.shellCommand(context),
@@ -878,6 +880,9 @@ unlet s:cpo_save
         };
 
         completion.file = function file(context, full, dir) {
+            if (/^jar:[^!]*$/.test(context.filter))
+                context.advance(4);
+
             // dir == "" is expanded inside readDirectory to the current dir
             function getDir(str) str.match(/^(?:.*[\/\\])?/)[0];
             dir = getDir(dir || context.filter);
@@ -900,10 +905,8 @@ unlet s:cpo_save
             };
             context.compare = function (a, b) b.isdir - a.isdir || String.localeCompare(a.text, b.text);
 
-            if (modules.options["wildignore"]) {
-                let wig = modules.options.get("wildignore");
-                context.filters.push(function (item) item.isdir || !wig.getKey(this.name));
-            }
+            if (modules.options["wildignore"])
+                context.filters.push(function (item) !modules.options.get("wildignore").getKey(item.path));
 
             // context.background = true;
             context.key = dir;
@@ -977,14 +980,17 @@ unlet s:cpo_save
                     context.key = match.prefix;
                     context.advance(match.prefix.length + 1);
                     context.generate = function () iter({
-                        content: "Chrome content",
-                        locale: "Locale-specific content",
-                        skin: "Theme-specific content"
+                        content: /*L*/"Chrome content",
+                        locale: /*L*/"Locale-specific content",
+                        skin: /*L*/"Theme-specific content"
                     });
                 }
             }
             if (!match || match.scheme === "resource" && match.path)
-                if (/^(\.{0,2}|~)\/|^file:/.test(context.filter) || util.getFile(context.filter) || io.isJarURL(context.filter))
+                if (/^(\.{0,2}|~)\/|^file:/.test(context.filter)
+                    || util.OS.isWindows && /^[a-z]:/i.test(context.filter)
+                    || util.getFile(context.filter)
+                    || io.isJarURL(context.filter))
                     completion.file(context, full);
         });
     },
@@ -1067,7 +1073,7 @@ unlet s:cpo_save
         options["shellcmdflag"];
 
         options.add(["wildignore", "wig"],
-            "List of file patterns to ignore when completing file names",
+            "List of path name patterns to ignore when completing files and directories",
             "regexplist", "");
     }
 });