File: simple_bindings.lua

package info (click to toggle)
notion 4.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 4,656 kB
  • sloc: ansic: 47,365; sh: 2,093; makefile: 594; perl: 270
file content (170 lines) | stat: -rw-r--r-- 4,749 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
-- Authors: Etan Reisner <deryni@gmail.com>
-- License: MIT, see http://opensource.org/licenses/mit-license.php
-- Last Changed: 2007-08-17
--
--[[
Author: Etan Reisner
Email: deryni@gmail.com
Summary: Read a simplified binding file to let people set up some custom
         bindings without needing to mess with lua directly. To use create a
         'bindings' file in ~/.ion3 .
Last Updated: 2007-08-17

Copyright (c) Etan Reisner 2007

This software is released under the terms of the MIT license. For more
information, see http://opensource.org/licenses/mit-license.php .
--]]

--[[
Examples:

go_to_workspace1 = "M-S-1"
go_to_workspace4 = "M-S-4"
xterm = "M-x"
urxvt = "M-u"
--]]

--[[
Available bindings

attach
detach
go_to_workspace#
next_frame_up
next_frame_down
next_frame_left
next_frame_right
move_tab_left
move_tab_right
split_horiz
split_vert
split_horiz_top
split_vert_top

any other single word will be interpreted as the name of a program to run.
--]]

--[[
cycle windows
--]]

--{{{ Standalone hacks

if not ioncore then
    ioncore = {get_paths = function() return {userdir="/home/deryni/.ion3"} end}
    warn = print
    loadstring = function(str) return function() print(str) end end
end

--}}} Standalone hacks

local bindings = {}

bindings.go_to_workspace = {section = "WScreen", funcstr = "WScreen.switch_nth(_, NUM)"}

bindings.split_at = {section = "WTiling", funcstr = "WTiling.split_at(_, _sub, 'DIR', true)"}
bindings.split_top = {section = "WTiling", funcstr = "WTiling.split_top(_, 'DIR')"}

bindings.next_tab = {section = "WFrame.toplevel", funcstr = "WFrame.switch_next(_)"}
bindings.prev_tab = {section = "WFrame.toplevel", funcstr = "WFrame.switch_prev(_)"}

bindings.next_frame = {section = "WTiling", funcstr = "ioncore.goto_next(_sub, 'DIR', {no_ascend=_})"}

bindings.move_tab = {section = "WFrame.toplevel", funcstr = "WFrame.DIR_index(_, _sub)"}

bindings.tag = {section = "WFrame.toplevel", funcstr = "WRegion.set_tagged(_sub, 'toggle')"}
bindings.attach_tagged = {section = "WFrame.toplevel", funcstr = "ioncore.tagged_attach(_)"}

bindings.close_window = {section = "WMPlex", funcstr = "WRegion.rqclose_propagate(_, _sub)"}
bindings.kill_window = {section = "WClientWin", "WClientWin.kill(_)"}

bindings.detach = {section = "WMPlex", funcstr = "ioncore.detach(_chld, 'toggle')"}

bindings.exec = {section = "WMPlex.toplevel", funcstr = "ioncore.exec_on(_, 'PROG')"}

local paths, chunk, ok, err, fenv

paths = ioncore.get_paths()
chunk, err = loadfile(paths.userdir.."/bindings")

if not chunk then
    warn("Failed to load bindings file")
    return
end

fenv = {}
chunk = setfenv(chunk, fenv)
ok, err = pcall(chunk)

if not ok then
    warn("Failed to run the bindings file: "..err)
    return
end

local sections = {}

for k,v in pairs(fenv) do
    local section, bindstr, keystr

    keystr = v:gsub("([MCS])%-", {M = "META+", C = "Control+", S = "Shift+"})

    if bindings[k] then
        bindstr = bindings[k].funcstr
        section = bindings[k].section
    end

    if (not bindstr) and k:match("^..tach$") then
        bindstr = bindings.detach.funcstr
        section = bindings.detach.section
    end

    local action, num = k:match("^(go_to_workspace)(%d+)$")
    if (not bindstr) and action and num then
        bindstr = bindings[action].funcstr:gsub("NUM", num - 1)
        section = bindings[action].section
    end

    local dir = k:match("^next_frame_(%w+)$")
    if (not bindstr) and dir then
        bindstr = bindings.next_frame.funcstr:gsub("DIR", dir)
        section = bindings.next_frame.section
    end

    local dir = k:match("^move_tab_(%w+)$")
    if (not bindstr) and dir then
        local dir = (dir == "right") and "inc" or "dec"
        bindstr = bindings.move_tab.funcstr:gsub("DIR", dir)
        section = bindings.move_tab.section
    end

    local dir, top = k:match("^split_([^_]+)_?(%w*)")
    if (not bindstr) and dir then
        local action = (top == "top") and "split_top" or "split_at"
        local dir = (dir == "horiz") and "right" or "bottom"
        bindstr = bindings[action].funcstr:gsub("DIR", dir)
        section = bindings[action].section
    end

    if not bindstr then
        bindstr = bindings.exec.funcstr:gsub("PROG", k)
        section = bindings.exec.section
    end

    if not sections[section] then
        sections[section] = {}
    end
    section = sections[section]
    section[#section + 1] = {bindstr = bindstr, keystr = keystr}
end

for section, tab in pairs(sections) do
    local str = [[defbindings("]]..section.."\", {\n"
    for i,bind in pairs(tab) do
        str = str.."\tkpress(\""..bind.keystr..[[", "]]..bind.bindstr.."\"),\n"
    end
    str = str.."})"
    loadstring(str)()
end

-- vim: set expandtab sw=4: