Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)

Wed, 01 Sep 2010 03:59:23 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 01 Sep 2010 03:59:23 +0100
changeset 1
4d7540af8518
parent 0
98e4b0c9fcac
child 2
1e9553b2f9a2

Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)

binds.lua file | annotate | diff | comparison | revisions
globals.lua file | annotate | diff | comparison | revisions
modes.lua file | annotate | diff | comparison | revisions
webview.lua file | annotate | diff | comparison | revisions
window.lua file | annotate | diff | comparison | revisions
--- a/binds.lua	Wed Sep 01 03:53:30 2010 +0100
+++ b/binds.lua	Wed Sep 01 03:59:23 2010 +0100
@@ -10,7 +10,7 @@
 -- Globals or defaults that are used in binds
 local scroll_step = globals.scroll_step or 20
 local zoom_step   = globals.zoom_step or 0.1
-local homepage    = globals.homepage or "http://luakit.org"
+local homepage    = globals.homepage or "http://google.co.uk/"
 
 -- Add key bindings to be used across all windows in the given modes.
 binds.mode_binds = {
@@ -18,101 +18,58 @@
      -- key({Modifiers}, Key name,      function (w, opts)         .. end, opts),
      -- but({Modifiers}, Button num,    function (w, opts)         .. end, opts),
     all = {
-        key({},          "Escape",      function (w) w:set_mode() end),
-        key({"Control"}, "[",           function (w) w:set_mode() end),
+        key({},          "Escape",      function (w) w:set_mode("normal") end),
+        key({"Control"}, "e",           function (w) w:set_mode("command") end),
+        key({"Control"}, "n",           function (w) w:set_mode("normal") end),
+        
+        key({"Control"}, "x",           function (w) w:close_tab() end),
 
-        but({},          8,             function (w) w:back()    end),
-        but({},          9,             function (w) w:forward() end),
-    },
-    normal = {
-        key({},          "i",           function (w) w:set_mode("insert")  end),
-        key({},          ":",           function (w) w:set_mode("command") end),
+        key({"Control"}, "c",           function (w) if w:get_mode() ~= "normal" then w:set_mode("normal"); end end),
+
+	-- Location
+        key({"Control"}, "t",           function (w) w:new_tab(homepage); end),
 
-        -- Scrolling
-        key({},          "j",           function (w) w:scroll_vert("+"..scroll_step.."px") end),
-        key({},          "k",           function (w) w:scroll_vert("-"..scroll_step.."px") end),
-        key({},          "h",           function (w) w:scroll_horiz("-"..scroll_step.."px") end),
-        key({},          "l",           function (w) w:scroll_horiz("+"..scroll_step.."px") end),
-        key({"Control"}, "d",           function (w) w:scroll_page(0.5)    end),
-        key({"Control"}, "u",           function (w) w:scroll_page(-0.5)   end),
-        key({"Control"}, "f",           function (w) w:scroll_page(1.0)    end),
-        key({"Control"}, "b",           function (w) w:scroll_page(-1.0)   end),
-        buf("^gg$",                     function (w) w:scroll_vert("0%")   end),
-        buf("^G$",                      function (w) w:scroll_vert("100%") end),
-        buf("^[\-\+]?[0-9]+[%%G]$",     function (w, b) w:scroll_vert(string.match(b, "^([\-\+]?%d+)[%%G]$") .. "%") end),
+	-- Location
+        key({"Control"}, "l",           function (w) w:set_mode("url-entry"); end),
+        
+        -- Web search
+        key({"Control"}, "k",           function (w) w:enter_cmd(":websearch google ") end);
+        
+        -- Back and forth
+	key({"Mod1"},    "Left",        function (w) w:back()    end);
+	key({"Mod1"},    "Right",       function (w) w:forward()    end);
+	
+	-- Tab/buffer switching
+	key({"Mod1"},    ".",           function (w) w:next_tab(1)    end);
+	key({"Mod1"},    ",",           function (w) w:prev_tab(1)    end);
+        key({"Control"}, "Page_Up",     function (w) w:prev_tab() end),
+        key({"Control"}, "Page_Down",   function (w) w:next_tab() end),
+	
+        key({"Control"}, "p",           function (w) w:navigate(luakit.get_selection("c")) end),
+        key({"Control"}, "P",           function (w) w:new_tab(luakit.get_selection("c"))  end),
+        key({"Control"}, "y",           function (w) luakit.set_selection((w:get_current() or {}).uri or "", "c") end),
+        key({"Control"}, "Y",           function (w) luakit.set_selection(w.win.title, "c") end),
 
-        -- Traditional scrolling commands
-        key({},          "Down",        function (w) w:scroll_vert("+"..scroll_step.."px") end),
-        key({},          "Up",          function (w) w:scroll_vert("-"..scroll_step.."px") end),
-        key({},          "Left",        function (w) w:scroll_horiz("-"..scroll_step.."px") end),
-        key({},          "Right",       function (w) w:scroll_horiz("+"..scroll_step.."px") end),
-        key({},          "Page_Down",   function (w) w:scroll_page(1.0)    end),
-        key({},          "Page_Up",     function (w) w:scroll_page(-1.0)   end),
-        key({},          "Home",        function (w) w:scroll_vert("0%")   end),
-        key({},          "End",         function (w) w:scroll_vert("100%") end),
+        key({"Control"}, "r",           function (w) w:reload() end),
 
-        -- Zooming
-        buf("^z0$",                     function (w) w:zoom_reset()        end),
-        buf("^zI$",                     function (w) w:zoom_in(zoom_step)  end),
-        buf("^zO$",                     function (w) w:zoom_out(zoom_step) end),
+	key({"Mod1"},    "Home",        function (w) w:navigate(homepage)  end);
+
         key({"Control"}, "+",           function (w) w:zoom_in(zoom_step)  end),
         key({"Control"}, "-",           function (w) w:zoom_out(zoom_step) end),
 
-        -- Clipboard
-        key({},          "p",           function (w) w:navigate(luakit.get_selection()) end),
-        key({},          "P",           function (w) w:new_tab(luakit.get_selection())  end),
-        buf("^yy$",                     function (w) luakit.set_selection((w:get_current() or {}).uri or "") end),
-        buf("^yt$",                     function (w) luakit.set_selection(w.win.title) end),
-
-        -- Commands
-        buf("^o$",                      function (w, c) w:enter_cmd(":open ")    end),
-        buf("^t$",                      function (w, c) w:enter_cmd(":tabopen ") end),
-        buf("^w$",                      function (w, c) w:enter_cmd(":winopen ") end),
-        buf("^O$",                      function (w, c) w:enter_cmd(":open "    .. ((w:get_current() or {}).uri or "")) end),
-        buf("^T$",                      function (w, c) w:enter_cmd(":tabopen " .. ((w:get_current() or {}).uri or "")) end),
-        buf("^W$",                      function (w, c) w:enter_cmd(":winopen " .. ((w:get_current() or {}).uri or "")) end),
-        buf("^,g$",                     function (w, c) w:enter_cmd(":websearch google ") end),
+        but({},          8,             function (w) w:back()    end),
+        but({},          9,             function (w) w:forward() end),
 
-        -- Debian search shorcut access
-        buf("^\\dbug$",                function (w, c) w:enter_cmd(":websearch debbugs ") end),
-        buf("^\\dpts$",                function (w, c) w:enter_cmd(":websearch dpts ") end),
-        buf("^\\dpkg$",                function (w, c) w:enter_cmd(":websearch dpkg ") end),
-
-        -- Searching
-        key({},          "/",           function (w) w:start_search("/")  end),
-        key({},          "?",           function (w) w:start_search("?") end),
-        key({},          "n",           function (w) w:search(nil, true) end),
-        key({},          "N",           function (w) w:search(nil, false) end),
-
-        -- History
-        buf("^[0-9]*H$",                function (w, b) w:back   (tonumber(string.match(b, "^(%d*)H$") or 1)) end),
-        buf("^[0-9]*L$",                function (w, b) w:forward(tonumber(string.match(b, "^(%d*)L$") or 1)) end),
-        key({},          "b",           function (w) w:back() end),
         key({},          "XF86Back",    function (w) w:back() end),
         key({},          "XF86Forward", function (w) w:forward() end),
-
-        -- Tab
-        key({"Control"}, "Page_Up",     function (w) w:prev_tab() end),
-        key({"Control"}, "Page_Down",   function (w) w:next_tab() end),
-        buf("^[0-9]*gT$",               function (w, b) w:prev_tab(tonumber(string.match(b, "^(%d*)gT$") or 1)) end),
-        buf("^[0-9]*gt$",               function (w, b) w:next_tab(tonumber(string.match(b, "^(%d*)gt$") or 1)) end),
-        buf("^gH$",                     function (w)    w:new_tab(homepage) end),
-        buf("^d$",                      function (w)    w:close_tab() end),
-
-        key({},          "r",           function (w) w:reload() end),
-        buf("^gh$",                     function (w) w:navigate(homepage) end),
-
-        -- Window
-        buf("^ZZ$",                     function (w) w:close_win() end),
-        buf("^D$",                      function (w) w:close_win() end),
-
+        
         -- Link following
-        key({},          "f",           function (w) w:set_mode("follow") end),
+        key({"Mod1"},    "f",           function (w) w:set_mode("follow") end),
 
         -- Bookmarking
-        key({},          "B",           function (w) w:enter_cmd(":bookmark " .. ((w:get_current() or {}).uri or "http://") .. " ") end),
-        buf("^gb$",                     function (w) w:navigate(bookmarks.dump_html()) end),
-        buf("^gB$",                     function (w) w:new_tab (bookmarks.dump_html()) end),
+        key({"Control"}, "d",           function (w) end),
+        key({"Control"}, "b",           function (w) w:navigate(bookmarks.dump_html()) end),
+        key({"Control"}, "B",           function (w) w:new_tab(bookmarks.dump_html()) end),
 
         -- Mouse bindings
         but({},          2,             function (w)
@@ -125,6 +82,10 @@
                                             end
                                         end),
     },
+    
+    normal = {
+    },
+    
     command = {
         key({"Shift"},   "Insert",      function (w) w:insert_cmd(luakit.get_selection()) end),
         key({},          "Up",          function (w) w:cmd_hist_prev() end),
@@ -137,6 +98,9 @@
         key({},          "Up",          function (w) w:srch_hist_prev() end),
         key({},          "Down",        function (w) w:srch_hist_next() end),
     },
+    ["url-entry"] = {
+        key({"Control"}, "l",          function (w) w.ibar.input:set_position(-1); end),
+    },
     insert = { },
 }
 
