1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
11 * ui.c: functions that handle the user interface.
12 * 1. Keyboard input stuff, and a bit of windowing stuff. These are called
13 * before the machine specific stuff (mch_*) so that we can call the GUI
14 * stuff instead if the GUI is running.
16 * 3. Input buffer stuff.
27 if (gui
.in_use
&& !gui
.dying
&& !gui
.starting
)
31 gui_wait_for_chars(p_wd
);
36 /* Don't output anything in silent mode ("ex -s") unless 'verbose' set */
37 if (!(silent_mode
&& p_verbose
== 0))
40 char_u
*tofree
= NULL
;
42 if (output_conv
.vc_type
!= CONV_NONE
)
44 /* Convert characters from 'encoding' to 'termencoding'. */
45 tofree
= string_convert(&output_conv
, s
, &len
);
54 if (output_conv
.vc_type
!= CONV_NONE
)
61 #if defined(UNIX) || defined(VMS) || defined(PROTO)
63 * When executing an external program, there may be some typed characters that
64 * are not consumed by it. Give them back to ui_inchar() and they are stored
65 * here for the next call.
67 static char_u
*ta_str
= NULL
;
68 static int ta_off
; /* offset for next char to use when ta_str != NULL */
69 static int ta_len
; /* length of ta_str when it's not NULL*/
72 ui_inchar_undo(s
, len
)
81 newlen
+= ta_len
- ta_off
;
87 mch_memmove(new, ta_str
+ ta_off
, (size_t)(ta_len
- ta_off
));
88 mch_memmove(new + ta_len
- ta_off
, s
, (size_t)len
);
92 mch_memmove(new, s
, (size_t)len
);
101 * ui_inchar(): low level input funcion.
102 * Get characters from the keyboard.
103 * Return the number of characters that are available.
104 * If "wtime" == 0 do not wait for characters.
105 * If "wtime" == -1 wait forever for characters.
106 * If "wtime" > 0 wait "wtime" milliseconds for a character.
108 * "tb_change_cnt" is the value of typebuf.tb_change_cnt if "buf" points into
109 * it. When typebuf.tb_change_cnt changes (e.g., when a message is received
110 * from a remote client) "buf" can no longer be used. "tb_change_cnt" is NULL
114 ui_inchar(buf
, maxlen
, wtime
, tb_change_cnt
)
117 long wtime
; /* don't use "time", MIPS cannot handle it */
122 #if defined(FEAT_GUI) && (defined(UNIX) || defined(VMS))
124 * Use the typeahead if there is any.
128 if (maxlen
>= ta_len
- ta_off
)
130 mch_memmove(buf
, ta_str
+ ta_off
, (size_t)ta_len
);
135 mch_memmove(buf
, ta_str
+ ta_off
, (size_t)maxlen
);
142 if (do_profiling
== PROF_YES
&& wtime
!= 0)
146 #ifdef NO_CONSOLE_INPUT
147 /* Don't wait for character input when the window hasn't been opened yet.
148 * Do try reading, this works when redirecting stdin from a file.
149 * Must return something, otherwise we'll loop forever. If we run into
150 * this very often we probably got stuck, exit Vim. */
151 if (no_console_input())
153 static int count
= 0;
156 retval
= mch_inchar(buf
, maxlen
, (wtime
>= 0 && wtime
< 10)
157 ? 10L : wtime
, tb_change_cnt
);
158 if (retval
> 0 || typebuf_changed(tb_change_cnt
) || wtime
>= 0)
161 if (wtime
== -1 && ++count
== 1000)
169 /* If we are going to wait for some time or block... */
170 if (wtime
== -1 || wtime
> 100L)
172 /* ... allow signals to kill us. */
173 (void)vim_handle_signal(SIGNAL_UNBLOCK
);
175 /* ... there is no need for CTRL-C to interrupt something, don't let
176 * it set got_int when it was mapped. */
178 ctrl_c_interrupts
= FALSE
;
184 if (gui_wait_for_chars(wtime
) && !typebuf_changed(tb_change_cnt
))
185 retval
= read_from_input_buf(buf
, (long)maxlen
);
193 retval
= mch_inchar(buf
, maxlen
, wtime
, tb_change_cnt
);
197 if (wtime
== -1 || wtime
> 100L)
198 /* block SIGHUP et al. */
199 (void)vim_handle_signal(SIGNAL_BLOCK
);
201 ctrl_c_interrupts
= TRUE
;
203 #ifdef NO_CONSOLE_INPUT
207 if (do_profiling
== PROF_YES
&& wtime
!= 0)
214 * return non-zero if a character is available
223 return input_available();
227 # ifdef NO_CONSOLE_INPUT
228 if (no_console_input())
231 return mch_char_avail();
238 * Delay for the given number of milliseconds. If ignoreinput is FALSE then we
239 * cancel the delay if a key is hit.
242 ui_delay(msec
, ignoreinput
)
247 if (gui
.in_use
&& !ignoreinput
)
248 gui_wait_for_chars(msec
);
252 #if defined(FEAT_GUI_MACVIM)
253 /* MacVim tries to be conservative with flushing, but when Vim takes a
254 * nap it really must flush (else timed error messages might not appear
255 * etc.). Note that gui_mch_wait_for_chars() already does force a
256 * flush, so only do it here. */
258 gui_macvim_force_flush();
260 mch_delay(msec
, ignoreinput
);
265 * If the machine has job control, use it to suspend the program,
266 * otherwise fake it by starting a new shell.
267 * When running the GUI iconify the window.
282 #if !defined(UNIX) || !defined(SIGTSTP) || defined(PROTO) || defined(__BEOS__)
284 * When the OS can't really suspend, call this function to start a shell.
285 * This is never called in the GUI.
291 EMSG(_(e_shellempty
));
294 MSG_PUTS(_("new shell started\n"));
301 * Try to get the current Vim shell size. Put the result in Rows and Columns.
302 * Use the new sizes as defaults for 'columns' and 'lines'.
303 * Return OK when size could be determined, FAIL otherwise.
312 retval
= gui_get_shellsize();
315 retval
= mch_get_shellsize();
319 /* adjust the default for 'lines' and 'columns' */
322 set_number_default("lines", Rows
);
323 set_number_default("columns", Columns
);
329 * Set the size of the Vim shell according to Rows and Columns, if possible.
330 * The gui_set_shellsize() or mch_set_shellsize() function will try to set the
331 * new size. If this is not possible, it will adjust Rows and Columns.
335 ui_set_shellsize(mustset
)
336 int mustset
; /* set by the user */
340 gui_set_shellsize(mustset
,
353 * Called when Rows and/or Columns changed. Adjust scroll region and mouse
359 if (full_screen
&& !exiting
)
381 /*****************************************************************************
382 * Functions for copying and pasting text between applications.
383 * This is always included in a GUI version, but may also be included when the
384 * clipboard and mouse is available to a terminal version such as xterm.
385 * Note: there are some more functions in ops.c that handle selection stuff.
387 * Also note that the majority of functions here deal with the X 'primary'
388 * (visible - for Visual mode use) selection, and only that. There are no
389 * versions of these for the 'clipboard' selection, as Visual mode has no use
393 #if defined(FEAT_CLIPBOARD) || defined(PROTO)
396 * Selection stuff using Visual mode, for cutting and pasting text to other
401 * Call this to initialise the clipboard. Pass it FALSE if the clipboard code
402 * is included, but the clipboard can not be used, or TRUE if the clipboard can
403 * be used. Eg unix may call this with FALSE, then call it again with TRUE if
415 cb
->available
= can_use
;
421 cb
->state
= SELECT_CLEARED
;
423 if (cb
== &clip_plus
)
430 * Check whether the VIsual area has changed, and if so try to become the owner
431 * of the selection, and free any old converted selection we may still have
432 * lying around. If the VIsual mode has ended, make a copy of what was
433 * selected so we can still give it to others. Will probably have to make sure
434 * this is called whenever VIsual mode is ended.
437 clip_update_selection()
441 /* If visual mode is only due to a redo command ("."), then ignore it */
442 if (!redo_VIsual_busy
&& VIsual_active
&& (State
& NORMAL
))
444 if (lt(VIsual
, curwin
->w_cursor
))
447 end
= curwin
->w_cursor
;
450 end
.col
+= (*mb_ptr2len
)(ml_get_cursor()) - 1;
455 start
= curwin
->w_cursor
;
458 if (!equalpos(clip_star
.start
, start
)
459 || !equalpos(clip_star
.end
, end
)
460 || clip_star
.vmode
!= VIsual_mode
)
462 clip_clear_selection();
463 clip_star
.start
= start
;
465 clip_star
.vmode
= VIsual_mode
;
466 clip_free_selection(&clip_star
);
467 clip_own_selection(&clip_star
);
468 clip_gen_set_selection(&clip_star
);
474 clip_own_selection(cbd
)
478 * Also want to check somehow that we are reading from the keyboard rather
479 * than a mapping etc.
481 if (!cbd
->owned
&& cbd
->available
)
483 cbd
->owned
= (clip_gen_own_selection(cbd
) == OK
);
485 if (cbd
== &clip_star
)
487 /* May have to show a different kind of highlighting for the
488 * selected area. There is no specific redraw command for this,
489 * just redraw all windows on the current buffer. */
491 && (get_real_state() == VISUAL
492 || get_real_state() == SELECTMODE
)
494 && hl_attr(HLF_V
) != hl_attr(HLF_VNC
))
495 redraw_curbuf_later(INVERTED_ALL
);
502 clip_lose_selection(cbd
)
506 int was_owned
= cbd
->owned
;
508 int visual_selection
= (cbd
== &clip_star
);
510 clip_free_selection(cbd
);
512 if (visual_selection
)
513 clip_clear_selection();
514 clip_gen_lose_selection(cbd
);
516 if (visual_selection
)
518 /* May have to show a different kind of highlighting for the selected
519 * area. There is no specific redraw command for this, just redraw all
520 * windows on the current buffer. */
522 && (get_real_state() == VISUAL
523 || get_real_state() == SELECTMODE
)
525 && hl_attr(HLF_V
) != hl_attr(HLF_VNC
))
527 update_curbuf(INVERTED_ALL
);
533 gui_update_cursor(TRUE
, FALSE
);
541 clip_copy_selection()
543 if (VIsual_active
&& (State
& NORMAL
) && clip_star
.available
)
545 if (clip_isautosel())
546 clip_update_selection();
547 clip_free_selection(&clip_star
);
548 clip_own_selection(&clip_star
);
550 clip_get_selection(&clip_star
);
551 clip_gen_set_selection(&clip_star
);
556 * Called when Visual mode is ended: update the selection.
561 if (clip_isautosel())
562 clip_copy_selection();
566 * Return TRUE if automatic selection of Visual area is desired.
573 gui
.in_use
? (vim_strchr(p_go
, GO_ASEL
) != NULL
) :
580 * Stuff for general mouse selection, without using Visual mode.
583 static int clip_compare_pos
__ARGS((int row1
, int col1
, int row2
, int col2
));
584 static void clip_invert_area
__ARGS((int, int, int, int, int how
));
585 static void clip_invert_rectangle
__ARGS((int row
, int col
, int height
, int width
, int invert
));
586 static void clip_get_word_boundaries
__ARGS((VimClipboard
*, int, int));
587 static int clip_get_line_end
__ARGS((int));
588 static void clip_update_modeless_selection
__ARGS((VimClipboard
*, int, int,
591 /* flags for clip_invert_area() */
594 #define CLIP_TOGGLE 3
597 * Start, continue or end a modeless selection. Used when editing the
598 * command-line and in the cmdline window.
601 clip_modeless(button
, is_click
, is_drag
)
608 repeat
= ((clip_star
.mode
== SELECT_MODE_CHAR
609 || clip_star
.mode
== SELECT_MODE_LINE
)
610 && (mod_mask
& MOD_MASK_2CLICK
))
611 || (clip_star
.mode
== SELECT_MODE_WORD
612 && (mod_mask
& MOD_MASK_3CLICK
));
613 if (is_click
&& button
== MOUSE_RIGHT
)
615 /* Right mouse button: If there was no selection, start one.
616 * Otherwise extend the existing selection. */
617 if (clip_star
.state
== SELECT_CLEARED
)
618 clip_start_selection(mouse_col
, mouse_row
, FALSE
);
619 clip_process_selection(button
, mouse_col
, mouse_row
, repeat
);
622 clip_start_selection(mouse_col
, mouse_row
, repeat
);
625 /* Don't try extending a selection if there isn't one. Happens when
626 * button-down is in the cmdline and them moving mouse upwards. */
627 if (clip_star
.state
!= SELECT_CLEARED
)
628 clip_process_selection(button
, mouse_col
, mouse_row
, repeat
);
631 clip_process_selection(MOUSE_RELEASE
, mouse_col
, mouse_row
, FALSE
);
635 * Compare two screen positions ala strcmp()
638 clip_compare_pos(row1
, col1
, row2
, col2
)
644 if (row1
> row2
) return(1);
645 if (row1
< row2
) return(-1);
646 if (col1
> col2
) return(1);
647 if (col1
< col2
) return(-1);
652 * Start the selection
655 clip_start_selection(col
, row
, repeated_click
)
660 VimClipboard
*cb
= &clip_star
;
662 if (cb
->state
== SELECT_DONE
)
663 clip_clear_selection();
665 row
= check_row(row
);
666 col
= check_col(col
);
668 col
= mb_fix_col(col
, row
);
671 cb
->start
.lnum
= row
;
674 cb
->origin_row
= (short_u
)cb
->start
.lnum
;
675 cb
->state
= SELECT_IN_PROGRESS
;
679 if (++cb
->mode
> SELECT_MODE_LINE
)
680 cb
->mode
= SELECT_MODE_CHAR
;
683 cb
->mode
= SELECT_MODE_CHAR
;
686 /* clear the cursor until the selection is made */
693 case SELECT_MODE_CHAR
:
694 cb
->origin_start_col
= cb
->start
.col
;
695 cb
->word_end_col
= clip_get_line_end((int)cb
->start
.lnum
);
698 case SELECT_MODE_WORD
:
699 clip_get_word_boundaries(cb
, (int)cb
->start
.lnum
, cb
->start
.col
);
700 cb
->origin_start_col
= cb
->word_start_col
;
701 cb
->origin_end_col
= cb
->word_end_col
;
703 clip_invert_area((int)cb
->start
.lnum
, cb
->word_start_col
,
704 (int)cb
->end
.lnum
, cb
->word_end_col
, CLIP_SET
);
705 cb
->start
.col
= cb
->word_start_col
;
706 cb
->end
.col
= cb
->word_end_col
;
709 case SELECT_MODE_LINE
:
710 clip_invert_area((int)cb
->start
.lnum
, 0, (int)cb
->start
.lnum
,
711 (int)Columns
, CLIP_SET
);
713 cb
->end
.col
= Columns
;
717 cb
->prev
= cb
->start
;
719 #ifdef DEBUG_SELECTION
720 printf("Selection started at (%u,%u)\n", cb
->start
.lnum
, cb
->start
.col
);
725 * Continue processing the selection
728 clip_process_selection(button
, col
, row
, repeated_click
)
732 int_u repeated_click
;
734 VimClipboard
*cb
= &clip_star
;
736 int slen
= 1; /* cursor shape width */
738 if (button
== MOUSE_RELEASE
)
740 /* Check to make sure we have something selected */
741 if (cb
->start
.lnum
== cb
->end
.lnum
&& cb
->start
.col
== cb
->end
.col
)
745 gui_update_cursor(FALSE
, FALSE
);
747 cb
->state
= SELECT_CLEARED
;
751 #ifdef DEBUG_SELECTION
752 printf("Selection ended: (%u,%u) to (%u,%u)\n", cb
->start
.lnum
,
753 cb
->start
.col
, cb
->end
.lnum
, cb
->end
.col
);
758 gui
.in_use
? (vim_strchr(p_go
, GO_ASELML
) != NULL
) :
761 clip_copy_modeless_selection(FALSE
);
764 gui_update_cursor(FALSE
, FALSE
);
767 cb
->state
= SELECT_DONE
;
771 row
= check_row(row
);
772 col
= check_col(col
);
774 col
= mb_fix_col(col
, row
);
777 if (col
== (int)cb
->prev
.col
&& row
== cb
->prev
.lnum
&& !repeated_click
)
781 * When extending the selection with the right mouse button, swap the
782 * start and end if the position is before half the selection
784 if (cb
->state
== SELECT_DONE
&& button
== MOUSE_RIGHT
)
787 * If the click is before the start, or the click is inside the
788 * selection and the start is the closest side, set the origin to the
789 * end of the selection.
791 if (clip_compare_pos(row
, col
, (int)cb
->start
.lnum
, cb
->start
.col
) < 0
792 || (clip_compare_pos(row
, col
,
793 (int)cb
->end
.lnum
, cb
->end
.col
) < 0
794 && (((cb
->start
.lnum
== cb
->end
.lnum
795 && cb
->end
.col
- col
> col
- cb
->start
.col
))
796 || ((diff
= (cb
->end
.lnum
- row
) -
797 (row
- cb
->start
.lnum
)) > 0
798 || (diff
== 0 && col
< (int)(cb
->start
.col
+
799 cb
->end
.col
) / 2)))))
801 cb
->origin_row
= (short_u
)cb
->end
.lnum
;
802 cb
->origin_start_col
= cb
->end
.col
- 1;
803 cb
->origin_end_col
= cb
->end
.col
;
807 cb
->origin_row
= (short_u
)cb
->start
.lnum
;
808 cb
->origin_start_col
= cb
->start
.col
;
809 cb
->origin_end_col
= cb
->start
.col
;
811 if (cb
->mode
== SELECT_MODE_WORD
&& !repeated_click
)
812 cb
->mode
= SELECT_MODE_CHAR
;
815 /* set state, for when using the right mouse button */
816 cb
->state
= SELECT_IN_PROGRESS
;
818 #ifdef DEBUG_SELECTION
819 printf("Selection extending to (%d,%d)\n", row
, col
);
822 if (repeated_click
&& ++cb
->mode
> SELECT_MODE_LINE
)
823 cb
->mode
= SELECT_MODE_CHAR
;
827 case SELECT_MODE_CHAR
:
828 /* If we're on a different line, find where the line ends */
829 if (row
!= cb
->prev
.lnum
)
830 cb
->word_end_col
= clip_get_line_end(row
);
832 /* See if we are before or after the origin of the selection */
833 if (clip_compare_pos(row
, col
, cb
->origin_row
,
834 cb
->origin_start_col
) >= 0)
836 if (col
>= (int)cb
->word_end_col
)
837 clip_update_modeless_selection(cb
, cb
->origin_row
,
838 cb
->origin_start_col
, row
, (int)Columns
);
842 if (has_mbyte
&& mb_lefthalve(row
, col
))
845 clip_update_modeless_selection(cb
, cb
->origin_row
,
846 cb
->origin_start_col
, row
, col
+ slen
);
853 && mb_lefthalve(cb
->origin_row
, cb
->origin_start_col
))
856 if (col
>= (int)cb
->word_end_col
)
857 clip_update_modeless_selection(cb
, row
, cb
->word_end_col
,
858 cb
->origin_row
, cb
->origin_start_col
+ slen
);
860 clip_update_modeless_selection(cb
, row
, col
,
861 cb
->origin_row
, cb
->origin_start_col
+ slen
);
865 case SELECT_MODE_WORD
:
866 /* If we are still within the same word, do nothing */
867 if (row
== cb
->prev
.lnum
&& col
>= (int)cb
->word_start_col
868 && col
< (int)cb
->word_end_col
&& !repeated_click
)
871 /* Get new word boundaries */
872 clip_get_word_boundaries(cb
, row
, col
);
874 /* Handle being after the origin point of selection */
875 if (clip_compare_pos(row
, col
, cb
->origin_row
,
876 cb
->origin_start_col
) >= 0)
877 clip_update_modeless_selection(cb
, cb
->origin_row
,
878 cb
->origin_start_col
, row
, cb
->word_end_col
);
880 clip_update_modeless_selection(cb
, row
, cb
->word_start_col
,
881 cb
->origin_row
, cb
->origin_end_col
);
884 case SELECT_MODE_LINE
:
885 if (row
== cb
->prev
.lnum
&& !repeated_click
)
888 if (clip_compare_pos(row
, col
, cb
->origin_row
,
889 cb
->origin_start_col
) >= 0)
890 clip_update_modeless_selection(cb
, cb
->origin_row
, 0, row
,
893 clip_update_modeless_selection(cb
, row
, 0, cb
->origin_row
,
901 #ifdef DEBUG_SELECTION
902 printf("Selection is: (%u,%u) to (%u,%u)\n", cb
->start
.lnum
,
903 cb
->start
.col
, cb
->end
.lnum
, cb
->end
.col
);
909 * Called after an Expose event to redraw the selection
912 clip_redraw_selection(x
, y
, w
, h
)
918 VimClipboard
*cb
= &clip_star
;
919 int row1
, col1
, row2
, col2
;
924 if (cb
->state
== SELECT_CLEARED
)
927 row1
= check_row(Y_2_ROW(y
));
928 col1
= check_col(X_2_COL(x
));
929 row2
= check_row(Y_2_ROW(y
+ h
- 1));
930 col2
= check_col(X_2_COL(x
+ w
- 1));
932 /* Limit the rows that need to be re-drawn */
933 if (cb
->start
.lnum
> row1
)
934 row1
= cb
->start
.lnum
;
935 if (cb
->end
.lnum
< row2
)
938 /* Look at each row that might need to be re-drawn */
939 for (row
= row1
; row
<= row2
; row
++)
941 /* For the first selection row, use the starting selection column */
942 if (row
== cb
->start
.lnum
)
943 start
= cb
->start
.col
;
947 /* For the last selection row, use the ending selection column */
948 if (row
== cb
->end
.lnum
)
960 gui_mch_invert_rectangle(row
, start
, 1, end
- start
);
965 # if defined(FEAT_GUI) || defined(PROTO)
967 * Redraw part of the selection if character at "row,col" is inside of it.
968 * Only used for the GUI.
971 clip_may_redraw_selection(row
, col
, len
)
978 if (clip_star
.state
!= SELECT_CLEARED
979 && row
>= clip_star
.start
.lnum
980 && row
<= clip_star
.end
.lnum
)
982 if (row
== clip_star
.start
.lnum
&& start
< (int)clip_star
.start
.col
)
983 start
= clip_star
.start
.col
;
984 if (row
== clip_star
.end
.lnum
&& end
> (int)clip_star
.end
.col
)
985 end
= clip_star
.end
.col
;
987 clip_invert_area(row
, start
, row
, end
, 0);
993 * Called from outside to clear selected region from the display
996 clip_clear_selection()
998 VimClipboard
*cb
= &clip_star
;
1000 if (cb
->state
== SELECT_CLEARED
)
1003 clip_invert_area((int)cb
->start
.lnum
, cb
->start
.col
, (int)cb
->end
.lnum
,
1004 cb
->end
.col
, CLIP_CLEAR
);
1005 cb
->state
= SELECT_CLEARED
;
1009 * Clear the selection if any lines from "row1" to "row2" are inside of it.
1012 clip_may_clear_selection(row1
, row2
)
1015 if (clip_star
.state
== SELECT_DONE
1016 && row2
>= clip_star
.start
.lnum
1017 && row1
<= clip_star
.end
.lnum
)
1018 clip_clear_selection();
1022 * Called before the screen is scrolled up or down. Adjusts the line numbers
1023 * of the selection. Call with big number when clearing the screen.
1026 clip_scroll_selection(rows
)
1027 int rows
; /* negative for scroll down */
1031 if (clip_star
.state
== SELECT_CLEARED
)
1034 lnum
= clip_star
.start
.lnum
- rows
;
1036 clip_star
.start
.lnum
= 0;
1037 else if (lnum
>= screen_Rows
) /* scrolled off of the screen */
1038 clip_star
.state
= SELECT_CLEARED
;
1040 clip_star
.start
.lnum
= lnum
;
1042 lnum
= clip_star
.end
.lnum
- rows
;
1043 if (lnum
< 0) /* scrolled off of the screen */
1044 clip_star
.state
= SELECT_CLEARED
;
1045 else if (lnum
>= screen_Rows
)
1046 clip_star
.end
.lnum
= screen_Rows
- 1;
1048 clip_star
.end
.lnum
= lnum
;
1052 * Invert a region of the display between a starting and ending row and column
1054 * CLIP_CLEAR: undo inversion
1055 * CLIP_SET: set inversion
1056 * CLIP_TOGGLE: set inversion if pos1 < pos2, undo inversion otherwise.
1057 * 0: invert (GUI only).
1060 clip_invert_area(row1
, col1
, row2
, col2
, how
)
1069 if (how
== CLIP_SET
)
1072 /* Swap the from and to positions so the from is always before */
1073 if (clip_compare_pos(row1
, col1
, row2
, col2
) > 0)
1075 int tmp_row
, tmp_col
;
1084 else if (how
== CLIP_TOGGLE
)
1087 /* If all on the same line, do it the easy way */
1090 clip_invert_rectangle(row1
, col1
, 1, col2
- col1
, invert
);
1094 /* Handle a piece of the first line */
1097 clip_invert_rectangle(row1
, col1
, 1, (int)Columns
- col1
, invert
);
1101 /* Handle a piece of the last line */
1102 if (col2
< Columns
- 1)
1104 clip_invert_rectangle(row2
, 0, 1, col2
, invert
);
1108 /* Handle the rectangle thats left */
1110 clip_invert_rectangle(row1
, 0, row2
- row1
+ 1, (int)Columns
,
1116 * Invert or un-invert a rectangle of the screen.
1117 * "invert" is true if the result is inverted.
1120 clip_invert_rectangle(row
, col
, height
, width
, invert
)
1129 # ifdef FEAT_GUI_MACVIM
1130 gui_mch_invert_rectangle(row
, col
, height
, width
, invert
);
1132 gui_mch_invert_rectangle(row
, col
, height
, width
);
1136 screen_draw_rectangle(row
, col
, height
, width
, invert
);
1140 * Copy the currently selected area into the '*' register so it will be
1141 * available for pasting.
1142 * When "both" is TRUE also copy to the '+' register.
1146 clip_copy_modeless_selection(both
)
1155 int add_newline_flag
= FALSE
;
1160 int row1
= clip_star
.start
.lnum
;
1161 int col1
= clip_star
.start
.col
;
1162 int row2
= clip_star
.end
.lnum
;
1163 int col2
= clip_star
.end
.col
;
1165 /* Can't use ScreenLines unless initialized */
1166 if (ScreenLines
== NULL
)
1170 * Make sure row1 <= row2, and if row1 == row2 that col1 <= col2.
1174 row
= row1
; row1
= row2
; row2
= row
;
1175 row
= col1
; col1
= col2
; col2
= row
;
1177 else if (row1
== row2
&& col1
> col2
)
1179 row
= col1
; col1
= col2
; col2
= row
;
1182 /* correct starting point for being on right halve of double-wide char */
1183 p
= ScreenLines
+ LineOffset
[row1
];
1185 col1
-= (*mb_head_off
)(p
, p
+ col1
);
1186 else if (enc_utf8
&& p
[col1
] == 0)
1190 /* Create a temporary buffer for storing the text */
1191 len
= (row2
- row1
+ 1) * Columns
+ 1;
1194 len
*= 2; /* max. 2 bytes per display cell */
1198 buffer
= lalloc((long_u
)len
, TRUE
);
1199 if (buffer
== NULL
) /* out of memory */
1202 /* Process each row in the selection */
1203 for (bufp
= buffer
, row
= row1
; row
<= row2
; row
++)
1215 line_end_col
= clip_get_line_end(row
);
1217 /* See if we need to nuke some trailing whitespace */
1218 if (end_col
>= Columns
&& (row
< row2
|| end_col
> line_end_col
))
1220 /* Get rid of trailing whitespace */
1221 end_col
= line_end_col
;
1222 if (end_col
< start_col
)
1223 end_col
= start_col
;
1225 /* If the last line extended to the end, add an extra newline */
1227 add_newline_flag
= TRUE
;
1230 /* If after the first row, we need to always add a newline */
1231 if (row
> row1
&& !LineWraps
[row
- 1])
1234 if (row
< screen_Rows
&& end_col
<= screen_Columns
)
1241 p
= ScreenLines
+ LineOffset
[row
];
1242 for (i
= start_col
; i
< end_col
; ++i
)
1243 if (enc_dbcs
== DBCS_JPNU
&& p
[i
] == 0x8e)
1245 /* single-width double-byte char */
1247 *bufp
++ = ScreenLines2
[LineOffset
[row
] + i
];
1252 if (MB_BYTE2LEN(p
[i
]) == 2)
1262 off
= LineOffset
[row
];
1263 for (i
= start_col
; i
< end_col
; ++i
)
1265 /* The base character is either in ScreenLinesUC[] or
1267 if (ScreenLinesUC
[off
+ i
] == 0)
1268 *bufp
++ = ScreenLines
[off
+ i
];
1271 bufp
+= utf_char2bytes(ScreenLinesUC
[off
+ i
], bufp
);
1272 for (ci
= 0; ci
< Screen_mco
; ++ci
)
1274 /* Add a composing character. */
1275 if (ScreenLinesC
[ci
][off
+ i
] == 0)
1277 bufp
+= utf_char2bytes(ScreenLinesC
[ci
][off
+ i
],
1281 /* Skip right halve of double-wide character. */
1282 if (ScreenLines
[off
+ i
+ 1] == 0)
1289 STRNCPY(bufp
, ScreenLines
+ LineOffset
[row
] + start_col
,
1290 end_col
- start_col
);
1291 bufp
+= end_col
- start_col
;
1296 /* Add a newline at the end if the selection ended there */
1297 if (add_newline_flag
)
1300 /* First cleanup any old selection and become the owner. */
1301 clip_free_selection(&clip_star
);
1302 clip_own_selection(&clip_star
);
1304 /* Yank the text into the '*' register. */
1305 clip_yank_selection(MCHAR
, buffer
, (long)(bufp
- buffer
), &clip_star
);
1307 /* Make the register contents available to the outside world. */
1308 clip_gen_set_selection(&clip_star
);
1313 /* Do the same for the '+' register. */
1314 clip_free_selection(&clip_plus
);
1315 clip_own_selection(&clip_plus
);
1316 clip_yank_selection(MCHAR
, buffer
, (long)(bufp
- buffer
), &clip_plus
);
1317 clip_gen_set_selection(&clip_plus
);
1324 * Find the starting and ending positions of the word at the given row and
1325 * column. Only white-separated words are recognized here.
1327 #define CHAR_CLASS(c) (c <= ' ' ? ' ' : vim_iswordc(c))
1330 clip_get_word_boundaries(cb
, row
, col
)
1342 if (row
>= screen_Rows
|| col
>= screen_Columns
|| ScreenLines
== NULL
)
1345 p
= ScreenLines
+ LineOffset
[row
];
1347 /* Correct for starting in the right halve of a double-wide char */
1349 col
-= dbcs_screen_head_off(p
, p
+ col
);
1350 else if (enc_utf8
&& p
[col
] == 0)
1353 start_class
= CHAR_CLASS(p
[col
]);
1356 for ( ; temp_col
> 0; temp_col
--)
1359 && (mboff
= dbcs_screen_head_off(p
, p
+ temp_col
- 1)) > 0)
1363 if (CHAR_CLASS(p
[temp_col
- 1]) != start_class
1365 && !(enc_utf8
&& p
[temp_col
- 1] == 0)
1369 cb
->word_start_col
= temp_col
;
1372 for ( ; temp_col
< screen_Columns
; temp_col
++)
1374 if (enc_dbcs
!= 0 && dbcs_ptr2cells(p
+ temp_col
) == 2)
1378 if (CHAR_CLASS(p
[temp_col
]) != start_class
1380 && !(enc_utf8
&& p
[temp_col
] == 0)
1384 cb
->word_end_col
= temp_col
;
1388 * Find the column position for the last non-whitespace character on the given
1392 clip_get_line_end(row
)
1397 if (row
>= screen_Rows
|| ScreenLines
== NULL
)
1399 for (i
= screen_Columns
; i
> 0; i
--)
1400 if (ScreenLines
[LineOffset
[row
] + i
- 1] != ' ')
1406 * Update the currently selected region by adding and/or subtracting from the
1407 * beginning or end and inverting the changed area(s).
1410 clip_update_modeless_selection(cb
, row1
, col1
, row2
, col2
)
1417 /* See if we changed at the beginning of the selection */
1418 if (row1
!= cb
->start
.lnum
|| col1
!= (int)cb
->start
.col
)
1420 clip_invert_area(row1
, col1
, (int)cb
->start
.lnum
, cb
->start
.col
,
1422 cb
->start
.lnum
= row1
;
1423 cb
->start
.col
= col1
;
1426 /* See if we changed at the end of the selection */
1427 if (row2
!= cb
->end
.lnum
|| col2
!= (int)cb
->end
.col
)
1429 clip_invert_area((int)cb
->end
.lnum
, cb
->end
.col
, row2
, col2
,
1431 cb
->end
.lnum
= row2
;
1437 clip_gen_own_selection(cbd
)
1440 #ifdef FEAT_XCLIPBOARD
1443 return clip_mch_own_selection(cbd
);
1446 return clip_xterm_own_selection(cbd
);
1448 return clip_mch_own_selection(cbd
);
1453 clip_gen_lose_selection(cbd
)
1456 #ifdef FEAT_XCLIPBOARD
1459 clip_mch_lose_selection(cbd
);
1462 clip_xterm_lose_selection(cbd
);
1464 clip_mch_lose_selection(cbd
);
1469 clip_gen_set_selection(cbd
)
1472 #ifdef FEAT_XCLIPBOARD
1475 clip_mch_set_selection(cbd
);
1478 clip_xterm_set_selection(cbd
);
1480 clip_mch_set_selection(cbd
);
1485 clip_gen_request_selection(cbd
)
1488 #ifdef FEAT_XCLIPBOARD
1491 clip_mch_request_selection(cbd
);
1494 clip_xterm_request_selection(cbd
);
1496 clip_mch_request_selection(cbd
);
1500 #endif /* FEAT_CLIPBOARD */
1502 /*****************************************************************************
1503 * Functions that handle the input buffer.
1504 * This is used for any GUI version, and the unix terminal version.
1506 * For Unix, the input characters are buffered to be able to check for a
1507 * CTRL-C. This should be done with signals, but I don't know how to do that
1508 * in a portable way for a tty in RAW mode.
1510 * For the client-server code in the console the received keys are put in the
1514 #if defined(USE_INPUT_BUF) || defined(PROTO)
1517 * Internal typeahead buffer. Includes extra space for long key code
1518 * descriptions which would otherwise overflow. The buffer is considered full
1519 * when only this extra space (or part of it) remains.
1521 #if defined(FEAT_SUN_WORKSHOP) || defined(FEAT_NETBEANS_INTG) \
1522 || defined(FEAT_CLIENTSERVER)
1524 * Sun WorkShop and NetBeans stuff debugger commands into the input buffer.
1525 * This requires a larger buffer...
1526 * (Madsen) Go with this for remote input as well ...
1528 # define INBUFLEN 4096
1530 # define INBUFLEN 250
1533 static char_u inbuf
[INBUFLEN
+ MAX_KEY_CODE_LEN
];
1534 static int inbufcount
= 0; /* number of chars in inbuf[] */
1537 * vim_is_input_buf_full(), vim_is_input_buf_empty(), add_to_input_buf(), and
1538 * trash_input_buf() are functions for manipulating the input buffer. These
1539 * are used by the gui_* calls when a GUI is used to handle keyboard input.
1543 vim_is_input_buf_full()
1545 return (inbufcount
>= INBUFLEN
);
1549 vim_is_input_buf_empty()
1551 return (inbufcount
== 0);
1554 #if defined(FEAT_OLE) || defined(PROTO)
1556 vim_free_in_input_buf()
1558 return (INBUFLEN
- inbufcount
);
1562 #if defined(FEAT_GUI_GTK) || defined(PROTO)
1564 vim_used_in_input_buf()
1570 #if defined(FEAT_EVAL) || defined(FEAT_EX_EXTRA) || defined(PROTO)
1572 * Return the current contents of the input buffer and make it empty.
1573 * The returned pointer must be passed to set_input_buf() later.
1580 /* We use a growarray to store the data pointer and the length. */
1581 gap
= (garray_T
*)alloc((unsigned)sizeof(garray_T
));
1584 /* Add one to avoid a zero size. */
1585 gap
->ga_data
= alloc((unsigned)inbufcount
+ 1);
1586 if (gap
->ga_data
!= NULL
)
1587 mch_memmove(gap
->ga_data
, inbuf
, (size_t)inbufcount
);
1588 gap
->ga_len
= inbufcount
;
1591 return (char_u
*)gap
;
1595 * Restore the input buffer with a pointer returned from get_input_buf().
1596 * The allocated memory is freed, this only works once!
1602 garray_T
*gap
= (garray_T
*)p
;
1606 if (gap
->ga_data
!= NULL
)
1608 mch_memmove(inbuf
, gap
->ga_data
, gap
->ga_len
);
1609 inbufcount
= gap
->ga_len
;
1610 vim_free(gap
->ga_data
);
1617 #if defined(FEAT_GUI) || defined(FEAT_MOUSE_GPM) \
1618 || defined(FEAT_XCLIPBOARD) || defined(VMS) \
1619 || defined(FEAT_SNIFF) || defined(FEAT_CLIENTSERVER) \
1622 * Add the given bytes to the input buffer
1623 * Special keys start with CSI. A real CSI must have been translated to
1624 * CSI KS_EXTRA KE_CSI. K_SPECIAL doesn't require translation.
1627 add_to_input_buf(s
, len
)
1631 if (inbufcount
+ len
> INBUFLEN
+ MAX_KEY_CODE_LEN
)
1632 return; /* Shouldn't ever happen! */
1634 #ifdef FEAT_HANGULIN
1635 if ((State
& (INSERT
|CMDLINE
)) && hangul_input_state_get())
1636 if ((len
= hangul_input_process(s
, len
)) == 0)
1641 inbuf
[inbufcount
++] = *s
++;
1645 #if ((defined(FEAT_XIM) || defined(FEAT_DND)) && defined(FEAT_GUI_GTK)) \
1646 || defined(FEAT_GUI_MSWIN) \
1647 || defined(FEAT_GUI_MAC) \
1648 || (defined(FEAT_MBYTE) && defined(FEAT_MBYTE_IME)) \
1649 || (defined(FEAT_GUI) && (!defined(USE_ON_FLY_SCROLL) \
1650 || defined(FEAT_MENU))) \
1653 * Add "str[len]" to the input buffer while escaping CSI bytes.
1656 add_to_input_buf_csi(char_u
*str
, int len
)
1661 for (i
= 0; i
< len
; ++i
)
1663 add_to_input_buf(str
+ i
, 1);
1666 /* Turn CSI into K_CSI. */
1668 buf
[1] = (int)KE_CSI
;
1669 add_to_input_buf(buf
, 2);
1675 #if defined(FEAT_HANGULIN) || defined(PROTO)
1677 push_raw_key (s
, len
)
1682 inbuf
[inbufcount
++] = *s
++;
1686 #if defined(FEAT_GUI) || defined(FEAT_EVAL) || defined(FEAT_EX_EXTRA) \
1688 /* Remove everything from the input buffer. Called when ^C is found */
1697 * Read as much data from the input buffer as possible up to maxlen, and store
1699 * Note: this function used to be Read() in unix.c
1702 read_from_input_buf(buf
, maxlen
)
1706 if (inbufcount
== 0) /* if the buffer is empty, fill it */
1707 fill_input_buf(TRUE
);
1708 if (maxlen
> inbufcount
)
1709 maxlen
= inbufcount
;
1710 mch_memmove(buf
, inbuf
, (size_t)maxlen
);
1711 inbufcount
-= maxlen
;
1713 mch_memmove(inbuf
, inbuf
+ maxlen
, (size_t)inbufcount
);
1719 fill_input_buf(exit_on_error
)
1722 #if defined(UNIX) || defined(OS2) || defined(VMS) || defined(MACOS_X_UNIX)
1725 static int did_read_something
= FALSE
;
1727 static char_u
*rest
= NULL
; /* unconverted rest of previous read */
1728 static int restlen
= 0;
1735 # ifdef NO_CONSOLE_INPUT
1736 /* Don't use the GUI input when the window hasn't been opened yet.
1737 * We get here from ui_inchar() when we should try reading from stdin. */
1738 && !no_console_input()
1746 #if defined(UNIX) || defined(OS2) || defined(VMS) || defined(MACOS_X_UNIX)
1747 if (vim_is_input_buf_full())
1750 * Fill_input_buf() is only called when we really need a character.
1751 * If we can't get any, but there is some in the buffer, just return.
1752 * If we can't get any, and there isn't any in the buffer, we give up and
1757 * On the BeBox version (for now), all input is secretly performed within
1758 * beos_select() which is called from RealWaitForChar().
1760 while (!vim_is_input_buf_full() && RealWaitForChar(read_cmd_fd
, 0, NULL
))
1767 if (sniff_request_waiting
)
1769 add_to_input_buf((char_u
*)"\233sniff",6); /* results in K_SNIFF */
1770 sniff_request_waiting
= 0;
1771 want_sniff_request
= 0;
1779 /* Use remainder of previous call, starts with an invalid character
1780 * that may become valid when reading more. */
1781 if (restlen
> INBUFLEN
- inbufcount
)
1782 unconverted
= INBUFLEN
- inbufcount
;
1784 unconverted
= restlen
;
1785 mch_memmove(inbuf
+ inbufcount
, rest
, unconverted
);
1786 if (unconverted
== restlen
)
1793 restlen
-= unconverted
;
1794 mch_memmove(rest
, rest
+ unconverted
, restlen
);
1796 inbufcount
+= unconverted
;
1802 len
= 0; /* to avoid gcc warning */
1803 for (try = 0; try < 100; ++try)
1808 len
= read(read_cmd_fd
,
1810 (char *)inbuf
+ inbufcount
, (size_t)((INBUFLEN
- inbufcount
)
1812 / input_conv
.vc_factor
1816 ) /* avoid syntax highlight error */
1819 if (len
> 0 || got_int
)
1822 * If reading stdin results in an error, continue reading stderr.
1823 * This helps when using "foo | xargs vim".
1825 if (!did_read_something
&& !isatty(read_cmd_fd
) && read_cmd_fd
== 0)
1829 /* We probably set the wrong file descriptor to raw mode. Switch
1830 * back to cooked mode, use another descriptor and set the mode to
1832 settmode(TMODE_COOK
);
1834 /* Use stderr for stdin, also works for shell commands. */
1838 read_cmd_fd
= 2; /* read from stderr instead of stdin */
1846 if (len
<= 0 && !got_int
)
1849 did_read_something
= TRUE
;
1852 /* Interrupted, pretend a CTRL-C was typed. */
1860 * May perform conversion on the input characters.
1861 * Include the unconverted rest of the previous call.
1862 * If there is an incomplete char at the end it is kept for the next
1863 * time, reading more bytes should make conversion possible.
1864 * Don't do this in the unlikely event that the input buffer is too
1865 * small ("rest" still contains more bytes).
1867 if (input_conv
.vc_type
!= CONV_NONE
)
1869 inbufcount
-= unconverted
;
1870 len
= convert_input_safe(inbuf
+ inbufcount
,
1871 len
+ unconverted
, INBUFLEN
- inbufcount
,
1872 rest
== NULL
? &rest
: NULL
, &restlen
);
1878 * if a CTRL-C was typed, remove it from the buffer and set got_int
1880 if (inbuf
[inbufcount
] == 3 && ctrl_c_interrupts
)
1882 /* remove everything typed before the CTRL-C */
1883 mch_memmove(inbuf
, inbuf
+ inbufcount
, (size_t)(len
+ 1));
1890 #endif /* UNIX or OS2 or VMS*/
1892 #endif /* defined(UNIX) || defined(FEAT_GUI) || defined(OS2) || defined(VMS) */
1895 * Exit because of an input read error.
1900 if (silent_mode
) /* Normal way to exit for "ex -s" */
1902 STRCPY(IObuff
, _("Vim: Error reading input, exiting...\n"));
1906 #if defined(CURSOR_SHAPE) || defined(PROTO)
1908 * May update the shape of the cursor.
1915 gui_update_cursor_later();
1918 term_cursor_shape();
1920 # ifdef MCH_CURSOR_SHAPE
1921 mch_update_cursor();
1926 #if defined(FEAT_CLIPBOARD) || defined(FEAT_GUI) || defined(FEAT_RIGHTLEFT) \
1929 * Check bounds for column number
1937 if (col
>= (int)screen_Columns
)
1938 return (int)screen_Columns
- 1;
1943 * Check bounds for row number
1951 if (row
>= (int)screen_Rows
)
1952 return (int)screen_Rows
- 1;
1958 * Stuff for the X clipboard. Shared between VMS and Unix.
1961 #if defined(FEAT_XCLIPBOARD) || defined(FEAT_GUI_X11) || defined(PROTO)
1962 # include <X11/Xatom.h>
1963 # include <X11/Intrinsic.h>
1966 * Open the application context (if it hasn't been opened yet).
1967 * Used for Motif and Athena GUI and the xterm clipboard.
1972 if (app_context
== NULL
)
1974 XtToolkitInitialize();
1975 app_context
= XtCreateApplicationContext();
1979 static Atom vim_atom
; /* Vim's own special selection format */
1981 static Atom vimenc_atom
; /* Vim's extended selection format */
1983 static Atom compound_text_atom
;
1984 static Atom text_atom
;
1985 static Atom targets_atom
;
1988 x11_setup_atoms(dpy
)
1991 vim_atom
= XInternAtom(dpy
, VIM_ATOM_NAME
, False
);
1993 vimenc_atom
= XInternAtom(dpy
, VIMENC_ATOM_NAME
,False
);
1995 compound_text_atom
= XInternAtom(dpy
, "COMPOUND_TEXT", False
);
1996 text_atom
= XInternAtom(dpy
, "TEXT", False
);
1997 targets_atom
= XInternAtom(dpy
, "TARGETS", False
);
1998 clip_star
.sel_atom
= XA_PRIMARY
;
1999 clip_plus
.sel_atom
= XInternAtom(dpy
, "CLIPBOARD", False
);
2003 * X Selection stuff, for cutting and pasting text to other windows.
2006 static void clip_x11_request_selection_cb
__ARGS((Widget
, XtPointer
, Atom
*, Atom
*, XtPointer
, long_u
*, int *));
2010 clip_x11_request_selection_cb(w
, success
, sel_atom
, type
, value
, length
,
2023 char **text_list
= NULL
;
2026 char_u
*tmpbuf
= NULL
;
2029 if (*sel_atom
== clip_plus
.sel_atom
)
2034 if (value
== NULL
|| *length
== 0)
2036 clip_free_selection(cbd
); /* ??? [what's the query?] */
2037 *(int *)success
= FALSE
;
2040 motion_type
= MCHAR
;
2041 p
= (char_u
*)value
;
2043 if (*type
== vim_atom
)
2050 else if (*type
== vimenc_atom
)
2063 /* If the encoding of the text is different from 'encoding', attempt
2065 conv
.vc_type
= CONV_NONE
;
2066 convert_setup(&conv
, enc
, p_enc
);
2067 if (conv
.vc_type
!= CONV_NONE
)
2069 convlen
= len
; /* Need to use an int here. */
2070 tmpbuf
= string_convert(&conv
, p
, &convlen
);
2074 convert_setup(&conv
, NULL
, NULL
);
2079 else if (*type
== compound_text_atom
|| (
2083 *type
== text_atom
))
2085 XTextProperty text_prop
;
2089 text_prop
.value
= (unsigned char *)value
;
2090 text_prop
.encoding
= *type
;
2091 text_prop
.format
= *format
;
2092 text_prop
.nitems
= STRLEN(value
);
2093 status
= XmbTextPropertyToTextList(X_DISPLAY
, &text_prop
,
2094 &text_list
, &n_text
);
2095 if (status
!= Success
|| n_text
< 1)
2097 *(int *)success
= FALSE
;
2100 p
= (char_u
*)text_list
[0];
2103 clip_yank_selection(motion_type
, p
, (long)len
, cbd
);
2105 if (text_list
!= NULL
)
2106 XFreeStringList(text_list
);
2110 XtFree((char *)value
);
2111 *(int *)success
= TRUE
;
2115 clip_x11_request_selection(myShell
, dpy
, cbd
)
2138 case 0: type
= vimenc_atom
; break;
2140 case 1: type
= vim_atom
; break;
2141 case 2: type
= compound_text_atom
; break;
2142 case 3: type
= text_atom
; break;
2143 default: type
= XA_STRING
;
2145 XtGetSelectionValue(myShell
, cbd
->sel_atom
, type
,
2146 clip_x11_request_selection_cb
, (XtPointer
)&success
, CurrentTime
);
2148 /* Make sure the request for the selection goes out before waiting for
2153 * Wait for result of selection request, otherwise if we type more
2154 * characters, then they will appear before the one that requested the
2155 * paste! Don't worry, we will catch up with any other events later.
2159 if (XCheckTypedEvent(dpy
, SelectionNotify
, &event
))
2161 if (XCheckTypedEvent(dpy
, SelectionRequest
, &event
))
2162 /* We may get a SelectionRequest here and if we don't handle
2163 * it we hang. KDE klipper does this, for example. */
2164 XtDispatchEvent(&event
);
2166 /* Do we need this? Probably not. */
2169 /* Bernhard Walle solved a slow paste response in an X terminal by
2170 * adding: usleep(10000); here. */
2173 /* this is where clip_x11_request_selection_cb() is actually called */
2174 XtDispatchEvent(&event
);
2180 /* Final fallback position - use the X CUT_BUFFER0 store */
2181 buffer
= (char_u
*)XFetchBuffer(dpy
, &nbytes
, 0);
2185 clip_yank_selection(MCHAR
, buffer
, (long)nbytes
, cbd
);
2186 XFree((void *)buffer
);
2188 verb_msg((char_u
*)_("Used CUT_BUFFER0 instead of empty selection"));
2192 static Boolean clip_x11_convert_selection_cb
__ARGS((Widget
, Atom
*, Atom
*, Atom
*, XtPointer
*, long_u
*, int *));
2196 clip_x11_convert_selection_cb(w
, sel_atom
, target
, type
, value
, length
, format
)
2211 if (*sel_atom
== clip_plus
.sel_atom
)
2217 return False
; /* Shouldn't ever happen */
2219 /* requestor wants to know what target types we support */
2220 if (*target
== targets_atom
)
2224 if ((array
= (Atom
*)XtMalloc((unsigned)(sizeof(Atom
) * 6))) == NULL
)
2226 *value
= (XtPointer
)array
;
2228 array
[i
++] = XA_STRING
;
2229 array
[i
++] = targets_atom
;
2231 array
[i
++] = vimenc_atom
;
2233 array
[i
++] = vim_atom
;
2234 array
[i
++] = text_atom
;
2235 array
[i
++] = compound_text_atom
;
2237 /* This used to be: *format = sizeof(Atom) * 8; but that caused
2238 * crashes on 64 bit machines. (Peter Derr) */
2244 if ( *target
!= XA_STRING
2246 && *target
!= vimenc_atom
2248 && *target
!= vim_atom
2249 && *target
!= text_atom
2250 && *target
!= compound_text_atom
)
2253 clip_get_selection(cbd
);
2254 motion_type
= clip_convert_selection(&string
, length
, cbd
);
2255 if (motion_type
< 0)
2258 /* For our own format, the first byte contains the motion type */
2259 if (*target
== vim_atom
)
2263 /* Our own format with encoding: motion 'encoding' NUL text */
2264 if (*target
== vimenc_atom
)
2265 *length
+= STRLEN(p_enc
) + 2;
2268 *value
= XtMalloc((Cardinal
)*length
);
2269 result
= (char_u
*)*value
;
2276 if (*target
== XA_STRING
)
2278 mch_memmove(result
, string
, (size_t)(*length
));
2281 else if (*target
== compound_text_atom
2282 || *target
== text_atom
)
2284 XTextProperty text_prop
;
2285 char *string_nt
= (char *)alloc((unsigned)*length
+ 1);
2287 /* create NUL terminated string which XmbTextListToTextProperty wants */
2288 mch_memmove(string_nt
, string
, (size_t)*length
);
2289 string_nt
[*length
] = NUL
;
2290 XmbTextListToTextProperty(X_DISPLAY
, (char **)&string_nt
, 1,
2291 XCompoundTextStyle
, &text_prop
);
2292 vim_free(string_nt
);
2293 XtFree(*value
); /* replace with COMPOUND text */
2294 *value
= (XtPointer
)(text_prop
.value
); /* from plain text */
2295 *length
= text_prop
.nitems
;
2296 *type
= compound_text_atom
;
2300 else if (*target
== vimenc_atom
)
2302 int l
= STRLEN(p_enc
);
2304 result
[0] = motion_type
;
2305 STRCPY(result
+ 1, p_enc
);
2306 mch_memmove(result
+ l
+ 2, string
, (size_t)(*length
- l
- 2));
2307 *type
= vimenc_atom
;
2313 result
[0] = motion_type
;
2314 mch_memmove(result
+ 1, string
, (size_t)(*length
- 1));
2317 *format
= 8; /* 8 bits per char */
2322 static void clip_x11_lose_ownership_cb
__ARGS((Widget
, Atom
*));
2326 clip_x11_lose_ownership_cb(w
, sel_atom
)
2330 if (*sel_atom
== clip_plus
.sel_atom
)
2331 clip_lose_selection(&clip_plus
);
2333 clip_lose_selection(&clip_star
);
2337 clip_x11_lose_selection(myShell
, cbd
)
2341 XtDisownSelection(myShell
, cbd
->sel_atom
, CurrentTime
);
2345 clip_x11_own_selection(myShell
, cbd
)
2349 if (XtOwnSelection(myShell
, cbd
->sel_atom
, CurrentTime
,
2350 clip_x11_convert_selection_cb
, clip_x11_lose_ownership_cb
,
2357 * Send the current selection to the clipboard. Do nothing for X because we
2358 * will fill in the selection only when requested by another app.
2362 clip_x11_set_selection(cbd
)
2368 #if defined(FEAT_MOUSE) || defined(PROTO)
2371 * Move the cursor to the specified row and column on the screen.
2372 * Change current window if necessary. Returns an integer with the
2373 * CURSOR_MOVED bit set if the cursor has moved or unset otherwise.
2375 * The MOUSE_FOLD_CLOSE bit is set when clicked on the '-' in a fold column.
2376 * The MOUSE_FOLD_OPEN bit is set when clicked on the '+' in a fold column.
2378 * If flags has MOUSE_FOCUS, then the current window will not be changed, and
2379 * if the mouse is outside the window then the text will scroll, or if the
2380 * mouse was previously on a status line, then the status line may be dragged.
2382 * If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the
2383 * cursor is moved unless the cursor was on a status line.
2384 * This function returns one of IN_UNKNOWN, IN_BUFFER, IN_STATUS_LINE or
2385 * IN_SEP_LINE depending on where the cursor was clicked.
2387 * If flags has MOUSE_MAY_STOP_VIS, then Visual mode will be stopped, unless
2388 * the mouse is on the status line of the same window.
2390 * If flags has MOUSE_DID_MOVE, nothing is done if the mouse didn't move since
2393 * If flags has MOUSE_SETPOS, nothing is done, only the current position is
2397 jump_to_mouse(flags
, inclusive
, which_button
)
2399 int *inclusive
; /* used for inclusive operator, can be NULL */
2400 int which_button
; /* MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE */
2402 static int on_status_line
= 0; /* #lines below bottom of window */
2403 #ifdef FEAT_VERTSPLIT
2404 static int on_sep_line
= 0; /* on separator right of window */
2406 static int prev_row
= -1;
2407 static int prev_col
= -1;
2408 static win_T
*dragwin
= NULL
; /* window being dragged */
2409 static int did_drag
= FALSE
; /* drag was noticed */
2411 win_T
*wp
, *old_curwin
;
2415 int row
= mouse_row
;
2416 int col
= mouse_col
;
2421 mouse_past_bottom
= FALSE
;
2422 mouse_past_eol
= FALSE
;
2424 if (flags
& MOUSE_RELEASED
)
2426 /* On button release we may change window focus if positioned on a
2427 * status line and no dragging happened. */
2428 if (dragwin
!= NULL
&& !did_drag
)
2429 flags
&= ~(MOUSE_FOCUS
| MOUSE_DID_MOVE
);
2434 if ((flags
& MOUSE_DID_MOVE
)
2435 && prev_row
== mouse_row
2436 && prev_col
== mouse_col
)
2439 /* before moving the cursor for a left click which is NOT in a status
2440 * line, stop Visual mode */
2442 return IN_STATUS_LINE
;
2443 #ifdef FEAT_VERTSPLIT
2448 if (flags
& MOUSE_MAY_STOP_VIS
)
2451 redraw_curbuf_later(INVERTED
); /* delete the inversion */
2454 #if defined(FEAT_CMDWIN) && defined(FEAT_CLIPBOARD)
2455 /* Continue a modeless selection in another window. */
2456 if (cmdwin_type
!= 0 && row
< W_WINROW(curwin
))
2457 return IN_OTHER_WIN
;
2462 prev_row
= mouse_row
;
2463 prev_col
= mouse_col
;
2465 if (flags
& MOUSE_SETPOS
)
2466 goto retnomove
; /* ugly goto... */
2469 /* Remember the character under the mouse, it might be a '-' or '+' in the
2471 if (row
>= 0 && row
< Rows
&& col
>= 0 && col
<= Columns
2472 && ScreenLines
!= NULL
)
2473 mouse_char
= ScreenLines
[LineOffset
[row
] + col
];
2478 old_curwin
= curwin
;
2479 old_cursor
= curwin
->w_cursor
;
2481 if (!(flags
& MOUSE_FOCUS
))
2483 if (row
< 0 || col
< 0) /* check if it makes sense */
2487 /* find the window where the row is in */
2488 wp
= mouse_find_win(&row
, &col
);
2494 * winpos and height may change in win_enter()!
2496 if (row
>= wp
->w_height
) /* In (or below) status line */
2498 on_status_line
= row
- wp
->w_height
+ 1;
2503 #ifdef FEAT_VERTSPLIT
2504 if (col
>= wp
->w_width
) /* In separator line */
2506 on_sep_line
= col
- wp
->w_width
+ 1;
2512 /* The rightmost character of the status line might be a vertical
2513 * separator character if there is no connecting window to the right. */
2514 if (on_status_line
&& on_sep_line
)
2516 if (stl_connected(wp
))
2524 /* Before jumping to another buffer, or moving the cursor for a left
2525 * click, stop Visual mode. */
2527 && (wp
->w_buffer
!= curwin
->w_buffer
2529 # ifdef FEAT_VERTSPLIT
2532 # ifdef FEAT_FOLDING
2534 # ifdef FEAT_RIGHTLEFT
2535 wp
->w_p_rl
? col
< W_WIDTH(wp
) - wp
->w_p_fdc
:
2539 + (cmdwin_type
== 0 && wp
== curwin
? 0 : 1)
2543 && (flags
& MOUSE_MAY_STOP_VIS
))))
2546 redraw_curbuf_later(INVERTED
); /* delete the inversion */
2550 if (cmdwin_type
!= 0 && wp
!= curwin
)
2552 /* A click outside the command-line window: Use modeless
2553 * selection if possible. Allow dragging the status line of
2554 * windows just above the command-line window. */
2555 if (wp
->w_winrow
+ wp
->w_height
2556 != curwin
->w_prev
->w_winrow
+ curwin
->w_prev
->w_height
)
2561 # ifdef FEAT_VERTSPLIT
2564 # ifdef FEAT_CLIPBOARD
2566 return IN_STATUS_LINE
;
2567 return IN_OTHER_WIN
;
2570 col
+= wp
->w_wincol
;
2576 /* Only change window focus when not clicking on or dragging the
2577 * status line. Do change focus when releasing the mouse button
2578 * (MOUSE_FOCUS was set above if we dragged first). */
2579 if (dragwin
== NULL
|| (flags
& MOUSE_RELEASED
))
2580 win_enter(wp
, TRUE
); /* can make wp invalid! */
2581 # ifdef CHECK_DOUBLE_CLICK
2582 /* set topline, to be able to check for double click ourselves */
2583 if (curwin
!= old_curwin
)
2584 set_mouse_topline(curwin
);
2587 if (on_status_line
) /* In (or below) status line */
2589 /* Don't use start_arrow() if we're in the same window */
2590 if (curwin
== old_curwin
)
2591 return IN_STATUS_LINE
;
2593 return IN_STATUS_LINE
| CURSOR_MOVED
;
2595 #ifdef FEAT_VERTSPLIT
2596 if (on_sep_line
) /* In (or below) status line */
2598 /* Don't use start_arrow() if we're in the same window */
2599 if (curwin
== old_curwin
)
2602 return IN_SEP_LINE
| CURSOR_MOVED
;
2606 curwin
->w_cursor
.lnum
= curwin
->w_topline
;
2608 /* remember topline, needed for double click */
2609 gui_prev_topline
= curwin
->w_topline
;
2611 gui_prev_topfill
= curwin
->w_topfill
;
2615 else if (on_status_line
&& which_button
== MOUSE_LEFT
)
2618 if (dragwin
!= NULL
)
2620 /* Drag the status line */
2621 count
= row
- dragwin
->w_winrow
- dragwin
->w_height
+ 1
2623 win_drag_status_line(dragwin
, count
);
2627 return IN_STATUS_LINE
; /* Cursor didn't move */
2629 #ifdef FEAT_VERTSPLIT
2630 else if (on_sep_line
&& which_button
== MOUSE_LEFT
)
2632 if (dragwin
!= NULL
)
2634 /* Drag the separator column */
2635 count
= col
- dragwin
->w_wincol
- dragwin
->w_width
+ 1
2637 win_drag_vsep_line(dragwin
, count
);
2640 return IN_SEP_LINE
; /* Cursor didn't move */
2643 else /* keep_window_focus must be TRUE */
2646 /* before moving the cursor for a left click, stop Visual mode */
2647 if (flags
& MOUSE_MAY_STOP_VIS
)
2650 redraw_curbuf_later(INVERTED
); /* delete the inversion */
2654 #if defined(FEAT_CMDWIN) && defined(FEAT_CLIPBOARD)
2655 /* Continue a modeless selection in another window. */
2656 if (cmdwin_type
!= 0 && row
< W_WINROW(curwin
))
2657 return IN_OTHER_WIN
;
2660 row
-= W_WINROW(curwin
);
2661 #ifdef FEAT_VERTSPLIT
2662 col
-= W_WINCOL(curwin
);
2666 * When clicking beyond the end of the window, scroll the screen.
2667 * Scroll by however many rows outside the window we are.
2672 for (first
= TRUE
; curwin
->w_topline
> 1; )
2675 if (curwin
->w_topfill
< diff_check(curwin
, curwin
->w_topline
))
2679 count
+= plines(curwin
->w_topline
- 1);
2680 if (!first
&& count
> -row
)
2684 hasFolding(curwin
->w_topline
, &curwin
->w_topline
, NULL
);
2687 if (curwin
->w_topfill
< diff_check(curwin
, curwin
->w_topline
))
2688 ++curwin
->w_topfill
;
2692 --curwin
->w_topline
;
2694 curwin
->w_topfill
= 0;
2699 check_topfill(curwin
, FALSE
);
2702 ~(VALID_WROW
|VALID_CROW
|VALID_BOTLINE
|VALID_BOTLINE_AP
);
2703 redraw_later(VALID
);
2706 else if (row
>= curwin
->w_height
)
2709 for (first
= TRUE
; curwin
->w_topline
< curbuf
->b_ml
.ml_line_count
; )
2712 if (curwin
->w_topfill
> 0)
2716 count
+= plines(curwin
->w_topline
);
2717 if (!first
&& count
> row
- curwin
->w_height
+ 1)
2721 if (hasFolding(curwin
->w_topline
, NULL
, &curwin
->w_topline
)
2722 && curwin
->w_topline
== curbuf
->b_ml
.ml_line_count
)
2726 if (curwin
->w_topfill
> 0)
2727 --curwin
->w_topfill
;
2731 ++curwin
->w_topline
;
2734 diff_check_fill(curwin
, curwin
->w_topline
);
2739 check_topfill(curwin
, FALSE
);
2741 redraw_later(VALID
);
2743 ~(VALID_WROW
|VALID_CROW
|VALID_BOTLINE
|VALID_BOTLINE_AP
);
2744 row
= curwin
->w_height
- 1;
2748 /* When dragging the mouse, while the text has been scrolled up as
2749 * far as it goes, moving the mouse in the top line should scroll
2750 * the text down (done later when recomputing w_topline). */
2751 if (mouse_dragging
> 0
2752 && curwin
->w_cursor
.lnum
2753 == curwin
->w_buffer
->b_ml
.ml_line_count
2754 && curwin
->w_cursor
.lnum
== curwin
->w_topline
)
2755 curwin
->w_valid
&= ~(VALID_TOPLINE
);
2760 /* Check for position outside of the fold column. */
2762 # ifdef FEAT_RIGHTLEFT
2763 curwin
->w_p_rl
? col
< W_WIDTH(curwin
) - curwin
->w_p_fdc
:
2765 col
>= curwin
->w_p_fdc
2767 + (cmdwin_type
== 0 ? 0 : 1)
2773 /* compute the position in the buffer line from the posn on the screen */
2774 if (mouse_comp_pos(curwin
, &row
, &col
, &curwin
->w_cursor
.lnum
))
2775 mouse_past_bottom
= TRUE
;
2778 /* Start Visual mode before coladvance(), for when 'sel' != "old" */
2779 if ((flags
& MOUSE_MAY_VIS
) && !VIsual_active
)
2781 check_visual_highlight();
2782 VIsual
= old_cursor
;
2783 VIsual_active
= TRUE
;
2784 VIsual_reselect
= TRUE
;
2785 /* if 'selectmode' contains "mouse", start Select mode */
2786 may_start_select('o');
2788 if (p_smd
&& msg_silent
== 0)
2789 redraw_cmdline
= TRUE
; /* show visual mode later */
2793 curwin
->w_curswant
= col
;
2794 curwin
->w_set_curswant
= FALSE
; /* May still have been TRUE */
2795 if (coladvance(col
) == FAIL
) /* Mouse click beyond end of line */
2797 if (inclusive
!= NULL
)
2799 mouse_past_eol
= TRUE
;
2801 else if (inclusive
!= NULL
)
2805 if (curwin
!= old_curwin
|| curwin
->w_cursor
.lnum
!= old_cursor
.lnum
2806 || curwin
->w_cursor
.col
!= old_cursor
.col
)
2807 count
|= CURSOR_MOVED
; /* Cursor has moved */
2810 if (mouse_char
== '+')
2811 count
|= MOUSE_FOLD_OPEN
;
2812 else if (mouse_char
!= ' ')
2813 count
|= MOUSE_FOLD_CLOSE
;
2820 * Compute the position in the buffer line from the posn on the screen in
2822 * Returns TRUE if the position is below the last line.
2825 mouse_comp_pos(win
, rowp
, colp
, lnump
)
2838 #ifdef FEAT_RIGHTLEFT
2840 col
= W_WIDTH(win
) - 1 - col
;
2843 lnum
= win
->w_topline
;
2848 /* Don't include filler lines in "count" */
2850 # ifdef FEAT_FOLDING
2851 && !hasFoldingWin(win
, lnum
, NULL
, NULL
, TRUE
, NULL
)
2855 if (lnum
== win
->w_topline
)
2856 row
-= win
->w_topfill
;
2858 row
-= diff_check_fill(win
, lnum
);
2859 count
= plines_win_nofill(win
, lnum
, TRUE
);
2863 count
= plines_win(win
, lnum
, TRUE
);
2865 break; /* Position is in this buffer line. */
2867 (void)hasFoldingWin(win
, lnum
, NULL
, &lnum
, TRUE
, NULL
);
2869 if (lnum
== win
->w_buffer
->b_ml
.ml_line_count
)
2872 break; /* past end of file */
2880 /* Compute the column without wrapping. */
2881 off
= win_col_off(win
) - win_col_off2(win
);
2884 col
+= row
* (W_WIDTH(win
) - off
);
2885 /* add skip column (for long wrapping line) */
2886 col
+= win
->w_skipcol
;
2890 col
+= win
->w_leftcol
;
2892 /* skip line number and fold column in front of the line */
2893 col
-= win_col_off(win
);
2896 #ifdef FEAT_NETBEANS_INTG
2898 netbeans_gutter_click(lnum
);
2909 #if defined(FEAT_WINDOWS) || defined(PROTO)
2911 * Find the window at screen position "*rowp" and "*colp". The positions are
2912 * updated to become relative to the top-left of the window.
2916 mouse_find_win(rowp
, colp
)
2923 *rowp
-= firstwin
->w_winrow
;
2926 if (fp
->fr_layout
== FR_LEAF
)
2928 #ifdef FEAT_VERTSPLIT
2929 if (fp
->fr_layout
== FR_ROW
)
2931 for (fp
= fp
->fr_child
; fp
->fr_next
!= NULL
; fp
= fp
->fr_next
)
2933 if (*colp
< fp
->fr_width
)
2935 *colp
-= fp
->fr_width
;
2939 else /* fr_layout == FR_COL */
2941 for (fp
= fp
->fr_child
; fp
->fr_next
!= NULL
; fp
= fp
->fr_next
)
2943 if (*rowp
< fp
->fr_height
)
2945 *rowp
-= fp
->fr_height
;
2953 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) || defined (FEAT_GUI_MAC) \
2954 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \
2955 || defined(FEAT_GUI_PHOTON) || defined(PROTO) \
2956 || defined(FEAT_GUI_MACVIM)
2958 * Translate window coordinates to buffer position without any side effects
2961 get_fpos_of_mouse(mpos
)
2965 int row
= mouse_row
;
2966 int col
= mouse_col
;
2968 if (row
< 0 || col
< 0) /* check if it makes sense */
2972 /* find the window where the row is in */
2973 wp
= mouse_find_win(&row
, &col
);
2978 * winpos and height may change in win_enter()!
2980 if (row
>= wp
->w_height
) /* In (or below) status line */
2981 return IN_STATUS_LINE
;
2982 #ifdef FEAT_VERTSPLIT
2983 if (col
>= wp
->w_width
) /* In vertical separator line */
2990 /* compute the position in the buffer line from the posn on the screen */
2991 if (mouse_comp_pos(curwin
, &row
, &col
, &mpos
->lnum
))
2992 return IN_STATUS_LINE
; /* past bottom */
2994 mpos
->col
= vcol2col(wp
, mpos
->lnum
, col
);
3002 * Convert a virtual (screen) column to a character column.
3003 * The first column is one.
3006 vcol2col(wp
, lnum
, vcol
)
3011 /* try to advance to the specified column */
3016 ptr
= ml_get_buf(wp
->w_buffer
, lnum
, FALSE
);
3017 while (count
<= vcol
&& *ptr
!= NUL
)
3020 count
+= win_lbr_chartabsize(wp
, ptr
, count
, NULL
);
3027 #endif /* FEAT_MOUSE */
3029 #if defined(FEAT_GUI) || defined(WIN3264) || defined(PROTO)
3031 * Called when focus changed. Used for the GUI or for systems where this can
3032 * be done in the console (Win32).
3035 ui_focus_change(in_focus
)
3036 int in_focus
; /* TRUE if focus gained. */
3038 static time_t last_time
= (time_t)0;
3039 int need_redraw
= FALSE
;
3041 /* When activated: Check if any file was modified outside of Vim.
3042 * Only do this when not done within the last two seconds (could get
3043 * several events in a row). */
3044 if (in_focus
&& last_time
+ 2 < time(NULL
))
3046 need_redraw
= check_timestamps(
3053 last_time
= time(NULL
);
3058 * Fire the focus gained/lost autocommand.
3060 need_redraw
|= apply_autocmds(in_focus
? EVENT_FOCUSGAINED
3061 : EVENT_FOCUSLOST
, NULL
, NULL
, FALSE
, curbuf
);
3066 /* Something was executed, make sure the cursor is put back where it
3068 need_wait_return
= FALSE
;
3070 if (State
& CMDLINE
)
3072 else if (State
== HITRETURN
|| State
== SETWSIZE
|| State
== ASKMORE
3073 || State
== EXTERNCMD
|| State
== CONFIRM
|| exmode_active
)
3075 else if ((State
& NORMAL
) || (State
& INSERT
))
3077 if (must_redraw
!= 0)
3081 cursor_on(); /* redrawing may have switched it off */
3086 gui_update_cursor(FALSE
, TRUE
);
3087 gui_update_scrollbars(FALSE
);
3092 /* File may have been changed from 'readonly' to 'noreadonly' */
3099 #if defined(USE_IM_CONTROL) || defined(PROTO)
3101 * Save current Input Method status to specified place.
3104 im_save_status(psave
)
3107 /* Don't save when 'imdisable' is set or "xic" is NULL, IM is always
3108 * disabled then (but might start later).
3109 * Also don't save when inside a mapping, vgetc_im_active has not been set
3111 * And don't save when the keys were stuffed (e.g., for a "." command).
3112 * And don't save when the GUI is running but our window doesn't have
3113 * input focus (e.g., when a find dialog is open). */
3114 if (!p_imdisable
&& KeyTyped
&& !KeyStuffed
3119 && (!gui
.in_use
|| gui
.in_focus
)
3123 /* Do save when IM is on, or IM is off and saved status is on. */
3124 if (vgetc_im_active
)
3125 *psave
= B_IMODE_IM
;
3126 else if (*psave
== B_IMODE_IM
)
3127 *psave
= B_IMODE_NONE
;