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` .