[PATCH] add 'autoexec' argument to awful.prompt

2010-10-11 Thread koniu
Hullo,

To celebrate hdd crash and some cleanups, I'd like to push these two
patches that I have lying around.

Basic idea is to have a command execute automatically on completion if
it's the only match. So instead of mod+r firetab enter we can
have mod+r firetab and there's firefox on our screen :)

2nd patch adds support for autoexec in awful.completion by returning
the table of matches from its callback functions. This  could also be
used for displaying a list of available completions (think dmenu).

koniu
From 9e5cad8b3b3a45b4af1d919ef20e166325f0db35 Mon Sep 17 00:00:00 2001
From: koniu gkusni...@gmail.com
Date: Mon, 11 Oct 2010 11:33:38 +0100
Subject: [PATCH 1/2] awful.prompt: add 'autoexec' argument

If set the prompt will execute the command upon completion which returns
only one match.

Signed-off-by: koniu gkusni...@gmail.com
---
 lib/awful/prompt.lua.in |   24 +---
 1 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/lib/awful/prompt.lua.in b/lib/awful/prompt.lua.in
index 2275e6d..a229660 100644
--- a/lib/awful/prompt.lua.in
+++ b/lib/awful/prompt.lua.in
@@ -143,7 +143,7 @@ local function prompt_text_with_cursor(args)
 end
 
 --- Run a prompt in a box.
--- @param args A table with optional arguments: fg_cursor, bg_cursor, ul_cursor, prompt, text, selectall, font.
+-- @param args A table with optional arguments: fg_cursor, bg_cursor, ul_cursor, prompt, text, selectall, font, autoexec.
 -- @param textbox The textbox to use for the prompt.
 -- @param exe_callback The callback function to call with command as argument when finished.
 -- @param completion_callback The callback function to call to get completion.
@@ -178,6 +178,14 @@ function run(args, textbox, exe_callback, completion_callback, history_path, his
 cursor_pos = cur_pos, cursor_ul = cur_ul, selectall = selectall,
 font = font, prompt = prettyprompt }
 
