aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/ui.lua37
-rw-r--r--doc/manual.md16
2 files changed, 43 insertions, 10 deletions
diff --git a/core/ui.lua b/core/ui.lua
index 3b9db7a2..a0474e04 100644
--- a/core/ui.lua
+++ b/core/ui.lua
@@ -171,13 +171,40 @@ ui.dialogs = setmetatable({}, {__index = function(_, k)
end
end})
+local buffers_zorder = {}
+
+-- Adds new buffers to the z-order list.
+events.connect(events.BUFFER_NEW, function()
+ if buffer == ui.command_entry then return end -- ignore this buffer
+ table.insert(buffers_zorder, 1, buffer)
+end)
+
+-- Updates the z-order list.
+events.connect(events.BUFFER_AFTER_SWITCH, function()
+ local i = 1
+ while i <= #buffers_zorder do
+ if buffers_zorder[i] == buffer or not _BUFFERS[buffers_zorder[i]] then
+ table.remove(buffers_zorder, i)
+ else
+ i = i + 1
+ end
+ end
+ table.insert(buffers_zorder, 1, buffer)
+end)
+
---
-- Prompts the user to select a buffer to switch to.
+-- Buffers are listed in the order they were opened unless `zorder` is `true`,
+-- in which case buffers are listed by their z-order (most recently viewed to
+-- least recently viewed).
+-- @param zorder Flag that indicates whether or not to list buffers by their
+-- z-order. The default value is `false`.
-- @name switch_buffer
-function ui.switch_buffer()
+function ui.switch_buffer(zorder)
+ local buffers = not zorder and _BUFFERS or buffers_zorder
local columns, utf8_list = {_L['Name'], _L['File']}, {}
- for i = 1, #_BUFFERS do
- local buffer = _BUFFERS[i]
+ for i = not zorder and 1 or 2, #buffers do
+ local buffer = buffers[i]
local filename = buffer.filename or buffer._type or _L['Untitled']
if buffer.filename then filename = filename:iconv('UTF-8', _CHARSET) end
local basename = buffer.filename and filename:match('[^/\\]+$') or filename
@@ -188,7 +215,9 @@ function ui.switch_buffer()
title = _L['Switch Buffers'], columns = columns, items = utf8_list,
width = CURSES and ui.size[1] - 2 or nil
}
- if button == 1 and i then view:goto_buffer(_BUFFERS[i]) end
+ if button == 1 and i then
+ view:goto_buffer(buffers[not zorder and i or i + 1])
+ end
end
---
diff --git a/doc/manual.md b/doc/manual.md
index ad882e50..a8e12414 100644
--- a/doc/manual.md
+++ b/doc/manual.md
@@ -365,11 +365,12 @@ in curses) to display this browser.
![Buffer Browser](images/bufferbrowser.png)
-The buffer browser displays a list of currently open buffers, the most recent
-towards the bottom. Typing part of any filename filters the list. Spaces are
-wildcards. The arrow keys move the selection up and down. Pressing `Enter`,
-selecting `OK`, or double-clicking a buffer in the list switches to the selected
-buffer.
+The buffer browser displays a list of currently open buffers. By default, the
+most recent buffers are towards the bottom of the list. The browser can be
+[configured](#Key.Bindings) to list the most recently viewed buffers first.
+Typing part of any filename filters the list. Spaces are wildcards. The arrow
+keys move the selection up and down. Pressing `Enter`, selecting `OK`, or
+double-clicking a buffer in the list switches to the selected buffer.
![Buffer Browser Filtered](images/bufferbrowserfiltered.png)
@@ -1106,10 +1107,13 @@ once.
Textadept provides key bindings for a vast majority of its features. If you
would like to add, tweak, or remove key bindings, you can do so from your
*~/.textadept/init.lua*. For example, maybe you prefer that `Ctrl+Shift+C`
-creates a new buffer instead of `Ctrl+N`:
+creates a new buffer instead of `Ctrl+N`, or that the buffer list (`Ctrl+B`)
+shows buffers by their z-order (most recently viewed to least recently viewed)
+instead of the order they were opened in:
keys.cC = buffer.new
keys.cn = nil
+ keys.cb = function() ui.switch_buffer(true) end
A key binding is simply a Lua function assigned to a key sequence in the global
`keys` table. Key sequences are composed of an ordered combination of modifier