1 -- Luakit configuration file, more information at http://luakit.org/
7 -- Widget construction aliases
8 function eventbox() return widget
{type="eventbox"} end
9 function hbox() return widget
{type="hbox"} end
10 function label() return widget
{type="label"} end
11 function notebook() return widget
{type="notebook"} end
12 function vbox() return widget
{type="vbox"} end
13 function webview() return widget
{type="webview"} end
14 function window() return widget
{type="window"} end
15 function entry() return widget
{type="entry"} end
17 -- Variable definitions
18 HOMEPAGE
= "http://luakit.org/"
19 --HOMEPAGE = "http://github.com/mason-larobina/luakit"
22 MAX_SRCH_HISTORY
= 100
27 font
= "monospace normal 9",
32 statusbar_fg
= "#fff",
33 statusbar_bg
= "#000",
38 loaded_fg
= "#33AADD",
41 selected_tablabel_fg
= "#fff",
42 selected_tablabel_bg
= "#000",
44 -- Enforce a minimum tab width of 30 characters to prevent longer tab
45 -- titles overshadowing small tab titles when things get crowded.
46 tablabel_format
= "%-30s",
49 widget
.add_signal("new", function(wi
)
50 wi
:add_signal("init", function(wi
)
51 if wi
.type == "window" then
52 wi
:add_signal("destroy", function ()
53 -- Call the quit function if this was the last window left
54 if #luakit
.windows
== 0 then luakit
.quit() end
62 google
= "http://google.com/search?q={0}",
63 imdb
= "http://imdb.com/find?s=all&q={0}",
64 sourceforge
= "http://sf.net/search/?words={0}"
67 -- Add key bindings to be used across all windows
69 -- bind.buf(Pattern, function (w, buffer, opts) .. end, opts),
70 -- bind.key({Modifiers}, Key name, function (w, opts) .. end, opts),
72 bind
.key({}, "Escape", function (w
) w
:set_mode() end),
73 bind
.key({"Control"}, "[", function (w
) w
:set_mode() end),
76 bind
.key({}, "i", function (w
) w
:set_mode("insert") end),
77 bind
.key({}, ":", function (w
) w
:set_mode("command") end),
80 bind
.key({}, "h", function (w
) w
:scroll_horiz("-"..SCROLL_STEP
.."px") end),
81 bind
.key({}, "j", function (w
) w
:scroll_vert ("+"..SCROLL_STEP
.."px") end),
82 bind
.key({}, "k", function (w
) w
:scroll_vert ("-"..SCROLL_STEP
.."px") end),
83 bind
.key({}, "l", function (w
) w
:scroll_horiz("+"..SCROLL_STEP
.."px") end),
84 bind
.key({}, "Left", function (w
) w
:scroll_horiz("-"..SCROLL_STEP
.."px") end),
85 bind
.key({}, "Down", function (w
) w
:scroll_vert ("+"..SCROLL_STEP
.."px") end),
86 bind
.key({}, "Up", function (w
) w
:scroll_vert ("-"..SCROLL_STEP
.."px") end),
87 bind
.key({}, "Right", function (w
) w
:scroll_horiz("+"..SCROLL_STEP
.."px") end),
88 bind
.buf("^gg$", function (w
) w
:scroll_vert("0%") end),
89 bind
.buf("^G$", function (w
) w
:scroll_vert("100%") end),
90 bind
.buf("^[\-\+]?[0-9]+[%%G]$", function (w
, b
) w
:scroll_vert(string.match(b
, "^([\-\+]?%d+)[%%G]$") .. "%") end),
93 bind
.key({}, "p", function (w
) w
:navigate(luakit
.selection()) end),
94 bind
.key({}, "P", function (w
) w
:new_tab(luakit
.selection()) end),
97 bind
.buf("^o$", function (w
, c
) w
:enter_cmd(":open ") end),
98 bind
.buf("^t$", function (w
, c
) w
:enter_cmd(":tabopen ") end),
99 bind
.buf("^,g$", function (w
, c
) w
:enter_cmd(":websearch google ") end),
102 bind
.key({}, "/", function (w
) w
:start_search(true) end),
103 bind
.key({}, "?", function (w
) w
:start_search(false) end),
104 bind
.key({}, "n", function (w
) w
:search(nil, true) end),
105 bind
.key({}, "N", function (w
) w
:search(nil, false) end),
108 bind
.buf("^[0-9]*H$", function (w
, b
) w
:back (tonumber(string.match(b
, "^(%d*)H$") or 1)) end),
109 bind
.buf("^[0-9]*L$", function (w
, b
) w
:forward(tonumber(string.match(b
, "^(%d*)L$") or 1)) end),
112 bind
.buf("^[0-9]*gT$", function (w
, b
) w
:prev_tab(tonumber(string.match(b
, "^(%d*)gT$") or 1)) end),
113 bind
.buf("^[0-9]*gt$", function (w
, b
) w
:next_tab(tonumber(string.match(b
, "^(%d*)gt$") or 1)) end),
114 bind
.buf("^gH$", function (w
) w
:new_tab(HOMEPAGE
) end),
115 bind
.buf("^d$", function (w
) w
:close_tab() end),
117 bind
.buf("^gh$", function (w
) w
:navigate(HOMEPAGE
) end),
118 bind
.buf("^ZZ$", function (w
) luakit
.quit() end),
121 bind
.key({"Shift"}, "Insert", function (w
) w
:insert_cmd(luakit
.selection()) end),
122 bind
.key({}, "Up", function (w
) w
:cmd_hist_prev() end),
123 bind
.key({}, "Down", function (w
) w
:cmd_hist_next() end),
124 bind
.key({}, "Tab", function (w
) w
:cmd_completion() end),
125 bind
.key({"Control"}, "w", function (w
) w
:del_word() end),
126 bind
.key({"Control"}, "u", function (w
) w
:del_line() end),
129 bind
.key({}, "Up", function (w
) w
:srch_hist_prev() end),
130 bind
.key({}, "Down", function (w
) w
:srch_hist_next() end),
137 -- bind.cmd({Command, Alias1, ...}, function (w, arg, opts) .. end, opts),
138 bind
.cmd({"open", "o"}, function (w
, a
) w
:navigate(a
) end),
139 bind
.cmd({"tabopen", "t"}, function (w
, a
) w
:new_tab(a
) end),
140 bind
.cmd({"back" }, function (w
, a
) w
:back(tonumber(a
) or 1) end),
141 bind
.cmd({"forward", "f"}, function (w
, a
) w
:forward(tonumber(a
) or 1) end),
142 bind
.cmd({"scroll" }, function (w
, a
) w
:scroll_vert(a
) end),
143 bind
.cmd({"quit", "q"}, function (w
) luakit
.quit() end),
144 bind
.cmd({"close", "c"}, function (w
) w
:close_tab() end),
145 bind
.cmd({"websearch", "ws"}, function (w
, e
, s
) w
:websearch(e
, s
) end),
148 -- Build and pack window widgets
149 function build_window()
150 -- Create a table for widgets and state variables for a window
162 -- Status bar widgets
166 -- Left aligned widgets
173 -- Fills space between the left and right aligned widgets
175 -- Right aligned widgets
194 w
.ebox
:set_child(w
.layout
)
195 w
.win
:set_child(w
.ebox
)
199 t
.ebox
:set_child(t
.layout
, false, false, 0)
200 w
.layout
:pack_start(t
.ebox
, false, false, 0)
203 w
.layout
:pack_start(w
.tabs
, true, true, 0)
205 -- Pack left-aligned statusbar elements
207 l
.layout
:pack_start(l
.uri
, false, false, 0)
208 l
.layout
:pack_start(l
.loaded
, false, false, 0)
209 l
.ebox
:set_child(l
.layout
)
211 -- Pack right-aligned statusbar elements
213 r
.layout
:pack_start(r
.buf
, false, false, 0)
214 r
.layout
:pack_start(r
.tabi
, false, false, 0)
215 r
.layout
:pack_start(r
.scroll
, false, false, 0)
216 r
.ebox
:set_child(r
.layout
)
218 -- Pack status bar elements
220 s
.layout
:pack_start(l
.ebox
, false, false, 0)
221 s
.layout
:pack_start(s
.filler
, true, true, 0)
222 s
.layout
:pack_start(r
.ebox
, false, false, 0)
223 s
.ebox
:set_child(s
.layout
)
224 w
.layout
:pack_start(s
.ebox
, false, false, 0)
228 i
.layout
:pack_start(i
.prompt
, false, false, 0)
229 i
.layout
:pack_start(i
.input
, true, true, 0)
230 i
.ebox
:set_child(i
.layout
)
231 w
.layout
:pack_start(i
.ebox
, false, false, 0)
234 i
.input
.show_frame
= false
235 w
.tabs
.show_tabs
= false
237 l
.uri
.selectable
= true
242 function attach_window_signals(w
)
243 -- Attach notebook widget signals
244 w
.tabs
:add_signal("page-added", function(nbook
, view
, idx
)
245 w
:update_tab_count(idx
)
246 w
:update_tab_labels()
249 w
.tabs
:add_signal("switch-page", function(nbook
, view
, idx
)
250 w
:update_tab_count(idx
)
251 w
:update_win_title(view
)
253 w
:update_progress(view
)
254 w
:update_tab_labels(idx
)
257 -- Attach window widget signals
258 w
.win
:add_signal("key-press", function(win
, mods
, key
)
259 -- Reset command line completion
260 if w
:get_mode() == "command" and key
~= "Tab" and w
.compl_start
then
265 if w
:hit(mods
, key
) then
270 w
.win
:add_signal("mode-changed", function(win
, mode
)
272 w
.cmd_hist_cursor
= nil
274 -- If a user aborts a search return to the original position
275 if w
.search_start_marker
then
276 w
:get_current():set_scroll_vert(w
.search_start_marker
)
277 w
.search_start_marker
= nil
280 if mode
== "normal" then
283 elseif mode
== "insert" then
285 w
.ibar
.input
.text
= ""
286 w
.ibar
.prompt
.text
= "-- INSERT --"
288 elseif mode
== "command" then
290 w
.ibar
.input
.text
= ":"
293 w
.ibar
.input
:set_position(-1)
294 elseif mode
== "search" then
298 w
.ibar
.prompt
.text
= ""
299 w
.ibar
.input
.text
= ""
303 -- Attach inputbar widget signals
304 w
.ibar
.input
:add_signal("changed", function()
305 local text
= w
.ibar
.input
.text
306 -- Auto-exit "command" mode if you backspace or delete the ":"
307 -- character at the start of the input box when in "command" mode.
308 if w
:is_mode("command") and not string.match(text
, "^:") then
310 elseif w
:is_mode("search") then
311 if string.match(text
, "^[\?\/]") then
312 w
:search(string.sub(text
, 2), (string.sub(text
, 1, 1) == "/"))
320 w
.ibar
.input
:add_signal("activate", function()
321 local text
= w
.ibar
.input
.text
322 if w
:is_mode("command") then
324 w
:match_cmd(string.sub(text
, 2))
326 elseif w
:is_mode("search") then
327 w
:srch_hist_add(text
)
328 w
:search(string.sub(text
, 2), string.sub(text
, 1, 1) == "/")
329 -- User doesn't want to return to start position
330 w
.search_start_marker
= nil
332 w
.ibar
.prompt
.text
= text
338 -- Attach signal handlers to a new tab's webview
339 function attach_webview_signals(w
, view
)
340 view
:add_signal("title-changed", function (v
)
341 w
:update_tab_labels()
342 if w
:is_current(v
) then
343 w
:update_win_title(v
)
347 view
:add_signal("property::uri", function(v
)
348 w
:update_tab_labels()
349 if w
:is_current(v
) then
354 view
:add_signal("key-press", function ()
355 -- Only allow key press events to hit the webview if the user is in
357 if not w
:is_mode("insert") then
362 view
:add_signal("load-start", function (v
)
363 if w
:is_current(v
) then
364 w
:update_progress(v
, 0)
369 view
:add_signal("progress-update", function (v
)
370 if w
:is_current(v
) then
375 view
:add_signal("expose", function(v
)
376 if w
:is_current(v
) then
382 -- Parses scroll amounts of the form:
383 -- Relative: "+20%", "-20%", "+20px", "-20px"
384 -- Absolute: 20, "20%", "20px"
385 -- And returns an absolute value.
386 function parse_scroll(current
, max, value
)
387 if string.match(value
, "^%d+px$") then
388 return tonumber(string.match(value
, "^(%d+)px$"))
389 elseif string.match(value
, "^%d+%%$") then
390 return math
.ceil(max * (tonumber(string.match(value
, "^(%d+)%%$")) / 100))
391 elseif string.match(value
, "^[\-\+]%d+px") then
392 return current
+ tonumber(string.match(value
, "^([\-\+]%d+)px"))
393 elseif string.match(value
, "^[\-\+]%d+%%$") then
394 return math
.ceil(current
+ (max * (tonumber(string.match(value
, "^([\-\+]%d+)%%$")) / 100)))
396 print("E: unable to parse scroll amount:", value
)
400 -- Helper functions which operate on a windows widget structure
402 -- Return the widget in the currently active tab
403 get_current
= function(w
) return w
.tabs
:atindex(w
.tabs
:current()) end,
404 -- Check if given widget is the widget in the currently active tab
405 is_current
= function(w
, wi
) return w
.tabs
:indexof(wi
) == w
.tabs
:current() end,
407 -- Wrappers around the mode plugin
408 set_mode
= function(w
, name
) mode
.set(w
.win
, name
) end,
409 get_mode
= function(w
) return mode
.get(w
.win
) end,
410 is_mode
= function(w
, name
) return name
== w
:get_mode() end,
411 is_any_mode
= function(w
, t
, name
) return util
.table.hasitem(t
, name
or w
:get_mode()) end,
413 -- Wrappers around the view:get_prop & view:set_prop methods
414 get
= function (w
, prop
, view
)
415 if not view
then view
= w
:get_current() end
416 return view
:get_prop(prop
)
419 set
= function (w
, prop
, val
, view
)
420 if not view
then view
= w
:get_current() end
421 view
:set_prop(prop
, val
)
424 get_tab_title
= function (w
, view
)
425 if not view
then view
= w
:get_current() end
426 return view
:get_prop("title") or view
.uri
or "(Untitled)"
429 navigate
= function(w
, uri
, view
)
430 local v
= view
or w
:get_current()
434 return w
:new_tab(uri
)
438 new_tab
= function(w
, uri
)
439 local view
= webview()
441 attach_webview_signals(w
, view
)
442 if uri
then view
.uri
= uri
end
443 view
.show_scrollbars
= false
447 -- close the current tab
448 close_tab
= function(w
)
449 view
= w
:get_current()
450 if not view
then return end
456 -- Wrapper around the bind plugin's hit method
457 hit
= function (w
, mods
, key
)
458 local caught
, newbuf
= bind
.hit(w
.binds
or {}, mods
, key
, w
.buffer
, w
:is_mode("normal"), w
)
464 -- Wrapper around the bind plugin's match_cmd method
465 match_cmd
= function (w
, buffer
)
466 return bind
.match_cmd(commands
, buffer
, w
)
469 -- enter command or characters into command line
470 enter_cmd
= function(w
, cmd
)
471 local i
= w
.ibar
.input
472 w
:set_mode("command")
477 -- insert a string into the command line at the current cursor position
478 insert_cmd
= function(w
, str
)
479 if not str
then return nil end
480 local i
= w
.ibar
.input
482 local pos
= i
:get_position()
483 local left
, right
= string.sub(text
, 1, pos
), string.sub(text
, pos
+1)
484 i
.text
= left
.. str
.. right
485 i
:set_position(pos
+ #str
+ 1)
488 -- search engine wrapper
489 websearch
= function(w
, args
)
490 local sep
= string.find(args
, " ")
491 local engine
= string.sub(args
, 1, sep
-1)
492 local search
= string.sub(args
, sep
+1)
493 if not search_engines
[engine
] then
494 print("E: No matching search engine found:", engine
)
497 local uri
= string.gsub(search_engines
[engine
], "{%d}", search
)
498 return w
:navigate(uri
)
501 -- Command line completion of available commands
502 cmd_completion
= function(w
)
503 local i
= w
.ibar
.input
504 local s
= w
.sbar
.l
.uri
507 -- Get last completion (is reset on key press other than <Tab>)
508 if not w
.compl_start
or w
.compl_index
== 0 then
509 w
.compl_start
= "^" .. string.sub(i
.text
, 2)
513 -- Get suitable commands
514 for _
, b
in ipairs(commands
) do
515 for _
, c
in pairs(b
.commands
) do
516 if c
and string.match(c
, w
.compl_start
) then
517 table.insert(cmpl
, c
)
526 for index
, comp
in pairs(cmpl
) do
527 if index
== w
.compl_index
then
528 i
.text
= ":" .. comp
.. " "
537 -- cycle through all possible completions
538 if w
.compl_index
== #cmpl
then
541 w
.compl_index
= w
.compl_index
+ 1
547 del_word
= function(w
)
548 local i
= w
.ibar
.input
550 local pos
= i
:get_position()
551 if text
and #text
> 1 and pos
> 1 then
552 local left
, right
= string.sub(text
, 2, pos
), string.sub(text
, pos
+1)
553 if not string.find(left
, "%s") then
555 elseif string.find(left
, "%w+%s*$") then
556 left
= string.sub(left
, 0, string.find(left
, "%w+%s*$") - 1)
557 elseif string.find(left
, "%W+%s*$") then
558 left
= string.sub(left
, 0, string.find(left
, "%W+%s*$") - 1)
560 i
.text
= string.sub(text
, 1, 1) .. left
.. right
561 i
:set_position(#left
+ 2)
565 del_line
= function(w
)
566 local i
= w
.ibar
.input
567 if i
.text
~= ":" then
573 -- Search history adding
574 srch_hist_add
= function(w
, srch
)
575 if not w
.srch_hist
then w
.srch_hist
= {} end
577 if #w
.srch_hist
> ((MAX_SRCH_HISTORY
or 100) + 5) then
578 while #w
.srch_hist
> (MAX_SRCH_HISTORY
or 100) do
579 table.remove(w
.srch_hist
, 1)
582 table.insert(w
.srch_hist
, srch
)
585 -- Search history traversing
586 srch_hist_prev
= function(w
)
587 if not w
.srch_hist
then w
.srch_hist
= {} end
588 if not w
.srch_hist_cursor
then
589 w
.srch_hist_cursor
= #w
.srch_hist
+ 1
590 w
.srch_hist_current
= w
.ibar
.input
.text
592 local c
= w
.srch_hist_cursor
- 1
593 if w
.srch_hist
[c
] then
594 w
.srch_hist_cursor
= c
595 w
.ibar
.input
.text
= w
.srch_hist
[c
]
596 w
.ibar
.input
:set_position(-1)
600 srch_hist_next
= function(w
)
601 if not w
.srch_hist
then w
.srch_hist
= {} end
602 local c
= (w
.srch_hist_cursor
or #w
.srch_hist
) + 1
603 if w
.srch_hist
[c
] then
604 w
.srch_hist_cursor
= c
605 w
.ibar
.input
.text
= w
.srch_hist
[c
]
606 w
.ibar
.input
:set_position(-1)
607 elseif w
.srch_hist_current
then
608 w
.srch_hist_cursor
= nil
609 w
.ibar
.input
.text
= w
.srch_hist_current
610 w
.ibar
.input
:set_position(-1)
614 -- Command history adding
615 cmd_hist_add
= function(w
, cmd
)
616 if not w
.cmd_hist
then w
.cmd_hist
= {} end
617 -- Make sure history doesn't overflow
618 if #w
.cmd_hist
> ((MAX_CMD_HISTORY
or 100) + 5) then
619 while #w
.cmd_hist
> (MAX_CMD_HISTORY
or 100) do
620 table.remove(w
.cmd_hist
, 1)
623 table.insert(w
.cmd_hist
, cmd
)
626 -- Command history traversing
627 cmd_hist_prev
= function(w
)
628 if not w
.cmd_hist
then w
.cmd_hist
= {} end
629 if not w
.cmd_hist_cursor
then
630 w
.cmd_hist_cursor
= #w
.cmd_hist
+ 1
631 w
.cmd_hist_current
= w
.ibar
.input
.text
633 local c
= w
.cmd_hist_cursor
- 1
634 if w
.cmd_hist
[c
] then
635 w
.cmd_hist_cursor
= c
636 w
.ibar
.input
.text
= w
.cmd_hist
[c
]
637 w
.ibar
.input
:set_position(-1)
641 cmd_hist_next
= function(w
)
642 if not w
.cmd_hist
then w
.cmd_hist
= {} end
643 local c
= (w
.cmd_hist_cursor
or #w
.cmd_hist
) + 1
644 if w
.cmd_hist
[c
] then
645 w
.cmd_hist_cursor
= c
646 w
.ibar
.input
.text
= w
.cmd_hist
[c
]
647 w
.ibar
.input
:set_position(-1)
648 elseif w
.cmd_hist_current
then
649 w
.cmd_hist_cursor
= nil
650 w
.ibar
.input
.text
= w
.cmd_hist_current
651 w
.ibar
.input
:set_position(-1)
655 -- Searching functions
656 start_search
= function(w
, forward
)
657 -- Clear previous search results
660 local i
= w
.ibar
.input
670 search
= function(w
, text
, forward
)
671 local view
= w
:get_current()
672 local text
= text
or w
.last_search
673 if forward
== nil then forward
= true end
674 local case_sensitive
= false
677 if not text
or #text
== 0 then
683 if w
.searching_forward
== nil then
684 w
.searching_forward
= forward
685 w
.search_start_marker
= view
:get_scroll_vert()
687 -- Invert the direction if originally searching in reverse
688 forward
= (w
.searching_forward
== forward
)
691 view
:search(text
, case_sensitive
, forward
, wrap
);
694 clear_search
= function (w
)
695 w
:get_current():clear_search()
696 -- Clear search state
698 w
.searching_forward
= nil
699 w
.search_start_marker
= nil
702 -- Webview scroll functions
703 scroll_vert
= function(w
, value
, view
)
704 if not view
then view
= w
:get_current() end
705 local cur
, max = view
:get_scroll_vert()
706 if type(value
) == "string" then
707 value
= parse_scroll(cur
, max, value
)
709 view
:set_scroll_vert(value
)
712 scroll_horiz
= function(w
, value
)
713 if not view
then view
= w
:get_current() end
714 local cur
, max = view
:get_scroll_horiz()
715 if type(value
) == "string" then
716 value
= parse_scroll(cur
, max, value
)
718 view
:set_scroll_horiz(value
)
721 -- Tab traversing functions
722 next_tab
= function(w
, n
)
723 w
.tabs
:switch((((n
or 1) + w
.tabs
:current() -1) % w
.tabs
:count()) + 1)
725 prev_tab
= function(w
, n
)
726 w
.tabs
:switch(((w
.tabs
:current() - (n
or 1) -1) % w
.tabs
:count()) + 1)
728 goto_tab
= function(w
, n
)
732 -- History traversing functions
733 back
= function(w
, n
, view
)
734 (view
or w
:get_current()):go_back(n
or 1)
736 forward
= function(w
, n
, view
)
737 (view
or w
:get_current()):go_forward(n
or 1)
740 -- GUI content update functions
741 update_tab_count
= function (w
, i
, t
)
742 w
.sbar
.r
.tabi
.text
= string.format("[%d/%d]", i
or w
.tabs
:current(), t
or w
.tabs
:count())
745 update_win_title
= function (w
, view
)
746 if not view
then view
= w
:get_current() end
747 local title
= view
:get_prop("title")
749 if not title
and not uri
then
750 w
.win
.title
= "luakit"
752 w
.win
.title
= (title
or "luakit") .. " - " .. (uri
or "about:blank")
756 update_uri
= function (w
, view
, uri
)
757 if not view
then view
= w
:get_current() end
758 w
.sbar
.l
.uri
.text
= (uri
or view
.uri
or "about:blank")
761 update_progress
= function (w
, view
, p
)
762 if not view
then view
= w
:get_current() end
763 if not p
then p
= view
:get_prop("progress") end
764 if not view
:loading() or p
== 1 then
765 w
.sbar
.l
.loaded
:hide()
767 w
.sbar
.l
.loaded
:show()
768 w
.sbar
.l
.loaded
.text
= string.format("(%d%%)", p
* 100)
772 update_scroll
= function (w
, view
)
773 if not view
then view
= w
:get_current() end
774 local val
, max = view
:get_scroll_vert()
775 if max == 0 then val
= "All"
776 elseif val
== 0 then val
= "Top"
777 elseif val
== max then val
= "Bot"
778 else val
= string.format("%2d%%", (val
/max) * 100)
780 w
.sbar
.r
.scroll
.text
= val
783 update_buf
= function (w
)
785 w
.sbar
.r
.buf
.text
= string.format(" %-3s", w
.buffer
)
792 update_binds
= function (w
, mode
)
793 -- Generate the list of active key & buffer binds for this mode
794 w
.binds
= util
.table.join(mode_binds
[mode
], mode_binds
.all
)
795 -- Clear & hide buffer
800 -- Tab label functions
801 make_tab_label
= function (w
, pos
)
808 t
.label
.font
= theme
.tablabel_font
or theme
.font
809 t
.layout
:pack_start(t
.label
, true, true, 0)
810 t
.layout
:pack_start(t
.sep
, false, false, 0)
811 t
.ebox
:set_child(t
.layout
)
812 t
.ebox
:add_signal("clicked", function(e
) w
.tabs
:switch(pos
) end)
816 destroy_tab_label
= function(w
, t
)
817 if not t
then t
= table.remove(w
.tbar
.titles
) end
818 for _
, wi
in pairs(t
) do
823 update_tab_labels
= function (w
, current
)
825 local count
, current
= w
.tabs
:count(), current
or w
.tabs
:current()
828 -- Leave the tablist hidden if there is only one tab open
833 if count
~= #tb
.titles
then
834 -- Grow the number of labels
835 while count
> #tb
.titles
do
836 local t
= w
:make_tab_label(#tb
.titles
+ 1)
837 tb
.layout
:pack_start(t
.ebox
, true, true, 0)
838 table.insert(tb
.titles
, t
)
840 -- Prune number of labels
841 while count
< #tb
.titles
do
842 w
:destroy_tab_label()
848 local t
= tb
.titles
[i
]
849 local title
= " " ..i
.. " "..w
:get_tab_title(w
.tabs
:atindex(i
))
850 t
.label
.text
= string.format(theme
.tablabel_format
or "%s", title
)
851 w
:apply_tablabel_theme(t
, i
== current
)
858 apply_tablabel_theme
= function (w
, t
, selected
, atheme
)
859 local theme
= atheme
or theme
861 t
.label
.fg
= theme
.selected_tablabel_fg
or theme
.tablabel_fg
or theme
.fg
862 t
.ebox
.bg
= theme
.selected_tablabel_bg
or theme
.tablabel_bg
or theme
.bg
864 t
.label
.fg
= theme
.tablabel_fg
or theme
.fg
865 t
.ebox
.bg
= theme
.tablabel_bg
or theme
.bg
869 apply_window_theme
= function (w
, atheme
)
870 local theme
= atheme
or theme
871 local s
, i
, t
= w
.sbar
, w
.ibar
, w
.tbar
872 local fg
, bg
, font
= theme
.fg
, theme
.bg
, theme
.font
876 [s
.l
.uri
] = theme
.uri_fg
or theme
.statusbar_fg
or fg
,
877 [s
.l
.loaded
] = theme
.loaded_fg
or theme
.statusbar_fg
or fg
,
878 [s
.r
.buf
] = theme
.buf_fg
or theme
.statusbar_fg
or fg
,
879 [s
.r
.tabi
] = theme
.tabi_fg
or theme
.statusbar_fg
or fg
,
880 [s
.r
.scroll
] = theme
.scroll_fg
or theme
.statusbar_fg
or fg
,
881 [i
.prompt
] = theme
.prompt_fg
or theme
.inputbar_fg
or fg
,
882 [i
.input
] = theme
.input_fg
or theme
.inputbar_fg
or fg
,
887 [s
.l
.ebox
] = theme
.statusbar_bg
or bg
,
888 [s
.r
.ebox
] = theme
.statusbar_bg
or bg
,
889 [s
.ebox
] = theme
.statusbar_bg
or bg
,
890 [i
.ebox
] = theme
.inputbar_bg
or bg
,
891 [i
.input
] = theme
.input_bg
or theme
.inputbar_bg
or bg
,
896 [s
.l
.uri
] = theme
.uri_font
or theme
.statusbar_font
or font
,
897 [s
.l
.loaded
] = theme
.loaded_font
or theme
.statusbar_font
or font
,
898 [s
.r
.buf
] = theme
.buf_font
or theme
.statusbar_font
or font
,
899 [s
.r
.tabi
] = theme
.tabi_font
or theme
.statusbar_font
or font
,
900 [s
.r
.scroll
] = theme
.scroll_font
or theme
.statusbar_font
or font
,
901 [i
.prompt
] = theme
.prompt_font
or theme
.inputbar_font
or font
,
902 [i
.input
] = theme
.input_font
or theme
.inputbar_font
or font
,
903 }) do wi
.font
= v
end
908 function new_window(uris
)
909 local w
= build_window()
911 -- Pack the window table full of the common helper functions
912 for k
, v
in pairs(window_helpers
) do w
[k
] = v
end
914 attach_window_signals(w
)
916 -- Apply window theme
917 w
:apply_window_theme()
919 -- Populate notebook with tabs
920 for _
, uri
in ipairs(uris
or {}) do
924 -- Make sure something is loaded
925 if w
.tabs
:count() == 0 then
937 -- vim: ft=lua:et:sw=4:ts=8:sts=4:tw=80