nano-copy-system.diff (4713B)
1 diff --git a/src/cut.c b/src/cut.c 2 index 856f6ff..3b9a9fe 100644 3 --- a/src/cut.c 4 +++ b/src/cut.c 5 @@ -442,6 +442,25 @@ void ingraft_buffer(linestruct *topline) 6 new_magicline(); 7 } 8 9 +void copy_to_system_clipboard(linestruct *somebuffer) 10 +{ 11 + linestruct *buf_copy = copy_buffer(somebuffer); 12 + 13 + FILE *f; 14 + f = fopen("/tmp/nano-copy.txt", "w"); 15 + linestruct* curline = buf_copy; 16 + int i = 0; 17 + while (curline != NULL) { 18 + if (i != 0) fprintf(f, "\n"); 19 + i++; 20 + fprintf(f, "%s", curline->data); 21 + curline = curline->next; 22 + } 23 + 24 + fclose(f); 25 + system("cat /tmp/nano-copy.txt | xclip -selection clipboard"); 26 +} 27 + 28 /* Meld a copy of the given buffer into the current file buffer. */ 29 void copy_from_buffer(linestruct *somebuffer) 30 { 31 @@ -604,7 +623,7 @@ void zap_text(void) 32 } 33 34 /* Make a copy of the marked region, putting it in the cutbuffer. */ 35 -void copy_marked_region(void) 36 +void copy_marked_region(int type) 37 { 38 linestruct *topline, *botline, *afterline; 39 char *was_datastart, saved_byte; 40 @@ -630,7 +649,11 @@ void copy_marked_region(void) 41 was_datastart = topline->data; 42 topline->data += top_x; 43 44 - cutbuffer = copy_buffer(topline); 45 + if (type == SYSTEM) { 46 + copy_to_system_clipboard(topline); 47 + } else { 48 + cutbuffer = copy_buffer(topline); 49 + } 50 51 /* Restore the proper state of the buffer. */ 52 topline->data = was_datastart; 53 @@ -639,6 +662,20 @@ void copy_marked_region(void) 54 } 55 #endif /* !NANO_TINY */ 56 57 + 58 +void copy_system(void) 59 +{ 60 + wipe_statusbar(); 61 + 62 +#ifndef NANO_TINY 63 + if (openfile->mark) { 64 + copy_marked_region(SYSTEM); 65 + statusbar(_("Copied to system clipboard")); 66 + return; 67 + } 68 +#endif 69 +} 70 + 71 /* Copy text from the current buffer into the cutbuffer. The text is either 72 * the marked region, the whole line, the text from cursor to end-of-line, 73 * just the line break, or nothing, depending on mode and cursor position. */ 74 @@ -664,7 +701,7 @@ void copy_text(void) 75 76 #ifndef NANO_TINY 77 if (openfile->mark) { 78 - copy_marked_region(); 79 + copy_marked_region(NORMAL); 80 return; 81 } 82 #endif 83 diff --git a/src/definitions.h b/src/definitions.h 84 index 443a1a0..62c9b6d 100644 85 --- a/src/definitions.h 86 +++ b/src/definitions.h 87 @@ -23,6 +23,9 @@ 88 #include <config.h> 89 #endif 90 91 +#define NORMAL 1 92 +#define SYSTEM 2 93 + 94 #ifdef NEED_XOPEN_SOURCE_EXTENDED 95 #ifndef _XOPEN_SOURCE_EXTENDED 96 #define _XOPEN_SOURCE_EXTENDED 1 97 diff --git a/src/files.c b/src/files.c 98 index 0cc8b9b..f1ba2b6 100644 99 --- a/src/files.c 100 +++ b/src/files.c 101 @@ -1050,7 +1050,7 @@ void execute_command(const char *command) 102 if (ISSET(MULTIBUFFER)) { 103 openfile = openfile->prev; 104 if (openfile->mark) 105 - copy_marked_region(); 106 + copy_marked_region(NORMAL); 107 else 108 whole_buffer = TRUE; 109 } else 110 diff --git a/src/global.c b/src/global.c 111 index 06294f4..3b8c545 100644 112 --- a/src/global.c 113 +++ b/src/global.c 114 @@ -595,6 +595,8 @@ void shortcut_init(void) 115 N_("Cut current line (or marked region) and store it in cutbuffer"); 116 const char *copy_gist = 117 N_("Copy current line (or marked region) and store it in cutbuffer"); 118 + const char *copysystem_gist = 119 + N_("Copy marked region to system clipboard (xclip)"); 120 const char *paste_gist = 121 N_("Paste the contents of cutbuffer at current cursor position"); 122 const char *cursorpos_gist = N_("Display the position of the cursor"); 123 @@ -862,6 +864,8 @@ void shortcut_init(void) 124 N_("Set Mark"), WHENHELP(mark_gist), TOGETHER); 125 add_to_funcs(copy_text, MMAIN, 126 N_("Copy"), WHENHELP(copy_gist), BLANKAFTER); 127 + add_to_funcs(copy_system, MMAIN, 128 + N_("Copy System"), WHENHELP(copysystem_gist), BLANKAFTER); 129 #endif 130 131 add_to_funcs(case_sens_void, MWHEREIS|MREPLACE, 132 @@ -1050,6 +1054,8 @@ void shortcut_init(void) 133 #else 134 add_to_funcs(copy_text, MMAIN, 135 N_("Copy"), WHENHELP(copy_gist), BLANKAFTER); 136 + add_to_funcs(copy_system, MMAIN, 137 + N_("Copy System"), WHENHELP(copysystem_gist), BLANKAFTER); 138 #endif 139 140 add_to_funcs(do_verbatim_input, MMAIN, 141 diff --git a/src/prototypes.h b/src/prototypes.h 142 index 18cd3eb..7182c1f 100644 143 --- a/src/prototypes.h 144 +++ b/src/prototypes.h 145 @@ -274,9 +274,10 @@ void cut_text(void); 146 #ifndef NANO_TINY 147 void cut_till_eof(void); 148 void zap_text(void); 149 -void copy_marked_region(void); 150 +void copy_marked_region(int); 151 #endif 152 void copy_text(void); 153 +void copy_system(void); 154 void paste_text(void); 155 156 /* Most functions in files.c. */ 157 diff --git a/src/rcfile.c b/src/rcfile.c 158 index 59d932a..0526c84 100644 159 --- a/src/rcfile.c 160 +++ b/src/rcfile.c 161 @@ -249,6 +249,8 @@ keystruct *strtosc(const char *input) 162 s->func = cut_text; 163 else if (!strcmp(input, "copy")) 164 s->func = copy_text; 165 + else if (!strcmp(input, "copysystem")) 166 + s->func = copy_system; 167 else if (!strcmp(input, "paste")) 168 s->func = paste_text; 169 #ifndef NANO_TINY