From 856244723c6c38d7d0942f3fcb35842942351fef Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Fri, 30 Dec 2016 00:43:04 -0500 Subject: [PATCH] prompt: Restore the ability to use hooks without exiting It was in an earlier version of the patchset but was lost at some point. --- lib/awful/prompt.lua | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/awful/prompt.lua b/lib/awful/prompt.lua index 9a86475fd..6fbefc8a1 100644 --- a/lib/awful/prompt.lua +++ b/lib/awful/prompt.lua @@ -485,16 +485,33 @@ function prompt.run(args, textbox, exe_callback, completion_callback, end if match then local cb - local ret = v[3](command) + local ret, quit = v[3](command) local original_command = command - if ret then - command = ret + + -- Support both a "simple" and a "complex" way to + -- control if the prompt should quit. + quit = quit == nil and (ret ~= true) or (quit~=false) + + -- Allow the callback to change the command + command = (ret ~= true) and ret or command + + -- Quit by default, but allow it to be disabled + if ret and type(ret) ~= "boolean" then cb = exe_callback - else + if not quit then + cur_pos = ret:wlen() + 1 + update() + end + elseif quit then -- No callback. cb = function() end end - exec(cb, original_command) + + -- Execute the callback + if cb then + exec(cb, original_command) + end + return end end