When executing a command wildcard in a snippet is it possible to find the current source of the file being editted, the current line and the current cursor position in that line at the invocation of the snippet?
The filename is set in an environment variable, see the manual, but AFAIK not the line and column.
Although the file name is provided via a variable GEANY_FILENAME, that does not mean that its contents will be equivalent to what is currently in the edit buffer. Snippets are very useful: their effectiveness would be further enhanced if one could manipulate the current text being edited around the current caret position via a command initiated by the command wild card feature.
Would it help if you would have additional ENV variables? Like GEANY_LINE_NUMBER and GEANY_COLUMN_POSITION or something like that?
I guess devs may be reluctant to add something with only an extremely limited use case perhaps (I assume so; I know that from the ruby core team which often asks for a use case when someone suggests a new feature).
Line number is simple, but as has been discussed in these issues before, column position has multiple possible definitions in a UTF-8 document:
. byte number . code point number (most code points are more than one byte) . character number (some characters are more than one code point) . glyph number (some glyphs are more than one code point) . visual column number (some glyphs are zero, narrow, single and double width, and then there is non-monospaced fonts)
The environment variable name therefore should be explicit what it provides. Byte number is the only one easily available.
As the command run from a snippet can only see files stored on the filesystem, they can't see anything in the buffer, so as @philiprbrenan pointed out line/column values may not match the buffer if it has been edited and not saved.
So the usefulness of adding these values would seem limited.
A possible use case from Perl. In the following *s* is a snippet that the user will expand with the tab key:
*s* variableName
which when expanded might produce:
use Data::Dump qw(dump); say "AAAA variableName=", dump($variableName), "\n";
( I spend much time typing such sequences which can be partially but not completed automated with the existing implementation of snippets)
Instead of snippets you could use custom commands, they are sent the current line or selection and the return value replaces it.
github-comments@lists.geany.org