Here’s a nifty little Lua script for the Geanylua plug-in for the Geany text editor: install it into your ~/.config/geany/plugins/geanylua folder and add the name of the script to ~/.config/geany/plugins/geanylua/hotkeys.cfg to allow binding it to a keyboard shortcut (I use Ctrl-Alt-b, see the Geanylua documentation for more information on assigning keys to scripts).
When the script is activated, it will select the block corresponding to the current code folding level of the line the cursor is on in the active document. E.g. if you place the cursor in the body of a Python function on a line that is on the same indentation level as the first line of the body of the function, it will select the whole function. Also, if the cursor is on the opening line of a block, e.g. a line starting with class, def, if, etc., the script will select the block started by this line.
Note: this strategy does not work well in conjunction with functions preceded by a decorator, since the selection will not include the decorator line. For this reason, the selection is inverted, i.e. it starts at the end of the block and ends at the beginning. This means you can hold down shift and move the cursor backwards, and the selection will extend from the beginning of the block backwards, instead of the end of the selection being shortened as it would be for a normal selection.
Here’s the code of the Lua script as a Gist:
The script makes use of some Scintilla messages, which are only accessible in Geanylua via the geany.scintilla() function. The available messages are documented here.