This I believe is my last Lua script request I have for the GeanyLua plugin.
This one although I do have a use for this, is more for learning purpose. I do not think any other users will really find this one useful.
Was wondering if anyone would be willing to provide two Lua scripts that when applied, adds a specified number of blank lines to current document. Basically the equivalent of hitting the "Enter" key over and over “x” amount of times. No dialog boxes need, would just like to be able to just change the number of lines to be added within the Lua script text file itself, if possible.
Two scripts
1.) Add 15 blank lines below line that cursor is currently in
2.) Add 25 blank lines to the bottom of the current document regardless of where cursor is.
Thank You to anyone interested.
Maybe something like this ```lua local function GetEmptyLines(sLE, iLE) local sR = "" for i = 1, iLE do sR = sR .. sLE end return sR end
local aEOL = {"\r\n", "\r", "\n"} local iEOL = geany.scintilla("SCI_GETEOLMODE") local sAdd = GetEmptyLines(aEOL[iEOL + 1], 15)
local iCurPos = geany.caret() local iL, iC = geany.rowcol(iCurPos) iCurPos = geany.scintilla("SCI_GETLINEENDPOSITION", iL - 1) geany.caret(iCurPos) geany.selection(sAdd) ``` ```lua local function GetEmptyLines(sLE, iLE) local sR = "" for i = 1, iLE do sR = sR .. sLE end return sR end
local aEOL = {"\r\n", "\r", "\n"} local iEOL = geany.scintilla("SCI_GETEOLMODE") local sAdd = GetEmptyLines(aEOL[iEOL + 1], 25)
local sTxt = geany.text() geany.text(sTxt .. sAdd) ``` ?
@Skif-off Thank you for providing these tools. I was able to test them out and here are the results.
-----------------------------------------------------
`ADD LINES BELOW CURSOR TOOL` Cursor Would it be possible to have the cursor show up at the top line of those new rows added? So for example if this tool was applied while cursor is in line 1, it adds 15 lines so now document shows 16 total lines and the cursor is at the beginning of line 2. Current behavior is cursor ends up in line 16. Which now when I think about this I actually have a use for this current behavior as well.
-----------------------------------------------------
`ADD LINES TO BOTTOM OF DOCUMENT TOOL` Cursor With this tool the cursor ends up moving automatically to the top of the document after adding the new lines to the bottom. Would it be possible to have
Adding Precision The precision is not important, so if this is not an easy fix it is not a problem, but this tool ends up adding 24 lines. For example if a document contains 15 lines and this tool is applied, the document ends up with 40 lines, which looks right, 15 + 25 = 40 but they are new lines being added so I think would be 41. Might have something to do with what you mentioned about each application using different staring points 0 or 1 “iL - 1)” The other tool might actually be off by 1 as well, but because it moves the cursor it is adding that extra line. Hopefully I am describing this correctly :)
-----------------------------------------------------
I tried looking this up in GeanyLua, strange that there are mentionings of "cursor" when searching the page. I ended up finding "geany.rowcol" but I would not have known this if I didn't remember seeing this in your script. Would think the word "cursor" would be used at least once to describe something in the GeanyLua documentation :)
Thank you again for all your help
In theory: ```lua local function GetEmptyLines(sLE, iLE) local sR = "" for i = 1, iLE do sR = sR .. sLE end return sR end
local aEOL = {"\r\n", "\r", "\n"} local iEOL = geany.scintilla("SCI_GETEOLMODE") local sAdd = GetEmptyLines(aEOL[iEOL + 1], 15)
local iCurPos = geany.caret() local iL, iC = geany.rowcol(iCurPos) iCurPos = geany.scintilla("SCI_GETLINEENDPOSITION", iL - 1) geany.caret(iCurPos) geany.selection(sAdd) geany.caret(iCurPos) ```
```lua local function GetEmptyLines(sLE, iLE) local sR = "" for i = 1, iLE do sR = sR .. sLE end return sR end
local aEOL = {"\r\n", "\r", "\n"} local iEOL = geany.scintilla("SCI_GETEOLMODE") local sAdd = GetEmptyLines(aEOL[iEOL + 1], 25)
local iLines = geany.height() local iCurPos = geany.rowcol(iLines + 1, 0) local sTxt = geany.text() geany.text(sTxt .. sAdd) geany.caret(iCurPos) ```
Adding Precision
Try this version of `GetEmptyLines`, only for tests ```lua local function GetEmptyLines(sLE, iLE) local sR = "" for i = 1, iLE do sR = sR .. "::" .. i .. "::" .. sLE end return sR end ```
Would think the word "cursor" would be used at least once to describe something in the GeanyLua documentation :)
Try "caret" :)
@Skif-off Thank you for working on these tools.
`PRECISION` (I will remove all of this once I know you have read it) Ignore everything I mentioned about precision I think everything works fine. I have removed/cleaned up my posts above about this already. If feel like it, you can remove the precision code you recently mentioned above to eliminate any confusion for future readers of this post. Turns out two things occurred in my tests that confused/generated that off by 1 precision. One of them might be a bug that I will post about.
`CARET TERMINOLOGY` I have tried them before, they add a nice splash of orange to any salad :) I completely overlooked that prefix, I was focusing on `iCurPos` which I figured meant something like Cursor Position, but you would think the word cursor would be used at least once somewhere in the documentation :) I do not think I ever heard it called a “caret” before. This is the symbol I think of when I hear the word caret “^” (I put the symbol in quotes, it is not meant to be a smug bird sticking its beak up at you :)
`CURSOR/CARET` These tools add the blank lines which work great, now I think they are all about cursor/caret position. The tools you have provided offered two different cursor positions then what I was looking for, which worked out because I ended up liking them both :) but this now brings this up to four different versions (just different caret locations). I will provide four categories to hopefully clearify, if still interested in working on this.
Thank You
`ADD LINES BELOW CURSOR - Cursor at Top`
`ADD LINES BELOW CURSOR - Cursor at Bottom` This one is done already, provided with original script you created for this.
`ADD LINES TO BOTTOM OF DOCUMENT - Cursor at Top`
`ADD LINES TO BOTTOM OF DOCUMENT - Cursor at Bottom`
In theory: ```lua local function GetEmptyLines(sLE, iLE) local sR = "" for i = 1, iLE do sR = sR .. sLE end return sR end
local aEOL = {"\r\n", "\r", "\n"} local iEOL = geany.scintilla("SCI_GETEOLMODE") local sAdd = GetEmptyLines(aEOL[iEOL + 1], 15)
local iCurPos = geany.caret() local iL, iC = geany.rowcol(iCurPos) iCurPos = geany.scintilla("SCI_GETLINEENDPOSITION", iL - 1) geany.caret(iCurPos) geany.selection(sAdd) geany.caret(iCurPos + string.len(aEOL[iEOL + 1])) ```
```lua local function GetEmptyLines(sLE, iLE) local sR = "" for i = 1, iLE do sR = sR .. sLE end return sR end
local aEOL = {"\r\n", "\r", "\n"} local iEOL = geany.scintilla("SCI_GETEOLMODE") local sAdd = GetEmptyLines(aEOL[iEOL + 1], 25)
local iLines = geany.height() local sTxt = geany.text() geany.text(sTxt .. sAdd) local iCurPos = geany.rowcol(iLines + 1, 0) geany.caret(iCurPos) ```
It seems, the second script did not work correctly: ```lua local iCurPos = geany.rowcol(iLines + 1, 0) ``` but in this moment, the line with the number `iLines + 1` does not yet exist.
P.S.
I do not think I ever heard it called a “caret” before.
"Cursor" can be either a "text cursor" or a "mouse cursor", maybe this is the reason? In any case, this word is an adequate word and can be seen in the documentation of various projects.
@Skif-off Thank you for continuing to work on these tools. The two new scripts you provided work great. The only one I had a question on was TOOL 4
`TOOL 1` `ADD LINES BELOW CURSOR - Cursor at Top` done
`TOOL 2` `ADD LINES BELOW CURSOR - Cursor at Bottom` done
`TOOL 3` `ADD LINES TO BOTTOM OF DOCUMENT - Cursor at Top` done
`TOOL 4` `ADD LINES TO BOTTOM OF DOCUMENT - Cursor at Bottom` Do you mean that this one cannot be achieved?
I had mentioned I tried combining your TOOL 2 with older version of TOOL 3 and it kind of works. The first time I tested this the document I used for the test had blank lines at the end. I just tested it again on a document that did have text in the last lines and realized that it actually appears that it is more like adding new blank lines in the line number right before the end, because that last line (with or without text in it) actually ends up at the bottom of the document. Again when last line is already blank it gives illusion that it is almost working.
Here is that code ``` local function GetEmptyLines(sLE, iLE) local sR = "" for i = 1, iLE do sR = sR .. sLE end return sR end
local aEOL = {"\r\n", "\r", "\n"} local iEOL = geany.scintilla("SCI_GETEOLMODE") local sAdd = GetEmptyLines(aEOL[iEOL + 1], 10)
local iLines = geany.height() local iCurPos = geany.caret() local iL, iC = geany.rowcol(iCurPos) iCurPos = geany.rowcol(iLines + 1, 0) geany.caret(iCurPos) geany.selection(sAdd) ``` Probably some issues in it, I just added some random lines to the bottom to see what would happen :)
I was wondering, to achieve TOOL 4, would it be possible to add a line to the latest version you just provided for TOOL 3, where after the new blank lines are added, then a new instruction to just move the caret to the bottom line of the document? Only thing I can think of.
Thank you again for your help with this.
_ADD LINES TO BOTTOM OF DOCUMENT - Cursor at Bottom_ For example: ```lua local function GetEmptyLines(sLE, iLE) local sR = "" for i = 1, iLE do sR = sR .. sLE end return sR end
local aEOL = {"\r\n", "\r", "\n"} local iEOL = geany.scintilla("SCI_GETEOLMODE") local sAdd = GetEmptyLines(aEOL[iEOL + 1], 25)
local sTxt = geany.text() geany.text(sTxt .. sAdd) geany.select(geany.length()) ```
github-comments@lists.geany.org