diff --git a/NEWS b/NEWS index de02edee..f5e7952c 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ 2007-xx-xx: * version 0.6 * THIS VERSION ONLY WORKS WITH FIREFOX 3.0 + * added new :mkvimperatorc command * you can edit textfields with Ctrl-i now using an external editor (thanks to Joseph Xu) * :open, :bmarks, etc. filter on space separated tokens now, so you can search with :open linux windows <tab> all your bookmarks/history diff --git a/content/commands.js b/content/commands.js index caa4b8d7..8c3ca87e 100644 --- a/content/commands.js +++ b/content/commands.js @@ -1200,6 +1200,57 @@ function Commands() //{{{ help: "If [arg] is specified then limit the list to those marks mentioned." } )); + addDefaultCommand(new Command(["mkv[imperatorrc]"], + function(args, special) + { + var filename; + + // TODO: "E172: Only one file name allowed" + if (args) + filename = args; + else + filename = vimperator.io.expandPath(navigator.platform == "Win32" ? "~/_vimperatorrc" : "~/.vimperatorrc"); + + var file = vimperator.io.getFile(filename); + if (file.exists() && !special) + { + vimperator.echoerr("E189: \".vimperatorrc\" exists (add ! to override)"); + return + } + + var line = "\" " + vimperator.version + "\n"; + + // TODO: write user maps for all modes when we have mode dependant map support + for (var map in vimperator.mappings.getUserIterator(vimperator.modes.NORMAL)) + { + for (var i = 0; i < map.names.length; i++) + line += "map " + map.names[i] + " " + map.rhs + "\n"; + } + + for (var option in vimperator.options) + { + // TODO: options should be queried for this info + if (!/fullscreen|usermode/.test(option.name) && option.value != option.default_value) + { + if (option.type == "boolean") + line += "set " + (option.value ? option.name : "no" + option.name) + "\n"; + else + line += "set " + option.name + "=" + option.value + "\n"; + } + } + + line += "\" vim: set ft=vimperator:"; + + vimperator.io.writeFile(file, line); + }, + { + usage: ["mkv[imperatorrc] [file]"], + short_help: "Write current keymappings and changed options to [file]", + help: "If no [file] is specified then ~/.vimperatorrc is written unless this file already exists. " + + "The special version will overwrite [file] if it exists.
" + + "WARNING: this differs from Vim's behaviour which defaults to writing the file in the current directory." + } + )); addDefaultCommand(new Command(["noh[lsearch]"], function(args) { diff --git a/content/mappings.js b/content/mappings.js index 07cbd319..baa36ff5 100644 --- a/content/mappings.js +++ b/content/mappings.js @@ -160,9 +160,9 @@ function Mappings() //{{{ } } - function mappingsIterator(mode) + function mappingsIterator(mode, stack) { - var mappings = main[mode]; + var mappings = stack[mode]; //// FIXME: do we want to document user commands by default? //mappings = user[mode].concat(main[mode]); @@ -186,12 +186,19 @@ function Mappings() //{{{ // NOTE: just normal mode for now this.__iterator__ = function() { - return mappingsIterator(vimperator.modes.NORMAL); + return mappingsIterator(vimperator.modes.NORMAL, main); } + // FIXME this.getIterator = function(mode) { - return mappingsIterator(mode); + return mappingsIterator(mode, main); + } + + // FIXME + this.getUserIterator = function(mode) + { + return mappingsIterator(mode, user); } this.hasMap = function(mode, cmd)