Very nice! I will use this.
I must admit I still find myself too lazy to want to hit Enter afterwards,
though,
since this only selects the lines.
I did think the feature might be useful, though,
so I changed your function to 'select-line' and defined 'copy-line'
to additionally copy the selection and exit copy-mode.
I'm attaching two patches:
- select-line-after-copy.patch can be applied on top of your last patch
- select-and-copy-line.patch can be applied to sf cvs as
of 2011-04-29T22:32:14Z
Note I did put a comment in there..
I'm not sure if there should be an additional "if (sess != NULL)" check in
there
or if the code above ensures it's there.
Please forgive my rusty C code, it's been a while, and it's never been good.
On Fri, Apr 29, 2011 at 2:14 PM, Dave Disser <dis...@gmail.com> wrote:
> Yes, I goofed it up spectacularly! Here's the correct patch.
>
> --Dave
>
>
> On Fri, Apr 29, 2011 at 1:40 PM, Randy Stauner <
> ra...@magnificent-tears.com> wrote:
>
>> is this patch missing something?
>> it looks awfully short and doesn't make sense to me... it just looks like
>> a line was moved up.
>> It doesn't apply to sf cvs and if i just add the line it won't compile.
>> Is there some other patch i need to apply first, or is this for a
>> different branch or is the patch incomplete?
>> Thanks.
>>
>>
>> On Fri, Apr 29, 2011 at 11:13 AM, Dave Disser <dis...@gmail.com> wrote:
>>
>>> I decided I didn't like my kludge. Here's a proper copy-line with
>>> working prefix arg. I also have another patch to use a single function for
>>> begin-selection and copy-selection since I like to have both bound to the
>>> same key, if anyone's interested.
>>>
>>> --Dave
>>>
>>>
>>> On Thu, Apr 28, 2011 at 6:49 PM, Randy Stauner <
>>> ra...@magnificent-tears.com> wrote:
>>>
>>>> thanks for the idea.
>>>> I definitely must applaud the effort.
>>>> you've given me an idea for the 5Y option... if i ever take it any
>>>> further i'll write back.
>>>>
>>>> On Thu, Apr 28, 2011 at 12:55 PM, Dave Disser <dis...@gmail.com> wrote:
>>>>
>>>>> I *just* subscribed now, but I was wrestling with nearly the same
>>>>> problem yesterday. Here's my kludge of rebinding with unprefixed keys.
>>>>>
>>>>> Hard to follow, I know, but the gist is that when entering copy mode it
>>>>> rebinds y and Enter (unprefixed) to source scripts. The scripts in turn
>>>>> do
>>>>> actions and rebind other keys. In order to execute copy-mode actions from
>>>>> the global bindings, it rebinds the copy-mode actions to a temporary key
>>>>> T,
>>>>> then send-keys T to execute the action. I'm sure there are bugs in this
>>>>> if
>>>>> there are ways to exit out of copy mode that I haven't considered.
>>>>>
>>>>> I think the cleaner solution would be to allow the full command parser
>>>>> in all the key tables, but this was easier than making that change to the
>>>>> source.
>>>>>
>>>>> .tmux.conf:
>>>>> bind-key C-c source-file /home/disser/.tmux-copy-mode
>>>>>
>>>>> /home/disser/.tmux-copy-mode:
>>>>> bind-key -n y send-keys 0 \; source
>>>>> "/home/disser/.tmux-begin-selection" \; send-keys "\$"
>>>>> bind-key -n Enter source /home/disser/.tmux-begin-selection
>>>>> bind-key -n q source /home/disser/.tmux-cancel-selection
>>>>> copy-mode
>>>>>
>>>>> /home/disser/.tmux-begin-selection:
>>>>> bind-key -n y source /home/disser/.tmux-copy-selection
>>>>> bind-key -n Enter source /home/disser/.tmux-copy-selection
>>>>> bind-key -t vi-copy T begin-selection
>>>>> send-keys T
>>>>> unbind-key -t vi-copy T
>>>>>
>>>>> /home/disser/.tmux-begin-selection:
>>>>> unbind-key -n y
>>>>> unbind-key -n Enter
>>>>> unbind-key -n q
>>>>> bind-key -t vi-copy T copy-selection
>>>>> send-keys T
>>>>> unbind-key -t vi-copy T
>>>>>
>>>>> /home/disser/.tmux-cancel-selection:
>>>>> unbind-key -n q
>>>>> unbind-key -n Enter
>>>>> unbind-key -n y
>>>>> bind-key -t vi-copy T cancel
>>>>> send-keys T
>>>>> unbind-key -t vi-copy T
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --------------------------------------------------------------------------------------
>>>>> Original message:
>>>>>
>>>>> With:
>>>>> bind-key Y send-keys '^' Space '$' Enter
>>>>> I can hit prefix + Y in copy-mode and get it to copy the line.
>>>>>
>>>>> Not an optimal solution, but an acceptable workaround.
>>>>>
>>>>> Of course now I remember that that sequence used to be repeatable (5Y
>>>>> to copy 5 lines)...
>>>>> that may be a bit trickier to recreate.
>>>>> It might be easier to patch the source and add a copy-line command
>>>>> instead...
>>>>> i'll put that on my todo list. Â :-)
>>>>>
>>>>> Thanks!
>>>>>
>>>>> On Fri, Apr 22, 2011 at 11:53 PM, Micah Cowan <mi...@cowan.name>
>>>>> wrote:
>>>>>
>>>>>> On 04/22/2011 05:26 PM, Randy Stauner wrote:
>>>>>> > I first tried using send-keys (bind-key -t vi-copy send-keys ^ ' ' $
>>>>>> Enter)
>>>>>> > but send-keys isn't a valid command in copy-mode.
>>>>>>
>>>>>> Drop the -t vi-copy; you want to use a normal-map binding so you can
>>>>>> use
>>>>>> the normal-map command (of course, this means you'll need to hit the
>>>>>> prefix before the bound key, or else use -n.
>>>>>>
>>>>>> --
>>>>>> Micah J. Cowan
>>>>>> http://micah.cowan.name/
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> ------------------------------------------------------------------------------
>>>>> WhatsUp Gold - Download Free Network Management Software
>>>>> The most intuitive, comprehensive, and cost-effective network
>>>>> management toolset available today. Delivers lowest initial
>>>>> acquisition cost and overall TCO of any competing solution.
>>>>> http://p.sf.net/sfu/whatsupgold-sd
>>>>> _______________________________________________
>>>>> tmux-users mailing list
>>>>> tmux-users@lists.sourceforge.net
>>>>> https://lists.sourceforge.net/lists/listinfo/tmux-users
>>>>>
>>>>>
>>>>
>>>
>>
>
diff --git a/mode-key.c b/mode-key.c
index eecbf18..bf6a61d 100644
--- a/mode-key.c
+++ b/mode-key.c
@@ -111,6 +111,7 @@ const struct mode_key_cmdstr mode_key_cmdstr_copy[] = {
{ MODEKEYCOPY_SEARCHDOWN, "search-forward" },
{ MODEKEYCOPY_SEARCHREVERSE, "search-reverse" },
{ MODEKEYCOPY_SEARCHUP, "search-backward" },
+ { MODEKEYCOPY_SELECTLINE, "select-line" },
{ MODEKEYCOPY_STARTNUMBERPREFIX, "start-number-prefix" },
{ MODEKEYCOPY_STARTOFLINE, "start-of-line" },
{ MODEKEYCOPY_STARTSELECTION, "begin-selection" },
diff --git a/tmux.h b/tmux.h
index df0d3ee..55c2f34 100644
--- a/tmux.h
+++ b/tmux.h
@@ -485,6 +485,7 @@ enum mode_key_cmd {
MODEKEYCOPY_SEARCHDOWN,
MODEKEYCOPY_SEARCHREVERSE,
MODEKEYCOPY_SEARCHUP,
+ MODEKEYCOPY_SELECTLINE,
MODEKEYCOPY_STARTNUMBERPREFIX,
MODEKEYCOPY_STARTOFLINE,
MODEKEYCOPY_STARTSELECTION,
diff --git a/window-copy.c b/window-copy.c
index af7d018..a0f4d6f 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -501,12 +501,22 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key)
window_copy_redraw_screen(wp);
break;
case MODEKEYCOPY_COPYLINE:
+ // copy-line includes select-line
+ case MODEKEYCOPY_SELECTLINE:
window_copy_cursor_start_of_line(wp);
window_copy_start_selection(wp);
for (; np > 1; np--)
window_copy_cursor_down(wp, 0);
window_copy_cursor_end_of_line(wp);
window_copy_redraw_screen(wp);
+
+ // do we need to check if sess != NULL
+ // or do we know it's not because of the above copying?
+ if (cmd == MODEKEYCOPY_COPYLINE) {
+ window_copy_copy_selection(wp);
+ window_pane_reset_mode(wp);
+ return;
+ }
break;
case MODEKEYCOPY_CLEARSELECTION:
window_copy_clear_selection(wp);
diff --git a/mode-key.c b/mode-key.c
index 89c3e90..bf6a61d 100644
--- a/mode-key.c
+++ b/mode-key.c
@@ -82,6 +82,7 @@ const struct mode_key_cmdstr mode_key_cmdstr_copy[] = {
{ MODEKEYCOPY_BOTTOMLINE, "bottom-line" },
{ MODEKEYCOPY_CANCEL, "cancel" },
{ MODEKEYCOPY_CLEARSELECTION, "clear-selection" },
+ { MODEKEYCOPY_COPYLINE, "copy-line" },
{ MODEKEYCOPY_COPYSELECTION, "copy-selection" },
{ MODEKEYCOPY_DOWN, "cursor-down" },
{ MODEKEYCOPY_ENDOFLINE, "end-of-line" },
@@ -110,6 +111,7 @@ const struct mode_key_cmdstr mode_key_cmdstr_copy[] = {
{ MODEKEYCOPY_SEARCHDOWN, "search-forward" },
{ MODEKEYCOPY_SEARCHREVERSE, "search-reverse" },
{ MODEKEYCOPY_SEARCHUP, "search-backward" },
+ { MODEKEYCOPY_SELECTLINE, "select-line" },
{ MODEKEYCOPY_STARTNUMBERPREFIX, "start-number-prefix" },
{ MODEKEYCOPY_STARTOFLINE, "start-of-line" },
{ MODEKEYCOPY_STARTSELECTION, "begin-selection" },
diff --git a/tmux.h b/tmux.h
index 89ea61b..55c2f34 100644
--- a/tmux.h
+++ b/tmux.h
@@ -454,6 +454,7 @@ enum mode_key_cmd {
MODEKEYCOPY_BOTTOMLINE,
MODEKEYCOPY_CANCEL,
MODEKEYCOPY_CLEARSELECTION,
+ MODEKEYCOPY_COPYLINE,
MODEKEYCOPY_COPYSELECTION,
MODEKEYCOPY_DOWN,
MODEKEYCOPY_ENDOFLINE,
@@ -484,6 +485,7 @@ enum mode_key_cmd {
MODEKEYCOPY_SEARCHDOWN,
MODEKEYCOPY_SEARCHREVERSE,
MODEKEYCOPY_SEARCHUP,
+ MODEKEYCOPY_SELECTLINE,
MODEKEYCOPY_STARTNUMBERPREFIX,
MODEKEYCOPY_STARTOFLINE,
MODEKEYCOPY_STARTSELECTION,
diff --git a/window-copy.c b/window-copy.c
index 123cc21..a0f4d6f 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -500,6 +500,24 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key)
window_copy_start_selection(wp);
window_copy_redraw_screen(wp);
break;
+ case MODEKEYCOPY_COPYLINE:
+ // copy-line includes select-line
+ case MODEKEYCOPY_SELECTLINE:
+ window_copy_cursor_start_of_line(wp);
+ window_copy_start_selection(wp);
+ for (; np > 1; np--)
+ window_copy_cursor_down(wp, 0);
+ window_copy_cursor_end_of_line(wp);
+ window_copy_redraw_screen(wp);
+
+ // do we need to check if sess != NULL
+ // or do we know it's not because of the above copying?
+ if (cmd == MODEKEYCOPY_COPYLINE) {
+ window_copy_copy_selection(wp);
+ window_pane_reset_mode(wp);
+ return;
+ }
+ break;
case MODEKEYCOPY_CLEARSELECTION:
window_copy_clear_selection(wp);
window_copy_redraw_screen(wp);
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users