+local exec = function()
+textbox.text = 
+history_add(history_path, command)
+capi.keygrabber.stop()
+exe_callback(command)
+if done_callback then done_callback() end
+end
+
 capi.keygrabber.run(
 function (modifiers, key, event)
 if event ~= press then return true end
@@ -193,11 +201,7 @@ function run(args, textbox, exe_callback, completion_callback, history_path, his
 elseif (mod.Control and (key == j or key == m))
 or (not mod.Control and key == Return)
 or (not mod.Control and key == KP_Enter) then
-textbox.text = 
-history_add(history_path, command)
-capi.keygrabber.stop()
-exe_callback(command)
-if done_callback then done_callback() end
+exec()
 -- We already unregistered ourselves so we don't want to return
 -- true, otherwise we may unregister someone else.
 return true
@@ -269,9 +273,15 @@ function run(args, textbox, exe_callback, completion_callback, history_path, his
 command_before_comp = command
 cur_pos_before_comp = cur_pos
 end
-command, cur_pos = completion_callback(command_before_comp, cur_pos_before_comp, ncomp)
+local matches
+command, cur_pos, matches = completion_callback(command_before_comp, cur_pos_before_comp, ncomp)
 ncomp = ncomp + 1
 key = 
+-- execute if only one match found and autoexec flag set
+if matches and #matches == 1 and args.autoexec then
+exec()
+return true
+end
 else
 ncomp = 1
 end
-- 
1.7.1

From 32bc9356126a334ee7eff3d8a2a5774e8a366956 Mon Sep 17 00:00:00 2001
From: koniu gkusni...@gmail.com
Date: Mon, 11 Oct 2010 11:34:58 +0100
Subject: [PATCH 2/2] awful.completion: callback functions return table of matches

Signed-off-by: koniu gkusni...@gmail.com
---
 lib/awful/completion.lua.in |   10 +-
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/awful/completion.lua.in b/lib/awful/completion.lua.in
index db0391d..e964b53 100644
--- a/lib/awful/completion.lua.in
+++ b/lib/awful/completion.lua.in
@@ -56,7 +56,7 @@ end
 -- @param cur_pos The cursor position.
 -- @param ncomp The element number to complete.
 -- @param shell The shell to use for completion (bash (default) or zsh).
--- @return The new command and the new cursor position.
+-- @return The new command, the new cursor position, the table of all matches.
 function shell(command, cur_pos, ncomp, shell)
 local wstart = 1
 local wend = 1
@@ -146,7 +146,7 @@ function shell(command, cur_pos, ncomp, shell)
 local str = command:sub(1, cword_start - 1) .. output[ncomp] .. command:sub(cword_end)
 cur_pos = cword_end + #output[ncomp] + 1
 
-return str, cur_pos
+return str, cur_pos, 

Re: [PATCH] add 'autoexec' argument to awful.prompt

2010-10-11 Thread Uli Schlachter
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Am 11.10.2010 12:45, koniu wrote:
 Hullo,
 
 To celebrate hdd crash and some cleanups, I'd like to push these two
 patches that I have lying around.

Wait, what? That doesn't sound good.

 Basic idea is to have a command execute automatically on completion if
 it's the only match. So instead of mod+r firetab enter we can
 have mod+r firetab and there's firefox on our screen :)
 
 2nd patch adds support for autoexec in awful.completion by returning
 the table of matches from its callback functions. This  could also be
 used for displaying a list of available completions (think dmenu).

Thanks for the patches.
Second patch applies fine, but git doesn't like the first patch at all. Seems
like they are against the 3.4 branch. I'll try to fix them up later if I find
the time.

Cheers,
Uli
- -- 
- - Buck, when, exactly, did you lose your mind?
- - Three months ago. I woke up one morning married to a pineapple.
  An ugly pineapple... But I loved her
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)

iQEcBAEBCAAGBQJMsu7KAAoJECLkKOvLj8sGKtQIAJkgVFYgjIxBK9EXZ7zKQaNE
iBcI1yRBxACXrw0LeftBfwfC+DLFQNpy/XQU9/r8i9A6Y3fGNZac9zxp+KTOdtEL
/3cSCbOtxgWmbbFwHjLkKdxATTXgrOnXVYViv8QQpXeYIQavFMA2Lrog+xiU2iAq
kWrVuk1dyJrCIeaoW1ukiCTIA3Lwuduq5d+g+Fhre/q6Nt0Zao5oQzOcr45IN3AU
7EkRj+ElSHHgjm3UGuEe6wTYn7Zrrm2bTmXhaZrIWOa+kqvM017hfKzqleRncPsK
6KrxV26rra4kVKIwT45ec+SBgXJ2auRKA25JigDhIIgMoadP+lg77GrYosajz1o=
=3DXD
-END PGP SIGNATURE-

-- 
To unsubscribe, send mail to awesome-devel-unsubscr...@naquadah.org.


Re: [PATCH] add 'autoexec' argument to awful.prompt

2010-10-11 Thread Uli Schlachter
Am 11.10.2010 12:45, koniu wrote:
 Hullo,
 
 To celebrate hdd crash and some cleanups, I'd like to push these two
 patches that I have lying around.
 
 Basic idea is to have a command execute automatically on completion if
 it's the only match. So instead of mod+r firetab enter we can
 have mod+r firetab and there's firefox on our screen :)
 
 2nd patch adds support for autoexec in awful.completion by returning
 the table of matches from its callback functions. This  could also be
 used for displaying a list of available completions (think dmenu).

Thanks, pushed.

-- 
- Buck, when, exactly, did you lose your mind?
- Three months ago. I woke up one morning married to a pineapple.
  An ugly pineapple... But I loved her

-- 
To unsubscribe, send mail to awesome-devel-unsubscr...@naquadah.org.