aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/.textadept.lua5
-rw-r--r--core/ext/key_commands.lua6
-rw-r--r--core/ext/menu.lua3
-rw-r--r--core/init.lua21
-rw-r--r--core/locale.conf4
5 files changed, 37 insertions, 2 deletions
diff --git a/core/.textadept.lua b/core/.textadept.lua
index bb541a2b..0ce0d19a 100644
--- a/core/.textadept.lua
+++ b/core/.textadept.lua
@@ -118,6 +118,11 @@ function _print(buffer_type, ...) end
function print(...) end
---
+-- Displays a dialog with a list of buffers to switch to and switches to the
+-- selected one, if any.
+function switch_buffer() end
+
+---
-- Displays a CocoaDialog of a specified type with the given string arguments.
-- Each argument is like a string in Lua's 'arg' table.
-- @return string CocoaDialog result.
diff --git a/core/ext/key_commands.lua b/core/ext/key_commands.lua
index 6181d378..98d32490 100644
--- a/core/ext/key_commands.lua
+++ b/core/ext/key_commands.lua
@@ -114,7 +114,7 @@ if not MAC then
-- Windows and Linux key commands.
--[[
- C: B D H I J K L M U
+ C: D H I J K L 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
@@ -214,6 +214,7 @@ if not MAC then
keys.ai = { m_snippets.show_style }
-- Buffers
+ keys.cb = { t.switch_buffer }
keys['c\t'] = { 'goto_buffer', v, 1, false }
keys['cs\t'] = { 'goto_buffer', v, -1, false }
local function toggle_setting(setting)
@@ -272,7 +273,7 @@ else
--[[
C: J L M U W X Z
- A: B D E H J K L U
+ A: D E H J K L U
CS: C D G H I J K L M O Q S T U V W X Y Z
SA: A B C D H I J K L M N O Q R T U V X
CA: A C E J K L M N O Q R S T U V W X Y Z
@@ -375,6 +376,7 @@ else
keys.ci = { m_snippets.show_style }
-- Buffers
+ keys.ab = { t.switch_buffer }
keys['c\t'] = { 'goto_buffer', v, 1, false }
keys['cs\t'] = { 'goto_buffer', v, -1, false }
local function toggle_setting(setting)
diff --git a/core/ext/menu.lua b/core/ext/menu.lua
index 0bb92a07..7d5649e5 100644
--- a/core/ext/menu.lua
+++ b/core/ext/menu.lua
@@ -115,6 +115,7 @@ local ID = {
ENCODING_MACROMAN = 515,
ENCODING_UTF16 = 516,
REFRESH_SYNTAX_HIGHLIGHTING = 508,
+ SWITCH_BUFFER = 517,
-- View
NEXT_VIEW = 601,
PREV_VIEW = 602,
@@ -243,6 +244,7 @@ local menubar = {
title = l.MENU_BUF_TITLE,
{ l.MENU_BUF_NEXT, ID.NEXT_BUFFER },
{ l.MENU_BUF_PREV, ID.PREV_BUFFER },
+ { l.MENU_BUF_SWITCH, ID.SWITCH_BUFFER },
{ SEPARATOR, ID.SEPARATOR },
{ l.MENU_BUF_TOGGLE_VIEW_EOL, ID.TOGGLE_VIEW_EOL },
{ l.MENU_BUF_TOGGLE_WRAP, ID.TOGGLE_WRAP_MODE },
@@ -476,6 +478,7 @@ local actions = {
[ID.ENCODING_MACROMAN] = { set_encoding, 'MacRoman' },
[ID.ENCODING_UTF16] = { set_encoding, 'UTF-16LE' },
[ID.REFRESH_SYNTAX_HIGHLIGHTING] = { 'colourise', b, 0, -1 },
+ [ID.SWITCH_BUFFER] = { t.switch_buffer },
-- View
[ID.NEXT_VIEW] = { t.goto_view, 1, false },
[ID.PREV_VIEW] = { t.goto_view, -1, false },
diff --git a/core/init.lua b/core/init.lua
index bb09a441..b55a3f04 100644
--- a/core/init.lua
+++ b/core/init.lua
@@ -78,3 +78,24 @@ end
-- LuaDoc is in core/.textadept.lua.
function textadept.print(...) textadept._print(locale.MESSAGE_BUFFER, ...) end
+
+-- LuaDoc is in core/.textadept.lua.
+function textadept.switch_buffer()
+ local items = {}
+ for _, buffer in ipairs(textadept.buffers) do
+ local filename = buffer.filename or buffer._type or locale.UNTITLED
+ local dirty = buffer.dirty and '*' or ''
+ items[#items + 1] = dirty..filename:match('[^/\\]+$')
+ items[#items + 1] = filename
+ end
+ local out =
+ textadept.dialog('filteredlist',
+ '--title', locale.SWITCH_BUFFERS,
+ '--button1', 'gtk-ok',
+ '--button2', 'gtk-cancel',
+ '--no-newline',
+ '--columns', 'Name', 'File',
+ '--items', unpack(items))
+ local i = tonumber(out:match('%-?%d+$'))
+ if i and i >= 0 then view:goto_buffer(i + 1, true) end
+end
diff --git a/core/locale.conf b/core/locale.conf
index abbaaebd..8080649c 100644
--- a/core/locale.conf
+++ b/core/locale.conf
@@ -500,6 +500,10 @@ MENU_BUF_NEXT "_Next Buffer"
MENU_BUF_PREV "_Previous Buffer"
% core/ext/menu.lua
+% "S_witch Buffer"
+MENU_BUF_SWITCH "Swit_ch Buffer"
+
+% core/ext/menu.lua
% "Toggle View _EOL"
MENU_BUF_TOGGLE_VIEW_EOL "Toggle View _EOL"