From 16614c637bdfa92db9240dec62c60fc4b0560d4c Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Mon, 22 Oct 2007 03:13:33 +0000 Subject: [PATCH] add new :mkvimperatorrc command --- NEWS | 3 ++- content/commands.js | 51 +++++++++++++++++++++++++++++++++++++++++++++ content/mappings.js | 15 +++++++++---- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 8ad8eba9..4db4ae28 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@
 2007-XX-XX:
 	* version 0.5.3
+	* added new :mkvimperatorc command
 	* remove :redraw and Ctrl-L commands as they rely on FF3 features
 	* :ls, :history and :bmarks output is now hyperlinked
 	* new gb and gB mappings to repeat the last :buffer[!] command,
@@ -33,7 +34,7 @@
 	* added 'visualbellstyle' for styling/hiding the visual bell
 	* merge the existing status bar with the standard FF status bar so that
 	  security information and extension buttons are included
-  	* :buffer partial_string works now as in vim, and with ! even better
+	* :buffer partial_string works now as in vim, and with ! even better
 	* new :time command for profiling
 	* added new :sidebar and :sbclose commands
 	* added 'more' and standard more-prompt key mappings to control
diff --git a/content/commands.js b/content/commands.js
index 0fd7c8d3..e6b2f7ab 100644
--- a/content/commands.js
+++ b/content/commands.js
@@ -883,6 +883,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 90368d80..dabb58de 100644 --- a/content/mappings.js +++ b/content/mappings.js @@ -156,9 +156,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]); @@ -182,12 +182,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)