rgieseke / textredux

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

Support for find_in_files? #30

Closed ghost closed 7 years ago

ghost commented 7 years ago

Is it possible to have TR take over the find_in_files dialog?

Unrelated but how do you make the TR version of snapopen accept the current working dir as starting point?

rgieseke commented 7 years ago

You mean the whole search dialogue or just the selection of directory and display of results? In principle, both are possible. One could hijack Textadept's find_in_file function like other overwritten functions.

As for the working drectory, not sure I understand the question, do you mean the directory Textadept was started from?

Maybe something like

keys.cj = function()
  local working_dir = lfs.currentdir()
  textredux.fs.snapopen(working_dir)
end
ghost commented 7 years ago

Either would be fine. I am not very proficient with lua so I thought I'd ask first before trying to break the code myself. A quick question about the save/save_as functions. These are not replaced when using require('textredux').hijack() correct? I tried using the replacements provided by TR but either I was using them wrong or something about them is broken.

Sorry about the confusion with the working directory thing. I was looking for a way to use quick_open in TR but after using the hijack option it works fine now.

rgieseke commented 7 years ago

It would of course be possible (but likely be a a lot of work) to have the full search box as a Textredux dialog, but if it's just about replacing the "find in files" it should be possible by something like (as a starting point):

ui.find.find_in_files = function(dir, filter)
    local list = textredux.core.list.new(
    'Searching: '..ui.find.find_entry_text, -- list title
    {'one', 'two', 'three'}, -- list items
    function (list, item) -- on selection callback
      ui.statusbar_text = 'You selected ' .. item
    end
  )
   --Show the list.
  list:show()
  ui.goto_view(_VIEWS[1])
end

But maybe it's easier to have a separate 'find in files' function written in Textredux, adapting it from Textadept's.

The save_as is indeed broken (I think it's not possible to "save as" when there is a overlap with the current name) - that's why I removed it from hijack.

ghost commented 7 years ago

How would you start the search after selecting a different directory though? After changing the directory in the default "find in files" function you can only start it by actually clicking the "open" button. In order to make this completely keyboard driven you might need a shortcut to start the actual search.

rgieseke commented 7 years ago

That's true - but basically you can have any kind of keyboard interaction in a Textredux list you want. In the buffer selection list for example you can also close buffers ...

ghost commented 7 years ago

Yeah that's right, the ctrl+d functionality is pretty nice. Would you mind implementing a simple "find in files" function once you have some time to spare?

rgieseke commented 7 years ago

It's definitely something useful to have, also interfacing with tools like ack or ag could be an option ... I'll keep this issue open as a feature request!

ghost commented 7 years ago

I cobbled together some code that accomplishes my goal (keyboard driven FIF search for TR), however it's quite shoddy and should probably not be merged. More like a POC to show it can be done.

ghost commented 7 years ago

I have improved my solution for this to a point where I am quite happy with it so I think this issue can be closed now.

rgieseke commented 7 years ago

Glas you found a solution and thanks for the request -- do you have a link, so others (and I) could try it?

ghost commented 7 years ago

Link I find myself using the find_in_files function much more often now that it is easily accessible without having to click anything.

You can implement save_as in the same way and it seems to work much better than the old TR way but I haven't really tested it much.