--- a/globals.lua	Wed Sep 01 03:53:30 2010 +0100
+++ b/globals.lua	Wed Sep 01 03:59:23 2010 +0100
@@ -1,13 +1,12 @@
 -- Global variables for luakit
 globals = {
-    homepage         = "http://luakit.org/",
- -- homepage         = "http://github.com/mason-larobina/luakit",
+    homepage         = "http://google.co.uk/",
     scroll_step      = 20,
     zoom_step        = 0.1,
     max_cmd_history  = 100,
     max_srch_history = 100,
  -- http_proxy       = "http://example.com:3128",
-    download_dir     = luakit.get_special_dir("DOWNLOAD") or (os.getenv("HOME") .. "/downloads"),
+    download_dir     = luakit.get_special_dir("DOWNLOAD") or (os.getenv("HOME") .. "/Downloads"),
 }
 
 -- Make useragent
--- a/modes.lua	Wed Sep 01 03:53:30 2010 +0100
+++ b/modes.lua	Wed Sep 01 03:59:23 2010 +0100
@@ -60,7 +60,7 @@
 }) do window.methods[name] = func end
 
 -- Setup normal mode
-new_mode("normal", {
+new_mode("key", {
     enter = function (w)
         local i, p = w.ibar.input, w.ibar.prompt
         i:hide()
@@ -69,16 +69,48 @@
 })
 
 -- Setup insert mode
-new_mode("insert", {
+new_mode("normal", {
     enter = function (w)
         local i, p = w.ibar.input, w.ibar.prompt
-        i:hide()
+        i:hide();
         i.text = ""
-        p.text = "-- INSERT --"
-        p:show()
+        p:hide();
+        p.text = ""
     end,
 })
 
+new_mode("url-entry", {
+	enter = function (w)
+		local i, p = w.ibar.input, w.ibar.prompt;
+		p.text = "Open:";
+		p:show();
+		i.text = (w:get_current() or {}).uri or "";
+		i:show();
+		i:focus();
+		i:select_region(0);
+	end;
+	activate = function (w, url)
+		w:navigate(url);
+		w:set_mode();
+	end;
+});
+
+new_mode("web-search", {
+	enter = function (w)
+		local i, p = w.ibar.input, w.ibar.prompt;
+		p.text = "Open:";
+		p:show();
+		i.text = (w:get_current() or {}).uri or "";
+		i:show();
+		i:focus();
+		i:set_position(-1);
+	end;
+	activate = function (w, url)
+		w:navigate(url);
+		w:set_mode();
+	end;
+});
+
 -- Setup command mode
 new_mode("command", {
     enter = function (w)
--- a/webview.lua	Wed Sep 01 03:53:30 2010 +0100
+++ b/webview.lua	Wed Sep 01 03:59:23 2010 +0100
@@ -85,7 +85,7 @@
     form_insert_mode = function (view, w)
         view:add_signal("form-active", function ()
             (w.search_state or {}).marker = nil
-            w:set_mode("insert")
+            w:set_mode("normal")
         end)
         view:add_signal("root-active", function ()
             (w.search_state or {}).marker = nil
@@ -96,7 +96,7 @@
     -- Stop key events hitting the webview if the user isn't in insert mode
     mode_key_filter = function (view, w)
         view:add_signal("key-press", function ()
-            if not w:is_mode("insert") then return true end
+            if not w:is_mode("normal") then return true end
         end)
     end,
 
--- a/window.lua	Wed Sep 01 03:53:30 2010 +0100
+++ b/window.lua	Wed Sep 01 03:59:23 2010 +0100
@@ -212,7 +212,7 @@
 
     -- Wrapper around the bind plugin's hit method
     hit = function (w, mods, key)
-        local caught, newbuf = lousy.bind.hit(w.binds or {}, mods, key, w.buffer, w:is_mode("normal"), w)
+        local caught, newbuf = lousy.bind.hit(w.binds or {}, mods, key, w.buffer, false, w)
         if w.win then
             w.buffer = newbuf
             w:update_buf()

mercurial