I was wondering if anyone would be interested in creating / adding on to an existing plugin. I see there is an existing plugin called “Addons” which is for various small features added to Geany, maybe it can be added to this plugin if anyone is interested.
This plugin would allow user to setup a keybinding that would create divider/separator lines when the keybinding is applied. User would be able to setup how they want the divider/separator lines to display visually and because each language has a different "comment" symbol, there would have to be a way for user to be able to set this up per language/file type.
EXAMPLES (plain regular text file which does not require a comment symbol) (not sure if any other users would find this useful, but ability to use this in plain text files for me would be very helpful) txt `######################################`
xml `<!--#################################-->`
lua `--#####################################`
Thank You
@Skif_off Most of my requests for this program unfortunately cannot be solved with Lua, but if interested, this is the only one I have left that might be? I am not sure though.
Would Lua in this case be able to know the language/file type of the currently opened document, in order to know which divider to use?
I / the user would just need a small “template” for how to type in the file type / desired divider.
If something like this could actually be achieved with Lua/GeanyLua plugin, I imagine they would be "if" statements something like
if "txt" use ######################################
if "xml" use <!--#################################-->
if "lua" use --#####################################
Then user would just assign a single keybinding to the Lua script and it would generate a divider based on the file type template/list from the Lua script. As mentioned not sure though, this might be something that would require Geany plugin specifically for something like this?
If interested let me know. Thank you again for all your help :)
@advice2020, you misspelled my nickname :) I didn't receive the notification, I saw it by accident.
Maybe something like this (but I didn't check it) ```lua local aTypes = { {"Lua", ".lua", "--#####################################"}, {"", ".txt", "######################################"}, {"XML", ".xml", "<!--#################################-->"} } local aFI = geany.fileinfo() local sExt, sStr for i = 1, #aTypes do if aTypes[i][1] == aFI.type then sStr = aTypes[i][3] break end end if sStr == nil then sExt = string.lower(aFI.ext) for i = 1, #aTypes do if aTypes[i][2] == sExt then sStr = aTypes[i][3] break end end end if sStr == nil then geany.status("Warning: Unknown file type!") return end local iEOL = geany.scintilla("SCI_GETEOLMODE") local sLE if iEOL == 0 then sLE = "\r\n" elseif iEOL == 1 then sLE = "\r" elseif iEOL == 2 then sLE = "\n" else sLE = "\n" end local iCurPos = geany.caret() local iL, iC = geany.rowcol(iCurPos) iCurPos = geany.scintilla("SCI_POSITIONFROMLINE", iL - 1) geany.select(iCurPos) geany.selection(sStr .. sLE) ``` `aTypes`: ``` {"file type", "file extension", "string"} ``` where "file extension" with dot, "file type" - see `filetype_extensions.conf` ([online](https://github.com/geany/geany/blob/master/data/filetype_extensions.conf)).
@Skif-off When I first saw that you provided a script so soon I was amazed, I was so distracted by the script that I missed what you said at the top. Now I just read the beginning of your post and now I am even more amazed :) You are so helpful I do not even need to spell your name right, you just find me :)
No problem, as mentioned you never have to check it, just the fact that you are willing to provide anything means so much, I have no problem testing things out. Speaking of which, I was able to test this and this works perfectly! Also amazing that you could create something like this and not have to test it out :) Noticed this adds the separator, creating a new line, no matter where the cursor is in the line which is nice.
Thank you so much for this! I will use this one a great deal, really appreciate it. Hopefully other users in the future will find this script useful as well. I will mention a couple of tweaks I came across, below if any future users are interested.
P.S. Skif-off Not sure if you use GeanyLua scripts plugin for your own use but I noticed something that could cause some issues, how it handles keybindings. Not sure if all plugin hotkeys are like this? I will mention in the plugins section and tag you just in case you are interested (hopefully with your name spelled correctly this time :)
For any users in the future, just couple things I came across that might be helpful.
---------------------------------------------------- Sometimes .txt files in Linux do not contain an extension in the filename, the following line will allow you to use this script with those files (remember to add coma at the end of this line if in the middle of your template list). `{"", "", "######################################"}`
---------------------------------------------------- The original script adds separator to the above line where the cursor is located. If for whatever reason you would like the separator to be added to the line below the cursor you can change `iCurPos = geany.scintilla("SCI_POSITIONFROMLINE", iL - 1)` to `iCurPos = geany.scintilla("SCI_POSITIONFROMLINE", iL - 0)` which seems to work. I always like to know little tweaks like this just in case certain situations benefit from one or the other.
----------------------------------------------------
Anyways, hopefully this will be helpful to someone someday.
Not sure what to do with this thread now? The issue has been solved, but if I close it then users will not be able to see it as easily. I guess could keep it open, maybe still valuable to be added to plugin for users who do not use GeanyLua plugin.
@advice2020, I just use the program and see the repositories from time to time.
The original script adds separator to the above line where the cursor is located.
The script moves the cursor to the beginning of the line and inserts the text and the corresponding line ending character(s). The line ending character is appended to the divider separator line before being inserted into the document. I.e. it looks like: the Home button > type the text or Ctrl+V > Enter.
```lua iCurPos = geany.scintilla("SCI_POSITIONFROMLINE", iL - 1) ``` `iCurPos` is the position in the document that corresponds to the beginning of the current line. `iL` is the line with the cursor. "- 1" because GeanyLua counts the line number from 1, but Scintilla counts from 0.
@Skif-off No that worked out great, I am just glad that you were able to see my post, did not even realize I held Shift when hitting "-" when tagging your name :) Again thank you so much for this script, really useful tool.
I think I see what you mean, I just did not describe it properly when I mentioned to other users that it "adds the separator above the line". The way you created the script is how I plan on using it, but as mentioned I always like to have little tweaks that can change little behaviors in scripts likes this. But the advice I shared for other users about changing the "iL - 1" to "iL - 0" is okay right? This appeared to work in my quick tests of it. Hopefully I did not share incorrect information. I know that what I just mentioned above is different than the 1 & 0 information you just shared, but that is good to know that the GeanyLua plugin handles the line numbers differently, because that could be confusing.
Thank You again
P.S. I do not have many ideas for how Lua scripts (GeanyLua plugin) can be used in the context of Geany, trying to think of some. I just posted a minor one in the Geany Discussions section (do not want to link it, but it is 4070) if interested.
github-comments@lists.geany.org