Dear all When working with R files, in order to use "Send selection to terminal" one would want to append a newline to the selection. While this can often be done manually in the written code, it can get awkward to do so when in need to execute only one line from the middle of a paragraph.
Could anyone suggest a way to tweak Geany to send to the terminal the selected code with an empty line appended? Thank you Liviu
On Thu, 26 Nov 2009 15:41:30 +0000 Liviu Andronic landronimirc@gmail.com wrote:
Dear all When working with R files, in order to use "Send selection to terminal" one would want to append a newline to the selection. While this can often be done manually in the written code, it can get awkward to do so when in need to execute only one line from the middle of a paragraph.
Could anyone suggest a way to tweak Geany to send to the terminal the selected code with an empty line appended? Thank you
Did try it but can't you just add a \n after %s if needed?
Thansk, Frank
On Sat, 28 Nov 2009 11:09:05 +0100, Frank wrote:
On Thu, 26 Nov 2009 15:41:30 +0000 Liviu Andronic landronimirc@gmail.com wrote:
Dear all When working with R files, in order to use "Send selection to terminal" one would want to append a newline to the selection. While this can often be done manually in the written code, it can get awkward to do so when in need to execute only one line from the middle of a paragraph.
Could anyone suggest a way to tweak Geany to send to the terminal the selected code with an empty line appended? Thank you
Did try it but can't you just add a \n after %s if needed?
Which %s? Liviu is talking about "Send Selection to terminal" which doesn't have a command setting where a %s can be specified. Instead, this feature just sends the selection directly to the VTE.
Regards, Enrico
On Thu, 26 Nov 2009 15:41:30 +0000, Liviu wrote:
Hey,
When working with R files, in order to use "Send selection to terminal" one would want to append a newline to the selection. While this can often be done manually in the written code, it can get awkward to do so when in need to execute only one line from the middle of a paragraph.
Well, I think it's a great feature that line breaks are not added magically. This could do much harm if one selects something like "rm -rf ~" (not the most originally example but still). I really think if the user really wants to execute this selection, he/she should either include the line break or hit Enter/Return manually in the terminal. Automatically executing commands is always risky.
Regards, Enrico
On Sat, 28 Nov 2009 12:24:27 +0100, Enrico wrote:
On Thu, 26 Nov 2009 15:41:30 +0000, Liviu wrote:
Hey,
When working with R files, in order to use "Send selection to terminal" one would want to append a newline to the selection. While this can often be done manually in the written code, it can get awkward to do so when in need to execute only one line from the middle of a paragraph.
Well, I think it's a great feature that line breaks are not added magically. This could do much harm if one selects something like "rm -rf ~" (not the most originally example but still). I really think if the user really wants to execute this selection, he/she should either include the line break or hit Enter/Return manually in the terminal. Automatically executing commands is always risky.
Forgot to mention: Geany actually removes the last trailing \n from the selection to explicitly try to prevent the requested behaviour and I still think this is good and should be kept.
Regards, Enrico
Hello Enrico
On 11/28/09, Enrico Tröger enrico.troeger@uvena.de wrote:
On Sat, 28 Nov 2009 12:24:27 +0100, Enrico wrote: Geany actually removes the last trailing \n from the selection to explicitly try to prevent the requested behaviour and I still think this is good and should be kept.
I understand the reasons for keeping the conservative approach default (the "rm -rf ~" example). However it makes the feature virtually useless in more specific cases (such as evaluating R code). As is, to evaluate the second line of the following dummy R paragraph "2+2 3+3 4+4
"
I would need to: - select "3+3" - send selection to terminal - with the mouse focus the terminal - hit enter - with the mouse hit on the correct part of the document to return editing.
To execute the last line is much easier: - select "4+4" and the following "" empty line - send selection to terminal.
Here the code gets evaluated quickly and I can resume editing immediately. Being unable to easily execute R code is one of the main reasons I cannot use Geany for my R projects.
On 11/28/09, Enrico Tröger enrico.troeger@uvena.de wrote:
On Sat, 28 Nov 2009 11:09:05 +0100, Frank wrote:
Did try it but can't you just add a \n after %s if needed?
Which %s? Liviu is talking about "Send Selection to terminal" which doesn't have a command setting where a %s can be specified. Instead, this feature just sends the selection directly to the VTE.
Would it be possible to make the feature configurable? Keep a default, as is "Send Selection to terminal", but allow the user to configure an additional "Send selection" action with custom behaviour? In the context of R, actions such as "Send current line to terminal" or "Send current paragraph to terminal" (and the ability to assign bindings to them) would be great, but a possible "Send Selection & empty-line to terminal" would already be a boon.
Regards Liviu
Liviu Andronic landronimirc@gmail.com dixit:
I understand the reasons for keeping the conservative approach default (the "rm -rf ~" example). However it makes the feature virtually useless in more specific cases (such as evaluating R code). As is, to evaluate the second line of the following dummy R paragraph "2+2 3+3 4+4
"
I would need to:
- select "3+3"
- send selection to terminal
- with the mouse focus the terminal
- hit enter
- with the mouse hit on the correct part of the document to return editing.
To execute the last line is much easier:
- select "4+4" and the following "" empty line
- send selection to terminal.
If this works, why don't you write the to-be-evaluated code with blank lines from start:
"2+2
3+3
4+4
" Or write it with simple line separators, then search&replace "\n" --> "\n\n" (with "use escape sequences" checked).
Here the code gets evaluated quickly and I can resume editing immediately. Being unable to easily execute R code is one of the main reasons I cannot use Geany for my R projects.
________________________________
la vita e estrany
On 11/29/09, spir denis.spir@free.fr wrote:
If this works, why don't you write the to-be-evaluated code with blank lines from start:
"2+2
3+3
4+4
" Or write it with simple line separators, then search&replace "\n" --> "\n\n" (with "use escape sequences" checked).
Apparently this no longer works in SVN. However, it is not a viable option. The written code can get hundreds of lines long, and would usually be grouped in paragraphs (separated by empty lines). Writing everything one-line-separated would simply render the code unreadable. While adding separators at the end of each line would seem to me an unnecessary, perhaps tedious burden.
Thank you Liviu
On Sat, 28 Nov 2009 22:00:11 +0000, Liviu wrote:
Hello Enrico
On 11/28/09, Enrico Tröger enrico.troeger@uvena.de wrote:
On Sat, 28 Nov 2009 12:24:27 +0100, Enrico wrote: Geany actually removes the last trailing \n from the selection to explicitly try to prevent the requested behaviour and I still think this is good and should be kept.
I understand the reasons for keeping the conservative approach default (the "rm -rf ~" example). However it makes the feature virtually useless in more specific cases (such as evaluating R code). As is, to evaluate the second line of the following dummy R paragraph "2+2 3+3 4+4
"
I would need to:
- select "3+3"
- send selection to terminal
- with the mouse focus the terminal
- hit enter
- with the mouse hit on the correct part of the document to return
editing.
To execute the last line is much easier:
- select "4+4" and the following "" empty line
- send selection to terminal.
Here the code gets evaluated quickly and I can resume editing immediately. Being unable to easily execute R code is one of the main reasons I cannot use Geany for my R projects.
In SVN, you got a new hidden preference:
send_selection_unsafe
It defaults to false, the current behaviour. If set to true, it does not strip trailing newline characters and even add one if not already present. This should pretty much do what you requested :). But be sure that this can be dangerous when you select some arbitary text, by accident hit the keybinding to send the selection to the VTE and it gets executed. If you boom away your system, you are on your own, you can't blame Geany :).
Btw, while I was at it, I fixed a bug where you could actually select some text followed by a multiple empty lines and so Geany executed it because it only stripped the first trailing newline. Now, it strips them all.
Which %s? Liviu is talking about "Send Selection to terminal" which doesn't have a command setting where a %s can be specified. Instead, this feature just sends the selection directly to the VTE.
Would it be possible to make the feature configurable? Keep a default, as is "Send Selection to terminal", but allow the user to configure an additional "Send selection" action with custom behaviour? In the context of R, actions such as "Send current line to terminal" or "Send current paragraph to terminal" (and the ability to assign bindings to them) would be great, but a possible "Send Selection & empty-line to terminal" would already be a boon.
I think this is too heavy for Geany itself, but could and should be easily implemented as a plugin. You just need to do it or find someone who is willing to do :).
Regards, Enrico
On 11/29/09, Enrico Tröger enrico.troeger@uvena.de wrote:
In SVN, you got a new hidden preference:
send_selection_unsafe
Nice. Works fine here.
It defaults to false, the current behaviour. If set to true, it does not strip trailing newline characters and even add one if not already present. This should pretty much do what you requested :).
Yes, a missing newline character is added just fine. :)
But be sure that this can be dangerous when you select some arbitary text, by accident hit the keybinding to send the selection to the VTE and it gets executed. If you boom away your system, you are on your own, you can't blame Geany :).
Would it make sense to implement an additional safety net? By default, on start-up, the terminal tab is hidden (inactive, not focused). Geany could always use the safe-send selection mechanism when the vte is hidden, and use unsafe-send only when vte is visible and send_selection_unsafe=true. Alternatively, Geany could prevent the user from sending a selection while the vte is not visible, and display a status message.
I think this is too heavy for Geany itself, but could and should be easily implemented as a plugin. You just need to do it or find someone who is willing to do :).
What would be a good place to start looking into developing such a plug-in?
Thank you Liviu
On Mon, 30 Nov 2009 11:47:39 +0000, Liviu wrote:
Hey,
But be sure that this can be dangerous when you select some arbitary text, by accident hit the keybinding to send the selection to the VTE and it gets executed. If you boom away your system, you are on your own, you can't blame Geany :).
Would it make sense to implement an additional safety net? By default, on start-up, the terminal tab is hidden (inactive, not focused). Geany could always use the safe-send selection mechanism when the vte is hidden, and use unsafe-send only when vte is visible and send_selection_unsafe=true. Alternatively, Geany could prevent the user from sending a selection while the vte is not visible, and display a status message.
I think this is way too complicated and non-intuitive. Having that option defaulting to false and force the users to explicitly turn it on is good enough. Anyway, if anyone wants to implement this, clean patches would be ok.
I think this is too heavy for Geany itself, but could and should be easily implemented as a plugin. You just need to do it or find someone who is willing to do :).
What would be a good place to start looking into developing such a plug-in?
The very first steps are described in the plugin howto: http://geany.org/manual/reference/howto.html
After that, the general plugin API docs at http://geany.org/manual/reference/ should help.
And in case of any questions, just ask.
Regards, Enrico
On Sat, 28 Nov 2009 12:24:27 +0100 Enrico Tröger enrico.troeger@uvena.de wrote:
When working with R files, in order to use "Send selection to terminal" one would want to append a newline to the selection. While this can often be done manually in the written code, it can get awkward to do so when in need to execute only one line from the middle of a paragraph.
Well, I think it's a great feature that line breaks are not added magically. This could do much harm if one selects something like "rm -rf ~" (not the most originally example but still). I really think if the user really wants to execute this selection, he/she should either include the line break or hit Enter/Return manually in the terminal. Automatically executing commands is always risky.
Personally I think the unchanged selection could be sent to the terminal. After all, the current behaviour allows multiple lines to be sent, so with:
./foo ./bar
./foo is already executed.
I understand the possibly harmful consequences, but I'm not sure they are particularly likely.
Another option would be to popup a dialog to confirm the selection being sent, so the user wouldn't have to focus the terminal and press enter and focus the editor again, just press enter for an 'Execute' button.
Regards, Nick
P.S. I will move this command's menu item to the new Commands menu as it's not really formatting related.