"Special" titles for "special" buffers

From: vais <vsalik....at.gmail.com>
Date: Sun, 8 Feb 2009 18:37:38 -0800 (PST)

Hello, Mitchell,

Special buffers (shows_files_found, shows_messages, and shows_errors)
are reported as Untitled in the buffer browser and window title. I
propose the following:

buffer_name = function(b)
  if b.shows_files_found then return "[Search]" end
  if b.shows_messages then return "[Output]" end
  if b.shows_errors then return "[Errors]" end
  return b.filename or textadept.locale.UNTITLED
end

Then, in buffer_browser.lua:

function get_contents_for()
  local contents = {}
  for index, buffer in ipairs(textadept.buffers) do
    index = string.format("%02i", index)
    contents[index] = {
      pixbuf = buffer.dirty and 'gtk-edit' or 'gtk-file',
--~ text = (buffer.filename or textadept.locale.UNTITLED):match
('[^/\\]+$')
text = (buffer_name(buffer)):match('[^/\\]+$')
    }
  end
  return contents
end

And in events.lua:

local function set_title(buffer)
  local buffer = buffer
--~ local filename = buffer.filename or textadept.locale.UNTITLED
local filename = buffer_name(buffer)
  local d = buffer.dirty and '*' or '-'
  textadept.title =
    string.format(title_text, filename:match('[^/\\]+$'), d, filename)
end

add_handler('quit',
...
    for _, buffer in ipairs(textadept.buffers) do
      if buffer.dirty then
--~ list[#list + 1] = buffer.filename or locale.UNTITLED
list[#list + 1] = buffer_name(buffer)
        any = true
      end
    end
...
end

Basically, buffer_name serves as a central place for calculating the
buffer name, instead of having this logic all over the place. What do
you think? 1.4 material?
Received on Sun 08 Feb 2009 - 21:37:38 EST

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:37:16 EST