Skip to content

Instantly share code, notes, and snippets.

@rgieseke
Created November 11, 2010 11:20
Show Gist options
  • Save rgieseke/672362 to your computer and use it in GitHub Desktop.
Save rgieseke/672362 to your computer and use it in GitHub Desktop.
Modification of Textadept's menu.lua
require 'textadept'
-- requires latest menu.lua from hg:
-- http://code.google.com/p/textadept/source/browse/modules/textadept/menu.lua
-- toggle menubar
local menubar_visible = true
keys['af10'] = {
function ()
if menubar_visible then
gui.menubar = {}
menubar_visible = false
else
_m.textadept.menu.set_menubar(_m.textadept.menu.menubar)
menubar_visible = true
end
end
}
-- remove accelerators
local menubar = _m.textadept.menu.menubar
for i = 1, #_m.textadept.menu.menubar do
menubar[i].title = menubar[i].title:gsub('_', '')
end
_m.textadept.menu.set_menubar(menubar)
--
-- show only some lexers in Lexers menu
local lexerlist = {'lua', 'python', 'ruby'}
local function set_lexer(lexer)
buffer:set_lexer(lexer)
buffer:colourise(0, -1)
events.emit('update_ui')
end
local lexer_menu = { title = 'Le_xers' }
for _, lexer in ipairs(lexerlist) do
lexer_menu[#lexer_menu + 1] = { lexer, { set_lexer, lexer} }
end
_m.textadept.menu.menubar[6] = lexer_menu
_m.textadept.menu.set_menubar(_m.textadept.menu.menubar)
-- Frank Smit's patch to show list of open buffers in context menu
local function create_buffer_list()
context_mbl = {}
index = 1
table.foreach(_G._BUFFERS, function(key, buffer)
-- Get a (file)name
fn = buffer.filename or buffer._type or 'Untitled'
-- Check if buffer content is modified
dirty = buffer.dirty and ' *' or ''
-- Find current buffer
if gui.focused_doc_pointer == buffer.doc_pointer then
current = ' (current)'
else
current = ''
end
-- Create menu data
context_mbl[#context_mbl + 1] = {
fn:match('[^/\\]+$'):gsub('_', '__') .. current .. dirty,
{ 'goto_buffer', 'view', index, true }
}
index = index + 1
end )
-- Update context menu
_m.textadept.menu.set_contextmenu(context_mbl)
end
--
events.connect('file_opened', create_buffer_list)
events.connect('buffer_new', create_buffer_list)
events.connect('buffer_deleted', create_buffer_list)
events.connect('save_point_left', create_buffer_list)
events.connect('save_point_reached', create_buffer_list)
events.connect('buffer_after_switch', create_buffer_list)
-- Language specific menu for Lua buffers
function create_lua_menu()
if buffer._lexer ~= 'lua' then
return
end
local snippets = _G.snippets
local m_snippets = _m.textadept.snippets
local menubar = _m.textadept.menu.menubar
local lua_menu = {
title = 'L_ua',
{'local... [l]', { function() m_snippets._insert(snippets.lua.l) end } },
{'print [p]', { function() m_snippets._insert(snippets.lua.p) end } },
}
if #menubar == 7 then
table.insert(menubar, 7, lua_menu)
_m.textadept.menu.set_menubar(menubar)
end
end
events.connect('buffer_after_switch', create_lua_menu)
events.connect('file_opened', create_lua_menu)
-- remove Lua menu
events.connect('buffer_before_switch',
function()
local menubar = _m.textadept.menu.menubar
if #menubar == 8 then
table.remove(menubar, 7)
_m.textadept.menu.set_menubar(menubar)
end
end )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment