[Github-comments] [geany/geany] After reformatting the code via CTRL+A and CTRL+1 ("Send selection to") the cursor position is lost (#1913)

Wojciech M. Zabolotny notifications at xxxxx
Wed Aug 1 13:46:59 UTC 2018


I have prepared a script in Lua, that is able to implement the behavior described in my previous post:

    --[[
    Script that reformats the C source code 
    passing it via external command 
    defined in variable "flt"
    --]]
    local flt = "astyle --indent-classes -Y"
    line, column = geany.rowcol()
    local fn=os.tmpname()
    local fo=assert(io.open(fn,'w'))
    assert(fo:write(geany.text()))
    fo:close()
    local cmd = "cat ".. fn .. " | " .. flt
    local f = assert(io.popen(cmd, 'r'))
    local s = assert(f:read('*a'))
    f:close()
    os.remove(fn)
    geany.text(s)
    position=geany.rowcol(line,column)
    geany.caret(position)

The cursor remains in the original location, or near to it. The only problem is that the position of the text on the screen may be changed (Usually after the processing, the line with the cursor is near to the bottom of the window).
Of course you must activate the "Lua Script" plugin to use the above script.
The script should be placed in `~/.config/geany/plugins/geanylua` directory or `~/.geany/plugins/geanylua` directory  (depending on distribution).
You may also create a `hotkeys.cfg` file in the same directory, and put the filename of the above script in a line in that file. That allows you to assign a keyboard shortcut (e.g., CTRL+ALT+F) to that autoformatting script via `Edit->Preferences->Key bindings->Lua Script` .


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/issues/1913#issuecomment-409580277
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20180801/d1eeba9c/attachment.html>


More information about the Github-comments mailing list