I was trying to come up with a way to have (two) static keyword find tools in Geany that can be linked to hotkeys. 1.) "Next" - One tool would find/navigate to/select the next instance of that static keyword 2.) "Previous" - The other tool would find/navigate to/select the previous instance of that static keyword
-They would be based on where the cursor/caret is in the document (which line they are in) -If there are no other instances of that keyword found below (or above if using "Previous" tool) then the highlight would just stay in that line and not advance any more to any other lines. -No dialogs would show up.
If this cannot be done specifically within Geany itself, I am trying to have any custom tools be Lua based if possible. In searching the GeanyLua plugin documentation I came across `geany.find` which appears to be able to achieve what I am looking to achieve. I was wondering if anyone would be interested in creating something like this in a Lua script?
`DESIRED TOOL USE` These two tools can obviously be used for any static words but one of the main uses I am looking for are tools to achieve the following. If I add a "separator/divider" line made out of keyboard symbols to a document such as `###################################` I would like to be able to find the next/previous instances of them.
I like some of the Find tools already provided by Geany but you cannot setup a static keyword search. If you try find tool and type in "####" it will literally find each instance of this so it finds "####" multiple times in each divider line, so that will not work.
Thank You
The GeanyLua documentation mentions https://plugins.geany.org/geanylua/geanylua-ref.html
`geany.find ( phrase, start, stop, options )`
Also gives the following example ``` a,b = geany.find( "foobar", 0, geany.length(), {"wholeword","matchcase"} ) if (a) then geany.select(a,b) else geany.message("Search phrase not found.") end ``` I have played around with this and done a little editing, but this just finds the first instance, cannot advance to next / previous more than once. In order to make go to previous keyword, the "start" value has to be greater than the "stop" value.
0 = starting line of document `geany.length ()` = I believe this means the length of the entire document top to bottom
Documentation says `geany.length ()` "Returns the text length of the current document"
You want to search from the current position, but specify "from the beginning of the file to the end of the file" :)
Select text and try something like: forward ```lua local sFind = geany.selection() if sFind == "" then geany.message("Did you forget to select any text?") return end
local iFindStart local iSelS, iSelE = geany.select() if iSelS < iSelE then iFindStart = iSelE else iFindStart = iSelS end
local iS, iE = geany.find(sFind, iFindStart, geany.length(), {"matchcase"}) if iS ~= nil then geany.select(iS, iE) else geany.message("Not found.") end ``` backward ```lua local sFind = geany.selection() if sFind == "" then geany.message("Did you forget to select any text?") return end
local iFindStart local iSelS, iSelE = geany.select() if iSelS < iSelE then iFindStart = iSelS else iFindStart = iSelE end
local iS, iE = geany.find(sFind, iFindStart, 0, {"matchcase"}) if iS ~= nil then geany.select(iS, iE) else geany.message("Not found.") end ```
@Skif-off Thank you for working on this. :) I know I was just using the example given in documentation, I was just seeing if I could even get it to find just one instance. Another confusing thing to me was the use of terminology GeanyLua uses “height” and “length" which typically mean different measurements directions but in this case both are applied to the same “direction” just different purposes, which makes sense once you look into what each of the them achieve. Anyways, thank you again for working on these tools. Ahh the two tools you have provided are slightly different then what I had mentioned, but again you have provided some tools I had not thought of. I like the idea of having versions that are based off "selection" like how the Geany find tool does, I have some use case ideas for these tools you have provided, I like when this happens :)
`REQUEST` Would it be possible to create versions that require the adding of the "static" keyword in the two script tool Lua files themselves?
If so, in the script could you use example keyword, something like `##########################` or `AAAAAAAAAAAAAAAAAAAAAAAAAAAA` in the script so I know what text I need to replace with my own static keyword?
`QUESTION` I was playing around with the case settings I changed `{"matchcase"}` to `{}` Which the GeanyLua documentation for `geany.find` mentions sets this to the default, which works, this did turn off the "matchcase" setting, but do you know if there is an actual term to ignore case?
Thank you again for all these tools you are working on
PS Also because of you I just learned how to add syntax highlighting to code added to my posts, I did not know that was possible until I saw your posts here Thank You :)
Case-sensitive search is usually faster and I added `matchcase` out of habit :) In your case, this option will not interfere, but if you want, you can use an empty value (i.e. `{}`) instead and `geany.find` will ignore the case of characters.
If we try to simplify it as much as possible, we'll probably get something like this: _next_: ```lua local iCurPos = geany.caret()
local iS, iE = geany.find("##########################", iCurPos + 1, geany.length(), {"matchcase"}) if iS ~= nil then geany.select(iS, iE) else geany.message("Not found.") end ``` _previous_:
```lua local iCurPos = geany.caret()
local iS, iE = geany.find("##########################", iCurPos - 1, 0, {"matchcase"}) if iS ~= nil then geany.select(iS, iE) else geany.message("Not found.") end ```
I use `iCurPos + 1` and `iCurPos - 1` so that the search does not capture the text in the current position (when we have "CURSOR##########################" or "##########################CURSOR"). It sounds logical, but I'm not sure if it's really necessary :)
@Skif-off No that is fine, matchcase was also used in the example I mentioned in GeanyLua documentation. Probably will keep, but was just curious if I did this correctly, okay so the `{}` I used was the correct way to turn this off, good to know..... just in case :) Thank you for making this new set of scripts, I tested this out with dividers and some keywords in general and both worked great. Also thank you again for providing the selection based find tools as well, I was not even thinking about how this could also be done with "selection", those are going to be very useful as well.
github-comments@lists.geany.org