rgieseke / textredux

Text-based interfaces for Textadept
http://rgieseke.github.io/textredux/
Other
58 stars 11 forks source link

Syntax highlighting each individual line of code in one column of a core list? #53

Closed Gavin-Holt closed 4 months ago

Gavin-Holt commented 4 years ago

Hi

I have modified (https://github.com/loomer/.textadept/tree/master/modules/tr_fif) to create an unsorted list of all lines from all open buffers - and then filter exact matches (its near the end of the attached file as 'func.find' - please note depends upon win32 findstr.exe).

functions_lua.txt

Q1. Is there any way to apply syntax highlighting to each individual line of code found, in this case column 3, depending upon the lexer for the specific file type?

Please note I am using Textadept-curses.exe and therefore just the TERM theme.

Q2. Is there an easy keybind to refresh the buffer containing the list?

Kind Regards Gavin Holt

PS I know this is listing from the saved disk version of the files. Using the live buffer versions is a project for my next empty weekend!

rgieseke commented 4 years ago

Hi,

interesting questions!

On Q1, i think it should be possible, the lexing functionality can be used programmatically, and Textredux' styling uses the same kinds of categories as the lexing module. Not sure, maybe worth asking on the mailing list, whether there is a way to reuse the already lexed state (Scintilla's state).

Q2: There is a refresh handler which you could call with a custom keybinding as well I think (not sure i understood the question)

Gavin-Holt commented 4 years ago

Hi,

Q1 I have asked for some help with the syntax highlighting on the textadept mailing list.

Q2. The refresh routines in Textredux seem to be concerned with the "filtering/fuzzy find" update actions.

I wanted to attach a keybinding to refresh the results list which is being filtered (to account for added/changed files/contents).

I could just close the buffer and open another - but it would be nice to keep the selected 'location+command line+filter text' and update the results list, then reapply the filter (Like F5 in the windows file explorer).

Would it be sensible/possible to use the variables held in the open buffer to spawn a new refreshed buffer, and close the original?

Many thanks

Kind Regards Gavin Holt

rgieseke commented 4 years ago

Hi Gavin,

that should definitley work somehow, from the manual:

When we say that a Textredux buffer “wraps” a Textadept buffer, there's more to it than just adding additional methods to the Textadept buffer API. A Textredux buffer will always exist, but the corresponding Textadept buffer, named target hereafter, may not. When the target buffer exists, a Textredux buffer will expose all the functions and attributes of the Textadept buffer, making it possible to use the Textredux buffer in just the same way as you would a Textadept buffer (i.e. invoking any of the ordinary buffer methods, setting attributes, etc.). Textredux takes care of creating the target buffer automatically if needed whenever you invoke @{reduxbuffer:show}. When the target buffer does not exist, for instance as the result of the user closing it, any attempt to invoke any of the ordinary buffer methods will raise an error. You can check explicitly whether the target buffer exists by using the @{reduxbuffer:is_attached} function. However, this is not something you will have to worry much about in practice, since you'll typically interact with the buffer as part of a refresh, key press, etc., where the target buffer will always exist.

Note hat i'm not saying please read the manual, it's more that i myslef need to look this up and think about it... i don't think it should be necessary to close/reopen, technically it's not different to re-rendering a list after a keystroke.

--[[-- Refreshes the buffer. A refresh works by ensuring that it's possible to write to the buffer and invoking the @{on_refresh} handler. After the refresh is complete, the @{read_only} state is reset to whatever it was before the refresh, and a save point is set.

Please note that a refresh will clear all content, along with hotspots, etc. If you want to perform smaller updates please use the @{buffer:update} function instead. ]] function reduxbuffer:refresh()

rgieseke commented 4 years ago

As a further example:

local function test_on_refresh(buffer)
  buffer:add_text(os.date("%H:%M:%S"))
end

local function testredux()
  local buffer = textredux.core.buffer.new('Testredux')
  buffer.on_refresh = test_on_refresh

  -- Bind Control+R to refresh
  buffer.keys.cr = function()
    buffer:refresh()
  end

  buffer:show()
end

keys.c3 = testredux

Press Ctrl-3 (you might have to adjust this to something else to use in the Curses version) to open a new Textredux buffer which displays the current time, inside the buffer press Ctrl-R to refresh (refresh the current time).

Gavin-Holt commented 4 months ago

Many thanks.