Re: [code] Improved File Browser

From: Mitchell <>
Date: Wed, 10 Oct 2018 08:46:24 -0400 (EDT)

Hi Alexander,

On Tue, 9 Oct 2018, Alexander Misel wrote:

> I found not so easy to solve the issues. As I placed a print(name) after the last buffer:set_styling but the print is fine, while the text is not colored. The second issue I tried the BUFFER_AFTER_SWITCH event, but I don't know how to color the text, simply copying the code from print_listing doesn't work.

Sorry about that. I cannot figure out why the last directory is not highlighted either :( This simple BUFFER_AFTER_SWITCH event highlights directories:

   events.connect(events.BUFFER_AFTER_SWITCH, function()
     if not (buffer._type or ''):match('^%[File Browser') then return end
     for i = 0, buffer.line_count - 1 do
       local line = buffer:get_line(i)
       if line:find('[/\\][\r\n]*$') then
         buffer:start_styling(buffer:position_from_line(i), 0xFF)

If you wanted to also highlight links and sockets correctly, you'd probably want to call `get_path()` for each line number and then call `lfs.attributes(path, 'mode')` to get the mode to use with `M.styles`.

The file browser was originally designed to be a dedicated split view, which is why I didn't bother supporting BUFFER_AFTER_SWITCH highlight-restoring.


You are subscribed to
To change subscription settings, send an e-mail to
To unsubscribe, send an e-mail to
Received on Wed 10 Oct 2018 - 08:46:24 EDT

This archive was generated by hypermail 2.2.0 : Thu 11 Oct 2018 - 06:49:31 EDT