aboutsummaryrefslogtreecommitdiffhomepage
path: root/core/ext
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2010-03-20 18:05:14 -0400
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2010-03-20 18:05:14 -0400
commitd8cc38cc49c6def21befc585e12530b55569ea7b (patch)
treebf9614c066b73c5f3e1088915e0c175f35ef81e5 /core/ext
parent0ddb039366844b1e5720601335b4bc278fa3e777 (diff)
Can change lexer from a filtered list dialog.
Diffstat (limited to 'core/ext')
-rw-r--r--core/ext/key_commands.lua8
-rw-r--r--core/ext/menu.lua19
-rw-r--r--core/ext/mime_types.lua43
3 files changed, 49 insertions, 21 deletions
diff --git a/core/ext/key_commands.lua b/core/ext/key_commands.lua
index 5aadf6c9..f318c08d 100644
--- a/core/ext/key_commands.lua
+++ b/core/ext/key_commands.lua
@@ -121,7 +121,7 @@ if not MAC then
-- Windows and Linux key commands.
--[[
- C: D H I J K L M U
+ C: D H I J K M U
A: A B C D E F G H J K L M N P R S T U V W X Y Z
CS: A B C D G H I J K L M N O Q T U V X Y Z
SA: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
@@ -240,7 +240,8 @@ if not MAC then
['\t'] = { toggle_setting, 'use_tabs' },
[' '] = { toggle_setting, 'view_ws' },
}
- keys['f5'] = { 'colourise', b, 0, -1 }
+ keys.cl = { t.mime_types.select_lexer }
+ keys['f5'] = { 'colourise', b, 0, -1 }
-- Views
keys.cav = {
@@ -402,7 +403,8 @@ else
['\t'] = { toggle_setting, 'use_tabs' },
[' '] = { toggle_setting, 'view_ws' },
}
- keys['f5'] = { 'colourise', b, 0, -1 }
+ keys.cl = { t.mime_types.select_lexer }
+ keys['f5'] = { 'colourise', b, 0, -1 }
-- Views
keys.cv = {
diff --git a/core/ext/menu.lua b/core/ext/menu.lua
index bf5f8857..b8391d6b 100644
--- a/core/ext/menu.lua
+++ b/core/ext/menu.lua
@@ -287,25 +287,8 @@ local menubar = {
{ l.MENU_HELP_LUADOC, ID.LUADOC },
},
}
-local lexers_found = {}
-local lexers = {}
local lexer_menu = { title = l.MENU_LEX_TITLE }
-local lfs = require 'lfs'
-for lexer in lfs.dir(_HOME..'/lexers/') do
- if lexer:find('%.lua$') and lexer ~= 'lexer.lua' then
- lexers_found[lexer:match('^(.+)%.lua$')] = true
- end
-end
-if lfs.attributes(_USERHOME..'/lexers/') then
- for lexer in lfs.dir(_USERHOME..'/lexers/') do
- if lexer:find('%.lua$') and lexer ~= 'lexer.lua' then
- lexers_found[lexer:match('^(.+)%.lua$')] = true
- end
- end
-end
-for lexer in pairs(lexers_found) do lexers[#lexers + 1] = lexer end
-table.sort(lexers)
-for _, lexer in ipairs(lexers) do
+for _, lexer in ipairs(textadept.mime_types.lexers) do
lexer_menu[#lexer_menu + 1] = { lexer, ID.LEXER_START + #lexer_menu }
end
table.insert(menubar, #menubar, gtkmenu(lexer_menu)) -- before 'Help'
diff --git a/core/ext/mime_types.lua b/core/ext/mime_types.lua
index 07a8f19d..8e014e18 100644
--- a/core/ext/mime_types.lua
+++ b/core/ext/mime_types.lua
@@ -105,6 +105,31 @@ for line in mime_types:gmatch('[^\r\n]+') do
end
end
+---
+-- List of detected lexers.
+-- Lexers are read from `lexers/` and `~/.textadept/lexers/`.
+-- @class table
+-- @name lexers
+lexers = {}
+
+-- Generate lexer list
+local lexers_found = {}
+local lfs = require 'lfs'
+for lexer in lfs.dir(_HOME..'/lexers/') do
+ if lexer:find('%.lua$') and lexer ~= 'lexer.lua' then
+ lexers_found[lexer:match('^(.+)%.lua$')] = true
+ end
+end
+if lfs.attributes(_USERHOME..'/lexers/') then
+ for lexer in lfs.dir(_USERHOME..'/lexers/') do
+ if lexer:find('%.lua$') and lexer ~= 'lexer.lua' then
+ lexers_found[lexer:match('^(.+)%.lua$')] = true
+ end
+ end
+end
+for lexer in pairs(lexers_found) do lexers[#lexers + 1] = lexer end
+table.sort(lexers)
+
--
-- Replacement for buffer:set_lexer_language().
-- Sets a buffer._lexer field so it can be restored without querying the
@@ -123,6 +148,7 @@ local function set_lexer(buffer, lang)
elseif not ret and not err:find("^module '"..lang.."' not found:") then
error(err)
end
+ buffer:colourise(0, -1)
end
textadept.events.add_handler('buffer_new',
function() buffer.set_lexer = set_lexer end)
@@ -168,3 +194,20 @@ textadept.events.add_handler('buffer_after_switch', restore_lexer)
textadept.events.add_handler('view_new', restore_lexer)
textadept.events.add_handler('reset_after',
function() buffer:set_lexer(buffer._lexer) end)
+
+---
+-- Prompts the user to select a lexer from a filtered list for the current
+-- buffer.
+function select_lexer()
+ local out =
+ textadept.dialog('filteredlist',
+ '--title', locale.MT_SELECT_LEXER,
+ '--button1', 'gtk-ok',
+ '--button2', 'gtk-cancel',
+ '--no-newline',
+ '--string-output',
+ '--columns', 'Name',
+ '--items', unpack(lexers))
+ local response, lexer = out:match('([^\n]+)\n([^\n]+)$')
+ if response and response ~= 'gtk-cancel' then buffer:set_lexer(lexer) end
+end