Date: Sun, 1 Oct 2000 00:06:58 +0400 From: "Artem Koutchine" <matrix@ipform.ru> To: <questions@FreeBSD.ORG> Cc: <kris@FreeBSD.ORG> Subject: Patch for ee (multi line cut/paste) Message-ID: <021301c02b19$ffebe3c0$0c00a8c0@ipform.ru>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
I have made a light patch for ee which enables it to support cutting and
pasting
blocks of text. It is a bit like emacs cut and paste, when you cut a line it
is added
to a lifo buffer and when you paste full content of the buffer is pasted
into the text.
The buffer is not cleared ever, so there is a key shortcut for clearing the
buffer.
I have also left the old mode as it is and added an option to the setting
menu
which turns new mode on/off. Strings are added also (only for english file).
I also, attached ctrl-s to SAVE_FILE and ctrl-q to clear_clipboard,
modified help texts.
Diff for ee.c and diff for english messages are attached to this message.
I really would like you to make it official, since it really make like
easier when
editing file where a lot fo copy-paste needed. I don't know who to contact,
so
i sent this message to questions, author of ee and the person who last time
edited ee in FreeBSD distribution.
diff against:
ee.c
FreeBSD: /src/usr.bin/ee/ee.c,v 1.16.2.1 2000/07/20 10:35:16
en_US.ISO_8859-1/ee.msg
FreeBSD: src/usr.bin/ee/nls/en_US.USO_8859-1/ee.msg,v 1.6 1999/10/18
16:30:35
Regards,
Artem
[-- Attachment #2 --]
186a187
> int cut_mode = FALSE; /* line cut mode: 0 - classical, 1 - clipboard */
198a200,202
> struct text **clipboard = NULL; /* clipboard for deleted lines */
> int clip_size =0; /* current clopboard size */
>
337a342,344
> void cut_into_clipboard P_((void));
> void paste_from_clipboard P_((void));
> void clear_clipboard P_((void));
353a361
> {"", NULL, NULL, NULL, NULL, -1},
358c366
< char *mode_strings[10];
---
> char *mode_strings[11];
360c368
< #define NUM_MODES_ITEMS 9
---
> #define NUM_MODES_ITEMS 10
431c439
< char *init_strings[20];
---
> char *init_strings[22];
521a530,531
> char *LIFOB_string;
> char *NOLIFOB_string;
528a539,544
> char *clipboard_cut;
> char *clipboard_paste;
> char *clipboard_clear;
> char *clipboard_nocut;
> char *clipboard_empty;
>
1177,1178c1193,1197
< else if (in == 17) /* control q */
< ;
---
> else if (in == 17){ /* control q */
> /* file_op(SAVE_FILE); */
> /* quit(0); */
> clear_clipboard();
> }
1182c1201
< ;
---
> file_op(SAVE_FILE);
1194c1213,1216
< del_line();
---
> if (!cut_mode)
> del_line();
> else
> cut_into_clipboard();
1196c1218,1221
< undel_line();
---
> if (!cut_mode)
> undel_line();
> else
> paste_from_clipboard();
1235c1260,1263
< del_line();
---
> if (!cut_mode)
> del_line();
> else
> cut_into_clipboard();
1237c1265,1269
< undel_line();
---
> if (!cut_mode)
> undel_line();
> else
> paste_from_clipboard();
>
1477c1509,1513
< del_line();
---
> if (!cut_mode)
> del_line();
> else
> cut_into_clipboard();
>
1494c1530,1533
< undel_line();
---
> if (!cut_mode)
> undel_line();
> else
> paste_from_clipboard();
2777a2817,2945
> /*
> Added by Artem Koutchine matrix@chat.ru 2000/09/30
> Cuts text from cursor to the end of line and add it to the
> internal clipboard as new line, so the whole clipboard can be inserted
> later. It works a bit different from emacs is that way that the
> clipboard must be cleared manually
> */
>
> void
> cut_into_clipboard()
> {
> char *dl1;
> char *dl2;
> int tposit;
>
> /* do not cut this line if length is 0 and no next line */
> if (!curr_line->line[0] && !curr_line->next_line){
> wmove(com_win, 0, 0);
> werase(com_win);
> wprintw(com_win, clipboard_nocut);
> wrefresh(com_win);
> return;
> }
>
> /* allocate array item for pointer to deleted line */
> clip_size++;
> clipboard = realloc(clipboard,clip_size*sizeof(int));
> /* allocate space for the deleted line info*/
> clipboard[clip_size-1]=malloc(sizeof(struct text));
> /* allocate space for the line itself */
> clipboard[clip_size-1]->line=malloc(curr_line->line_length);
> dl1 = clipboard[clip_size-1]->line;
> dl2 = point;
> tposit = position;
> while (tposit < curr_line->line_length)
> {
> *dl1 = *dl2;
> dl1++;
> dl2++;
> tposit++;
> }
> clipboard[clip_size-1]->line_length = 1 + tposit - position;
> *dl1 = (char) NULL;
> *point = (char) NULL;
> curr_line->line_length = position;
> wclrtoeol(text_win);
> if (curr_line->next_line != NULL)
> {
> right(FALSE);
> delete(FALSE);
> }
>
> wmove(com_win, 0, 0);
> werase(com_win);
> wprintw(com_win, clipboard_cut, clip_size);
> wrefresh(com_win);
> text_changes = TRUE;
> }
>
>
> /*
> Added by Artem Koutchine matrix@chat.ru 2000/09/30
> Paste all lines stored in clipboard. Leave clipboard as it is.
> */
> void
> paste_from_clipboard()
> {
> char *ud1;
> char *ud2;
> int tposit;
> int i;
> if (clip_size<1){
> wmove(com_win, 0, 0);
> werase(com_win);
> wprintw(com_win, clipboard_empty, clip_size);
> wrefresh(com_win);
> text_changes = TRUE;
> return;
> }
>
> for (i=clip_size-1;i>-1;i--){
> insert_line(TRUE);
> left(TRUE);
> point = resiz_line(clipboard[i]->line_length, curr_line, position);
> curr_line->line_length += clipboard[i]->line_length - 1;
> ud1 = point;
> ud2 = clipboard[i]->line;
> tposit = 1;
> while (tposit < clipboard[i]->line_length)
> {
> tposit++;
> *ud1 = *ud2;
> ud1++;
> ud2++;
> }
> *ud1 = (char) NULL;
> draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
> }
> wmove(com_win, 0, 0);
> werase(com_win);
> wprintw(com_win, clipboard_paste, clip_size);
> wrefresh(com_win);
> text_changes = TRUE;
> }
>
> void
> clear_clipboard()
> {
> int i;
> if (clip_size>0){
> for (i=0;i<clip_size;i++){
> if (clipboard[i] != NULL && clipboard[i]->line != NULL)
> free(clipboard[i]->line);
> if (clipboard[i] != NULL)
> free(clipboard[i]);
> }
> if (clipboard != NULL){
> free(clipboard);
> clipboard=NULL;
> }
>
> clip_size=0;
> }
> wmove(com_win, 0, 0);
> werase(com_win);
> wprintw(com_win, clipboard_clear, clip_size);
> wrefresh(com_win);
> }
>
4064a4233,4236
> else if (compare(str1, LIFOB_string, FALSE))
> cut_mode = TRUE;
> else if (compare(str1, NOLIFOB_string, FALSE))
> cut_mode = FALSE;
4163a4336
> fprintf(init_file, "%s\n", cut_mode ? LIFOB_string : NOLIFOB_string );
4587c4760,4762
< right_margin);
---
> right_margin);
> sprintf(modes_menu[9].item_string, "%s %s", mode_strings[9],
> (cut_mode ? ON : OFF));
4623c4798
< case 8:
---
> case 8:
4632a4808,4811
> case 9:
> cut_mode = !cut_mode;
> break;
>
4915c5094
< help_text[9] = catgetlocal( 44, "^[ (escape) menu ESC-Enter: exit ee ");
---
> help_text[9] = catgetlocal( 44, "^[ (escape) menu ^q clear lifo buffer ESC-Enter: exit ee ");
5052c5231
< modes_menu[9].item_string = catgetlocal( 164, "save editor configuration");
---
> modes_menu[10].item_string = catgetlocal( 164, "save editor configuration");
5062a5242,5250
> clipboard_cut = catgetlocal( 183, "Clipboard size: %d line(s)");
> clipboard_paste = catgetlocal ( 184, "%d line(s) inserted from clipboard");
> clipboard_clear = catgetlocal ( 185, "Clipboard cleared");
> clipboard_nocut = catgetlocal ( 186, "Nothing to cut (maybe lf on the last line?)");
> mode_strings[9] = catgetlocal( 187, "lifo clipboard ");
> LIFOB_string = catgetlocal( 188, "LIFOBUFFER");
> NOLIFOB_string = catgetlocal( 189, "NOLIFOBUFFER");
> clipboard_empty = catgetlocal ( 190, "Clipboard is empty");
>
5112c5300,5302
< init_strings[19] = NULL;
---
> init_strings[19] = LIFOB_string;
> init_strings[20] = NOLIFOB_string;
> init_strings[21] = NULL;
[-- Attachment #3 --]
53c53
< 44 "^[ (escape) menu ESC-Enter: exit ee "
---
> 44 "^[ (escape) menu ^q clear lifp buffer ESC-Enter: exit ee "
182a183,190
> 183 "Clipboard size: %d line(s)"
> 184 "%d line(s) inserted from clipboard"
> 185 "Clipboard cleared"
> 186 "Nothing to cut (maybe lf on the last line?)"
> 187 "lifo clipboard "
> 188 "LIFOBUFFER"
> 189 "NOLIFOBUFFER"
> 190 "Clipboard is empty"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?021301c02b19$ffebe3c0$0c00a8c0>
