From d18cc76091dfc69c2ed4edc7b853f24c559e24da Mon Sep 17 00:00:00 2001 From: nberth Date: Tue, 7 Jun 2011 14:50:25 +0200 Subject: [PATCH] Improved custom links module, and updated configuration accordingly --- links.lua | 176 ++++++++++++++++++++++---------------------------------------- rc.lua | 85 +++++++++++++++--------------- 2 files changed, 103 insertions(+), 158 deletions(-) diff --git a/links.lua b/links.lua index 400c10b..a5cd67c 100644 --- a/links.lua +++ b/links.lua @@ -5,6 +5,7 @@ require ("naughty") local spawn = awful.util.spawn local gsub = string.gsub local match = string.match +local prompt = awful.prompt.run -- `mypromptbox' should be defined. @@ -29,147 +30,92 @@ local function url_encode (str) return str end --- }}} - --- {{{ Hack for some publishing site at verimag... +local function prmpt (prompt_text, cache, fun) + return + function (from_selection) + if from_selection then + local str = selection () + if str == "" then + naughty.notify ({ text = "Need a selection!" }) + else + fun (str) + end + else + prompt ({ prompt = prompt_text }, mypromptbox[mouse.screen].widget, + fun, nil, cache) + end + end +end local xbrowser="firefox" +local term_browser="w3m" -function query_open_gate6_link (from_selection) - - local function append_to_hostname (httphostname, to_append) - return gsub (httphostname, - "([^/]*://[^/]+)(.*)", "%1"..to_append.."%2") - end - - -- Basic check: we have an adress: - local function is_an_address (str) - return match (str, "^[^/]*://[^/]+.*$") - end +-- }}} - local function openit (address) +-- {{{ Hack for some publishing site at verimag... - if not is_an_address (address) then - naughty.notify ({ text = "Needs a valid URI!" }) - return false - end +-- Basic check: we have an adress: +local function is_an_uri (str) return match (str, "^[^/]*://[^/]+.*$") end - local command = xbrowser.." \"".. - append_to_hostname (address, ".gate6.inist.fr").. - "\"" - naughty.notify ({ text = command }) - spawn (command) +local function open_gate6_link (uri) + local function append_host (hostname, to_append) + return gsub (hostname, "([^/]*://[^/]+)(.*)", "%1"..to_append.."%2") end - if from_selection then - local str = selection () - if str == "" then - naughty.notify ({ text = "Needs a selection!" }) - else - openit (str) - end - else - awful.prompt.run ({ prompt = "Address: " }, - mypromptbox[mouse.screen].widget, - openit) + if not is_an_uri (uri) then + naughty.notify ({ text = "Need a valid URI!" }) + return false end + local cmd = xbrowser.." \""..append_host (uri, ".gate6.inist.fr").."\"" + naughty.notify ({ text = cmd }) + spawn (cmd) end +query_open_gate6_link = + prmpt ("Address: ", nil, open_gate6_link) + -- }}} --{{{ Translations and language tools... ---local term_browser="w3m -o use_mouse=true -o anchor_color=cyan -o bg_color=black" -local term_browser="w3m" ---local term_browser="links" - function find_translation (langs, from_selection) - local function launch_wrlinks (string) - open_in_term (term_browser.. - " \"http://www.wordreference.com/".. - langs.."/"..string.."\"") - end + prmpt ("Word: ", + awful.util.getdir ("cache").."/history_transl_"..langs, + function (string) + open_in_term (term_browser.." \"http://www.wordreference.com/".. + langs.."/"..string.."\"") + end) (from_selection) - if from_selection then - local str = selection () - if str == "" then - naughty.notify ({ text = "Needs a selection!" }) - else - launch_wrlinks (str) - end - else - awful.prompt.run ({ prompt = "Word: " }, - mypromptbox[mouse.screen].widget, - launch_wrlinks, nil, - awful.util.getdir ("cache") .. - "/history_transl_"..langs) - end end --- This does not really work since -function find_conj (lang, from_selection) - - local function openit (string) - if lang == "fr" then - open_in_term (term_browser.. - " \"http://leconjugueur.com/php5/index.php?v=".. - url_encode (string).."\"") - -- else - -- open_in_term (mplex, term_browser.." -I iso-8859-1 ".. - -- "\"http://dico.isc.cnrs.fr/dico/en/search?b=1&send=Look+it+up&r=".. - -- url_encode (string).."\"") - end - end +find_fr_conj = + prmpt ("Verb: ", + awful.util.getdir ("cache").."/history_conj_fr", + function (string) + open_in_term (term_browser.. + " \"http://leconjugueur.com/php5/index.php?v=".. + url_encode (string).."\"") + end) - if from_selection then - local str = selection () - if str == "" then - naughty.notify ({ text = "Needs a selection!" }) - else - openit (str) - end +function find_synonym (lang, from_selection) + local req + if lang == "fr" then + req = "fr/search?r=" else - awful.prompt.run ({ prompt = "Verb: " }, - mypromptbox[mouse.screen].widget, - openit, nil, - awful.util.getdir ("cache") .. - "/history_conj_"..lang) + req = "en/search?b=1&r=" end -end - -function find_synonym (lang, from_selection) - local function openit (string) - local req - if lang == "fr" then - req = "fr/search?r=" - else - req = "en/search?b=1&r=" - end - open_in_term (term_browser.. - " -I iso-8859-1 \"http://dico.isc.cnrs.fr/dico/".. - req.. url_encode (string).. - --"&send=Look+it+up".. - "\"") - end + -- XXX: Note I have a huge problem with accents in prompts... + prmpt ("Word: ", + awful.util.getdir ("cache").."/history_synonym_"..lang, + function (string) + open_in_term (term_browser.. + " -I iso-8859-1 \"http://dico.isc.cnrs.fr/dico/"..req.. + url_encode (string).. "\"") + end) (from_selection) - if from_selection then - local str = selection () - if str == "" then - naughty.notify ({ text = "Needs a selection!" }) - else - openit (str) - end - else - -- XXX: Note I have a huge problem with accents in prompts... - awful.prompt.run ({ prompt = "Word: " }, - mypromptbox[mouse.screen].widget, - openit, nil, - awful.util.getdir ("cache") .. - "/history_synonym_"..lang) - end end --}}} diff --git a/rc.lua b/rc.lua index c28dd82..9d7dbea 100644 --- a/rc.lua +++ b/rc.lua @@ -50,10 +50,6 @@ EMMS_SEEK_FORWARD = "emacsclient -e '(emms-seek-forward)'" EMMS_VOLUME_RAISE = "emacsclient -e '(emms-volume-raise)'" EMMS_VOLUME_LOWER = "emacsclient -e '(emms-volume-lower)'" -terminal = XTERM --- editor = os.getenv ("EDITOR") or "nano" --- editor_cmd = terminal.." -e "..editor - TERM_GEOMETRY="180x60+20+20" -- Keyboard mapping configuration shortcuts @@ -72,7 +68,7 @@ SOUND_MIXER = XTERM.." -e alsamixer" -- --- -- Default modkey. Usually, Mod4 is the key with a logo between Control and --- Alt. If you do not like this or do not have such a key, I suggest you to +-- Alt. If you do not like this or do not have such a key, I suggest you to -- remap Mod4 to another key using xmodmap or other tools. However, you can use -- another modifier like Mod1, but it may interact with others. modkey = "Mod4" @@ -133,7 +129,7 @@ shifty.init () -- XXX: Note this menu is not displayed properly, but as I never use it, I did -- not try to fix that problem... myawesomemenu = { - { "manual", terminal .. " -e man awesome" }, + { "manual", XTERM .. " -e man awesome" }, { "restart", awesome.restart }, { "quit", awesome.quit }, } @@ -141,7 +137,7 @@ myawesomemenu = { mymenuitems = { { "awesome", myawesomemenu, beautiful.awesome_icon }, { "debian", menu.debian_menu }, - { "open terminal", terminal }, + { "open terminal", XTERM }, } mymainmenu = amenu ({ items = mymenuitems }) @@ -257,16 +253,11 @@ for s = 1, screen.count () do mytasklist.buttons) -- Actually create the wibox - mywibox[s] = awful.wibox ({ - position = "top", - screen = s, - height = 14, - }) + mywibox[s] = awful.wibox ({ position = "top", screen = s, height = 14, }) -- Add widgets to the wibox --- note order matters here mywibox[s].widgets = { { -- the content of this table is aligned to the left.. - -- mylauncher, mytaglist[s], mypromptbox[s], -- ... and goes left-right: layout = awful.widget.layout.horizontal.leftright @@ -306,11 +297,11 @@ root.buttons (rootbuttons) keychain.init ({ -- configutation table content should go here: default values - -- I chose are here (@see keychain.init documentation for - -- further details): + -- I chose are repeated here (@see keychain.init documentation + -- for further details): escapes = { - keychain.keystroke ( { }, "Escape" ), - keychain.keystroke ( { modkey }, "g" ), -- <- "emacs-like" + keychain.keystroke ( { }, "Escape" ), + keychain.keystroke ( { mk, }, "g" ), -- <- "emacs-like" }, -- enable infolines, appearing 2 seconds after the typing of -- the first prefix keys. @@ -342,13 +333,10 @@ local function man_prompt () local function man (page) -- Use GNU Emacs for manual page display spawn ("emacsclient --eval '(manual-entry \"'" .. page .. "'\")'", false) - -- Use the KDE Help Center for manual page display - -- spawn ("khelpcenter man:" .. page, false) - -- Use the terminal emulator for manual page display - -- spawn ("urxvt -e man " .. page, false) end - awful.prompt.run ({ prompt = "Manual: " }, mypromptbox[mouse.screen].widget, + awful.prompt.run ({ prompt = "Manual: " }, + mypromptbox[mouse.screen].widget, man) end @@ -372,19 +360,30 @@ local function switch_focus () end local function focus_byidx (i) - awful.client.focus.byidx (i) - if client.focus then - client.focus:raise () - mouse_to_client (client.focus) + return + function () + awful.client.focus.byidx (i) + if client.focus then + client.focus:raise () + mouse_to_client (client.focus) + end end end +local function swap_byidx (i) + return function (c) awful.client.swap.byidx (i) end +end + +local function focus_relative (i) + return function () awful.screen.focus_relative (i) end +end + --}}} --{{{ Misc. local function new_tag (nopopup) - shifty.add ({ rel_index = 1, nopopup = nopopup }) + return function () shifty.add ({ rel_index = 1, nopopup = nopopup }) end end local function spn (cmd) @@ -409,7 +408,7 @@ local function cli_raise (c) client.focus = c; c:raise () end --}}} ---{{{ Custom part of the configuration goes in another file... +--{{{ Part of the configuration that is related to quick link accesses require ("links") @@ -461,16 +460,16 @@ globalkeys = ksub ({ }, "s", function () find_synonym ("en", false) end), ksub ({ mk, }, "s", function () find_synonym ("en", true) end), }), - + bind ({ mk, }, "f", { ksub ({ }, "e", function () find_translation ("fren", false) end), ksub ({ mk, }, "e", function () find_translation ("fren", true) end), ksub ({ }, "s", function () find_synonym ("fr", false) end), ksub ({ mk, }, "s", function () find_synonym ("fr", true) end), - ksub ({ }, "c", function () find_conj ("fr", false) end), - ksub ({ mk, }, "c", function () find_conj ("fr", true) end), + ksub ({ }, "c", function () find_fr_conj (false) end), + ksub ({ mk, }, "c", function () find_fr_conj (true) end), }), - + -- Keymaps bind ({ mk, }, "k", { ksub ({ mk, }, "a", setup_advanced_keymap ), @@ -478,7 +477,7 @@ globalkeys = ksub ({ mk, }, "d", setup_default_keymap ), ksub ({ }, "d", setup_default_keymap ), }), - + -- Custom link manipulation... bind ({ mk, }, "o", function () query_open_gate6_link (true) end), bind ({ mk, ak, }, "o", function () query_open_gate6_link (false) end), @@ -507,19 +506,19 @@ globalkeys = bind ({ mk, sk, }, "Left", shifty.shift_prev ), bind ({ mk, sk, }, "Right", shifty.shift_next ), bind ({ mk, }, "t", { - ksub ({ }, "n", function () new_tag (false) end), - ksub ({ mk, }, "n", function () new_tag (true) end), + ksub ({ }, "n", new_tag (false) ), + ksub ({ mk, }, "n", new_tag (true) ), ksub ({ }, "k", shifty.del ), ksub ({ }, "r", shifty.rename ), }), -- Layout manipulation: - bind ({ mk, sk, }, ",", function () awful.client.swap.byidx (-1) end), - bind ({ mk, sk, }, ".", function () awful.client.swap.byidx ( 1) end), - bind ({ mk, ck, }, "j", function () awful.screen.focus_relative ( 1) end), - bind ({ mk, ck, }, "k", function () awful.screen.focus_relative (-1) end), - bind ({ mk, }, "Tab", function () focus_byidx ( 1) end ), - bind ({ mk, sk, }, "Tab", function () focus_byidx (-1) end ), + bind ({ mk, sk, }, ",", swap_byidx (-1) ), + bind ({ mk, sk, }, ".", swap_byidx ( 1) ), + bind ({ mk, ck, }, "j", focus_relative ( 1) ), + bind ({ mk, ck, }, "k", focus_relative (-1) ), + bind ({ mk, }, "Tab", focus_byidx ( 1) ), + bind ({ mk, sk, }, "Tab", focus_byidx (-1) ), bind ({ mk, }, "u", awful.client.urgent.jumpto ), bind ({ mk, }, "l", { ksub ({ }, "l", prev_layout ), @@ -558,8 +557,8 @@ clientkeys = ksub ({ mk, }, "c", cli_kill ), ksub ({ }, "o", switch_focus ), -- Bound twice: - ksub ({ }, ",", function (c) awful.client.swap.byidx (-1) end), - ksub ({ }, ".", function (c) awful.client.swap.byidx ( 1) end), + ksub ({ }, ",", swap_byidx (-1) ), + ksub ({ }, ".", swap_byidx ( 1) ), -- I never use them...: -- ksub ({ }, "2", function (c) awful.tag.incmaster ( 1) end), -- ksub ({ }, "3", function (c) awful.tag.incncol ( 1) end), -- 2.1.4