Mercurial > vim
annotate src/normal.c @ 14363:dcae605ebd07
Added tag v8.1.0196 for changeset 74470fae51f904407c2942159550e3ee3fb31f48
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 19 Jul 2018 04:15:05 +0200 |
parents | c1fcfafa8d1a |
children | 19d99d9e670c |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
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. | |
8 */ | |
9 /* | |
10 * normal.c: Contains the main routine for processing characters in command | |
11 * mode. Communicates closely with the code in ops.c to handle | |
12 * the operators. | |
13 */ | |
14 | |
15 #include "vim.h" | |
16 | |
17 /* | |
18 * The Visual area is remembered for reselection. | |
19 */ | |
20 static int resel_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ | |
21 static linenr_T resel_VIsual_line_count; /* number of lines */ | |
3125 | 22 static colnr_T resel_VIsual_vcol; /* nr of cols or end col */ |
5682 | 23 static int VIsual_mode_orig = NUL; /* saved Visual mode */ |
7 | 24 |
25 static int restart_VIsual_select = 0; | |
26 | |
2667 | 27 #ifdef FEAT_EVAL |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
28 static void set_vcount_ca(cmdarg_T *cap, int *set_prevcount); |
2667 | 29 #endif |
7 | 30 static int |
3531 | 31 #ifdef __BORLANDC__ |
32 _RTLENTRYF | |
33 #endif | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
34 nv_compare(const void *s1, const void *s2); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
35 static int find_command(int cmdchar); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
36 static void op_colon(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
37 static void op_function(oparg_T *oap); |
5735 | 38 #if defined(FEAT_MOUSE) |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
39 static void find_start_of_word(pos_T *); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
40 static void find_end_of_word(pos_T *); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
41 static int get_mouse_class(char_u *p); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
42 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
43 static void prep_redo_cmd(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
44 static void prep_redo(int regname, long, int, int, int, int, int); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
45 static int checkclearop(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
46 static int checkclearopq(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
47 static void clearop(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
48 static void clearopbeep(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
49 static void unshift_special(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
50 static void may_clear_cmdline(void); |
7 | 51 #ifdef FEAT_CMDL_INFO |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
52 static void del_from_showcmd(int); |
7 | 53 #endif |
54 | |
55 /* | |
56 * nv_*(): functions called to handle Normal and Visual mode commands. | |
57 * n_*(): functions called to handle Normal mode commands. | |
58 * v_*(): functions called to handle Visual mode commands. | |
59 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
60 static void nv_ignore(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
61 static void nv_nop(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
62 static void nv_error(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
63 static void nv_help(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
64 static void nv_addsub(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
65 static void nv_page(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
66 static void nv_gd(oparg_T *oap, int nchar, int thisblock); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
67 static int nv_screengo(oparg_T *oap, int dir, long dist); |
7 | 68 #ifdef FEAT_MOUSE |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
69 static void nv_mousescroll(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
70 static void nv_mouse(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
71 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
72 static void nv_scroll_line(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
73 static void nv_zet(cmdarg_T *cap); |
7 | 74 #ifdef FEAT_GUI |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
75 static void nv_ver_scrollbar(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
76 static void nv_hor_scrollbar(cmdarg_T *cap); |
7 | 77 #endif |
685 | 78 #ifdef FEAT_GUI_TABLINE |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
79 static void nv_tabline(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
80 static void nv_tabmenu(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
81 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
82 static void nv_exmode(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
83 static void nv_colon(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
84 static void nv_ctrlg(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
85 static void nv_ctrlh(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
86 static void nv_clear(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
87 static void nv_ctrlo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
88 static void nv_hat(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
89 static void nv_Zet(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
90 static void nv_ident(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
91 static void nv_tagpop(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
92 static void nv_scroll(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
93 static void nv_right(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
94 static void nv_left(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
95 static void nv_up(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
96 static void nv_down(cmdarg_T *cap); |
7 | 97 #ifdef FEAT_SEARCHPATH |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
98 static void nv_gotofile(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
99 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
100 static void nv_end(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
101 static void nv_dollar(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
102 static void nv_search(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
103 static void nv_next(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
104 static int normal_search(cmdarg_T *cap, int dir, char_u *pat, int opt); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
105 static void nv_csearch(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
106 static void nv_brackets(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
107 static void nv_percent(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
108 static void nv_brace(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
109 static void nv_mark(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
110 static void nv_findpar(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
111 static void nv_undo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
112 static void nv_kundo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
113 static void nv_Replace(cmdarg_T *cap); |
7 | 114 #ifdef FEAT_VREPLACE |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
115 static void nv_vreplace(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
116 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
117 static void v_swap_corners(int cmdchar); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
118 static void nv_replace(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
119 static void n_swapchar(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
120 static void nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
121 static void v_visop(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
122 static void nv_subst(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
123 static void nv_abbrev(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
124 static void nv_optrans(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
125 static void nv_gomark(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
126 static void nv_pcmark(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
127 static void nv_regname(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
128 static void nv_visual(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
129 static void n_start_visual_mode(int c); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
130 static void nv_window(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
131 static void nv_suspend(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
132 static void nv_g_cmd(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
133 static void n_opencmd(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
134 static void nv_dot(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
135 static void nv_redo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
136 static void nv_Undo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
137 static void nv_tilde(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
138 static void nv_operator(cmdarg_T *cap); |
1490 | 139 #ifdef FEAT_EVAL |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
140 static void set_op_var(int optype); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
141 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
142 static void nv_lineop(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
143 static void nv_home(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
144 static void nv_pipe(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
145 static void nv_bck_word(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
146 static void nv_wordcmd(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
147 static void nv_beginline(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
148 static void adjust_cursor(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
149 static void adjust_for_sel(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
150 static int unadjust_for_sel(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
151 static void nv_select(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
152 static void nv_goto(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
153 static void nv_normal(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
154 static void nv_esc(cmdarg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
155 static void nv_edit(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
156 static void invoke_edit(cmdarg_T *cap, int repl, int cmd, int startln); |
7 | 157 #ifdef FEAT_TEXTOBJ |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
158 static void nv_object(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
159 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
160 static void nv_record(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
161 static void nv_at(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
162 static void nv_halfpage(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
163 static void nv_join(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
164 static void nv_put(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
165 static void nv_open(cmdarg_T *cap); |
7 | 166 #ifdef FEAT_NETBEANS_INTG |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
167 static void nv_nbcmd(cmdarg_T *cap); |
7 | 168 #endif |
169 #ifdef FEAT_DND | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
170 static void nv_drop(cmdarg_T *cap); |
7 | 171 #endif |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
172 static void nv_cursorhold(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
173 static void get_op_vcol(oparg_T *oap, colnr_T col, int initial); |
7 | 174 |
1728 | 175 static char *e_noident = N_("E349: No identifier under cursor"); |
176 | |
7 | 177 /* |
178 * Function to be called for a Normal or Visual mode command. | |
179 * The argument is a cmdarg_T. | |
180 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
181 typedef void (*nv_func_T)(cmdarg_T *cap); |
7 | 182 |
183 /* Values for cmd_flags. */ | |
184 #define NV_NCH 0x01 /* may need to get a second char */ | |
185 #define NV_NCH_NOP (0x02|NV_NCH) /* get second char when no operator pending */ | |
186 #define NV_NCH_ALW (0x04|NV_NCH) /* always get a second char */ | |
187 #define NV_LANG 0x08 /* second char needs language adjustment */ | |
188 | |
189 #define NV_SS 0x10 /* may start selection */ | |
190 #define NV_SSS 0x20 /* may start selection with shift modifier */ | |
191 #define NV_STS 0x40 /* may stop selection without shift modif. */ | |
192 #define NV_RL 0x80 /* 'rightleft' modifies command */ | |
193 #define NV_KEEPREG 0x100 /* don't clear regname */ | |
194 #define NV_NCW 0x200 /* not allowed in command-line window */ | |
195 | |
196 /* | |
197 * Generally speaking, every Normal mode command should either clear any | |
198 * pending operator (with *clearop*()), or set the motion type variable | |
199 * oap->motion_type. | |
200 * | |
201 * When a cursor motion command is made, it is marked as being a character or | |
202 * line oriented motion. Then, if an operator is in effect, the operation | |
203 * becomes character or line oriented accordingly. | |
204 */ | |
205 | |
206 /* | |
207 * This table contains one entry for every Normal or Visual mode command. | |
208 * The order doesn't matter, init_normal_cmds() will create a sorted index. | |
209 * It is faster when all keys from zero to '~' are present. | |
210 */ | |
211 static const struct nv_cmd | |
212 { | |
213 int cmd_char; /* (first) command character */ | |
214 nv_func_T cmd_func; /* function for this command */ | |
215 short_u cmd_flags; /* NV_ flags */ | |
216 short cmd_arg; /* value for ca.arg */ | |
217 } nv_cmds[] = | |
218 { | |
219 {NUL, nv_error, 0, 0}, | |
220 {Ctrl_A, nv_addsub, 0, 0}, | |
221 {Ctrl_B, nv_page, NV_STS, BACKWARD}, | |
222 {Ctrl_C, nv_esc, 0, TRUE}, | |
223 {Ctrl_D, nv_halfpage, 0, 0}, | |
224 {Ctrl_E, nv_scroll_line, 0, TRUE}, | |
225 {Ctrl_F, nv_page, NV_STS, FORWARD}, | |
226 {Ctrl_G, nv_ctrlg, 0, 0}, | |
227 {Ctrl_H, nv_ctrlh, 0, 0}, | |
228 {Ctrl_I, nv_pcmark, 0, 0}, | |
229 {NL, nv_down, 0, FALSE}, | |
230 {Ctrl_K, nv_error, 0, 0}, | |
231 {Ctrl_L, nv_clear, 0, 0}, | |
376 | 232 {Ctrl_M, nv_down, 0, TRUE}, |
7 | 233 {Ctrl_N, nv_down, NV_STS, FALSE}, |
234 {Ctrl_O, nv_ctrlo, 0, 0}, | |
235 {Ctrl_P, nv_up, NV_STS, FALSE}, | |
167 | 236 {Ctrl_Q, nv_visual, 0, FALSE}, |
7 | 237 {Ctrl_R, nv_redo, 0, 0}, |
238 {Ctrl_S, nv_ignore, 0, 0}, | |
239 {Ctrl_T, nv_tagpop, NV_NCW, 0}, | |
240 {Ctrl_U, nv_halfpage, 0, 0}, | |
241 {Ctrl_V, nv_visual, 0, FALSE}, | |
242 {'V', nv_visual, 0, FALSE}, | |
243 {'v', nv_visual, 0, FALSE}, | |
244 {Ctrl_W, nv_window, 0, 0}, | |
245 {Ctrl_X, nv_addsub, 0, 0}, | |
246 {Ctrl_Y, nv_scroll_line, 0, FALSE}, | |
247 {Ctrl_Z, nv_suspend, 0, 0}, | |
248 {ESC, nv_esc, 0, FALSE}, | |
249 {Ctrl_BSL, nv_normal, NV_NCH_ALW, 0}, | |
250 {Ctrl_RSB, nv_ident, NV_NCW, 0}, | |
251 {Ctrl_HAT, nv_hat, NV_NCW, 0}, | |
252 {Ctrl__, nv_error, 0, 0}, | |
253 {' ', nv_right, 0, 0}, | |
254 {'!', nv_operator, 0, 0}, | |
255 {'"', nv_regname, NV_NCH_NOP|NV_KEEPREG, 0}, | |
256 {'#', nv_ident, 0, 0}, | |
257 {'$', nv_dollar, 0, 0}, | |
258 {'%', nv_percent, 0, 0}, | |
259 {'&', nv_optrans, 0, 0}, | |
260 {'\'', nv_gomark, NV_NCH_ALW, TRUE}, | |
261 {'(', nv_brace, 0, BACKWARD}, | |
262 {')', nv_brace, 0, FORWARD}, | |
263 {'*', nv_ident, 0, 0}, | |
264 {'+', nv_down, 0, TRUE}, | |
265 {',', nv_csearch, 0, TRUE}, | |
266 {'-', nv_up, 0, TRUE}, | |
267 {'.', nv_dot, NV_KEEPREG, 0}, | |
268 {'/', nv_search, 0, FALSE}, | |
269 {'0', nv_beginline, 0, 0}, | |
270 {'1', nv_ignore, 0, 0}, | |
271 {'2', nv_ignore, 0, 0}, | |
272 {'3', nv_ignore, 0, 0}, | |
273 {'4', nv_ignore, 0, 0}, | |
274 {'5', nv_ignore, 0, 0}, | |
275 {'6', nv_ignore, 0, 0}, | |
276 {'7', nv_ignore, 0, 0}, | |
277 {'8', nv_ignore, 0, 0}, | |
278 {'9', nv_ignore, 0, 0}, | |
279 {':', nv_colon, 0, 0}, | |
280 {';', nv_csearch, 0, FALSE}, | |
281 {'<', nv_operator, NV_RL, 0}, | |
282 {'=', nv_operator, 0, 0}, | |
283 {'>', nv_operator, NV_RL, 0}, | |
284 {'?', nv_search, 0, FALSE}, | |
285 {'@', nv_at, NV_NCH_NOP, FALSE}, | |
286 {'A', nv_edit, 0, 0}, | |
287 {'B', nv_bck_word, 0, 1}, | |
288 {'C', nv_abbrev, NV_KEEPREG, 0}, | |
289 {'D', nv_abbrev, NV_KEEPREG, 0}, | |
290 {'E', nv_wordcmd, 0, TRUE}, | |
291 {'F', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
292 {'G', nv_goto, 0, TRUE}, | |
293 {'H', nv_scroll, 0, 0}, | |
294 {'I', nv_edit, 0, 0}, | |
295 {'J', nv_join, 0, 0}, | |
296 {'K', nv_ident, 0, 0}, | |
297 {'L', nv_scroll, 0, 0}, | |
298 {'M', nv_scroll, 0, 0}, | |
299 {'N', nv_next, 0, SEARCH_REV}, | |
300 {'O', nv_open, 0, 0}, | |
301 {'P', nv_put, 0, 0}, | |
302 {'Q', nv_exmode, NV_NCW, 0}, | |
303 {'R', nv_Replace, 0, FALSE}, | |
304 {'S', nv_subst, NV_KEEPREG, 0}, | |
305 {'T', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
306 {'U', nv_Undo, 0, 0}, | |
307 {'W', nv_wordcmd, 0, TRUE}, | |
308 {'X', nv_abbrev, NV_KEEPREG, 0}, | |
309 {'Y', nv_abbrev, NV_KEEPREG, 0}, | |
310 {'Z', nv_Zet, NV_NCH_NOP|NV_NCW, 0}, | |
311 {'[', nv_brackets, NV_NCH_ALW, BACKWARD}, | |
312 {'\\', nv_error, 0, 0}, | |
313 {']', nv_brackets, NV_NCH_ALW, FORWARD}, | |
314 {'^', nv_beginline, 0, BL_WHITE | BL_FIX}, | |
315 {'_', nv_lineop, 0, 0}, | |
316 {'`', nv_gomark, NV_NCH_ALW, FALSE}, | |
317 {'a', nv_edit, NV_NCH, 0}, | |
318 {'b', nv_bck_word, 0, 0}, | |
319 {'c', nv_operator, 0, 0}, | |
320 {'d', nv_operator, 0, 0}, | |
321 {'e', nv_wordcmd, 0, FALSE}, | |
322 {'f', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
323 {'g', nv_g_cmd, NV_NCH_ALW, FALSE}, | |
324 {'h', nv_left, NV_RL, 0}, | |
325 {'i', nv_edit, NV_NCH, 0}, | |
326 {'j', nv_down, 0, FALSE}, | |
327 {'k', nv_up, 0, FALSE}, | |
328 {'l', nv_right, NV_RL, 0}, | |
329 {'m', nv_mark, NV_NCH_NOP, 0}, | |
330 {'n', nv_next, 0, 0}, | |
331 {'o', nv_open, 0, 0}, | |
332 {'p', nv_put, 0, 0}, | |
333 {'q', nv_record, NV_NCH, 0}, | |
334 {'r', nv_replace, NV_NCH_NOP|NV_LANG, 0}, | |
335 {'s', nv_subst, NV_KEEPREG, 0}, | |
336 {'t', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
337 {'u', nv_undo, 0, 0}, | |
338 {'w', nv_wordcmd, 0, FALSE}, | |
339 {'x', nv_abbrev, NV_KEEPREG, 0}, | |
340 {'y', nv_operator, 0, 0}, | |
341 {'z', nv_zet, NV_NCH_ALW, 0}, | |
342 {'{', nv_findpar, 0, BACKWARD}, | |
343 {'|', nv_pipe, 0, 0}, | |
344 {'}', nv_findpar, 0, FORWARD}, | |
345 {'~', nv_tilde, 0, 0}, | |
346 | |
347 /* pound sign */ | |
348 {POUND, nv_ident, 0, 0}, | |
349 #ifdef FEAT_MOUSE | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
350 {K_MOUSEUP, nv_mousescroll, 0, MSCR_UP}, |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
351 {K_MOUSEDOWN, nv_mousescroll, 0, MSCR_DOWN}, |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
352 {K_MOUSELEFT, nv_mousescroll, 0, MSCR_LEFT}, |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
353 {K_MOUSERIGHT, nv_mousescroll, 0, MSCR_RIGHT}, |
7 | 354 {K_LEFTMOUSE, nv_mouse, 0, 0}, |
355 {K_LEFTMOUSE_NM, nv_mouse, 0, 0}, | |
356 {K_LEFTDRAG, nv_mouse, 0, 0}, | |
357 {K_LEFTRELEASE, nv_mouse, 0, 0}, | |
358 {K_LEFTRELEASE_NM, nv_mouse, 0, 0}, | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
359 {K_MOUSEMOVE, nv_mouse, 0, 0}, |
7 | 360 {K_MIDDLEMOUSE, nv_mouse, 0, 0}, |
361 {K_MIDDLEDRAG, nv_mouse, 0, 0}, | |
362 {K_MIDDLERELEASE, nv_mouse, 0, 0}, | |
363 {K_RIGHTMOUSE, nv_mouse, 0, 0}, | |
364 {K_RIGHTDRAG, nv_mouse, 0, 0}, | |
365 {K_RIGHTRELEASE, nv_mouse, 0, 0}, | |
366 {K_X1MOUSE, nv_mouse, 0, 0}, | |
367 {K_X1DRAG, nv_mouse, 0, 0}, | |
368 {K_X1RELEASE, nv_mouse, 0, 0}, | |
369 {K_X2MOUSE, nv_mouse, 0, 0}, | |
370 {K_X2DRAG, nv_mouse, 0, 0}, | |
371 {K_X2RELEASE, nv_mouse, 0, 0}, | |
372 #endif | |
819 | 373 {K_IGNORE, nv_ignore, NV_KEEPREG, 0}, |
620 | 374 {K_NOP, nv_nop, 0, 0}, |
7 | 375 {K_INS, nv_edit, 0, 0}, |
376 {K_KINS, nv_edit, 0, 0}, | |
377 {K_BS, nv_ctrlh, 0, 0}, | |
378 {K_UP, nv_up, NV_SSS|NV_STS, FALSE}, | |
379 {K_S_UP, nv_page, NV_SS, BACKWARD}, | |
380 {K_DOWN, nv_down, NV_SSS|NV_STS, FALSE}, | |
381 {K_S_DOWN, nv_page, NV_SS, FORWARD}, | |
382 {K_LEFT, nv_left, NV_SSS|NV_STS|NV_RL, 0}, | |
383 {K_S_LEFT, nv_bck_word, NV_SS|NV_RL, 0}, | |
384 {K_C_LEFT, nv_bck_word, NV_SSS|NV_RL|NV_STS, 1}, | |
385 {K_RIGHT, nv_right, NV_SSS|NV_STS|NV_RL, 0}, | |
386 {K_S_RIGHT, nv_wordcmd, NV_SS|NV_RL, FALSE}, | |
387 {K_C_RIGHT, nv_wordcmd, NV_SSS|NV_RL|NV_STS, TRUE}, | |
388 {K_PAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
389 {K_KPAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
390 {K_PAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
391 {K_KPAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
392 {K_END, nv_end, NV_SSS|NV_STS, FALSE}, | |
393 {K_KEND, nv_end, NV_SSS|NV_STS, FALSE}, | |
394 {K_S_END, nv_end, NV_SS, FALSE}, | |
395 {K_C_END, nv_end, NV_SSS|NV_STS, TRUE}, | |
396 {K_HOME, nv_home, NV_SSS|NV_STS, 0}, | |
397 {K_KHOME, nv_home, NV_SSS|NV_STS, 0}, | |
398 {K_S_HOME, nv_home, NV_SS, 0}, | |
399 {K_C_HOME, nv_goto, NV_SSS|NV_STS, FALSE}, | |
400 {K_DEL, nv_abbrev, 0, 0}, | |
401 {K_KDEL, nv_abbrev, 0, 0}, | |
402 {K_UNDO, nv_kundo, 0, 0}, | |
403 {K_HELP, nv_help, NV_NCW, 0}, | |
404 {K_F1, nv_help, NV_NCW, 0}, | |
405 {K_XF1, nv_help, NV_NCW, 0}, | |
406 {K_SELECT, nv_select, 0, 0}, | |
407 #ifdef FEAT_GUI | |
408 {K_VER_SCROLLBAR, nv_ver_scrollbar, 0, 0}, | |
409 {K_HOR_SCROLLBAR, nv_hor_scrollbar, 0, 0}, | |
410 #endif | |
685 | 411 #ifdef FEAT_GUI_TABLINE |
412 {K_TABLINE, nv_tabline, 0, 0}, | |
686 | 413 {K_TABMENU, nv_tabmenu, 0, 0}, |
685 | 414 #endif |
7 | 415 #ifdef FEAT_FKMAP |
9399
43b8570abbec
commit https://github.com/vim/vim/commit/ee2615af64fdcee87d8e4b13b65356e77fbd969b
Christian Brabandt <cb@256bit.org>
parents:
9315
diff
changeset
|
416 {K_F8, farsi_f8, 0, 0}, |
43b8570abbec
commit https://github.com/vim/vim/commit/ee2615af64fdcee87d8e4b13b65356e77fbd969b
Christian Brabandt <cb@256bit.org>
parents:
9315
diff
changeset
|
417 {K_F9, farsi_f9, 0, 0}, |
7 | 418 #endif |
419 #ifdef FEAT_NETBEANS_INTG | |
420 {K_F21, nv_nbcmd, NV_NCH_ALW, 0}, | |
421 #endif | |
422 #ifdef FEAT_DND | |
423 {K_DROP, nv_drop, NV_STS, 0}, | |
424 #endif | |
819 | 425 {K_CURSORHOLD, nv_cursorhold, NV_KEEPREG, 0}, |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
426 {K_PS, nv_edit, 0, 0}, |
7 | 427 }; |
428 | |
429 /* Number of commands in nv_cmds[]. */ | |
430 #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd)) | |
431 | |
432 /* Sorted index of commands in nv_cmds[]. */ | |
433 static short nv_cmd_idx[NV_CMDS_SIZE]; | |
434 | |
435 /* The highest index for which | |
436 * nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] */ | |
437 static int nv_max_linear; | |
438 | |
439 /* | |
440 * Compare functions for qsort() below, that checks the command character | |
441 * through the index in nv_cmd_idx[]. | |
442 */ | |
443 static int | |
444 #ifdef __BORLANDC__ | |
445 _RTLENTRYF | |
446 #endif | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
447 nv_compare(const void *s1, const void *s2) |
7 | 448 { |
449 int c1, c2; | |
450 | |
451 /* The commands are sorted on absolute value. */ | |
452 c1 = nv_cmds[*(const short *)s1].cmd_char; | |
453 c2 = nv_cmds[*(const short *)s2].cmd_char; | |
454 if (c1 < 0) | |
455 c1 = -c1; | |
456 if (c2 < 0) | |
457 c2 = -c2; | |
458 return c1 - c2; | |
459 } | |
460 | |
461 /* | |
462 * Initialize the nv_cmd_idx[] table. | |
463 */ | |
464 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
465 init_normal_cmds(void) |
7 | 466 { |
467 int i; | |
468 | |
469 /* Fill the index table with a one to one relation. */ | |
1877 | 470 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 471 nv_cmd_idx[i] = i; |
472 | |
473 /* Sort the commands by the command character. */ | |
474 qsort((void *)&nv_cmd_idx, (size_t)NV_CMDS_SIZE, sizeof(short), nv_compare); | |
475 | |
476 /* Find the first entry that can't be indexed by the command character. */ | |
1877 | 477 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 478 if (i != nv_cmds[nv_cmd_idx[i]].cmd_char) |
479 break; | |
480 nv_max_linear = i - 1; | |
481 } | |
482 | |
483 /* | |
484 * Search for a command in the commands table. | |
485 * Returns -1 for invalid command. | |
486 */ | |
487 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
488 find_command(int cmdchar) |
7 | 489 { |
490 int i; | |
491 int idx; | |
492 int top, bot; | |
493 int c; | |
494 | |
495 #ifdef FEAT_MBYTE | |
496 /* A multi-byte character is never a command. */ | |
497 if (cmdchar >= 0x100) | |
498 return -1; | |
499 #endif | |
500 | |
501 /* We use the absolute value of the character. Special keys have a | |
502 * negative value, but are sorted on their absolute value. */ | |
503 if (cmdchar < 0) | |
504 cmdchar = -cmdchar; | |
505 | |
506 /* If the character is in the first part: The character is the index into | |
507 * nv_cmd_idx[]. */ | |
508 if (cmdchar <= nv_max_linear) | |
509 return nv_cmd_idx[cmdchar]; | |
510 | |
511 /* Perform a binary search. */ | |
512 bot = nv_max_linear + 1; | |
513 top = NV_CMDS_SIZE - 1; | |
514 idx = -1; | |
515 while (bot <= top) | |
516 { | |
517 i = (top + bot) / 2; | |
518 c = nv_cmds[nv_cmd_idx[i]].cmd_char; | |
519 if (c < 0) | |
520 c = -c; | |
521 if (cmdchar == c) | |
522 { | |
523 idx = nv_cmd_idx[i]; | |
524 break; | |
525 } | |
526 if (cmdchar > c) | |
527 bot = i + 1; | |
528 else | |
529 top = i - 1; | |
530 } | |
531 return idx; | |
532 } | |
533 | |
534 /* | |
535 * Execute a command in Normal mode. | |
536 */ | |
537 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
538 normal_cmd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
539 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
540 int toplevel UNUSED) /* TRUE when called from main() */ |
7 | 541 { |
542 cmdarg_T ca; /* command arguments */ | |
543 int c; | |
544 int ctrl_w = FALSE; /* got CTRL-W command */ | |
545 int old_col = curwin->w_curswant; | |
546 #ifdef FEAT_CMDL_INFO | |
547 int need_flushbuf; /* need to call out_flush() */ | |
548 #endif | |
549 pos_T old_pos; /* cursor position before command */ | |
550 int mapped_len; | |
551 static int old_mapped_len = 0; | |
552 int idx; | |
1751 | 553 #ifdef FEAT_EVAL |
554 int set_prevcount = FALSE; | |
555 #endif | |
7 | 556 |
557 vim_memset(&ca, 0, sizeof(ca)); /* also resets ca.retval */ | |
558 ca.oap = oap; | |
1692 | 559 |
560 /* Use a count remembered from before entering an operator. After typing | |
561 * "3d" we return from normal_cmd() and come back here, the "3" is | |
562 * remembered in "opcount". */ | |
7 | 563 ca.opcount = opcount; |
564 | |
565 /* | |
566 * If there is an operator pending, then the command we take this time | |
567 * will terminate it. Finish_op tells us to finish the operation before | |
568 * returning this time (unless the operation was cancelled). | |
569 */ | |
570 #ifdef CURSOR_SHAPE | |
571 c = finish_op; | |
572 #endif | |
573 finish_op = (oap->op_type != OP_NOP); | |
574 #ifdef CURSOR_SHAPE | |
575 if (finish_op != c) | |
576 { | |
577 ui_cursor_shape(); /* may show different cursor shape */ | |
578 # ifdef FEAT_MOUSESHAPE | |
579 update_mouseshape(-1); | |
580 # endif | |
581 } | |
582 #endif | |
583 | |
1692 | 584 /* When not finishing an operator and no register name typed, reset the |
585 * count. */ | |
7 | 586 if (!finish_op && !oap->regname) |
1751 | 587 { |
7 | 588 ca.opcount = 0; |
1751 | 589 #ifdef FEAT_EVAL |
590 set_prevcount = TRUE; | |
591 #endif | |
592 } | |
7 | 593 |
1692 | 594 /* Restore counts from before receiving K_CURSORHOLD. This means after |
595 * typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not | |
596 * "3 * 2". */ | |
597 if (oap->prev_opcount > 0 || oap->prev_count0 > 0) | |
598 { | |
599 ca.opcount = oap->prev_opcount; | |
600 ca.count0 = oap->prev_count0; | |
601 oap->prev_opcount = 0; | |
602 oap->prev_count0 = 0; | |
603 } | |
604 | |
7 | 605 mapped_len = typebuf_maplen(); |
606 | |
607 State = NORMAL_BUSY; | |
608 #ifdef USE_ON_FLY_SCROLL | |
609 dont_scroll = FALSE; /* allow scrolling here */ | |
610 #endif | |
611 | |
2667 | 612 #ifdef FEAT_EVAL |
613 /* Set v:count here, when called from main() and not a stuffed | |
614 * command, so that v:count can be used in an expression mapping | |
5649 | 615 * when there is no count. Do set it for redo. */ |
616 if (toplevel && readbuf1_empty()) | |
2667 | 617 set_vcount_ca(&ca, &set_prevcount); |
618 #endif | |
619 | |
7 | 620 /* |
621 * Get the command character from the user. | |
622 */ | |
623 c = safe_vgetc(); | |
7703
39251e981d1f
commit https://github.com/vim/vim/commit/25281634cda03ce302aaf9f906a9520b5f81f91e
Christian Brabandt <cb@256bit.org>
parents:
7578
diff
changeset
|
624 LANGMAP_ADJUST(c, get_real_state() != SELECTMODE); |
7 | 625 |
626 /* | |
627 * If a mapping was started in Visual or Select mode, remember the length | |
628 * of the mapping. This is used below to not return to Insert mode for as | |
629 * long as the mapping is being executed. | |
630 */ | |
631 if (restart_edit == 0) | |
632 old_mapped_len = 0; | |
633 else if (old_mapped_len | |
819 | 634 || (VIsual_active && mapped_len == 0 && typebuf_maplen() > 0)) |
7 | 635 old_mapped_len = typebuf_maplen(); |
636 | |
637 if (c == NUL) | |
638 c = K_ZERO; | |
639 | |
640 /* | |
641 * In Select mode, typed text replaces the selection. | |
642 */ | |
643 if (VIsual_active | |
644 && VIsual_select | |
645 && (vim_isprintc(c) || c == NL || c == CAR || c == K_KENTER)) | |
646 { | |
275 | 647 /* Fake a "c"hange command. When "restart_edit" is set (e.g., because |
648 * 'insertmode' is set) fake a "d"elete command, Insert mode will | |
649 * restart automatically. | |
1051 | 650 * Insert the typed character in the typeahead buffer, so that it can |
651 * be mapped in Insert mode. Required for ":lmap" to work. */ | |
852 | 652 ins_char_typebuf(c); |
275 | 653 if (restart_edit != 0) |
654 c = 'd'; | |
655 else | |
656 c = 'c'; | |
695 | 657 msg_nowait = TRUE; /* don't delay going to insert mode */ |
4472 | 658 old_mapped_len = 0; /* do go to Insert mode */ |
7 | 659 } |
660 | |
661 #ifdef FEAT_CMDL_INFO | |
662 need_flushbuf = add_to_showcmd(c); | |
663 #endif | |
664 | |
665 getcount: | |
666 if (!(VIsual_active && VIsual_select)) | |
667 { | |
668 /* | |
669 * Handle a count before a command and compute ca.count0. | |
670 * Note that '0' is a command and not the start of a count, but it's | |
671 * part of a count after other digits. | |
672 */ | |
673 while ( (c >= '1' && c <= '9') | |
674 || (ca.count0 != 0 && (c == K_DEL || c == K_KDEL || c == '0'))) | |
675 { | |
676 if (c == K_DEL || c == K_KDEL) | |
677 { | |
678 ca.count0 /= 10; | |
679 #ifdef FEAT_CMDL_INFO | |
680 del_from_showcmd(4); /* delete the digit and ~@% */ | |
681 #endif | |
682 } | |
683 else | |
684 ca.count0 = ca.count0 * 10 + (c - '0'); | |
685 if (ca.count0 < 0) /* got too large! */ | |
686 ca.count0 = 999999999L; | |
1425 | 687 #ifdef FEAT_EVAL |
688 /* Set v:count here, when called from main() and not a stuffed | |
689 * command, so that v:count can be used in an expression mapping | |
5649 | 690 * right after the count. Do set it for redo. */ |
691 if (toplevel && readbuf1_empty()) | |
2667 | 692 set_vcount_ca(&ca, &set_prevcount); |
1425 | 693 #endif |
7 | 694 if (ctrl_w) |
695 { | |
696 ++no_mapping; | |
697 ++allow_keys; /* no mapping for nchar, but keys */ | |
698 } | |
699 ++no_zero_mapping; /* don't map zero here */ | |
1389 | 700 c = plain_vgetc(); |
7 | 701 LANGMAP_ADJUST(c, TRUE); |
702 --no_zero_mapping; | |
703 if (ctrl_w) | |
704 { | |
705 --no_mapping; | |
706 --allow_keys; | |
707 } | |
708 #ifdef FEAT_CMDL_INFO | |
709 need_flushbuf |= add_to_showcmd(c); | |
710 #endif | |
711 } | |
712 | |
713 /* | |
714 * If we got CTRL-W there may be a/another count | |
715 */ | |
716 if (c == Ctrl_W && !ctrl_w && oap->op_type == OP_NOP) | |
717 { | |
718 ctrl_w = TRUE; | |
719 ca.opcount = ca.count0; /* remember first count */ | |
720 ca.count0 = 0; | |
721 ++no_mapping; | |
722 ++allow_keys; /* no mapping for nchar, but keys */ | |
1389 | 723 c = plain_vgetc(); /* get next character */ |
7 | 724 LANGMAP_ADJUST(c, TRUE); |
725 --no_mapping; | |
726 --allow_keys; | |
727 #ifdef FEAT_CMDL_INFO | |
728 need_flushbuf |= add_to_showcmd(c); | |
729 #endif | |
730 goto getcount; /* jump back */ | |
731 } | |
732 } | |
733 | |
1692 | 734 if (c == K_CURSORHOLD) |
735 { | |
736 /* Save the count values so that ca.opcount and ca.count0 are exactly | |
737 * the same when coming back here after handling K_CURSORHOLD. */ | |
738 oap->prev_opcount = ca.opcount; | |
739 oap->prev_count0 = ca.count0; | |
740 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
741 else if (ca.opcount != 0) |
1692 | 742 { |
743 /* | |
744 * If we're in the middle of an operator (including after entering a | |
745 * yank buffer with '"') AND we had a count before the operator, then | |
746 * that count overrides the current value of ca.count0. | |
747 * What this means effectively, is that commands like "3dw" get turned | |
748 * into "d3w" which makes things fall into place pretty neatly. | |
749 * If you give a count before AND after the operator, they are | |
750 * multiplied. | |
751 */ | |
7 | 752 if (ca.count0) |
753 ca.count0 *= ca.opcount; | |
754 else | |
755 ca.count0 = ca.opcount; | |
756 } | |
757 | |
758 /* | |
759 * Always remember the count. It will be set to zero (on the next call, | |
760 * above) when there is no pending operator. | |
761 * When called from main(), save the count for use by the "count" built-in | |
762 * variable. | |
763 */ | |
764 ca.opcount = ca.count0; | |
765 ca.count1 = (ca.count0 == 0 ? 1 : ca.count0); | |
766 | |
767 #ifdef FEAT_EVAL | |
768 /* | |
769 * Only set v:count when called from main() and not a stuffed command. | |
5649 | 770 * Do set it for redo. |
7 | 771 */ |
5649 | 772 if (toplevel && readbuf1_empty()) |
1751 | 773 set_vcount(ca.count0, ca.count1, set_prevcount); |
7 | 774 #endif |
775 | |
776 /* | |
777 * Find the command character in the table of commands. | |
778 * For CTRL-W we already got nchar when looking for a count. | |
779 */ | |
780 if (ctrl_w) | |
781 { | |
782 ca.nchar = c; | |
783 ca.cmdchar = Ctrl_W; | |
784 } | |
785 else | |
786 ca.cmdchar = c; | |
787 idx = find_command(ca.cmdchar); | |
788 if (idx < 0) | |
789 { | |
790 /* Not a known command: beep. */ | |
791 clearopbeep(oap); | |
792 goto normal_end; | |
793 } | |
631 | 794 |
633 | 795 if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW)) |
631 | 796 { |
5848 | 797 /* This command is not allowed while editing a cmdline: beep. */ |
7 | 798 clearopbeep(oap); |
633 | 799 text_locked_msg(); |
7 | 800 goto normal_end; |
801 } | |
819 | 802 if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked()) |
803 goto normal_end; | |
7 | 804 |
805 /* | |
806 * In Visual/Select mode, a few keys are handled in a special way. | |
807 */ | |
808 if (VIsual_active) | |
809 { | |
810 /* when 'keymodel' contains "stopsel" may stop Select/Visual mode */ | |
811 if (km_stopsel | |
812 && (nv_cmds[idx].cmd_flags & NV_STS) | |
813 && !(mod_mask & MOD_MASK_SHIFT)) | |
814 { | |
815 end_visual_mode(); | |
816 redraw_curbuf_later(INVERTED); | |
817 } | |
818 | |
819 /* Keys that work different when 'keymodel' contains "startsel" */ | |
820 if (km_startsel) | |
821 { | |
822 if (nv_cmds[idx].cmd_flags & NV_SS) | |
823 { | |
824 unshift_special(&ca); | |
825 idx = find_command(ca.cmdchar); | |
840 | 826 if (idx < 0) |
827 { | |
828 /* Just in case */ | |
829 clearopbeep(oap); | |
830 goto normal_end; | |
831 } | |
7 | 832 } |
833 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
834 && (mod_mask & MOD_MASK_SHIFT)) | |
835 { | |
836 mod_mask &= ~MOD_MASK_SHIFT; | |
837 } | |
838 } | |
839 } | |
840 | |
841 #ifdef FEAT_RIGHTLEFT | |
842 if (curwin->w_p_rl && KeyTyped && !KeyStuffed | |
843 && (nv_cmds[idx].cmd_flags & NV_RL)) | |
844 { | |
845 /* Invert horizontal movements and operations. Only when typed by the | |
846 * user directly, not when the result of a mapping or "x" translated | |
847 * to "dl". */ | |
848 switch (ca.cmdchar) | |
849 { | |
850 case 'l': ca.cmdchar = 'h'; break; | |
851 case K_RIGHT: ca.cmdchar = K_LEFT; break; | |
852 case K_S_RIGHT: ca.cmdchar = K_S_LEFT; break; | |
853 case K_C_RIGHT: ca.cmdchar = K_C_LEFT; break; | |
854 case 'h': ca.cmdchar = 'l'; break; | |
855 case K_LEFT: ca.cmdchar = K_RIGHT; break; | |
856 case K_S_LEFT: ca.cmdchar = K_S_RIGHT; break; | |
857 case K_C_LEFT: ca.cmdchar = K_C_RIGHT; break; | |
858 case '>': ca.cmdchar = '<'; break; | |
859 case '<': ca.cmdchar = '>'; break; | |
860 } | |
861 idx = find_command(ca.cmdchar); | |
862 } | |
863 #endif | |
864 | |
865 /* | |
866 * Get an additional character if we need one. | |
867 */ | |
868 if ((nv_cmds[idx].cmd_flags & NV_NCH) | |
869 && (((nv_cmds[idx].cmd_flags & NV_NCH_NOP) == NV_NCH_NOP | |
870 && oap->op_type == OP_NOP) | |
871 || (nv_cmds[idx].cmd_flags & NV_NCH_ALW) == NV_NCH_ALW | |
872 || (ca.cmdchar == 'q' | |
873 && oap->op_type == OP_NOP | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13876
diff
changeset
|
874 && reg_recording == 0 |
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13876
diff
changeset
|
875 && reg_executing == 0) |
7 | 876 || ((ca.cmdchar == 'a' || ca.cmdchar == 'i') |
5735 | 877 && (oap->op_type != OP_NOP || VIsual_active)))) |
7 | 878 { |
879 int *cp; | |
880 int repl = FALSE; /* get character for replace mode */ | |
881 int lit = FALSE; /* get extra character literally */ | |
882 int langmap_active = FALSE; /* using :lmap mappings */ | |
883 int lang; /* getting a text character */ | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
884 #ifdef HAVE_INPUT_METHOD |
7 | 885 int save_smd; /* saved value of p_smd */ |
886 #endif | |
887 | |
888 ++no_mapping; | |
889 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1343 | 890 /* Don't generate a CursorHold event here, most commands can't handle |
891 * it, e.g., nv_replace(), nv_csearch(). */ | |
892 did_cursorhold = TRUE; | |
7 | 893 if (ca.cmdchar == 'g') |
894 { | |
895 /* | |
896 * For 'g' get the next character now, so that we can check for | |
897 * "gr", "g'" and "g`". | |
898 */ | |
1389 | 899 ca.nchar = plain_vgetc(); |
7 | 900 LANGMAP_ADJUST(ca.nchar, TRUE); |
901 #ifdef FEAT_CMDL_INFO | |
902 need_flushbuf |= add_to_showcmd(ca.nchar); | |
903 #endif | |
904 if (ca.nchar == 'r' || ca.nchar == '\'' || ca.nchar == '`' | |
5523 | 905 || ca.nchar == Ctrl_BSL) |
7 | 906 { |
907 cp = &ca.extra_char; /* need to get a third character */ | |
908 if (ca.nchar != 'r') | |
909 lit = TRUE; /* get it literally */ | |
910 else | |
911 repl = TRUE; /* get it in replace mode */ | |
912 } | |
913 else | |
914 cp = NULL; /* no third character needed */ | |
915 } | |
916 else | |
917 { | |
918 if (ca.cmdchar == 'r') /* get it in replace mode */ | |
919 repl = TRUE; | |
920 cp = &ca.nchar; | |
921 } | |
922 lang = (repl || (nv_cmds[idx].cmd_flags & NV_LANG)); | |
923 | |
924 /* | |
925 * Get a second or third character. | |
926 */ | |
927 if (cp != NULL) | |
928 { | |
929 #ifdef CURSOR_SHAPE | |
930 if (repl) | |
931 { | |
932 State = REPLACE; /* pretend Replace mode */ | |
933 ui_cursor_shape(); /* show different cursor shape */ | |
934 } | |
935 #endif | |
936 if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) | |
937 { | |
938 /* Allow mappings defined with ":lmap". */ | |
939 --no_mapping; | |
940 --allow_keys; | |
941 if (repl) | |
942 State = LREPLACE; | |
943 else | |
944 State = LANGMAP; | |
945 langmap_active = TRUE; | |
946 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
947 #ifdef HAVE_INPUT_METHOD |
7 | 948 save_smd = p_smd; |
949 p_smd = FALSE; /* Don't let the IM code show the mode here */ | |
950 if (lang && curbuf->b_p_iminsert == B_IMODE_IM) | |
951 im_set_active(TRUE); | |
952 #endif | |
953 | |
1389 | 954 *cp = plain_vgetc(); |
7 | 955 |
956 if (langmap_active) | |
957 { | |
958 /* Undo the decrement done above */ | |
959 ++no_mapping; | |
960 ++allow_keys; | |
961 State = NORMAL_BUSY; | |
962 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
963 #ifdef HAVE_INPUT_METHOD |
7 | 964 if (lang) |
965 { | |
966 if (curbuf->b_p_iminsert != B_IMODE_LMAP) | |
967 im_save_status(&curbuf->b_p_iminsert); | |
968 im_set_active(FALSE); | |
969 } | |
970 p_smd = save_smd; | |
971 #endif | |
972 #ifdef CURSOR_SHAPE | |
973 State = NORMAL_BUSY; | |
974 #endif | |
975 #ifdef FEAT_CMDL_INFO | |
976 need_flushbuf |= add_to_showcmd(*cp); | |
977 #endif | |
978 | |
979 if (!lit) | |
980 { | |
981 #ifdef FEAT_DIGRAPHS | |
982 /* Typing CTRL-K gets a digraph. */ | |
983 if (*cp == Ctrl_K | |
984 && ((nv_cmds[idx].cmd_flags & NV_LANG) | |
985 || cp == &ca.extra_char) | |
986 && vim_strchr(p_cpo, CPO_DIGRAPH) == NULL) | |
987 { | |
988 c = get_digraph(FALSE); | |
989 if (c > 0) | |
990 { | |
991 *cp = c; | |
992 # ifdef FEAT_CMDL_INFO | |
993 /* Guessing how to update showcmd here... */ | |
994 del_from_showcmd(3); | |
995 need_flushbuf |= add_to_showcmd(*cp); | |
996 # endif | |
997 } | |
998 } | |
999 #endif | |
1000 | |
1001 /* adjust chars > 127, except after "tTfFr" commands */ | |
1002 LANGMAP_ADJUST(*cp, !lang); | |
1003 #ifdef FEAT_RIGHTLEFT | |
1004 /* adjust Hebrew mapped char */ | |
1005 if (p_hkmap && lang && KeyTyped) | |
1006 *cp = hkmap(*cp); | |
1007 # ifdef FEAT_FKMAP | |
1008 /* adjust Farsi mapped char */ | |
1009 if (p_fkmap && lang && KeyTyped) | |
1010 *cp = fkmap(*cp); | |
1011 # endif | |
1012 #endif | |
1013 } | |
1014 | |
1015 /* | |
1016 * When the next character is CTRL-\ a following CTRL-N means the | |
1017 * command is aborted and we go to Normal mode. | |
1018 */ | |
1019 if (cp == &ca.extra_char | |
1020 && ca.nchar == Ctrl_BSL | |
1021 && (ca.extra_char == Ctrl_N || ca.extra_char == Ctrl_G)) | |
1022 { | |
1023 ca.cmdchar = Ctrl_BSL; | |
1024 ca.nchar = ca.extra_char; | |
1025 idx = find_command(ca.cmdchar); | |
1026 } | |
3908 | 1027 else if ((ca.nchar == 'n' || ca.nchar == 'N') && ca.cmdchar == 'g') |
3896 | 1028 ca.oap->op_type = get_op_type(*cp, NUL); |
7 | 1029 else if (*cp == Ctrl_BSL) |
1030 { | |
1031 long towait = (p_ttm >= 0 ? p_ttm : p_tm); | |
1032 | |
1033 /* There is a busy wait here when typing "f<C-\>" and then | |
1034 * something different from CTRL-N. Can't be avoided. */ | |
1035 while ((c = vpeekc()) <= 0 && towait > 0L) | |
1036 { | |
1037 do_sleep(towait > 50L ? 50L : towait); | |
1038 towait -= 50L; | |
1039 } | |
1040 if (c > 0) | |
1041 { | |
1389 | 1042 c = plain_vgetc(); |
7 | 1043 if (c != Ctrl_N && c != Ctrl_G) |
1044 vungetc(c); | |
1045 else | |
1046 { | |
1047 ca.cmdchar = Ctrl_BSL; | |
1048 ca.nchar = c; | |
1049 idx = find_command(ca.cmdchar); | |
1050 } | |
1051 } | |
1052 } | |
1053 | |
1054 #ifdef FEAT_MBYTE | |
1055 /* When getting a text character and the next character is a | |
1056 * multi-byte character, it could be a composing character. | |
6071 | 1057 * However, don't wait for it to arrive. Also, do enable mapping, |
1058 * because if it's put back with vungetc() it's too late to apply | |
1059 * mapping. */ | |
1060 --no_mapping; | |
7 | 1061 while (enc_utf8 && lang && (c = vpeekc()) > 0 |
1062 && (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) | |
1063 { | |
1389 | 1064 c = plain_vgetc(); |
7 | 1065 if (!utf_iscomposing(c)) |
1066 { | |
1067 vungetc(c); /* it wasn't, put it back */ | |
1068 break; | |
1069 } | |
1070 else if (ca.ncharC1 == 0) | |
1071 ca.ncharC1 = c; | |
1072 else | |
1073 ca.ncharC2 = c; | |
1074 } | |
6071 | 1075 ++no_mapping; |
7 | 1076 #endif |
1077 } | |
1078 --no_mapping; | |
1079 --allow_keys; | |
1080 } | |
1081 | |
1082 #ifdef FEAT_CMDL_INFO | |
1083 /* | |
1084 * Flush the showcmd characters onto the screen so we can see them while | |
1085 * the command is being executed. Only do this when the shown command was | |
1086 * actually displayed, otherwise this will slow down a lot when executing | |
1087 * mappings. | |
1088 */ | |
1089 if (need_flushbuf) | |
1090 out_flush(); | |
1091 #endif | |
1727 | 1092 if (ca.cmdchar != K_IGNORE) |
1093 did_cursorhold = FALSE; | |
7 | 1094 |
1095 State = NORMAL; | |
1096 | |
1097 if (ca.nchar == ESC) | |
1098 { | |
1099 clearop(oap); | |
1100 if (restart_edit == 0 && goto_im()) | |
1101 restart_edit = 'a'; | |
1102 goto normal_end; | |
1103 } | |
1104 | |
24 | 1105 if (ca.cmdchar != K_IGNORE) |
1106 { | |
1107 msg_didout = FALSE; /* don't scroll screen up for normal command */ | |
1108 msg_col = 0; | |
1109 } | |
7 | 1110 |
1111 old_pos = curwin->w_cursor; /* remember where cursor was */ | |
1112 | |
1113 /* When 'keymodel' contains "startsel" some keys start Select/Visual | |
1114 * mode. */ | |
1115 if (!VIsual_active && km_startsel) | |
1116 { | |
1117 if (nv_cmds[idx].cmd_flags & NV_SS) | |
1118 { | |
1119 start_selection(); | |
1120 unshift_special(&ca); | |
1121 idx = find_command(ca.cmdchar); | |
1122 } | |
1123 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
1124 && (mod_mask & MOD_MASK_SHIFT)) | |
1125 { | |
1126 start_selection(); | |
1127 mod_mask &= ~MOD_MASK_SHIFT; | |
1128 } | |
1129 } | |
1130 | |
1131 /* | |
1132 * Execute the command! | |
1133 * Call the command function found in the commands table. | |
1134 */ | |
1135 ca.arg = nv_cmds[idx].cmd_arg; | |
1136 (nv_cmds[idx].cmd_func)(&ca); | |
1137 | |
1138 /* | |
1139 * If we didn't start or finish an operator, reset oap->regname, unless we | |
1140 * need it later. | |
1141 */ | |
1142 if (!finish_op | |
1143 && !oap->op_type | |
1144 && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) | |
1145 { | |
1146 clearop(oap); | |
1147 #ifdef FEAT_EVAL | |
2821 | 1148 { |
1149 int regname = 0; | |
2829 | 1150 |
2821 | 1151 /* Adjust the register according to 'clipboard', so that when |
1152 * "unnamed" is present it becomes '*' or '+' instead of '"'. */ | |
2829 | 1153 # ifdef FEAT_CLIPBOARD |
2821 | 1154 adjust_clip_reg(®name); |
2829 | 1155 # endif |
2821 | 1156 set_reg_var(regname); |
1157 } | |
7 | 1158 #endif |
1159 } | |
1160 | |
570 | 1161 /* Get the length of mapped chars again after typing a count, second |
36 | 1162 * character or "z333<cr>". */ |
1163 if (old_mapped_len > 0) | |
1164 old_mapped_len = typebuf_maplen(); | |
1165 | |
7 | 1166 /* |
1167 * If an operation is pending, handle it... | |
1168 */ | |
1169 do_pending_operator(&ca, old_col, FALSE); | |
1170 | |
1171 /* | |
1172 * Wait for a moment when a message is displayed that will be overwritten | |
1173 * by the mode message. | |
1174 * In Visual mode and with "^O" in Insert mode, a short message will be | |
1175 * overwritten by the mode message. Wait a bit, until a key is hit. | |
1176 * In Visual mode, it's more important to keep the Visual area updated | |
1177 * than keeping a message (e.g. from a /pat search). | |
1178 * Only do this if the command was typed, not from a mapping. | |
1179 * Don't wait when emsg_silent is non-zero. | |
1180 * Also wait a bit after an error message, e.g. for "^O:". | |
1181 * Don't redraw the screen, it would remove the message. | |
1182 */ | |
1183 if ( ((p_smd | |
641 | 1184 && msg_silent == 0 |
7 | 1185 && (restart_edit != 0 |
1186 || (VIsual_active | |
1187 && old_pos.lnum == curwin->w_cursor.lnum | |
1188 && old_pos.col == curwin->w_cursor.col) | |
1189 ) | |
1190 && (clear_cmdline | |
1191 || redraw_cmdline) | |
1192 && (msg_didout || (msg_didany && msg_scroll)) | |
1193 && !msg_nowait | |
1194 && KeyTyped) | |
1195 || (restart_edit != 0 | |
1196 && !VIsual_active | |
1197 && (msg_scroll | |
1198 || emsg_on_display))) | |
1199 && oap->regname == 0 | |
1200 && !(ca.retval & CA_COMMAND_BUSY) | |
1201 && stuff_empty() | |
1202 && typebuf_typed() | |
1203 && emsg_silent == 0 | |
1204 && !did_wait_return | |
1205 && oap->op_type == OP_NOP) | |
1206 { | |
1207 int save_State = State; | |
1208 | |
1209 /* Draw the cursor with the right shape here */ | |
1210 if (restart_edit != 0) | |
1211 State = INSERT; | |
1212 | |
1213 /* If need to redraw, and there is a "keep_msg", redraw before the | |
1214 * delay */ | |
1215 if (must_redraw && keep_msg != NULL && !emsg_on_display) | |
1216 { | |
1217 char_u *kmsg; | |
1218 | |
1219 kmsg = keep_msg; | |
1220 keep_msg = NULL; | |
1221 /* showmode() will clear keep_msg, but we want to use it anyway */ | |
1222 update_screen(0); | |
1223 /* now reset it, otherwise it's put in the history again */ | |
1224 keep_msg = kmsg; | |
1225 msg_attr(kmsg, keep_msg_attr); | |
1226 vim_free(kmsg); | |
1227 } | |
1228 setcursor(); | |
1229 cursor_on(); | |
1230 out_flush(); | |
1231 if (msg_scroll || emsg_on_display) | |
1232 ui_delay(1000L, TRUE); /* wait at least one second */ | |
1233 ui_delay(3000L, FALSE); /* wait up to three seconds */ | |
1234 State = save_State; | |
1235 | |
1236 msg_scroll = FALSE; | |
1237 emsg_on_display = FALSE; | |
1238 } | |
1239 | |
1240 /* | |
1241 * Finish up after executing a Normal mode command. | |
1242 */ | |
1243 normal_end: | |
1244 | |
1245 msg_nowait = FALSE; | |
1246 | |
1247 /* Reset finish_op, in case it was set */ | |
1248 #ifdef CURSOR_SHAPE | |
1249 c = finish_op; | |
1250 #endif | |
1251 finish_op = FALSE; | |
1252 #ifdef CURSOR_SHAPE | |
1253 /* Redraw the cursor with another shape, if we were in Operator-pending | |
1254 * mode or did a replace command. */ | |
1255 if (c || ca.cmdchar == 'r') | |
1256 { | |
1257 ui_cursor_shape(); /* may show different cursor shape */ | |
1258 # ifdef FEAT_MOUSESHAPE | |
1259 update_mouseshape(-1); | |
1260 # endif | |
1261 } | |
1262 #endif | |
1263 | |
1264 #ifdef FEAT_CMDL_INFO | |
1692 | 1265 if (oap->op_type == OP_NOP && oap->regname == 0 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
1266 && ca.cmdchar != K_CURSORHOLD) |
7 | 1267 clear_showcmd(); |
1268 #endif | |
1269 | |
1270 checkpcmark(); /* check if we moved since setting pcmark */ | |
1271 vim_free(ca.searchbuf); | |
1272 | |
1273 #ifdef FEAT_MBYTE | |
1274 if (has_mbyte) | |
1275 mb_adjust_cursor(); | |
1276 #endif | |
1277 | |
1278 if (curwin->w_p_scb && toplevel) | |
1279 { | |
1280 validate_cursor(); /* may need to update w_leftcol */ | |
1281 do_check_scrollbind(TRUE); | |
1282 } | |
13384
6740c499de13
patch 8.0.1566: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1283 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1284 if (curwin->w_p_crb && toplevel) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1285 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1286 validate_cursor(); /* may need to update w_leftcol */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1287 do_check_cursorbind(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1288 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1289 |
12134
e83c6c10320c
patch 8.0.0947: entering terminal using C-O C-W C-W goes to Insert mode
Christian Brabandt <cb@256bit.org>
parents:
11993
diff
changeset
|
1290 #ifdef FEAT_TERMINAL |
12467
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
1291 /* don't go to Insert mode if a terminal has a running job */ |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
1292 if (term_job_running(curbuf->b_term)) |
12134
e83c6c10320c
patch 8.0.0947: entering terminal using C-O C-W C-W goes to Insert mode
Christian Brabandt <cb@256bit.org>
parents:
11993
diff
changeset
|
1293 restart_edit = 0; |
e83c6c10320c
patch 8.0.0947: entering terminal using C-O C-W C-W goes to Insert mode
Christian Brabandt <cb@256bit.org>
parents:
11993
diff
changeset
|
1294 #endif |
e83c6c10320c
patch 8.0.0947: entering terminal using C-O C-W C-W goes to Insert mode
Christian Brabandt <cb@256bit.org>
parents:
11993
diff
changeset
|
1295 |
7 | 1296 /* |
1297 * May restart edit(), if we got here with CTRL-O in Insert mode (but not | |
1298 * if still inside a mapping that started in Visual mode). | |
1299 * May switch from Visual to Select mode after CTRL-O command. | |
1300 */ | |
1301 if ( oap->op_type == OP_NOP | |
1302 && ((restart_edit != 0 && !VIsual_active && old_mapped_len == 0) | |
1303 || restart_VIsual_select == 1) | |
1304 && !(ca.retval & CA_COMMAND_BUSY) | |
1305 && stuff_empty() | |
1306 && oap->regname == 0) | |
1307 { | |
1308 if (restart_VIsual_select == 1) | |
1309 { | |
1310 VIsual_select = TRUE; | |
1311 showmode(); | |
1312 restart_VIsual_select = 0; | |
1313 } | |
5735 | 1314 if (restart_edit != 0 && !VIsual_active && old_mapped_len == 0) |
7 | 1315 (void)edit(restart_edit, FALSE, 1L); |
1316 } | |
1317 | |
1318 if (restart_VIsual_select == 2) | |
1319 restart_VIsual_select = 1; | |
1320 | |
1321 /* Save count before an operator for next time. */ | |
1322 opcount = ca.opcount; | |
1323 } | |
1324 | |
2667 | 1325 #ifdef FEAT_EVAL |
1326 /* | |
1327 * Set v:count and v:count1 according to "cap". | |
1328 * Set v:prevcount only when "set_prevcount" is TRUE. | |
1329 */ | |
1330 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1331 set_vcount_ca(cmdarg_T *cap, int *set_prevcount) |
2667 | 1332 { |
1333 long count = cap->count0; | |
1334 | |
1335 /* multiply with cap->opcount the same way as above */ | |
1336 if (cap->opcount != 0) | |
1337 count = cap->opcount * (count == 0 ? 1 : count); | |
1338 set_vcount(count, count == 0 ? 1 : count, *set_prevcount); | |
1339 *set_prevcount = FALSE; /* only set v:prevcount once */ | |
1340 } | |
1341 #endif | |
1342 | |
7 | 1343 /* |
1344 * Handle an operator after visual mode or when the movement is finished | |
1345 */ | |
1346 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1347 do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank) |
7 | 1348 { |
1349 oparg_T *oap = cap->oap; | |
1350 pos_T old_cursor; | |
1351 int empty_region_error; | |
1352 int restart_edit_save; | |
6266 | 1353 #ifdef FEAT_LINEBREAK |
1354 int lbr_saved = curwin->w_p_lbr; | |
1355 #endif | |
7 | 1356 |
1357 /* The visual area is remembered for redo */ | |
1358 static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ | |
1359 static linenr_T redo_VIsual_line_count; /* number of lines */ | |
3125 | 1360 static colnr_T redo_VIsual_vcol; /* number of cols or end column */ |
7 | 1361 static long redo_VIsual_count; /* count for Visual operator */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
1362 static int redo_VIsual_arg; /* extra argument */ |
5735 | 1363 #ifdef FEAT_VIRTUALEDIT |
7 | 1364 int include_line_break = FALSE; |
1365 #endif | |
1366 | |
1367 #if defined(FEAT_CLIPBOARD) | |
1368 /* | |
1369 * Yank the visual area into the GUI selection register before we operate | |
1370 * on it and lose it forever. | |
1371 * Don't do it if a specific register was specified, so that ""x"*P works. | |
1372 * This could call do_pending_operator() recursively, but that's OK | |
1373 * because gui_yank will be TRUE for the nested call. | |
1374 */ | |
3674 | 1375 if ((clip_star.available || clip_plus.available) |
7 | 1376 && oap->op_type != OP_NOP |
1377 && !gui_yank | |
1378 && VIsual_active | |
1379 && !redo_VIsual_busy | |
1380 && oap->regname == 0) | |
1381 clip_auto_select(); | |
1382 #endif | |
1383 old_cursor = curwin->w_cursor; | |
1384 | |
1385 /* | |
1386 * If an operation is pending, handle it... | |
1387 */ | |
5735 | 1388 if ((finish_op || VIsual_active) && oap->op_type != OP_NOP) |
1389 { | |
6497 | 1390 #ifdef FEAT_LINEBREAK |
1391 /* Avoid a problem with unwanted linebreaks in block mode. */ | |
6866 | 1392 if (curwin->w_p_lbr) |
1393 curwin->w_valid &= ~VALID_VIRTCOL; | |
6497 | 1394 curwin->w_p_lbr = FALSE; |
1395 #endif | |
7 | 1396 oap->is_VIsual = VIsual_active; |
1397 if (oap->motion_force == 'V') | |
1398 oap->motion_type = MLINE; | |
1399 else if (oap->motion_force == 'v') | |
1400 { | |
1401 /* If the motion was linewise, "inclusive" will not have been set. | |
1402 * Use "exclusive" to be consistent. Makes "dvj" work nice. */ | |
1403 if (oap->motion_type == MLINE) | |
1404 oap->inclusive = FALSE; | |
1405 /* If the motion already was characterwise, toggle "inclusive" */ | |
1406 else if (oap->motion_type == MCHAR) | |
1407 oap->inclusive = !oap->inclusive; | |
1408 oap->motion_type = MCHAR; | |
1409 } | |
1410 else if (oap->motion_force == Ctrl_V) | |
1411 { | |
1412 /* Change line- or characterwise motion into Visual block mode. */ | |
1413 VIsual_active = TRUE; | |
1414 VIsual = oap->start; | |
1415 VIsual_mode = Ctrl_V; | |
1416 VIsual_select = FALSE; | |
1417 VIsual_reselect = FALSE; | |
1418 } | |
1419 | |
4337 | 1420 /* Only redo yank when 'y' flag is in 'cpoptions'. */ |
1421 /* Never redo "zf" (define fold). */ | |
7 | 1422 if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) |
4337 | 1423 && ((!VIsual_active || oap->motion_force) |
1424 /* Also redo Operator-pending Visual mode mappings */ | |
1425 || (VIsual_active && cap->cmdchar == ':' | |
1426 && oap->op_type != OP_COLON)) | |
164 | 1427 && cap->cmdchar != 'D' |
7 | 1428 #ifdef FEAT_FOLDING |
1429 && oap->op_type != OP_FOLD | |
1430 && oap->op_type != OP_FOLDOPEN | |
1431 && oap->op_type != OP_FOLDOPENREC | |
1432 && oap->op_type != OP_FOLDCLOSE | |
1433 && oap->op_type != OP_FOLDCLOSEREC | |
1434 && oap->op_type != OP_FOLDDEL | |
1435 && oap->op_type != OP_FOLDDELREC | |
1436 #endif | |
1437 ) | |
1438 { | |
1439 prep_redo(oap->regname, cap->count0, | |
1440 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1441 oap->motion_force, cap->cmdchar, cap->nchar); | |
1442 if (cap->cmdchar == '/' || cap->cmdchar == '?') /* was a search */ | |
1443 { | |
1444 /* | |
1445 * If 'cpoptions' does not contain 'r', insert the search | |
1446 * pattern to really repeat the same command. | |
1447 */ | |
1448 if (vim_strchr(p_cpo, CPO_REDO) == NULL) | |
620 | 1449 AppendToRedobuffLit(cap->searchbuf, -1); |
7 | 1450 AppendToRedobuff(NL_STR); |
1451 } | |
1452 else if (cap->cmdchar == ':') | |
1453 { | |
1454 /* do_cmdline() has stored the first typed line in | |
1455 * "repeat_cmdline". When several lines are typed repeating | |
1456 * won't be possible. */ | |
1457 if (repeat_cmdline == NULL) | |
1458 ResetRedobuff(); | |
1459 else | |
1460 { | |
620 | 1461 AppendToRedobuffLit(repeat_cmdline, -1); |
7 | 1462 AppendToRedobuff(NL_STR); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
1463 VIM_CLEAR(repeat_cmdline); |
7 | 1464 } |
1465 } | |
1466 } | |
1467 | |
1468 if (redo_VIsual_busy) | |
1469 { | |
3125 | 1470 /* Redo of an operation on a Visual area. Use the same size from |
1471 * redo_VIsual_line_count and redo_VIsual_vcol. */ | |
7 | 1472 oap->start = curwin->w_cursor; |
1473 curwin->w_cursor.lnum += redo_VIsual_line_count - 1; | |
1474 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
1475 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
1476 VIsual_mode = redo_VIsual_mode; | |
3125 | 1477 if (redo_VIsual_vcol == MAXCOL || VIsual_mode == 'v') |
7 | 1478 { |
3125 | 1479 if (VIsual_mode == 'v') |
1480 { | |
1481 if (redo_VIsual_line_count <= 1) | |
1482 { | |
1483 validate_virtcol(); | |
1484 curwin->w_curswant = | |
1485 curwin->w_virtcol + redo_VIsual_vcol - 1; | |
1486 } | |
1487 else | |
1488 curwin->w_curswant = redo_VIsual_vcol; | |
1489 } | |
7 | 1490 else |
3125 | 1491 { |
1492 curwin->w_curswant = MAXCOL; | |
1493 } | |
1494 coladvance(curwin->w_curswant); | |
7 | 1495 } |
1496 cap->count0 = redo_VIsual_count; | |
1497 if (redo_VIsual_count != 0) | |
1498 cap->count1 = redo_VIsual_count; | |
1499 else | |
1500 cap->count1 = 1; | |
1501 } | |
1502 else if (VIsual_active) | |
1503 { | |
999 | 1504 if (!gui_yank) |
1505 { | |
1506 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
1507 curbuf->b_visual.vi_start = VIsual; | |
1508 curbuf->b_visual.vi_end = curwin->w_cursor; | |
1509 curbuf->b_visual.vi_mode = VIsual_mode; | |
4213 | 1510 if (VIsual_mode_orig != NUL) |
1511 { | |
1512 curbuf->b_visual.vi_mode = VIsual_mode_orig; | |
1513 VIsual_mode_orig = NUL; | |
1514 } | |
999 | 1515 curbuf->b_visual.vi_curswant = curwin->w_curswant; |
7 | 1516 # ifdef FEAT_EVAL |
999 | 1517 curbuf->b_visual_mode_eval = VIsual_mode; |
7 | 1518 # endif |
999 | 1519 } |
7 | 1520 |
1521 /* In Select mode, a linewise selection is operated upon like a | |
6826 | 1522 * characterwise selection. |
1523 * Special case: gH<Del> deletes the last line. */ | |
1524 if (VIsual_select && VIsual_mode == 'V' | |
1525 && cap->oap->op_type != OP_DELETE) | |
7 | 1526 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1527 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 1528 { |
1529 VIsual.col = 0; | |
1530 curwin->w_cursor.col = | |
1531 (colnr_T)STRLEN(ml_get(curwin->w_cursor.lnum)); | |
1532 } | |
1533 else | |
1534 { | |
1535 curwin->w_cursor.col = 0; | |
1536 VIsual.col = (colnr_T)STRLEN(ml_get(VIsual.lnum)); | |
1537 } | |
1538 VIsual_mode = 'v'; | |
1539 } | |
1540 /* If 'selection' is "exclusive", backup one character for | |
1541 * charwise selections. */ | |
1542 else if (VIsual_mode == 'v') | |
1543 { | |
1544 # ifdef FEAT_VIRTUALEDIT | |
1545 include_line_break = | |
1546 # endif | |
1547 unadjust_for_sel(); | |
1548 } | |
1549 | |
1550 oap->start = VIsual; | |
1551 if (VIsual_mode == 'V') | |
12164
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1552 { |
7 | 1553 oap->start.col = 0; |
12164
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1554 # ifdef FEAT_VIRTUALEDIT |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1555 oap->start.coladd = 0; |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1556 # endif |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1557 } |
7 | 1558 } |
1559 | |
1560 /* | |
1561 * Set oap->start to the first position of the operated text, oap->end | |
1562 * to the end of the operated text. w_cursor is equal to oap->start. | |
1563 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1564 if (LT_POS(oap->start, curwin->w_cursor)) |
7 | 1565 { |
1566 #ifdef FEAT_FOLDING | |
1567 /* Include folded lines completely. */ | |
1568 if (!VIsual_active) | |
1569 { | |
1570 if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL)) | |
1571 oap->start.col = 0; | |
1572 if (hasFolding(curwin->w_cursor.lnum, NULL, | |
1573 &curwin->w_cursor.lnum)) | |
1574 curwin->w_cursor.col = (colnr_T)STRLEN(ml_get_curline()); | |
1575 } | |
1576 #endif | |
1577 oap->end = curwin->w_cursor; | |
1578 curwin->w_cursor = oap->start; | |
1579 | |
1580 /* w_virtcol may have been updated; if the cursor goes back to its | |
1581 * previous position w_virtcol becomes invalid and isn't updated | |
1582 * automatically. */ | |
1583 curwin->w_valid &= ~VALID_VIRTCOL; | |
1584 } | |
1585 else | |
1586 { | |
1587 #ifdef FEAT_FOLDING | |
1588 /* Include folded lines completely. */ | |
1589 if (!VIsual_active && oap->motion_type == MLINE) | |
1590 { | |
1591 if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, | |
1592 NULL)) | |
1593 curwin->w_cursor.col = 0; | |
1594 if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) | |
1595 oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum)); | |
1596 } | |
1597 #endif | |
1598 oap->end = oap->start; | |
1599 oap->start = curwin->w_cursor; | |
1600 } | |
1601 | |
10154
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10110
diff
changeset
|
1602 /* Just in case lines were deleted that make the position invalid. */ |
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10110
diff
changeset
|
1603 check_pos(curwin->w_buffer, &oap->end); |
7 | 1604 oap->line_count = oap->end.lnum - oap->start.lnum + 1; |
1605 | |
1606 #ifdef FEAT_VIRTUALEDIT | |
1607 /* Set "virtual_op" before resetting VIsual_active. */ | |
1608 virtual_op = virtual_active(); | |
1609 #endif | |
1610 | |
1611 if (VIsual_active || redo_VIsual_busy) | |
1612 { | |
6866 | 1613 get_op_vcol(oap, redo_VIsual_vcol, TRUE); |
7 | 1614 |
1615 if (!redo_VIsual_busy && !gui_yank) | |
1616 { | |
1617 /* | |
1618 * Prepare to reselect and redo Visual: this is based on the | |
1619 * size of the Visual text | |
1620 */ | |
1621 resel_VIsual_mode = VIsual_mode; | |
1622 if (curwin->w_curswant == MAXCOL) | |
3125 | 1623 resel_VIsual_vcol = MAXCOL; |
7 | 1624 else |
3125 | 1625 { |
1626 if (VIsual_mode != Ctrl_V) | |
1627 getvvcol(curwin, &(oap->end), | |
1628 NULL, NULL, &oap->end_vcol); | |
1629 if (VIsual_mode == Ctrl_V || oap->line_count <= 1) | |
1630 { | |
1631 if (VIsual_mode != Ctrl_V) | |
1632 getvvcol(curwin, &(oap->start), | |
1633 &oap->start_vcol, NULL, NULL); | |
1634 resel_VIsual_vcol = oap->end_vcol - oap->start_vcol + 1; | |
1635 } | |
1636 else | |
1637 resel_VIsual_vcol = oap->end_vcol; | |
1638 } | |
7 | 1639 resel_VIsual_line_count = oap->line_count; |
1640 } | |
1641 | |
1642 /* can't redo yank (unless 'y' is in 'cpoptions') and ":" */ | |
1643 if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) | |
1644 && oap->op_type != OP_COLON | |
1645 #ifdef FEAT_FOLDING | |
1646 && oap->op_type != OP_FOLD | |
1647 && oap->op_type != OP_FOLDOPEN | |
1648 && oap->op_type != OP_FOLDOPENREC | |
1649 && oap->op_type != OP_FOLDCLOSE | |
1650 && oap->op_type != OP_FOLDCLOSEREC | |
1651 && oap->op_type != OP_FOLDDEL | |
1652 && oap->op_type != OP_FOLDDELREC | |
1653 #endif | |
1654 && oap->motion_force == NUL | |
1655 ) | |
1656 { | |
1657 /* Prepare for redoing. Only use the nchar field for "r", | |
1658 * otherwise it might be the second char of the operator. */ | |
3701 | 1659 if (cap->cmdchar == 'g' && (cap->nchar == 'n' |
1660 || cap->nchar == 'N')) | |
5523 | 1661 prep_redo(oap->regname, cap->count0, |
1662 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1663 oap->motion_force, cap->cmdchar, cap->nchar); | |
4337 | 1664 else if (cap->cmdchar != ':') |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1665 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1666 int nchar = oap->op_type == OP_REPLACE ? cap->nchar : NUL; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1667 |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1668 /* reverse what nv_replace() did */ |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1669 if (nchar == REPLACE_CR_NCHAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1670 nchar = CAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1671 else if (nchar == REPLACE_NL_NCHAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1672 nchar = NL; |
3701 | 1673 prep_redo(oap->regname, 0L, NUL, 'v', |
1674 get_op_char(oap->op_type), | |
1675 get_extra_op_char(oap->op_type), | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1676 nchar); |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1677 } |
7 | 1678 if (!redo_VIsual_busy) |
1679 { | |
1680 redo_VIsual_mode = resel_VIsual_mode; | |
3125 | 1681 redo_VIsual_vcol = resel_VIsual_vcol; |
7 | 1682 redo_VIsual_line_count = resel_VIsual_line_count; |
1683 redo_VIsual_count = cap->count0; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
1684 redo_VIsual_arg = cap->arg; |
7 | 1685 } |
1686 } | |
1687 | |
1688 /* | |
1689 * oap->inclusive defaults to TRUE. | |
1690 * If oap->end is on a NUL (empty line) oap->inclusive becomes | |
1691 * FALSE. This makes "d}P" and "v}dP" work the same. | |
1692 */ | |
1693 if (oap->motion_force == NUL || oap->motion_type == MLINE) | |
1694 oap->inclusive = TRUE; | |
1695 if (VIsual_mode == 'V') | |
1696 oap->motion_type = MLINE; | |
1697 else | |
1698 { | |
1699 oap->motion_type = MCHAR; | |
1700 if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL | |
5735 | 1701 #ifdef FEAT_VIRTUALEDIT |
7 | 1702 && (include_line_break || !virtual_op) |
5735 | 1703 #endif |
7 | 1704 ) |
1705 { | |
1706 oap->inclusive = FALSE; | |
1707 /* Try to include the newline, unless it's an operator | |
2957 | 1708 * that works on lines only. */ |
6826 | 1709 if (*p_sel != 'o' |
1710 && !op_on_lines(oap->op_type) | |
1711 && oap->end.lnum < curbuf->b_ml.ml_line_count) | |
7 | 1712 { |
6826 | 1713 ++oap->end.lnum; |
1714 oap->end.col = 0; | |
5735 | 1715 #ifdef FEAT_VIRTUALEDIT |
6826 | 1716 oap->end.coladd = 0; |
1717 #endif | |
1718 ++oap->line_count; | |
7 | 1719 } |
1720 } | |
1721 } | |
1722 | |
1723 redo_VIsual_busy = FALSE; | |
592 | 1724 |
7 | 1725 /* |
1726 * Switch Visual off now, so screen updating does | |
1727 * not show inverted text when the screen is redrawn. | |
1728 * With OP_YANK and sometimes with OP_COLON and OP_FILTER there is | |
1729 * no screen redraw, so it is done here to remove the inverted | |
1730 * part. | |
1731 */ | |
1732 if (!gui_yank) | |
1733 { | |
1734 VIsual_active = FALSE; | |
5735 | 1735 #ifdef FEAT_MOUSE |
7 | 1736 setmouse(); |
1737 mouse_dragging = 0; | |
5735 | 1738 #endif |
6979 | 1739 may_clear_cmdline(); |
7 | 1740 if ((oap->op_type == OP_YANK |
1741 || oap->op_type == OP_COLON | |
592 | 1742 || oap->op_type == OP_FUNCTION |
7 | 1743 || oap->op_type == OP_FILTER) |
1744 && oap->motion_force == NUL) | |
6497 | 1745 { |
1746 #ifdef FEAT_LINEBREAK | |
1747 /* make sure redrawing is correct */ | |
1748 curwin->w_p_lbr = lbr_saved; | |
1749 #endif | |
7 | 1750 redraw_curbuf_later(INVERTED); |
6497 | 1751 } |
7 | 1752 } |
1753 } | |
1754 | |
1755 #ifdef FEAT_MBYTE | |
1756 /* Include the trailing byte of a multi-byte char. */ | |
1757 if (has_mbyte && oap->inclusive) | |
1758 { | |
1759 int l; | |
1760 | |
474 | 1761 l = (*mb_ptr2len)(ml_get_pos(&oap->end)); |
7 | 1762 if (l > 1) |
1763 oap->end.col += l - 1; | |
1764 } | |
1765 #endif | |
1766 curwin->w_set_curswant = TRUE; | |
1767 | |
1768 /* | |
1769 * oap->empty is set when start and end are the same. The inclusive | |
1770 * flag affects this too, unless yanking and the end is on a NUL. | |
1771 */ | |
1772 oap->empty = (oap->motion_type == MCHAR | |
1773 && (!oap->inclusive | |
1774 || (oap->op_type == OP_YANK | |
1775 && gchar_pos(&oap->end) == NUL)) | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1776 && EQUAL_POS(oap->start, oap->end) |
7 | 1777 #ifdef FEAT_VIRTUALEDIT |
1778 && !(virtual_op && oap->start.coladd != oap->end.coladd) | |
1779 #endif | |
1780 ); | |
1781 /* | |
1782 * For delete, change and yank, it's an error to operate on an | |
1783 * empty region, when 'E' included in 'cpoptions' (Vi compatible). | |
1784 */ | |
1785 empty_region_error = (oap->empty | |
1786 && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL); | |
1787 | |
1788 /* Force a redraw when operating on an empty Visual region, when | |
1789 * 'modifiable is off or creating a fold. */ | |
1790 if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma | |
5735 | 1791 #ifdef FEAT_FOLDING |
7 | 1792 || oap->op_type == OP_FOLD |
5735 | 1793 #endif |
7 | 1794 )) |
6497 | 1795 { |
1796 #ifdef FEAT_LINEBREAK | |
1797 curwin->w_p_lbr = lbr_saved; | |
1798 #endif | |
7 | 1799 redraw_curbuf_later(INVERTED); |
6497 | 1800 } |
7 | 1801 |
1802 /* | |
1803 * If the end of an operator is in column one while oap->motion_type | |
1804 * is MCHAR and oap->inclusive is FALSE, we put op_end after the last | |
1805 * character in the previous line. If op_start is on or before the | |
1806 * first non-blank in the line, the operator becomes linewise | |
1807 * (strange, but that's the way vi does it). | |
1808 */ | |
1809 if ( oap->motion_type == MCHAR | |
1810 && oap->inclusive == FALSE | |
1811 && !(cap->retval & CA_NO_ADJ_OP_END) | |
1812 && oap->end.col == 0 | |
1813 && (!oap->is_VIsual || *p_sel == 'o') | |
47 | 1814 && !oap->block_mode |
7 | 1815 && oap->line_count > 1) |
1816 { | |
1817 oap->end_adjusted = TRUE; /* remember that we did this */ | |
1818 --oap->line_count; | |
1819 --oap->end.lnum; | |
1820 if (inindent(0)) | |
1821 oap->motion_type = MLINE; | |
1822 else | |
1823 { | |
1824 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
1825 if (oap->end.col) | |
1826 { | |
1827 --oap->end.col; | |
1828 oap->inclusive = TRUE; | |
1829 } | |
1830 } | |
1831 } | |
1832 else | |
1833 oap->end_adjusted = FALSE; | |
1834 | |
1835 switch (oap->op_type) | |
1836 { | |
1837 case OP_LSHIFT: | |
1838 case OP_RSHIFT: | |
5735 | 1839 op_shift(oap, TRUE, oap->is_VIsual ? (int)cap->count1 : 1); |
7 | 1840 auto_format(FALSE, TRUE); |
1841 break; | |
1842 | |
1843 case OP_JOIN_NS: | |
1844 case OP_JOIN: | |
1845 if (oap->line_count < 2) | |
1846 oap->line_count = 2; | |
1847 if (curwin->w_cursor.lnum + oap->line_count - 1 > | |
1848 curbuf->b_ml.ml_line_count) | |
1849 beep_flush(); | |
1850 else | |
1851 { | |
5735 | 1852 (void)do_join(oap->line_count, oap->op_type == OP_JOIN, |
5848 | 1853 TRUE, TRUE, TRUE); |
7 | 1854 auto_format(FALSE, TRUE); |
1855 } | |
1856 break; | |
1857 | |
1858 case OP_DELETE: | |
1859 VIsual_reselect = FALSE; /* don't reselect now */ | |
1860 if (empty_region_error) | |
3324 | 1861 { |
6949 | 1862 vim_beep(BO_OPER); |
3324 | 1863 CancelRedo(); |
1864 } | |
7 | 1865 else |
1866 { | |
1867 (void)op_delete(oap); | |
1868 if (oap->motion_type == MLINE && has_format_option(FO_AUTO)) | |
1869 u_save_cursor(); /* cursor line wasn't saved yet */ | |
1870 auto_format(FALSE, TRUE); | |
1871 } | |
1872 break; | |
1873 | |
1874 case OP_YANK: | |
1875 if (empty_region_error) | |
1876 { | |
1877 if (!gui_yank) | |
3324 | 1878 { |
6949 | 1879 vim_beep(BO_OPER); |
3324 | 1880 CancelRedo(); |
1881 } | |
7 | 1882 } |
1883 else | |
6497 | 1884 { |
1885 #ifdef FEAT_LINEBREAK | |
1886 curwin->w_p_lbr = lbr_saved; | |
1887 #endif | |
7 | 1888 (void)op_yank(oap, FALSE, !gui_yank); |
6497 | 1889 } |
7 | 1890 check_cursor_col(); |
1891 break; | |
1892 | |
1893 case OP_CHANGE: | |
1894 VIsual_reselect = FALSE; /* don't reselect now */ | |
1895 if (empty_region_error) | |
3324 | 1896 { |
6949 | 1897 vim_beep(BO_OPER); |
3324 | 1898 CancelRedo(); |
1899 } | |
7 | 1900 else |
1901 { | |
1902 /* This is a new edit command, not a restart. Need to | |
1903 * remember it to make 'insertmode' work with mappings for | |
1904 * Visual mode. But do this only once and not when typed and | |
1905 * 'insertmode' isn't set. */ | |
1906 if (p_im || !KeyTyped) | |
1907 restart_edit_save = restart_edit; | |
1908 else | |
1909 restart_edit_save = 0; | |
1910 restart_edit = 0; | |
6497 | 1911 #ifdef FEAT_LINEBREAK |
1912 /* Restore linebreak, so that when the user edits it looks as | |
1913 * before. */ | |
6866 | 1914 if (curwin->w_p_lbr != lbr_saved) |
1915 { | |
1916 curwin->w_p_lbr = lbr_saved; | |
1917 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
1918 } | |
6497 | 1919 #endif |
7 | 1920 /* Reset finish_op now, don't want it set inside edit(). */ |
1921 finish_op = FALSE; | |
1922 if (op_change(oap)) /* will call edit() */ | |
1923 cap->retval |= CA_COMMAND_BUSY; | |
1924 if (restart_edit == 0) | |
1925 restart_edit = restart_edit_save; | |
1926 } | |
1927 break; | |
1928 | |
1929 case OP_FILTER: | |
1930 if (vim_strchr(p_cpo, CPO_FILTER) != NULL) | |
1931 AppendToRedobuff((char_u *)"!\r"); /* use any last used !cmd */ | |
1932 else | |
1933 bangredo = TRUE; /* do_bang() will put cmd in redo buffer */ | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
1934 /* FALLTHROUGH */ |
7 | 1935 |
1936 case OP_INDENT: | |
1937 case OP_COLON: | |
1938 | |
1939 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
1940 /* | |
1941 * If 'equalprg' is empty, do the indenting internally. | |
1942 */ | |
1943 if (oap->op_type == OP_INDENT && *get_equalprg() == NUL) | |
1944 { | |
1945 # ifdef FEAT_LISP | |
1946 if (curbuf->b_p_lisp) | |
1947 { | |
1948 op_reindent(oap, get_lisp_indent); | |
1949 break; | |
1950 } | |
1951 # endif | |
1952 # ifdef FEAT_CINDENT | |
1953 op_reindent(oap, | |
1954 # ifdef FEAT_EVAL | |
1955 *curbuf->b_p_inde != NUL ? get_expr_indent : | |
1956 # endif | |
1957 get_c_indent); | |
1958 break; | |
1959 # endif | |
1960 } | |
1961 #endif | |
1962 | |
1963 op_colon(oap); | |
1964 break; | |
1965 | |
1966 case OP_TILDE: | |
1967 case OP_UPPER: | |
1968 case OP_LOWER: | |
1969 case OP_ROT13: | |
1970 if (empty_region_error) | |
3324 | 1971 { |
6949 | 1972 vim_beep(BO_OPER); |
3324 | 1973 CancelRedo(); |
1974 } | |
7 | 1975 else |
1976 op_tilde(oap); | |
1977 check_cursor_col(); | |
1978 break; | |
1979 | |
1980 case OP_FORMAT: | |
667 | 1981 #if defined(FEAT_EVAL) |
1982 if (*curbuf->b_p_fex != NUL) | |
1983 op_formatexpr(oap); /* use expression */ | |
1984 else | |
1985 #endif | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
1986 if (*p_fp != NUL || *curbuf->b_p_fp != NUL) |
7 | 1987 op_colon(oap); /* use external command */ |
1988 else | |
1989 op_format(oap, FALSE); /* use internal function */ | |
1990 break; | |
1991 | |
1992 case OP_FORMAT2: | |
1993 op_format(oap, TRUE); /* use internal function */ | |
1994 break; | |
1995 | |
592 | 1996 case OP_FUNCTION: |
10342
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1997 #ifdef FEAT_LINEBREAK |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1998 /* Restore linebreak, so that when the user edits it looks as |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1999 * before. */ |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2000 curwin->w_p_lbr = lbr_saved; |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2001 #endif |
592 | 2002 op_function(oap); /* call 'operatorfunc' */ |
2003 break; | |
2004 | |
7 | 2005 case OP_INSERT: |
2006 case OP_APPEND: | |
2007 VIsual_reselect = FALSE; /* don't reselect now */ | |
2008 #ifdef FEAT_VISUALEXTRA | |
2009 if (empty_region_error) | |
3324 | 2010 { |
6949 | 2011 vim_beep(BO_OPER); |
3324 | 2012 CancelRedo(); |
2013 } | |
7 | 2014 else |
2015 { | |
2016 /* This is a new edit command, not a restart. Need to | |
2017 * remember it to make 'insertmode' work with mappings for | |
2018 * Visual mode. But do this only once. */ | |
2019 restart_edit_save = restart_edit; | |
2020 restart_edit = 0; | |
6497 | 2021 #ifdef FEAT_LINEBREAK |
2022 /* Restore linebreak, so that when the user edits it looks as | |
2023 * before. */ | |
6866 | 2024 if (curwin->w_p_lbr != lbr_saved) |
2025 { | |
2026 curwin->w_p_lbr = lbr_saved; | |
2027 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
2028 } | |
6497 | 2029 #endif |
7 | 2030 op_insert(oap, cap->count1); |
6497 | 2031 #ifdef FEAT_LINEBREAK |
2032 /* Reset linebreak, so that formatting works correctly. */ | |
2033 curwin->w_p_lbr = FALSE; | |
2034 #endif | |
7 | 2035 |
2036 /* TODO: when inserting in several lines, should format all | |
2037 * the lines. */ | |
2038 auto_format(FALSE, TRUE); | |
2039 | |
2040 if (restart_edit == 0) | |
2041 restart_edit = restart_edit_save; | |
10785
9938c90d1e6c
patch 8.0.0282: need to use CTRL-O twice when in Visual-Insert mode
Christian Brabandt <cb@256bit.org>
parents:
10640
diff
changeset
|
2042 else |
9938c90d1e6c
patch 8.0.0282: need to use CTRL-O twice when in Visual-Insert mode
Christian Brabandt <cb@256bit.org>
parents:
10640
diff
changeset
|
2043 cap->retval |= CA_COMMAND_BUSY; |
7 | 2044 } |
2045 #else | |
6949 | 2046 vim_beep(BO_OPER); |
7 | 2047 #endif |
2048 break; | |
2049 | |
2050 case OP_REPLACE: | |
2051 VIsual_reselect = FALSE; /* don't reselect now */ | |
2052 #ifdef FEAT_VISUALEXTRA | |
2053 if (empty_region_error) | |
2054 #endif | |
3324 | 2055 { |
6949 | 2056 vim_beep(BO_OPER); |
3324 | 2057 CancelRedo(); |
2058 } | |
7 | 2059 #ifdef FEAT_VISUALEXTRA |
2060 else | |
6497 | 2061 { |
6866 | 2062 # ifdef FEAT_LINEBREAK |
6497 | 2063 /* Restore linebreak, so that when the user edits it looks as |
2064 * before. */ | |
6866 | 2065 if (curwin->w_p_lbr != lbr_saved) |
2066 { | |
2067 curwin->w_p_lbr = lbr_saved; | |
2068 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
2069 } | |
2070 # endif | |
7 | 2071 op_replace(oap, cap->nchar); |
6497 | 2072 } |
7 | 2073 #endif |
2074 break; | |
2075 | |
2076 #ifdef FEAT_FOLDING | |
2077 case OP_FOLD: | |
2078 VIsual_reselect = FALSE; /* don't reselect now */ | |
2079 foldCreate(oap->start.lnum, oap->end.lnum); | |
2080 break; | |
2081 | |
2082 case OP_FOLDOPEN: | |
2083 case OP_FOLDOPENREC: | |
2084 case OP_FOLDCLOSE: | |
2085 case OP_FOLDCLOSEREC: | |
2086 VIsual_reselect = FALSE; /* don't reselect now */ | |
2087 opFoldRange(oap->start.lnum, oap->end.lnum, | |
2088 oap->op_type == OP_FOLDOPEN | |
2089 || oap->op_type == OP_FOLDOPENREC, | |
2090 oap->op_type == OP_FOLDOPENREC | |
2091 || oap->op_type == OP_FOLDCLOSEREC, | |
2092 oap->is_VIsual); | |
2093 break; | |
2094 | |
2095 case OP_FOLDDEL: | |
2096 case OP_FOLDDELREC: | |
2097 VIsual_reselect = FALSE; /* don't reselect now */ | |
2098 deleteFold(oap->start.lnum, oap->end.lnum, | |
2099 oap->op_type == OP_FOLDDELREC, oap->is_VIsual); | |
2100 break; | |
2101 #endif | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2102 case OP_NR_ADD: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2103 case OP_NR_SUB: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2104 if (empty_region_error) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2105 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2106 vim_beep(BO_OPER); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2107 CancelRedo(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2108 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2109 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2110 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2111 VIsual_active = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2112 #ifdef FEAT_LINEBREAK |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2113 curwin->w_p_lbr = lbr_saved; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2114 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2115 op_addsub(oap, cap->count1, redo_VIsual_arg); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2116 VIsual_active = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2117 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2118 check_cursor_col(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2119 break; |
7 | 2120 default: |
2121 clearopbeep(oap); | |
2122 } | |
2123 #ifdef FEAT_VIRTUALEDIT | |
2124 virtual_op = MAYBE; | |
2125 #endif | |
2126 if (!gui_yank) | |
2127 { | |
2128 /* | |
2129 * if 'sol' not set, go back to old column for some commands | |
2130 */ | |
2131 if (!p_sol && oap->motion_type == MLINE && !oap->end_adjusted | |
2132 && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT | |
2133 || oap->op_type == OP_DELETE)) | |
6497 | 2134 { |
2135 #ifdef FEAT_LINEBREAK | |
2136 curwin->w_p_lbr = FALSE; | |
2137 #endif | |
7 | 2138 coladvance(curwin->w_curswant = old_col); |
6497 | 2139 } |
7 | 2140 } |
2141 else | |
2142 { | |
2143 curwin->w_cursor = old_cursor; | |
2144 } | |
2145 oap->block_mode = FALSE; | |
2146 clearop(oap); | |
2147 } | |
6266 | 2148 #ifdef FEAT_LINEBREAK |
2149 curwin->w_p_lbr = lbr_saved; | |
2150 #endif | |
7 | 2151 } |
2152 | |
2153 /* | |
2154 * Handle indent and format operators and visual mode ":". | |
2155 */ | |
2156 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2157 op_colon(oparg_T *oap) |
7 | 2158 { |
2159 stuffcharReadbuff(':'); | |
2160 if (oap->is_VIsual) | |
2161 stuffReadbuff((char_u *)"'<,'>"); | |
2162 else | |
2163 { | |
2164 /* | |
2165 * Make the range look nice, so it can be repeated. | |
2166 */ | |
2167 if (oap->start.lnum == curwin->w_cursor.lnum) | |
2168 stuffcharReadbuff('.'); | |
2169 else | |
2170 stuffnumReadbuff((long)oap->start.lnum); | |
2171 if (oap->end.lnum != oap->start.lnum) | |
2172 { | |
2173 stuffcharReadbuff(','); | |
2174 if (oap->end.lnum == curwin->w_cursor.lnum) | |
2175 stuffcharReadbuff('.'); | |
2176 else if (oap->end.lnum == curbuf->b_ml.ml_line_count) | |
2177 stuffcharReadbuff('$'); | |
2178 else if (oap->start.lnum == curwin->w_cursor.lnum) | |
2179 { | |
2180 stuffReadbuff((char_u *)".+"); | |
2181 stuffnumReadbuff((long)oap->line_count - 1); | |
2182 } | |
2183 else | |
2184 stuffnumReadbuff((long)oap->end.lnum); | |
2185 } | |
2186 } | |
2187 if (oap->op_type != OP_COLON) | |
2188 stuffReadbuff((char_u *)"!"); | |
2189 if (oap->op_type == OP_INDENT) | |
2190 { | |
2191 #ifndef FEAT_CINDENT | |
2192 if (*get_equalprg() == NUL) | |
2193 stuffReadbuff((char_u *)"indent"); | |
2194 else | |
2195 #endif | |
2196 stuffReadbuff(get_equalprg()); | |
2197 stuffReadbuff((char_u *)"\n"); | |
2198 } | |
2199 else if (oap->op_type == OP_FORMAT) | |
2200 { | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2201 if (*curbuf->b_p_fp != NUL) |
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2202 stuffReadbuff(curbuf->b_p_fp); |
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2203 else if (*p_fp != NUL) |
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2204 stuffReadbuff(p_fp); |
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2205 else |
7 | 2206 stuffReadbuff((char_u *)"fmt"); |
216 | 2207 stuffReadbuff((char_u *)"\n']"); |
7 | 2208 } |
2209 | |
2210 /* | |
2211 * do_cmdline() does the rest | |
2212 */ | |
2213 } | |
2214 | |
592 | 2215 /* |
602 | 2216 * Handle the "g@" operator: call 'operatorfunc'. |
592 | 2217 */ |
690 | 2218 static void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2219 op_function(oparg_T *oap UNUSED) |
592 | 2220 { |
2221 #ifdef FEAT_EVAL | |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2222 typval_T argv[2]; |
4133 | 2223 # ifdef FEAT_VIRTUALEDIT |
3431 | 2224 int save_virtual_op = virtual_op; |
4133 | 2225 # endif |
592 | 2226 |
2227 if (*p_opfunc == NUL) | |
2228 EMSG(_("E774: 'operatorfunc' is empty")); | |
2229 else | |
2230 { | |
2231 /* Set '[ and '] marks to text to be operated on. */ | |
2232 curbuf->b_op_start = oap->start; | |
2233 curbuf->b_op_end = oap->end; | |
2234 if (oap->motion_type != MLINE && !oap->inclusive) | |
2235 /* Exclude the end position. */ | |
2236 decl(&curbuf->b_op_end); | |
2237 | |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2238 argv[0].v_type = VAR_STRING; |
592 | 2239 if (oap->block_mode) |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2240 argv[0].vval.v_string = (char_u *)"block"; |
592 | 2241 else if (oap->motion_type == MLINE) |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2242 argv[0].vval.v_string = (char_u *)"line"; |
592 | 2243 else |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2244 argv[0].vval.v_string = (char_u *)"char"; |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2245 argv[1].v_type = VAR_UNKNOWN; |
3431 | 2246 |
4133 | 2247 # ifdef FEAT_VIRTUALEDIT |
3431 | 2248 /* Reset virtual_op so that 'virtualedit' can be changed in the |
2249 * function. */ | |
2250 virtual_op = MAYBE; | |
4133 | 2251 # endif |
3431 | 2252 |
592 | 2253 (void)call_func_retnr(p_opfunc, 1, argv, FALSE); |
3431 | 2254 |
4133 | 2255 # ifdef FEAT_VIRTUALEDIT |
3431 | 2256 virtual_op = save_virtual_op; |
4133 | 2257 # endif |
592 | 2258 } |
2259 #else | |
2260 EMSG(_("E775: Eval feature not available")); | |
2261 #endif | |
2262 } | |
2263 | |
7 | 2264 #if defined(FEAT_MOUSE) || defined(PROTO) |
2265 /* | |
2266 * Do the appropriate action for the current mouse click in the current mode. | |
2267 * Not used for Command-line mode. | |
2268 * | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2269 * Normal and Visual Mode: |
7 | 2270 * event modi- position visual change action |
2271 * fier cursor window | |
2272 * left press - yes end yes | |
2273 * left press C yes end yes "^]" (2) | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2274 * left press S yes end (popup: extend) yes "*" (2) |
7 | 2275 * left drag - yes start if moved no |
2276 * left relse - yes start if moved no | |
2277 * middle press - yes if not active no put register | |
2278 * middle press - yes if active no yank and put | |
2279 * right press - yes start or extend yes | |
2280 * right press S yes no change yes "#" (2) | |
2281 * right drag - yes extend no | |
2282 * right relse - yes extend no | |
2283 * | |
2284 * Insert or Replace Mode: | |
2285 * event modi- position visual change action | |
2286 * fier cursor window | |
2287 * left press - yes (cannot be active) yes | |
2288 * left press C yes (cannot be active) yes "CTRL-O^]" (2) | |
2289 * left press S yes (cannot be active) yes "CTRL-O*" (2) | |
2290 * left drag - yes start or extend (1) no CTRL-O (1) | |
2291 * left relse - yes start or extend (1) no CTRL-O (1) | |
2292 * middle press - no (cannot be active) no put register | |
2293 * right press - yes start or extend yes CTRL-O | |
2294 * right press S yes (cannot be active) yes "CTRL-O#" (2) | |
2295 * | |
2296 * (1) only if mouse pointer moved since press | |
2297 * (2) only if click is in same buffer | |
2298 * | |
2299 * Return TRUE if start_arrow() should be called for edit mode. | |
2300 */ | |
2301 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2302 do_mouse( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2303 oparg_T *oap, /* operator argument, can be NULL */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2304 int c, /* K_LEFTMOUSE, etc */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2305 int dir, /* Direction to 'put' if necessary */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2306 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2307 int fixindent) /* PUT_FIXINDENT if fixing indent necessary */ |
7 | 2308 { |
2309 static int do_always = FALSE; /* ignore 'mouse' setting next time */ | |
2310 static int got_click = FALSE; /* got a click some time back */ | |
2311 | |
2312 int which_button; /* MOUSE_LEFT, _MIDDLE or _RIGHT */ | |
2313 int is_click; /* If FALSE it's a drag or release event */ | |
2314 int is_drag; /* If TRUE it's a drag event */ | |
2315 int jump_flags = 0; /* flags for jump_to_mouse() */ | |
2316 pos_T start_visual; | |
2317 int moved; /* Has cursor moved? */ | |
2318 int in_status_line; /* mouse in status line */ | |
2326
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2319 static int in_tab_line = FALSE; /* mouse clicked in tab line */ |
7 | 2320 int in_sep_line; /* mouse in vertical separator line */ |
2321 int c1, c2; | |
2322 #if defined(FEAT_FOLDING) | |
2323 pos_T save_cursor; | |
2324 #endif | |
2325 win_T *old_curwin = curwin; | |
2326 static pos_T orig_cursor; | |
2327 colnr_T leftcol, rightcol; | |
2328 pos_T end_visual; | |
2329 int diff; | |
2330 int old_active = VIsual_active; | |
2331 int old_mode = VIsual_mode; | |
2332 int regname; | |
2333 | |
2334 #if defined(FEAT_FOLDING) | |
2335 save_cursor = curwin->w_cursor; | |
2336 #endif | |
2337 | |
2338 /* | |
2339 * When GUI is active, always recognize mouse events, otherwise: | |
2340 * - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'. | |
2341 * - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'. | |
2342 * - For command line and insert mode 'mouse' is checked before calling | |
2343 * do_mouse(). | |
2344 */ | |
2345 if (do_always) | |
2346 do_always = FALSE; | |
2347 else | |
2348 #ifdef FEAT_GUI | |
2349 if (!gui.in_use) | |
2350 #endif | |
2351 { | |
2352 if (VIsual_active) | |
2353 { | |
2354 if (!mouse_has(MOUSE_VISUAL)) | |
2355 return FALSE; | |
2356 } | |
5735 | 2357 else if (State == NORMAL && !mouse_has(MOUSE_NORMAL)) |
7 | 2358 return FALSE; |
2359 } | |
2360 | |
4221 | 2361 for (;;) |
2362 { | |
2363 which_button = get_mouse_button(KEY2TERMCAP1(c), &is_click, &is_drag); | |
2364 if (is_drag) | |
2365 { | |
2366 /* If the next character is the same mouse event then use that | |
2367 * one. Speeds up dragging the status line. */ | |
2368 if (vpeekc() != NUL) | |
2369 { | |
2370 int nc; | |
2371 int save_mouse_row = mouse_row; | |
2372 int save_mouse_col = mouse_col; | |
2373 | |
2374 /* Need to get the character, peeking doesn't get the actual | |
2375 * one. */ | |
2376 nc = safe_vgetc(); | |
2377 if (c == nc) | |
2378 continue; | |
2379 vungetc(nc); | |
2380 mouse_row = save_mouse_row; | |
2381 mouse_col = save_mouse_col; | |
2382 } | |
2383 } | |
2384 break; | |
2385 } | |
7 | 2386 |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2387 if (c == K_MOUSEMOVE) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2388 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2389 /* Mouse moved without a button pressed. */ |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
2390 #ifdef FEAT_BEVAL_TERM |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2391 ui_may_remove_balloon(); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2392 if (p_bevalterm && !VIsual_active) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2393 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2394 profile_setlimit(p_bdlay, &bevalexpr_due); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2395 bevalexpr_due_set = TRUE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2396 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2397 #endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2398 return FALSE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2399 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2400 |
7 | 2401 #ifdef FEAT_MOUSESHAPE |
2402 /* May have stopped dragging the status or separator line. The pointer is | |
2403 * most likely still on the status or separator line. */ | |
2404 if (!is_drag && drag_status_line) | |
2405 { | |
2406 drag_status_line = FALSE; | |
2407 update_mouseshape(SHAPE_IDX_STATUS); | |
2408 } | |
2409 if (!is_drag && drag_sep_line) | |
2410 { | |
2411 drag_sep_line = FALSE; | |
2412 update_mouseshape(SHAPE_IDX_VSEP); | |
2413 } | |
2414 #endif | |
2415 | |
2416 /* | |
2417 * Ignore drag and release events if we didn't get a click. | |
2418 */ | |
2419 if (is_click) | |
2420 got_click = TRUE; | |
2421 else | |
2422 { | |
2423 if (!got_click) /* didn't get click, ignore */ | |
2424 return FALSE; | |
2425 if (!is_drag) /* release, reset got_click */ | |
2326
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2426 { |
7 | 2427 got_click = FALSE; |
2326
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2428 if (in_tab_line) |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2429 { |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2430 in_tab_line = FALSE; |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2431 return FALSE; |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2432 } |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2433 } |
7 | 2434 } |
2435 | |
2436 /* | |
2437 * CTRL right mouse button does CTRL-T | |
2438 */ | |
2439 if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) | |
2440 { | |
2441 if (State & INSERT) | |
2442 stuffcharReadbuff(Ctrl_O); | |
2443 if (count > 1) | |
2444 stuffnumReadbuff(count); | |
2445 stuffcharReadbuff(Ctrl_T); | |
2446 got_click = FALSE; /* ignore drag&release now */ | |
2447 return FALSE; | |
2448 } | |
2449 | |
2450 /* | |
2451 * CTRL only works with left mouse button | |
2452 */ | |
2453 if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT) | |
2454 return FALSE; | |
2455 | |
2456 /* | |
2457 * When a modifier is down, ignore drag and release events, as well as | |
2458 * multiple clicks and the middle mouse button. | |
2459 * Accept shift-leftmouse drags when 'mousemodel' is "popup.*". | |
2460 */ | |
179 | 2461 if ((mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT |
2462 | MOD_MASK_META)) | |
7 | 2463 && (!is_click |
2464 || (mod_mask & MOD_MASK_MULTI_CLICK) | |
2465 || which_button == MOUSE_MIDDLE) | |
598 | 2466 && !((mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT)) |
7 | 2467 && mouse_model_popup() |
2468 && which_button == MOUSE_LEFT) | |
598 | 2469 && !((mod_mask & MOD_MASK_ALT) |
2470 && !mouse_model_popup() | |
2471 && which_button == MOUSE_RIGHT) | |
7 | 2472 ) |
2473 return FALSE; | |
2474 | |
2475 /* | |
2476 * If the button press was used as the movement command for an operator | |
2477 * (eg "d<MOUSE>"), or it is the middle button that is held down, ignore | |
2478 * drag/release events. | |
2479 */ | |
2480 if (!is_click && which_button == MOUSE_MIDDLE) | |
2481 return FALSE; | |
2482 | |
2483 if (oap != NULL) | |
2484 regname = oap->regname; | |
2485 else | |
2486 regname = 0; | |
2487 | |
2488 /* | |
2489 * Middle mouse button does a 'put' of the selected text | |
2490 */ | |
2491 if (which_button == MOUSE_MIDDLE) | |
2492 { | |
2493 if (State == NORMAL) | |
2494 { | |
2495 /* | |
2496 * If an operator was pending, we don't know what the user wanted | |
2497 * to do. Go back to normal mode: Clear the operator and beep(). | |
2498 */ | |
2499 if (oap != NULL && oap->op_type != OP_NOP) | |
2500 { | |
2501 clearopbeep(oap); | |
2502 return FALSE; | |
2503 } | |
2504 | |
2505 /* | |
2506 * If visual was active, yank the highlighted text and put it | |
2507 * before the mouse pointer position. | |
1016 | 2508 * In Select mode replace the highlighted text with the clipboard. |
7 | 2509 */ |
2510 if (VIsual_active) | |
2511 { | |
1016 | 2512 if (VIsual_select) |
2513 { | |
2514 stuffcharReadbuff(Ctrl_G); | |
1019 | 2515 stuffReadbuff((char_u *)"\"+p"); |
1016 | 2516 } |
2517 else | |
2518 { | |
2519 stuffcharReadbuff('y'); | |
2520 stuffcharReadbuff(K_MIDDLEMOUSE); | |
2521 } | |
7 | 2522 do_always = TRUE; /* ignore 'mouse' setting next time */ |
2523 return FALSE; | |
2524 } | |
2525 /* | |
2526 * The rest is below jump_to_mouse() | |
2527 */ | |
2528 } | |
2529 | |
2530 else if ((State & INSERT) == 0) | |
2531 return FALSE; | |
2532 | |
2533 /* | |
2534 * Middle click in insert mode doesn't move the mouse, just insert the | |
2535 * contents of a register. '.' register is special, can't insert that | |
2536 * with do_put(). | |
2537 * Also paste at the cursor if the current mode isn't in 'mouse' (only | |
2538 * happens for the GUI). | |
2539 */ | |
2540 if ((State & INSERT) || !mouse_has(MOUSE_NORMAL)) | |
2541 { | |
2542 if (regname == '.') | |
2543 insert_reg(regname, TRUE); | |
2544 else | |
2545 { | |
2546 #ifdef FEAT_CLIPBOARD | |
2547 if (clip_star.available && regname == 0) | |
2548 regname = '*'; | |
2549 #endif | |
2550 if ((State & REPLACE_FLAG) && !yank_register_mline(regname)) | |
2551 insert_reg(regname, TRUE); | |
2552 else | |
2553 { | |
2554 do_put(regname, BACKWARD, 1L, fixindent | PUT_CURSEND); | |
2555 | |
2556 /* Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r */ | |
2557 AppendCharToRedobuff(Ctrl_R); | |
2558 AppendCharToRedobuff(fixindent ? Ctrl_P : Ctrl_O); | |
2559 AppendCharToRedobuff(regname == 0 ? '"' : regname); | |
2560 } | |
2561 } | |
2562 return FALSE; | |
2563 } | |
2564 } | |
2565 | |
2566 /* When dragging or button-up stay in the same window. */ | |
2567 if (!is_click) | |
2568 jump_flags |= MOUSE_FOCUS | MOUSE_DID_MOVE; | |
2569 | |
2570 start_visual.lnum = 0; | |
2571 | |
671 | 2572 /* Check for clicking in the tab page line. */ |
2573 if (mouse_row == 0 && firstwin->w_winrow > 0) | |
2574 { | |
1619 | 2575 if (is_drag) |
2326
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2576 { |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2577 if (in_tab_line) |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2578 { |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2579 c1 = TabPageIdxs[mouse_col]; |
7090
052043fc57ab
commit https://github.com/vim/vim/commit/4a4b821085847651b71d8ad9fab9f180635cb453
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2580 tabpage_move(c1 <= 0 ? 9999 : c1 < tabpage_index(curtab) |
052043fc57ab
commit https://github.com/vim/vim/commit/4a4b821085847651b71d8ad9fab9f180635cb453
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2581 ? c1 - 1 : c1); |
2326
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2582 } |
1619 | 2583 return FALSE; |
2326
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2584 } |
671 | 2585 |
2586 /* click in a tab selects that tab page */ | |
2587 if (is_click | |
2588 # ifdef FEAT_CMDWIN | |
2589 && cmdwin_type == 0 | |
2590 # endif | |
681 | 2591 && mouse_col < Columns) |
2592 { | |
2326
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2593 in_tab_line = TRUE; |
681 | 2594 c1 = TabPageIdxs[mouse_col]; |
2595 if (c1 >= 0) | |
2596 { | |
682 | 2597 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) |
2598 { | |
2599 /* double click opens new page */ | |
681 | 2600 end_visual_mode(); |
682 | 2601 tabpage_new(); |
2602 tabpage_move(c1 == 0 ? 9999 : c1 - 1); | |
2603 } | |
2604 else | |
2605 { | |
2606 /* Go to specified tab page, or next one if not clicking | |
2607 * on a label. */ | |
2608 goto_tabpage(c1); | |
2609 | |
2610 /* It's like clicking on the status line of a window. */ | |
2611 if (curwin != old_curwin) | |
2612 end_visual_mode(); | |
2613 } | |
681 | 2614 } |
13762
9de2b25932eb
patch 8.0.1753: various warnings from a static analyser
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2615 else |
681 | 2616 { |
2617 tabpage_T *tp; | |
2618 | |
2619 /* Close the current or specified tab page. */ | |
2620 if (c1 == -999) | |
2621 tp = curtab; | |
2622 else | |
2623 tp = find_tabpage(-c1); | |
2624 if (tp == curtab) | |
2625 { | |
2626 if (first_tabpage->tp_next != NULL) | |
2627 tabpage_close(FALSE); | |
2628 } | |
2629 else if (tp != NULL) | |
2630 tabpage_close_other(tp, FALSE); | |
2631 } | |
2632 } | |
2633 return TRUE; | |
671 | 2634 } |
2326
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2635 else if (is_drag && in_tab_line) |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2636 { |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2637 c1 = TabPageIdxs[mouse_col]; |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2638 tabpage_move(c1 <= 0 ? 9999 : c1 - 1); |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2639 return FALSE; |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2640 } |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2641 |
7 | 2642 /* |
2643 * When 'mousemodel' is "popup" or "popup_setpos", translate mouse events: | |
2644 * right button up -> pop-up menu | |
2645 * shift-left button -> right button | |
598 | 2646 * alt-left button -> alt-right button |
7 | 2647 */ |
2648 if (mouse_model_popup()) | |
2649 { | |
2650 if (which_button == MOUSE_RIGHT | |
2651 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | |
2652 { | |
573 | 2653 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \ |
7 | 2654 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \ |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2655 || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_PHOTON) \ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2656 || defined(FEAT_TERM_POPUP_MENU) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2657 # ifdef FEAT_GUI |
7 | 2658 if (gui.in_use) |
2659 { | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2660 # if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2661 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2662 if (!is_click) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2663 /* Ignore right button release events, only shows the popup |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2664 * menu on the button down event. */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2665 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2666 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2667 # if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2668 if (is_click || is_drag) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2669 /* Ignore right button down and drag mouse events. Windows |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2670 * only shows the popup menu on the button up event. */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2671 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2672 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2673 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2674 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2675 # if defined(FEAT_GUI) && defined(FEAT_TERM_POPUP_MENU) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2676 else |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2677 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2678 # if defined(FEAT_TERM_POPUP_MENU) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2679 if (!is_click) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2680 /* Ignore right button release events, only shows the popup |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2681 * menu on the button down event. */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2682 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2683 #endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2684 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2685 jump_flags = 0; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2686 if (STRCMP(p_mousem, "popup_setpos") == 0) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2687 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2688 /* First set the cursor position before showing the popup |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2689 * menu. */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2690 if (VIsual_active) |
7 | 2691 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2692 pos_T m_pos; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2693 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2694 /* |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2695 * set MOUSE_MAY_STOP_VIS if we are outside the |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2696 * selection or the current window (might have false |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2697 * negative here) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2698 */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2699 if (mouse_row < curwin->w_winrow |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2700 || mouse_row |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2701 > (curwin->w_winrow + curwin->w_height)) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2702 jump_flags = MOUSE_MAY_STOP_VIS; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2703 else if (get_fpos_of_mouse(&m_pos) != IN_BUFFER) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2704 jump_flags = MOUSE_MAY_STOP_VIS; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2705 else |
7 | 2706 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2707 if ((LT_POS(curwin->w_cursor, VIsual) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2708 && (LT_POS(m_pos, curwin->w_cursor) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2709 || LT_POS(VIsual, m_pos))) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2710 || (LT_POS(VIsual, curwin->w_cursor) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2711 && (LT_POS(m_pos, VIsual) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2712 || LT_POS(curwin->w_cursor, m_pos)))) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2713 { |
7 | 2714 jump_flags = MOUSE_MAY_STOP_VIS; |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2715 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2716 else if (VIsual_mode == Ctrl_V) |
7 | 2717 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2718 getvcols(curwin, &curwin->w_cursor, &VIsual, |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2719 &leftcol, &rightcol); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2720 getvcol(curwin, &m_pos, NULL, &m_pos.col, NULL); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2721 if (m_pos.col < leftcol || m_pos.col > rightcol) |
7 | 2722 jump_flags = MOUSE_MAY_STOP_VIS; |
2723 } | |
2724 } | |
2725 } | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2726 else |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2727 jump_flags = MOUSE_MAY_STOP_VIS; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2728 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2729 if (jump_flags) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2730 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2731 jump_flags = jump_to_mouse(jump_flags, NULL, which_button); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2732 update_curbuf(VIsual_active ? INVERTED : VALID); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2733 setcursor(); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2734 out_flush(); /* Update before showing popup menu */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2735 } |
7 | 2736 # ifdef FEAT_MENU |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2737 show_popupmenu(); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2738 got_click = FALSE; /* ignore release events */ |
7 | 2739 # endif |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2740 return (jump_flags & CURSOR_MOVED) != 0; |
7 | 2741 #else |
2742 return FALSE; | |
2743 #endif | |
2744 } | |
598 | 2745 if (which_button == MOUSE_LEFT |
2746 && (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT))) | |
7 | 2747 { |
2748 which_button = MOUSE_RIGHT; | |
2749 mod_mask &= ~MOD_MASK_SHIFT; | |
2750 } | |
2751 } | |
2752 | |
2753 if ((State & (NORMAL | INSERT)) | |
2754 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | |
2755 { | |
2756 if (which_button == MOUSE_LEFT) | |
2757 { | |
2758 if (is_click) | |
2759 { | |
2760 /* stop Visual mode for a left click in a window, but not when | |
2761 * on a status line */ | |
2762 if (VIsual_active) | |
2763 jump_flags |= MOUSE_MAY_STOP_VIS; | |
2764 } | |
2765 else if (mouse_has(MOUSE_VISUAL)) | |
2766 jump_flags |= MOUSE_MAY_VIS; | |
2767 } | |
2768 else if (which_button == MOUSE_RIGHT) | |
2769 { | |
2770 if (is_click && VIsual_active) | |
2771 { | |
2772 /* | |
2773 * Remember the start and end of visual before moving the | |
2774 * cursor. | |
2775 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2776 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 2777 { |
2778 start_visual = curwin->w_cursor; | |
2779 end_visual = VIsual; | |
2780 } | |
2781 else | |
2782 { | |
2783 start_visual = VIsual; | |
2784 end_visual = curwin->w_cursor; | |
2785 } | |
2786 } | |
2787 jump_flags |= MOUSE_FOCUS; | |
2788 if (mouse_has(MOUSE_VISUAL)) | |
2789 jump_flags |= MOUSE_MAY_VIS; | |
2790 } | |
2791 } | |
2792 | |
2793 /* | |
2794 * If an operator is pending, ignore all drags and releases until the | |
2795 * next mouse click. | |
2796 */ | |
2797 if (!is_drag && oap != NULL && oap->op_type != OP_NOP) | |
2798 { | |
2799 got_click = FALSE; | |
2800 oap->motion_type = MCHAR; | |
2801 } | |
2802 | |
2803 /* When releasing the button let jump_to_mouse() know. */ | |
2804 if (!is_click && !is_drag) | |
2805 jump_flags |= MOUSE_RELEASED; | |
2806 | |
2807 /* | |
2808 * JUMP! | |
2809 */ | |
2810 jump_flags = jump_to_mouse(jump_flags, | |
2811 oap == NULL ? NULL : &(oap->inclusive), which_button); | |
12519
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2812 |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2813 #ifdef FEAT_MENU |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2814 /* A click in the window toolbar has no side effects. */ |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2815 if (jump_flags & MOUSE_WINBAR) |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2816 return FALSE; |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2817 #endif |
7 | 2818 moved = (jump_flags & CURSOR_MOVED); |
2819 in_status_line = (jump_flags & IN_STATUS_LINE); | |
2820 in_sep_line = (jump_flags & IN_SEP_LINE); | |
2821 | |
2822 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2823 if (isNetbeansBuffer(curbuf) |
7 | 2824 && !(jump_flags & (IN_STATUS_LINE | IN_SEP_LINE))) |
2825 { | |
2826 int key = KEY2TERMCAP1(c); | |
2827 | |
2828 if (key == (int)KE_LEFTRELEASE || key == (int)KE_MIDDLERELEASE | |
2829 || key == (int)KE_RIGHTRELEASE) | |
2830 netbeans_button_release(which_button); | |
2831 } | |
2832 #endif | |
2833 | |
2834 /* When jumping to another window, clear a pending operator. That's a bit | |
2835 * friendlier than beeping and not jumping to that window. */ | |
2836 if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP) | |
2837 clearop(oap); | |
2838 | |
2839 #ifdef FEAT_FOLDING | |
2840 if (mod_mask == 0 | |
2841 && !is_drag | |
2842 && (jump_flags & (MOUSE_FOLD_CLOSE | MOUSE_FOLD_OPEN)) | |
2843 && which_button == MOUSE_LEFT) | |
2844 { | |
2845 /* open or close a fold at this line */ | |
2846 if (jump_flags & MOUSE_FOLD_OPEN) | |
2847 openFold(curwin->w_cursor.lnum, 1L); | |
2848 else | |
2849 closeFold(curwin->w_cursor.lnum, 1L); | |
2850 /* don't move the cursor if still in the same window */ | |
2851 if (curwin == old_curwin) | |
2852 curwin->w_cursor = save_cursor; | |
2853 } | |
2854 #endif | |
2855 | |
2856 #if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN) | |
2857 if ((jump_flags & IN_OTHER_WIN) && !VIsual_active && clip_star.available) | |
2858 { | |
2859 clip_modeless(which_button, is_click, is_drag); | |
2860 return FALSE; | |
2861 } | |
2862 #endif | |
2863 | |
2864 /* Set global flag that we are extending the Visual area with mouse | |
1188 | 2865 * dragging; temporarily minimize 'scrolloff'. */ |
7 | 2866 if (VIsual_active && is_drag && p_so) |
2867 { | |
2868 /* In the very first line, allow scrolling one line */ | |
2869 if (mouse_row == 0) | |
2870 mouse_dragging = 2; | |
2871 else | |
2872 mouse_dragging = 1; | |
2873 } | |
2874 | |
2875 /* When dragging the mouse above the window, scroll down. */ | |
2876 if (is_drag && mouse_row < 0 && !in_status_line) | |
2877 { | |
2878 scroll_redraw(FALSE, 1L); | |
2879 mouse_row = 0; | |
2880 } | |
2881 | |
2882 if (start_visual.lnum) /* right click in visual mode */ | |
2883 { | |
598 | 2884 /* When ALT is pressed make Visual mode blockwise. */ |
2885 if (mod_mask & MOD_MASK_ALT) | |
2886 VIsual_mode = Ctrl_V; | |
2887 | |
7 | 2888 /* |
2889 * In Visual-block mode, divide the area in four, pick up the corner | |
2890 * that is in the quarter that the cursor is in. | |
2891 */ | |
2892 if (VIsual_mode == Ctrl_V) | |
2893 { | |
2894 getvcols(curwin, &start_visual, &end_visual, &leftcol, &rightcol); | |
2895 if (curwin->w_curswant > (leftcol + rightcol) / 2) | |
2896 end_visual.col = leftcol; | |
2897 else | |
2898 end_visual.col = rightcol; | |
7009 | 2899 if (curwin->w_cursor.lnum >= |
7 | 2900 (start_visual.lnum + end_visual.lnum) / 2) |
2901 end_visual.lnum = start_visual.lnum; | |
2902 | |
2903 /* move VIsual to the right column */ | |
2904 start_visual = curwin->w_cursor; /* save the cursor pos */ | |
2905 curwin->w_cursor = end_visual; | |
2906 coladvance(end_visual.col); | |
2907 VIsual = curwin->w_cursor; | |
2908 curwin->w_cursor = start_visual; /* restore the cursor */ | |
2909 } | |
2910 else | |
2911 { | |
2912 /* | |
2913 * If the click is before the start of visual, change the start. | |
2914 * If the click is after the end of visual, change the end. If | |
2915 * the click is inside the visual, change the closest side. | |
2916 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2917 if (LT_POS(curwin->w_cursor, start_visual)) |
7 | 2918 VIsual = end_visual; |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2919 else if (LT_POS(end_visual, curwin->w_cursor)) |
7 | 2920 VIsual = start_visual; |
2921 else | |
2922 { | |
2923 /* In the same line, compare column number */ | |
2924 if (end_visual.lnum == start_visual.lnum) | |
2925 { | |
2926 if (curwin->w_cursor.col - start_visual.col > | |
2927 end_visual.col - curwin->w_cursor.col) | |
2928 VIsual = start_visual; | |
2929 else | |
2930 VIsual = end_visual; | |
2931 } | |
2932 | |
2933 /* In different lines, compare line number */ | |
2934 else | |
2935 { | |
2936 diff = (curwin->w_cursor.lnum - start_visual.lnum) - | |
2937 (end_visual.lnum - curwin->w_cursor.lnum); | |
2938 | |
2939 if (diff > 0) /* closest to end */ | |
2940 VIsual = start_visual; | |
2941 else if (diff < 0) /* closest to start */ | |
2942 VIsual = end_visual; | |
2943 else /* in the middle line */ | |
2944 { | |
2945 if (curwin->w_cursor.col < | |
2946 (start_visual.col + end_visual.col) / 2) | |
2947 VIsual = end_visual; | |
2948 else | |
2949 VIsual = start_visual; | |
2950 } | |
2951 } | |
2952 } | |
2953 } | |
2954 } | |
2955 /* | |
2956 * If Visual mode started in insert mode, execute "CTRL-O" | |
2957 */ | |
2958 else if ((State & INSERT) && VIsual_active) | |
2959 stuffcharReadbuff(Ctrl_O); | |
2960 | |
2961 /* | |
2962 * Middle mouse click: Put text before cursor. | |
2963 */ | |
2964 if (which_button == MOUSE_MIDDLE) | |
2965 { | |
2966 #ifdef FEAT_CLIPBOARD | |
2967 if (clip_star.available && regname == 0) | |
2968 regname = '*'; | |
2969 #endif | |
2970 if (yank_register_mline(regname)) | |
2971 { | |
2972 if (mouse_past_bottom) | |
2973 dir = FORWARD; | |
2974 } | |
2975 else if (mouse_past_eol) | |
2976 dir = FORWARD; | |
2977 | |
2978 if (fixindent) | |
2979 { | |
2980 c1 = (dir == BACKWARD) ? '[' : ']'; | |
2981 c2 = 'p'; | |
2982 } | |
2983 else | |
2984 { | |
2985 c1 = (dir == FORWARD) ? 'p' : 'P'; | |
2986 c2 = NUL; | |
2987 } | |
2988 prep_redo(regname, count, NUL, c1, NUL, c2, NUL); | |
2989 | |
2990 /* | |
2991 * Remember where the paste started, so in edit() Insstart can be set | |
2992 * to this position | |
2993 */ | |
2994 if (restart_edit != 0) | |
2995 where_paste_started = curwin->w_cursor; | |
2996 do_put(regname, dir, count, fixindent | PUT_CURSEND); | |
2997 } | |
2998 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
2999 #if defined(FEAT_QUICKFIX) |
7 | 3000 /* |
3001 * Ctrl-Mouse click or double click in a quickfix window jumps to the | |
3002 * error under the mouse pointer. | |
3003 */ | |
3004 else if (((mod_mask & MOD_MASK_CTRL) | |
3005 || (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
3006 && bt_quickfix(curbuf)) | |
3007 { | |
643 | 3008 if (curwin->w_llist_ref == NULL) /* quickfix window */ |
10636
3db97def0f35
patch 8.0.0208: internally used commands end up in history
Christian Brabandt <cb@256bit.org>
parents:
10579
diff
changeset
|
3009 do_cmdline_cmd((char_u *)".cc"); |
643 | 3010 else /* location list window */ |
10636
3db97def0f35
patch 8.0.0208: internally used commands end up in history
Christian Brabandt <cb@256bit.org>
parents:
10579
diff
changeset
|
3011 do_cmdline_cmd((char_u *)".ll"); |
7 | 3012 got_click = FALSE; /* ignore drag&release now */ |
3013 } | |
3014 #endif | |
3015 | |
3016 /* | |
3017 * Ctrl-Mouse click (or double click in a help window) jumps to the tag | |
3018 * under the mouse pointer. | |
3019 */ | |
3020 else if ((mod_mask & MOD_MASK_CTRL) || (curbuf->b_help | |
3021 && (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)) | |
3022 { | |
3023 if (State & INSERT) | |
3024 stuffcharReadbuff(Ctrl_O); | |
3025 stuffcharReadbuff(Ctrl_RSB); | |
3026 got_click = FALSE; /* ignore drag&release now */ | |
3027 } | |
3028 | |
3029 /* | |
3030 * Shift-Mouse click searches for the next occurrence of the word under | |
3031 * the mouse pointer | |
3032 */ | |
3033 else if ((mod_mask & MOD_MASK_SHIFT)) | |
3034 { | |
5735 | 3035 if ((State & INSERT) || (VIsual_active && VIsual_select)) |
7 | 3036 stuffcharReadbuff(Ctrl_O); |
3037 if (which_button == MOUSE_LEFT) | |
3038 stuffcharReadbuff('*'); | |
3039 else /* MOUSE_RIGHT */ | |
3040 stuffcharReadbuff('#'); | |
3041 } | |
3042 | |
3043 /* Handle double clicks, unless on status line */ | |
3044 else if (in_status_line) | |
3045 { | |
3046 #ifdef FEAT_MOUSESHAPE | |
3047 if ((is_drag || is_click) && !drag_status_line) | |
3048 { | |
3049 drag_status_line = TRUE; | |
3050 update_mouseshape(-1); | |
3051 } | |
3052 #endif | |
3053 } | |
3054 else if (in_sep_line) | |
3055 { | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3056 #ifdef FEAT_MOUSESHAPE |
7 | 3057 if ((is_drag || is_click) && !drag_sep_line) |
3058 { | |
3059 drag_sep_line = TRUE; | |
3060 update_mouseshape(-1); | |
3061 } | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3062 #endif |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3063 } |
7 | 3064 else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT)) |
3065 && mouse_has(MOUSE_VISUAL)) | |
3066 { | |
3067 if (is_click || !VIsual_active) | |
3068 { | |
3069 if (VIsual_active) | |
3070 orig_cursor = VIsual; | |
3071 else | |
3072 { | |
3073 check_visual_highlight(); | |
3074 VIsual = curwin->w_cursor; | |
3075 orig_cursor = VIsual; | |
3076 VIsual_active = TRUE; | |
3077 VIsual_reselect = TRUE; | |
3078 /* start Select mode if 'selectmode' contains "mouse" */ | |
3079 may_start_select('o'); | |
3080 setmouse(); | |
3081 } | |
3082 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
598 | 3083 { |
3084 /* Double click with ALT pressed makes it blockwise. */ | |
3085 if (mod_mask & MOD_MASK_ALT) | |
3086 VIsual_mode = Ctrl_V; | |
3087 else | |
3088 VIsual_mode = 'v'; | |
3089 } | |
7 | 3090 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK) |
3091 VIsual_mode = 'V'; | |
3092 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK) | |
3093 VIsual_mode = Ctrl_V; | |
3094 #ifdef FEAT_CLIPBOARD | |
3095 /* Make sure the clipboard gets updated. Needed because start and | |
3096 * end may still be the same, and the selection needs to be owned */ | |
3097 clip_star.vmode = NUL; | |
3098 #endif | |
3099 } | |
3100 /* | |
3101 * A double click selects a word or a block. | |
3102 */ | |
3103 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
3104 { | |
3105 pos_T *pos = NULL; | |
300 | 3106 int gc; |
7 | 3107 |
3108 if (is_click) | |
3109 { | |
3110 /* If the character under the cursor (skipping white space) is | |
3111 * not a word character, try finding a match and select a (), | |
3112 * {}, [], #if/#endif, etc. block. */ | |
3113 end_visual = curwin->w_cursor; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3114 while (gc = gchar_pos(&end_visual), VIM_ISWHITE(gc)) |
7 | 3115 inc(&end_visual); |
3116 if (oap != NULL) | |
3117 oap->motion_type = MCHAR; | |
3118 if (oap != NULL | |
3119 && VIsual_mode == 'v' | |
3120 && !vim_iswordc(gchar_pos(&end_visual)) | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3121 && EQUAL_POS(curwin->w_cursor, VIsual) |
7 | 3122 && (pos = findmatch(oap, NUL)) != NULL) |
3123 { | |
3124 curwin->w_cursor = *pos; | |
3125 if (oap->motion_type == MLINE) | |
3126 VIsual_mode = 'V'; | |
3127 else if (*p_sel == 'e') | |
3128 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3129 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 3130 ++VIsual.col; |
3131 else | |
3132 ++curwin->w_cursor.col; | |
3133 } | |
3134 } | |
3135 } | |
3136 | |
3137 if (pos == NULL && (is_click || is_drag)) | |
3138 { | |
3139 /* When not found a match or when dragging: extend to include | |
3140 * a word. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3141 if (LT_POS(curwin->w_cursor, orig_cursor)) |
7 | 3142 { |
3143 find_start_of_word(&curwin->w_cursor); | |
3144 find_end_of_word(&VIsual); | |
3145 } | |
3146 else | |
3147 { | |
3148 find_start_of_word(&VIsual); | |
3149 if (*p_sel == 'e' && *ml_get_cursor() != NUL) | |
3150 #ifdef FEAT_MBYTE | |
3151 curwin->w_cursor.col += | |
474 | 3152 (*mb_ptr2len)(ml_get_cursor()); |
7 | 3153 #else |
3154 ++curwin->w_cursor.col; | |
3155 #endif | |
3156 find_end_of_word(&curwin->w_cursor); | |
3157 } | |
3158 } | |
3159 curwin->w_set_curswant = TRUE; | |
3160 } | |
3161 if (is_click) | |
3162 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
3163 } | |
3164 else if (VIsual_active && !old_active) | |
598 | 3165 { |
3166 if (mod_mask & MOD_MASK_ALT) | |
3167 VIsual_mode = Ctrl_V; | |
3168 else | |
3169 VIsual_mode = 'v'; | |
3170 } | |
7 | 3171 |
3172 /* If Visual mode changed show it later. */ | |
643 | 3173 if ((!VIsual_active && old_active && mode_displayed) |
3174 || (VIsual_active && p_smd && msg_silent == 0 | |
3175 && (!old_active || VIsual_mode != old_mode))) | |
7 | 3176 redraw_cmdline = TRUE; |
3177 | |
3178 return moved; | |
3179 } | |
3180 | |
3181 /* | |
3182 * Move "pos" back to the start of the word it's in. | |
3183 */ | |
3184 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3185 find_start_of_word(pos_T *pos) |
7 | 3186 { |
3187 char_u *line; | |
3188 int cclass; | |
3189 int col; | |
3190 | |
3191 line = ml_get(pos->lnum); | |
3192 cclass = get_mouse_class(line + pos->col); | |
3193 | |
3194 while (pos->col > 0) | |
3195 { | |
3196 col = pos->col - 1; | |
3197 #ifdef FEAT_MBYTE | |
3198 col -= (*mb_head_off)(line, line + col); | |
3199 #endif | |
3200 if (get_mouse_class(line + col) != cclass) | |
3201 break; | |
3202 pos->col = col; | |
3203 } | |
3204 } | |
3205 | |
3206 /* | |
3207 * Move "pos" forward to the end of the word it's in. | |
3208 * When 'selection' is "exclusive", the position is just after the word. | |
3209 */ | |
3210 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3211 find_end_of_word(pos_T *pos) |
7 | 3212 { |
3213 char_u *line; | |
3214 int cclass; | |
3215 int col; | |
3216 | |
3217 line = ml_get(pos->lnum); | |
3218 if (*p_sel == 'e' && pos->col > 0) | |
3219 { | |
3220 --pos->col; | |
3221 #ifdef FEAT_MBYTE | |
3222 pos->col -= (*mb_head_off)(line, line + pos->col); | |
3223 #endif | |
3224 } | |
3225 cclass = get_mouse_class(line + pos->col); | |
3226 while (line[pos->col] != NUL) | |
3227 { | |
3228 #ifdef FEAT_MBYTE | |
474 | 3229 col = pos->col + (*mb_ptr2len)(line + pos->col); |
7 | 3230 #else |
3231 col = pos->col + 1; | |
3232 #endif | |
3233 if (get_mouse_class(line + col) != cclass) | |
3234 { | |
3235 if (*p_sel == 'e') | |
3236 pos->col = col; | |
3237 break; | |
3238 } | |
3239 pos->col = col; | |
3240 } | |
3241 } | |
3242 | |
3243 /* | |
3244 * Get class of a character for selection: same class means same word. | |
3245 * 0: blank | |
3246 * 1: punctuation groups | |
3247 * 2: normal word character | |
3248 * >2: multi-byte word character. | |
3249 */ | |
3250 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3251 get_mouse_class(char_u *p) |
7 | 3252 { |
3253 int c; | |
3254 | |
3255 #ifdef FEAT_MBYTE | |
3256 if (has_mbyte && MB_BYTE2LEN(p[0]) > 1) | |
3257 return mb_get_class(p); | |
3258 #endif | |
3259 | |
3260 c = *p; | |
3261 if (c == ' ' || c == '\t') | |
3262 return 0; | |
3263 | |
3264 if (vim_iswordc(c)) | |
3265 return 2; | |
3266 | |
3267 /* | |
3268 * There are a few special cases where we want certain combinations of | |
3269 * characters to be considered as a single word. These are things like | |
3270 * "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
3271 * character is in its own class. |
7 | 3272 */ |
3273 if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL) | |
3274 return 1; | |
3275 return c; | |
3276 } | |
3277 #endif /* FEAT_MOUSE */ | |
3278 | |
3279 /* | |
3280 * Check if highlighting for visual mode is possible, give a warning message | |
3281 * if not. | |
3282 */ | |
3283 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3284 check_visual_highlight(void) |
7 | 3285 { |
3286 static int did_check = FALSE; | |
3287 | |
3288 if (full_screen) | |
3289 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3290 if (!did_check && HL_ATTR(HLF_V) == 0) |
7 | 3291 MSG(_("Warning: terminal cannot highlight")); |
3292 did_check = TRUE; | |
3293 } | |
3294 } | |
3295 | |
3296 /* | |
638 | 3297 * End Visual mode. |
7 | 3298 * This function should ALWAYS be called to end Visual mode, except from |
3299 * do_pending_operator(). | |
3300 */ | |
3301 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3302 end_visual_mode(void) |
7 | 3303 { |
3304 #ifdef FEAT_CLIPBOARD | |
3305 /* | |
3306 * If we are using the clipboard, then remember what was selected in case | |
3307 * we need to paste it somewhere while we still own the selection. | |
3308 * Only do this when the clipboard is already owned. Don't want to grab | |
3309 * the selection when hitting ESC. | |
3310 */ | |
3311 if (clip_star.available && clip_star.owned) | |
3312 clip_auto_select(); | |
3313 #endif | |
3314 | |
3315 VIsual_active = FALSE; | |
3316 #ifdef FEAT_MOUSE | |
3317 setmouse(); | |
3318 mouse_dragging = 0; | |
3319 #endif | |
3320 | |
3321 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
690 | 3322 curbuf->b_visual.vi_mode = VIsual_mode; |
3323 curbuf->b_visual.vi_start = VIsual; | |
3324 curbuf->b_visual.vi_end = curwin->w_cursor; | |
3325 curbuf->b_visual.vi_curswant = curwin->w_curswant; | |
7 | 3326 #ifdef FEAT_EVAL |
3327 curbuf->b_visual_mode_eval = VIsual_mode; | |
3328 #endif | |
3329 #ifdef FEAT_VIRTUALEDIT | |
3330 if (!virtual_active()) | |
3331 curwin->w_cursor.coladd = 0; | |
3332 #endif | |
6979 | 3333 may_clear_cmdline(); |
7 | 3334 |
844 | 3335 adjust_cursor_eol(); |
7 | 3336 } |
3337 | |
3338 /* | |
3339 * Reset VIsual_active and VIsual_reselect. | |
3340 */ | |
3341 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3342 reset_VIsual_and_resel(void) |
7 | 3343 { |
3344 if (VIsual_active) | |
3345 { | |
3346 end_visual_mode(); | |
3347 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
3348 } | |
3349 VIsual_reselect = FALSE; | |
3350 } | |
3351 | |
3352 /* | |
3353 * Reset VIsual_active and VIsual_reselect if it's set. | |
3354 */ | |
3355 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3356 reset_VIsual(void) |
7 | 3357 { |
3358 if (VIsual_active) | |
3359 { | |
3360 end_visual_mode(); | |
3361 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
3362 VIsual_reselect = FALSE; | |
3363 } | |
3364 } | |
3365 | |
3366 /* | |
3367 * Check for a balloon-eval special item to include when searching for an | |
3368 * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid! | |
3369 * Returns TRUE if the character at "*ptr" should be included. | |
3370 * "dir" is FORWARD or BACKWARD, the direction of searching. | |
3371 * "*colp" is in/decremented if "ptr[-dir]" should also be included. | |
3372 * "bnp" points to a counter for square brackets. | |
3373 */ | |
3374 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3375 find_is_eval_item( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3376 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3377 int *colp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3378 int *bnp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3379 int dir) |
7 | 3380 { |
3381 /* Accept everything inside []. */ | |
3382 if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) | |
3383 ++*bnp; | |
3384 if (*bnp > 0) | |
3385 { | |
3386 if ((*ptr == '[' && dir == BACKWARD) || (*ptr == ']' && dir == FORWARD)) | |
3387 --*bnp; | |
3388 return TRUE; | |
3389 } | |
3390 | |
3391 /* skip over "s.var" */ | |
3392 if (*ptr == '.') | |
3393 return TRUE; | |
3394 | |
3395 /* two-character item: s->var */ | |
3396 if (ptr[dir == BACKWARD ? 0 : 1] == '>' | |
3397 && ptr[dir == BACKWARD ? -1 : 0] == '-') | |
3398 { | |
3399 *colp += dir; | |
3400 return TRUE; | |
3401 } | |
3402 return FALSE; | |
3403 } | |
3404 | |
3405 /* | |
3406 * Find the identifier under or to the right of the cursor. | |
3407 * "find_type" can have one of three values: | |
3408 * FIND_IDENT: find an identifier (keyword) | |
3409 * FIND_STRING: find any non-white string | |
3410 * FIND_IDENT + FIND_STRING: find any non-white string, identifier preferred. | |
184 | 3411 * FIND_EVAL: find text useful for C program debugging |
7 | 3412 * |
3413 * There are three steps: | |
3414 * 1. Search forward for the start of an identifier/string. Doesn't move if | |
3415 * already on one. | |
3416 * 2. Search backward for the start of this identifier/string. | |
3417 * This doesn't match the real Vi but I like it a little better and it | |
3418 * shouldn't bother anyone. | |
3419 * 3. Search forward to the end of this identifier/string. | |
3420 * When FIND_IDENT isn't defined, we backup until a blank. | |
3421 * | |
3422 * Returns the length of the string, or zero if no string is found. | |
3423 * If a string is found, a pointer to the string is put in "*string". This | |
3424 * string is not always NUL terminated. | |
3425 */ | |
3426 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3427 find_ident_under_cursor(char_u **string, int find_type) |
7 | 3428 { |
3429 return find_ident_at_pos(curwin, curwin->w_cursor.lnum, | |
3430 curwin->w_cursor.col, string, find_type); | |
3431 } | |
3432 | |
3433 /* | |
3434 * Like find_ident_under_cursor(), but for any window and any position. | |
3435 * However: Uses 'iskeyword' from the current window!. | |
3436 */ | |
3437 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3438 find_ident_at_pos( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3439 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3440 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3441 colnr_T startcol, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3442 char_u **string, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3443 int find_type) |
7 | 3444 { |
3445 char_u *ptr; | |
3446 int col = 0; /* init to shut up GCC */ | |
3447 int i; | |
3448 #ifdef FEAT_MBYTE | |
3449 int this_class = 0; | |
3450 int prev_class; | |
3451 int prevcol; | |
3452 #endif | |
3453 int bn = 0; /* bracket nesting */ | |
3454 | |
3455 /* | |
3456 * if i == 0: try to find an identifier | |
3457 * if i == 1: try to find any non-white string | |
3458 */ | |
3459 ptr = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3460 for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; ++i) | |
3461 { | |
3462 /* | |
3463 * 1. skip to start of identifier/string | |
3464 */ | |
3465 col = startcol; | |
3466 #ifdef FEAT_MBYTE | |
3467 if (has_mbyte) | |
3468 { | |
3469 while (ptr[col] != NUL) | |
3470 { | |
3471 /* Stop at a ']' to evaluate "a[x]". */ | |
3472 if ((find_type & FIND_EVAL) && ptr[col] == ']') | |
3473 break; | |
3474 this_class = mb_get_class(ptr + col); | |
3475 if (this_class != 0 && (i == 1 || this_class != 1)) | |
3476 break; | |
474 | 3477 col += (*mb_ptr2len)(ptr + col); |
7 | 3478 } |
3479 } | |
3480 else | |
3481 #endif | |
3482 while (ptr[col] != NUL | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3483 && (i == 0 ? !vim_iswordc(ptr[col]) : VIM_ISWHITE(ptr[col])) |
7 | 3484 && (!(find_type & FIND_EVAL) || ptr[col] != ']') |
3485 ) | |
3486 ++col; | |
3487 | |
3488 /* When starting on a ']' count it, so that we include the '['. */ | |
3489 bn = ptr[col] == ']'; | |
3490 | |
3491 /* | |
3492 * 2. Back up to start of identifier/string. | |
3493 */ | |
3494 #ifdef FEAT_MBYTE | |
3495 if (has_mbyte) | |
3496 { | |
3497 /* Remember class of character under cursor. */ | |
3498 if ((find_type & FIND_EVAL) && ptr[col] == ']') | |
3499 this_class = mb_get_class((char_u *)"a"); | |
3500 else | |
3501 this_class = mb_get_class(ptr + col); | |
835 | 3502 while (col > 0 && this_class != 0) |
7 | 3503 { |
3504 prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1); | |
3505 prev_class = mb_get_class(ptr + prevcol); | |
3506 if (this_class != prev_class | |
3507 && (i == 0 | |
3508 || prev_class == 0 | |
3509 || (find_type & FIND_IDENT)) | |
3510 && (!(find_type & FIND_EVAL) | |
3511 || prevcol == 0 | |
3512 || !find_is_eval_item(ptr + prevcol, &prevcol, | |
3513 &bn, BACKWARD)) | |
3514 ) | |
3515 break; | |
3516 col = prevcol; | |
3517 } | |
3518 | |
3519 /* If we don't want just any old string, or we've found an | |
3520 * identifier, stop searching. */ | |
3521 if (this_class > 2) | |
3522 this_class = 2; | |
3523 if (!(find_type & FIND_STRING) || this_class == 2) | |
3524 break; | |
3525 } | |
3526 else | |
3527 #endif | |
3528 { | |
3529 while (col > 0 | |
3530 && ((i == 0 | |
3531 ? vim_iswordc(ptr[col - 1]) | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3532 : (!VIM_ISWHITE(ptr[col - 1]) |
7 | 3533 && (!(find_type & FIND_IDENT) |
3534 || !vim_iswordc(ptr[col - 1])))) | |
3535 || ((find_type & FIND_EVAL) | |
3536 && col > 1 | |
3537 && find_is_eval_item(ptr + col - 1, &col, | |
3538 &bn, BACKWARD)) | |
3539 )) | |
3540 --col; | |
3541 | |
3542 /* If we don't want just any old string, or we've found an | |
3543 * identifier, stop searching. */ | |
3544 if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col])) | |
3545 break; | |
3546 } | |
3547 } | |
3548 | |
3549 if (ptr[col] == NUL || (i == 0 && ( | |
3550 #ifdef FEAT_MBYTE | |
3551 has_mbyte ? this_class != 2 : | |
3552 #endif | |
3553 !vim_iswordc(ptr[col])))) | |
3554 { | |
3555 /* | |
3556 * didn't find an identifier or string | |
3557 */ | |
3558 if (find_type & FIND_STRING) | |
3559 EMSG(_("E348: No string under cursor")); | |
3560 else | |
1728 | 3561 EMSG(_(e_noident)); |
7 | 3562 return 0; |
3563 } | |
3564 ptr += col; | |
3565 *string = ptr; | |
3566 | |
3567 /* | |
3568 * 3. Find the end if the identifier/string. | |
3569 */ | |
3570 bn = 0; | |
3571 startcol -= col; | |
3572 col = 0; | |
3573 #ifdef FEAT_MBYTE | |
3574 if (has_mbyte) | |
3575 { | |
3576 /* Search for point of changing multibyte character class. */ | |
3577 this_class = mb_get_class(ptr); | |
3578 while (ptr[col] != NUL | |
3579 && ((i == 0 ? mb_get_class(ptr + col) == this_class | |
3580 : mb_get_class(ptr + col) != 0) | |
3581 || ((find_type & FIND_EVAL) | |
3582 && col <= (int)startcol | |
3583 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
3584 )) | |
474 | 3585 col += (*mb_ptr2len)(ptr + col); |
7 | 3586 } |
3587 else | |
3588 #endif | |
3589 while ((i == 0 ? vim_iswordc(ptr[col]) | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3590 : (ptr[col] != NUL && !VIM_ISWHITE(ptr[col]))) |
7 | 3591 || ((find_type & FIND_EVAL) |
3592 && col <= (int)startcol | |
3593 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
3594 ) | |
3595 { | |
3596 ++col; | |
3597 } | |
3598 | |
3599 return col; | |
3600 } | |
3601 | |
3602 /* | |
3603 * Prepare for redo of a normal command. | |
3604 */ | |
3605 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3606 prep_redo_cmd(cmdarg_T *cap) |
7 | 3607 { |
3608 prep_redo(cap->oap->regname, cap->count0, | |
3609 NUL, cap->cmdchar, NUL, NUL, cap->nchar); | |
3610 } | |
3611 | |
3612 /* | |
3613 * Prepare for redo of any command. | |
3614 * Note that only the last argument can be a multi-byte char. | |
3615 */ | |
3616 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3617 prep_redo( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3618 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3619 long num, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3620 int cmd1, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3621 int cmd2, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3622 int cmd3, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3623 int cmd4, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3624 int cmd5) |
7 | 3625 { |
3626 ResetRedobuff(); | |
3627 if (regname != 0) /* yank from specified buffer */ | |
3628 { | |
3629 AppendCharToRedobuff('"'); | |
3630 AppendCharToRedobuff(regname); | |
3631 } | |
3632 if (num) | |
3633 AppendNumberToRedobuff(num); | |
3634 | |
3635 if (cmd1 != NUL) | |
3636 AppendCharToRedobuff(cmd1); | |
3637 if (cmd2 != NUL) | |
3638 AppendCharToRedobuff(cmd2); | |
3639 if (cmd3 != NUL) | |
3640 AppendCharToRedobuff(cmd3); | |
3641 if (cmd4 != NUL) | |
3642 AppendCharToRedobuff(cmd4); | |
3643 if (cmd5 != NUL) | |
3644 AppendCharToRedobuff(cmd5); | |
3645 } | |
3646 | |
3647 /* | |
3648 * check for operator active and clear it | |
3649 * | |
3650 * return TRUE if operator was active | |
3651 */ | |
3652 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3653 checkclearop(oparg_T *oap) |
7 | 3654 { |
3655 if (oap->op_type == OP_NOP) | |
3656 return FALSE; | |
3657 clearopbeep(oap); | |
3658 return TRUE; | |
3659 } | |
3660 | |
3661 /* | |
1131 | 3662 * Check for operator or Visual active. Clear active operator. |
7 | 3663 * |
1131 | 3664 * Return TRUE if operator or Visual was active. |
7 | 3665 */ |
3666 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3667 checkclearopq(oparg_T *oap) |
7 | 3668 { |
5735 | 3669 if (oap->op_type == OP_NOP && !VIsual_active) |
7 | 3670 return FALSE; |
3671 clearopbeep(oap); | |
3672 return TRUE; | |
3673 } | |
3674 | |
3675 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3676 clearop(oparg_T *oap) |
7 | 3677 { |
3678 oap->op_type = OP_NOP; | |
3679 oap->regname = 0; | |
3680 oap->motion_force = NUL; | |
3681 oap->use_reg_one = FALSE; | |
3682 } | |
3683 | |
3684 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3685 clearopbeep(oparg_T *oap) |
7 | 3686 { |
3687 clearop(oap); | |
3688 beep_flush(); | |
3689 } | |
3690 | |
3691 /* | |
3692 * Remove the shift modifier from a special key. | |
3693 */ | |
3694 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3695 unshift_special(cmdarg_T *cap) |
7 | 3696 { |
3697 switch (cap->cmdchar) | |
3698 { | |
3699 case K_S_RIGHT: cap->cmdchar = K_RIGHT; break; | |
3700 case K_S_LEFT: cap->cmdchar = K_LEFT; break; | |
3701 case K_S_UP: cap->cmdchar = K_UP; break; | |
3702 case K_S_DOWN: cap->cmdchar = K_DOWN; break; | |
3703 case K_S_HOME: cap->cmdchar = K_HOME; break; | |
3704 case K_S_END: cap->cmdchar = K_END; break; | |
3705 } | |
3706 cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask); | |
3707 } | |
3708 | |
6979 | 3709 /* |
3710 * If the mode is currently displayed clear the command line or update the | |
3711 * command displayed. | |
3712 */ | |
3713 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3714 may_clear_cmdline(void) |
6979 | 3715 { |
3716 if (mode_displayed) | |
3717 clear_cmdline = TRUE; /* unshow visual mode later */ | |
3718 #ifdef FEAT_CMDL_INFO | |
3719 else | |
3720 clear_showcmd(); | |
3721 #endif | |
3722 } | |
3723 | |
7 | 3724 #if defined(FEAT_CMDL_INFO) || defined(PROTO) |
3725 /* | |
3726 * Routines for displaying a partly typed command | |
3727 */ | |
3728 | |
5735 | 3729 #define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 |
7 | 3730 static char_u showcmd_buf[SHOWCMD_BUFLEN]; |
3731 static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */ | |
3732 static int showcmd_is_clear = TRUE; | |
3733 static int showcmd_visual = FALSE; | |
3734 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
3735 static void display_showcmd(void); |
7 | 3736 |
3737 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3738 clear_showcmd(void) |
7 | 3739 { |
3740 if (!p_sc) | |
3741 return; | |
3742 | |
3743 if (VIsual_active && !char_avail()) | |
3744 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3745 int cursor_bot = LT_POS(VIsual, curwin->w_cursor); |
7 | 3746 long lines; |
3747 colnr_T leftcol, rightcol; | |
3748 linenr_T top, bot; | |
3749 | |
3750 /* Show the size of the Visual area. */ | |
1866 | 3751 if (cursor_bot) |
7 | 3752 { |
3753 top = VIsual.lnum; | |
3754 bot = curwin->w_cursor.lnum; | |
3755 } | |
3756 else | |
3757 { | |
3758 top = curwin->w_cursor.lnum; | |
3759 bot = VIsual.lnum; | |
3760 } | |
3761 # ifdef FEAT_FOLDING | |
3762 /* Include closed folds as a whole. */ | |
7009 | 3763 (void)hasFolding(top, &top, NULL); |
3764 (void)hasFolding(bot, NULL, &bot); | |
7 | 3765 # endif |
3766 lines = bot - top + 1; | |
3767 | |
3768 if (VIsual_mode == Ctrl_V) | |
3769 { | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3770 # ifdef FEAT_LINEBREAK |
1866 | 3771 char_u *saved_sbr = p_sbr; |
3772 | |
3773 /* Make 'sbr' empty for a moment to get the correct size. */ | |
3774 p_sbr = empty_option; | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3775 # endif |
7 | 3776 getvcols(curwin, &curwin->w_cursor, &VIsual, &leftcol, &rightcol); |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3777 # ifdef FEAT_LINEBREAK |
1866 | 3778 p_sbr = saved_sbr; |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3779 # endif |
7 | 3780 sprintf((char *)showcmd_buf, "%ldx%ld", lines, |
3781 (long)(rightcol - leftcol + 1)); | |
3782 } | |
3783 else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum) | |
3784 sprintf((char *)showcmd_buf, "%ld", lines); | |
3785 else | |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3786 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3787 char_u *s, *e; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3788 int l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3789 int bytes = 0; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3790 int chars = 0; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3791 |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3792 if (cursor_bot) |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3793 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3794 s = ml_get_pos(&VIsual); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3795 e = ml_get_cursor(); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3796 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3797 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3798 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3799 s = ml_get_cursor(); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3800 e = ml_get_pos(&VIsual); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3801 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3802 while ((*p_sel != 'e') ? s <= e : s < e) |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3803 { |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3804 # ifdef FEAT_MBYTE |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3805 l = (*mb_ptr2len)(s); |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3806 # else |
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3807 l = (*s == NUL) ? 0 : 1; |
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3808 # endif |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3809 if (l == 0) |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3810 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3811 ++bytes; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3812 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3813 break; /* end of line */ |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3814 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3815 bytes += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3816 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3817 s += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3818 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3819 if (bytes == chars) |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3820 sprintf((char *)showcmd_buf, "%d", chars); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3821 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3822 sprintf((char *)showcmd_buf, "%d-%d", chars, bytes); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3823 } |
7 | 3824 showcmd_buf[SHOWCMD_COLS] = NUL; /* truncate */ |
3825 showcmd_visual = TRUE; | |
3826 } | |
3827 else | |
3828 { | |
3829 showcmd_buf[0] = NUL; | |
3830 showcmd_visual = FALSE; | |
3831 | |
3832 /* Don't actually display something if there is nothing to clear. */ | |
3833 if (showcmd_is_clear) | |
3834 return; | |
3835 } | |
3836 | |
3837 display_showcmd(); | |
3838 } | |
3839 | |
3840 /* | |
3841 * Add 'c' to string of shown command chars. | |
3842 * Return TRUE if output has been written (and setcursor() has been called). | |
3843 */ | |
3844 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3845 add_to_showcmd(int c) |
7 | 3846 { |
3847 char_u *p; | |
3848 int old_len; | |
3849 int extra_len; | |
3850 int overflow; | |
3851 #if defined(FEAT_MOUSE) | |
3852 int i; | |
3853 static int ignore[] = | |
3854 { | |
660 | 3855 # ifdef FEAT_GUI |
7 | 3856 K_VER_SCROLLBAR, K_HOR_SCROLLBAR, |
3857 K_LEFTMOUSE_NM, K_LEFTRELEASE_NM, | |
660 | 3858 # endif |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
3859 K_IGNORE, K_PS, |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
3860 K_LEFTMOUSE, K_LEFTDRAG, K_LEFTRELEASE, K_MOUSEMOVE, |
7 | 3861 K_MIDDLEMOUSE, K_MIDDLEDRAG, K_MIDDLERELEASE, |
3862 K_RIGHTMOUSE, K_RIGHTDRAG, K_RIGHTRELEASE, | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
3863 K_MOUSEDOWN, K_MOUSEUP, K_MOUSELEFT, K_MOUSERIGHT, |
7 | 3864 K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE, |
631 | 3865 K_CURSORHOLD, |
7 | 3866 0 |
3867 }; | |
3868 #endif | |
3869 | |
641 | 3870 if (!p_sc || msg_silent != 0) |
7 | 3871 return FALSE; |
3872 | |
3873 if (showcmd_visual) | |
3874 { | |
3875 showcmd_buf[0] = NUL; | |
3876 showcmd_visual = FALSE; | |
3877 } | |
3878 | |
3879 #if defined(FEAT_MOUSE) | |
3880 /* Ignore keys that are scrollbar updates and mouse clicks */ | |
3881 if (IS_SPECIAL(c)) | |
3882 for (i = 0; ignore[i] != 0; ++i) | |
3883 if (ignore[i] == c) | |
3884 return FALSE; | |
3885 #endif | |
3886 | |
3887 p = transchar(c); | |
5535 | 3888 if (*p == ' ') |
3889 STRCPY(p, "<20>"); | |
7 | 3890 old_len = (int)STRLEN(showcmd_buf); |
3891 extra_len = (int)STRLEN(p); | |
3892 overflow = old_len + extra_len - SHOWCMD_COLS; | |
3893 if (overflow > 0) | |
1362 | 3894 mch_memmove(showcmd_buf, showcmd_buf + overflow, |
3895 old_len - overflow + 1); | |
7 | 3896 STRCAT(showcmd_buf, p); |
3897 | |
3898 if (char_avail()) | |
3899 return FALSE; | |
3900 | |
3901 display_showcmd(); | |
3902 | |
3903 return TRUE; | |
3904 } | |
3905 | |
3906 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3907 add_to_showcmd_c(int c) |
7 | 3908 { |
3909 if (!add_to_showcmd(c)) | |
3910 setcursor(); | |
3911 } | |
3912 | |
3913 /* | |
3914 * Delete 'len' characters from the end of the shown command. | |
3915 */ | |
3916 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3917 del_from_showcmd(int len) |
7 | 3918 { |
3919 int old_len; | |
3920 | |
3921 if (!p_sc) | |
3922 return; | |
3923 | |
3924 old_len = (int)STRLEN(showcmd_buf); | |
3925 if (len > old_len) | |
3926 len = old_len; | |
3927 showcmd_buf[old_len - len] = NUL; | |
3928 | |
3929 if (!char_avail()) | |
3930 display_showcmd(); | |
3931 } | |
3932 | |
3933 /* | |
3934 * push_showcmd() and pop_showcmd() are used when waiting for the user to type | |
3935 * something and there is a partial mapping. | |
3936 */ | |
3937 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3938 push_showcmd(void) |
7 | 3939 { |
3940 if (p_sc) | |
3941 STRCPY(old_showcmd_buf, showcmd_buf); | |
3942 } | |
3943 | |
3944 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3945 pop_showcmd(void) |
7 | 3946 { |
3947 if (!p_sc) | |
3948 return; | |
3949 | |
3950 STRCPY(showcmd_buf, old_showcmd_buf); | |
3951 | |
3952 display_showcmd(); | |
3953 } | |
3954 | |
3955 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3956 display_showcmd(void) |
7 | 3957 { |
3958 int len; | |
3959 | |
3960 cursor_off(); | |
3961 | |
3962 len = (int)STRLEN(showcmd_buf); | |
3963 if (len == 0) | |
3964 showcmd_is_clear = TRUE; | |
3965 else | |
3966 { | |
3967 screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0); | |
3968 showcmd_is_clear = FALSE; | |
3969 } | |
3970 | |
3971 /* | |
1188 | 3972 * clear the rest of an old message by outputting up to SHOWCMD_COLS |
3973 * spaces | |
7 | 3974 */ |
3975 screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0); | |
3976 | |
3977 setcursor(); /* put cursor back where it belongs */ | |
3978 } | |
3979 #endif | |
3980 | |
3981 /* | |
3982 * When "check" is FALSE, prepare for commands that scroll the window. | |
3983 * When "check" is TRUE, take care of scroll-binding after the window has | |
3984 * scrolled. Called from normal_cmd() and edit(). | |
3985 */ | |
3986 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3987 do_check_scrollbind(int check) |
7 | 3988 { |
3989 static win_T *old_curwin = NULL; | |
3990 static linenr_T old_topline = 0; | |
3991 #ifdef FEAT_DIFF | |
3992 static int old_topfill = 0; | |
3993 #endif | |
3994 static buf_T *old_buf = NULL; | |
3995 static colnr_T old_leftcol = 0; | |
3996 | |
3997 if (check && curwin->w_p_scb) | |
3998 { | |
3999 /* If a ":syncbind" command was just used, don't scroll, only reset | |
4000 * the values. */ | |
4001 if (did_syncbind) | |
4002 did_syncbind = FALSE; | |
4003 else if (curwin == old_curwin) | |
4004 { | |
4005 /* | |
4006 * Synchronize other windows, as necessary according to | |
4007 * 'scrollbind'. Don't do this after an ":edit" command, except | |
4008 * when 'diff' is set. | |
4009 */ | |
4010 if ((curwin->w_buffer == old_buf | |
4011 #ifdef FEAT_DIFF | |
4012 || curwin->w_p_diff | |
4013 #endif | |
4014 ) | |
4015 && (curwin->w_topline != old_topline | |
4016 #ifdef FEAT_DIFF | |
4017 || curwin->w_topfill != old_topfill | |
4018 #endif | |
4019 || curwin->w_leftcol != old_leftcol)) | |
4020 { | |
4021 check_scrollbind(curwin->w_topline - old_topline, | |
4022 (long)(curwin->w_leftcol - old_leftcol)); | |
4023 } | |
4024 } | |
4025 else if (vim_strchr(p_sbo, 'j')) /* jump flag set in 'scrollopt' */ | |
4026 { | |
4027 /* | |
4028 * When switching between windows, make sure that the relative | |
4029 * vertical offset is valid for the new window. The relative | |
4030 * offset is invalid whenever another 'scrollbind' window has | |
4031 * scrolled to a point that would force the current window to | |
4032 * scroll past the beginning or end of its buffer. When the | |
4033 * resync is performed, some of the other 'scrollbind' windows may | |
4034 * need to jump so that the current window's relative position is | |
4035 * visible on-screen. | |
4036 */ | |
4037 check_scrollbind(curwin->w_topline - curwin->w_scbind_pos, 0L); | |
4038 } | |
4039 curwin->w_scbind_pos = curwin->w_topline; | |
4040 } | |
4041 | |
4042 old_curwin = curwin; | |
4043 old_topline = curwin->w_topline; | |
4044 #ifdef FEAT_DIFF | |
4045 old_topfill = curwin->w_topfill; | |
4046 #endif | |
4047 old_buf = curwin->w_buffer; | |
4048 old_leftcol = curwin->w_leftcol; | |
4049 } | |
4050 | |
4051 /* | |
4052 * Synchronize any windows that have "scrollbind" set, based on the | |
4053 * number of rows by which the current window has changed | |
4054 * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>) | |
4055 */ | |
4056 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4057 check_scrollbind(linenr_T topline_diff, long leftcol_diff) |
7 | 4058 { |
4059 int want_ver; | |
4060 int want_hor; | |
4061 win_T *old_curwin = curwin; | |
4062 buf_T *old_curbuf = curbuf; | |
4063 int old_VIsual_select = VIsual_select; | |
4064 int old_VIsual_active = VIsual_active; | |
4065 colnr_T tgt_leftcol = curwin->w_leftcol; | |
4066 long topline; | |
4067 long y; | |
4068 | |
4069 /* | |
4070 * check 'scrollopt' string for vertical and horizontal scroll options | |
4071 */ | |
4072 want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0); | |
4073 #ifdef FEAT_DIFF | |
4074 want_ver |= old_curwin->w_p_diff; | |
4075 #endif | |
4076 want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0)); | |
4077 | |
4078 /* | |
4079 * loop through the scrollbound windows and scroll accordingly | |
4080 */ | |
4081 VIsual_select = VIsual_active = 0; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9399
diff
changeset
|
4082 FOR_ALL_WINDOWS(curwin) |
7 | 4083 { |
4084 curbuf = curwin->w_buffer; | |
4085 /* skip original window and windows with 'noscrollbind' */ | |
4086 if (curwin != old_curwin && curwin->w_p_scb) | |
4087 { | |
4088 /* | |
4089 * do the vertical scroll | |
4090 */ | |
4091 if (want_ver) | |
4092 { | |
4093 #ifdef FEAT_DIFF | |
4094 if (old_curwin->w_p_diff && curwin->w_p_diff) | |
4095 { | |
4096 diff_set_topline(old_curwin, curwin); | |
4097 } | |
4098 else | |
4099 #endif | |
4100 { | |
4101 curwin->w_scbind_pos += topline_diff; | |
4102 topline = curwin->w_scbind_pos; | |
4103 if (topline > curbuf->b_ml.ml_line_count) | |
4104 topline = curbuf->b_ml.ml_line_count; | |
4105 if (topline < 1) | |
4106 topline = 1; | |
4107 | |
4108 y = topline - curwin->w_topline; | |
4109 if (y > 0) | |
4110 scrollup(y, FALSE); | |
4111 else | |
4112 scrolldown(-y, FALSE); | |
4113 } | |
4114 | |
4115 redraw_later(VALID); | |
4116 cursor_correct(); | |
4117 curwin->w_redr_status = TRUE; | |
4118 } | |
4119 | |
4120 /* | |
4121 * do the horizontal scroll | |
4122 */ | |
4123 if (want_hor && curwin->w_leftcol != tgt_leftcol) | |
4124 { | |
4125 curwin->w_leftcol = tgt_leftcol; | |
4126 leftcol_changed(); | |
4127 } | |
4128 } | |
4129 } | |
4130 | |
4131 /* | |
4132 * reset current-window | |
4133 */ | |
4134 VIsual_select = old_VIsual_select; | |
4135 VIsual_active = old_VIsual_active; | |
4136 curwin = old_curwin; | |
4137 curbuf = old_curbuf; | |
4138 } | |
4139 | |
4140 /* | |
4141 * Command character that's ignored. | |
4142 * Used for CTRL-Q and CTRL-S to avoid problems with terminals that use | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
4143 * xon/xoff. |
7 | 4144 */ |
4145 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4146 nv_ignore(cmdarg_T *cap) |
7 | 4147 { |
226 | 4148 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
7 | 4149 } |
4150 | |
4151 /* | |
620 | 4152 * Command character that doesn't do anything, but unlike nv_ignore() does |
4153 * start edit(). Used for "startinsert" executed while starting up. | |
4154 */ | |
4155 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4156 nv_nop(cmdarg_T *cap UNUSED) |
620 | 4157 { |
4158 } | |
4159 | |
4160 /* | |
7 | 4161 * Command character doesn't exist. |
4162 */ | |
4163 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4164 nv_error(cmdarg_T *cap) |
7 | 4165 { |
4166 clearopbeep(cap->oap); | |
4167 } | |
4168 | |
4169 /* | |
4170 * <Help> and <F1> commands. | |
4171 */ | |
4172 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4173 nv_help(cmdarg_T *cap) |
7 | 4174 { |
4175 if (!checkclearopq(cap->oap)) | |
4176 ex_help(NULL); | |
4177 } | |
4178 | |
4179 /* | |
4180 * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor. | |
4181 */ | |
4182 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4183 nv_addsub(cmdarg_T *cap) |
7 | 4184 { |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4185 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4186 if (bt_prompt(curbuf) && !prompt_curpos_editable()) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4187 clearopbeep(cap->oap); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4188 else |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
4189 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4190 if (!VIsual_active && cap->oap->op_type == OP_NOP) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4191 { |
7578
fdae4c496775
commit https://github.com/vim/vim/commit/ef2b5036b3005f1ce15d146dce72379a9834c56d
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
4192 prep_redo_cmd(cap); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4193 cap->oap->op_type = cap->cmdchar == Ctrl_A ? OP_NR_ADD : OP_NR_SUB; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4194 op_addsub(cap->oap, cap->count1, cap->arg); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4195 cap->oap->op_type = OP_NOP; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4196 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4197 else if (VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4198 nv_operator(cap); |
6868 | 4199 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4200 clearop(cap->oap); |
7 | 4201 } |
4202 | |
4203 /* | |
4204 * CTRL-F, CTRL-B, etc: Scroll page up or down. | |
4205 */ | |
4206 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4207 nv_page(cmdarg_T *cap) |
7 | 4208 { |
4209 if (!checkclearop(cap->oap)) | |
819 | 4210 { |
4211 if (mod_mask & MOD_MASK_CTRL) | |
4212 { | |
4213 /* <C-PageUp>: tab page back; <C-PageDown>: tab page forward */ | |
4214 if (cap->arg == BACKWARD) | |
4215 goto_tabpage(-(int)cap->count1); | |
4216 else | |
4217 goto_tabpage((int)cap->count0); | |
4218 } | |
4219 else | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
4220 (void)onepage(cap->arg, cap->count1); |
819 | 4221 } |
7 | 4222 } |
4223 | |
4224 /* | |
4225 * Implementation of "gd" and "gD" command. | |
4226 */ | |
4227 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4228 nv_gd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4229 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4230 int nchar, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4231 int thisblock) /* 1 for "1gd" and "1gD" */ |
7 | 4232 { |
4233 int len; | |
503 | 4234 char_u *ptr; |
4235 | |
4236 if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0 | |
8923
face93b02af4
commit https://github.com/vim/vim/commit/1538fc34fae3fae39773ca43f6ff52401fce61d8
Christian Brabandt <cb@256bit.org>
parents:
8651
diff
changeset
|
4237 || find_decl(ptr, len, nchar == 'd', thisblock, SEARCH_START) |
face93b02af4
commit https://github.com/vim/vim/commit/1538fc34fae3fae39773ca43f6ff52401fce61d8
Christian Brabandt <cb@256bit.org>
parents:
8651
diff
changeset
|
4238 == FAIL) |
503 | 4239 clearopbeep(oap); |
4240 #ifdef FEAT_FOLDING | |
4241 else if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) | |
4242 foldOpenCursor(); | |
4243 #endif | |
4244 } | |
4245 | |
4246 /* | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4247 * Return TRUE if line[offset] is not inside a C-style comment or string, FALSE |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4248 * otherwise. |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4249 */ |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4250 static int |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4251 is_ident(char_u *line, int offset) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4252 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4253 int i; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4254 int incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4255 int instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4256 int prev = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4257 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4258 for (i = 0; i < offset && line[i] != NUL; i++) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4259 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4260 if (instring != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4261 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4262 if (prev != '\\' && line[i] == instring) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4263 instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4264 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4265 else if ((line[i] == '"' || line[i] == '\'') && !incomment) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4266 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4267 instring = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4268 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4269 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4270 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4271 if (incomment) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4272 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4273 if (prev == '*' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4274 incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4275 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4276 else if (prev == '/' && line[i] == '*') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4277 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4278 incomment = TRUE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4279 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4280 else if (prev == '/' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4281 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4282 return FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4283 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4284 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4285 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4286 prev = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4287 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4288 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4289 return incomment == FALSE && instring == 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4290 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4291 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4292 /* |
523 | 4293 * Search for variable declaration of "ptr[len]". |
4294 * When "locally" is TRUE in the current function ("gd"), otherwise in the | |
4295 * current file ("gD"). | |
4296 * When "thisblock" is TRUE check the {} block scope. | |
503 | 4297 * Return FAIL when not found. |
4298 */ | |
4299 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4300 find_decl( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4301 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4302 int len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4303 int locally, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4304 int thisblock, |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4305 int flags_arg) /* flags passed to searchit() */ |
503 | 4306 { |
7 | 4307 char_u *pat; |
4308 pos_T old_pos; | |
503 | 4309 pos_T par_pos; |
4310 pos_T found_pos; | |
7 | 4311 int t; |
4312 int save_p_ws; | |
4313 int save_p_scs; | |
503 | 4314 int retval = OK; |
944 | 4315 int incll; |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4316 int searchflags = flags_arg; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4317 int valid; |
503 | 4318 |
4319 if ((pat = alloc(len + 7)) == NULL) | |
4320 return FAIL; | |
268 | 4321 |
4322 /* Put "\V" before the pattern to avoid that the special meaning of "." | |
4323 * and "~" causes trouble. */ | |
4324 sprintf((char *)pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", | |
4325 len, ptr); | |
7 | 4326 old_pos = curwin->w_cursor; |
4327 save_p_ws = p_ws; | |
4328 save_p_scs = p_scs; | |
4329 p_ws = FALSE; /* don't wrap around end of file now */ | |
4330 p_scs = FALSE; /* don't switch ignorecase off now */ | |
4331 | |
4332 /* | |
4333 * With "gD" go to line 1. | |
4334 * With "gd" Search back for the start of the current function, then go | |
4335 * back until a blank line. If this fails go to line 1. | |
4336 */ | |
944 | 4337 if (!locally || !findpar(&incll, BACKWARD, 1L, '{', FALSE)) |
7 | 4338 { |
4339 setpcmark(); /* Set in findpar() otherwise */ | |
4340 curwin->w_cursor.lnum = 1; | |
539 | 4341 par_pos = curwin->w_cursor; |
7 | 4342 } |
4343 else | |
4344 { | |
539 | 4345 par_pos = curwin->w_cursor; |
7 | 4346 while (curwin->w_cursor.lnum > 1 && *skipwhite(ml_get_curline()) != NUL) |
4347 --curwin->w_cursor.lnum; | |
4348 } | |
4349 curwin->w_cursor.col = 0; | |
4350 | |
4351 /* Search forward for the identifier, ignore comment lines. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4352 CLEAR_POS(&found_pos); |
503 | 4353 for (;;) |
4354 { | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4355 valid = FALSE; |
503 | 4356 t = searchit(curwin, curbuf, &curwin->w_cursor, FORWARD, |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11451
diff
changeset
|
4357 pat, 1L, searchflags, RE_LAST, (linenr_T)0, NULL, NULL); |
503 | 4358 if (curwin->w_cursor.lnum >= old_pos.lnum) |
4359 t = FAIL; /* match after start is failure too */ | |
523 | 4360 |
718 | 4361 if (thisblock && t != FAIL) |
523 | 4362 { |
4363 pos_T *pos; | |
4364 | |
4365 /* Check that the block the match is in doesn't end before the | |
4366 * position where we started the search from. */ | |
4367 if ((pos = findmatchlimit(NULL, '}', FM_FORWARD, | |
4368 (int)(old_pos.lnum - curwin->w_cursor.lnum + 1))) != NULL | |
4369 && pos->lnum < old_pos.lnum) | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4370 { |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4371 /* There can't be a useful match before the end of this block. |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4372 * Skip to the end. */ |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4373 curwin->w_cursor = *pos; |
523 | 4374 continue; |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4375 } |
523 | 4376 } |
4377 | |
503 | 4378 if (t == FAIL) |
4379 { | |
4380 /* If we previously found a valid position, use it. */ | |
4381 if (found_pos.lnum != 0) | |
4382 { | |
4383 curwin->w_cursor = found_pos; | |
4384 t = OK; | |
4385 } | |
4386 break; | |
4387 } | |
7 | 4388 #ifdef FEAT_COMMENTS |
3562 | 4389 if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0) |
503 | 4390 { |
4391 /* Ignore this line, continue at start of next line. */ | |
4392 ++curwin->w_cursor.lnum; | |
4393 curwin->w_cursor.col = 0; | |
4394 continue; | |
4395 } | |
4396 #endif | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4397 valid = is_ident(ml_get_curline(), curwin->w_cursor.col); |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4398 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4399 /* If the current position is not a valid identifier and a previous |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4400 * match is present, favor that one instead. */ |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4401 if (!valid && found_pos.lnum != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4402 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4403 curwin->w_cursor = found_pos; |
503 | 4404 break; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4405 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4406 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4407 /* Global search: use first valid match found */ |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4408 if (valid && !locally) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4409 break; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4410 if (valid && curwin->w_cursor.lnum >= par_pos.lnum) |
503 | 4411 { |
4412 /* If we previously found a valid position, use it. */ | |
4413 if (found_pos.lnum != 0) | |
4414 curwin->w_cursor = found_pos; | |
4415 break; | |
4416 } | |
4417 | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4418 /* For finding a local variable and the match is before the "{" or |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4419 * inside a comment, continue searching. For K&R style function |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4420 * declarations this skips the function header without types. */ |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4421 if (!valid) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4422 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4423 CLEAR_POS(&found_pos); |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4424 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4425 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4426 found_pos = curwin->w_cursor; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4427 /* Remove SEARCH_START from flags to avoid getting stuck at one |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4428 * position. */ |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4429 searchflags &= ~SEARCH_START; |
503 | 4430 } |
4431 | |
4432 if (t == FAIL) | |
4433 { | |
4434 retval = FAIL; | |
7 | 4435 curwin->w_cursor = old_pos; |
4436 } | |
4437 else | |
4438 { | |
4439 curwin->w_set_curswant = TRUE; | |
4440 /* "n" searches forward now */ | |
4441 reset_search_dir(); | |
4442 } | |
4443 | |
4444 vim_free(pat); | |
4445 p_ws = save_p_ws; | |
4446 p_scs = save_p_scs; | |
503 | 4447 |
4448 return retval; | |
7 | 4449 } |
4450 | |
4451 /* | |
4452 * Move 'dist' lines in direction 'dir', counting lines by *screen* | |
4453 * lines rather than lines in the file. | |
4454 * 'dist' must be positive. | |
4455 * | |
4456 * Return OK if able to move cursor, FAIL otherwise. | |
4457 */ | |
4458 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4459 nv_screengo(oparg_T *oap, int dir, long dist) |
7 | 4460 { |
4461 int linelen = linetabsize(ml_get_curline()); | |
4462 int retval = OK; | |
4463 int atend = FALSE; | |
4464 int n; | |
4465 int col_off1; /* margin offset for first screen line */ | |
4466 int col_off2; /* margin offset for wrapped screen line */ | |
4467 int width1; /* text width for first screen line */ | |
4468 int width2; /* test width for wrapped screen line */ | |
4469 | |
4470 oap->motion_type = MCHAR; | |
5192
c28202427d71
updated for version 7.4a.022
Bram Moolenaar <bram@vim.org>
parents:
5162
diff
changeset
|
4471 oap->inclusive = (curwin->w_curswant == MAXCOL); |
7 | 4472 |
4473 col_off1 = curwin_col_off(); | |
4474 col_off2 = col_off1 - curwin_col_off2(); | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
4475 width1 = curwin->w_width - col_off1; |
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
4476 width2 = curwin->w_width - col_off2; |
6559 | 4477 if (width2 == 0) |
4478 width2 = 1; /* avoid divide by zero */ | |
7 | 4479 |
4480 if (curwin->w_width != 0) | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4481 { |
7 | 4482 /* |
4483 * Instead of sticking at the last character of the buffer line we | |
4484 * try to stick in the last column of the screen. | |
4485 */ | |
4486 if (curwin->w_curswant == MAXCOL) | |
4487 { | |
4488 atend = TRUE; | |
4489 validate_virtcol(); | |
4490 if (width1 <= 0) | |
4491 curwin->w_curswant = 0; | |
4492 else | |
4493 { | |
4494 curwin->w_curswant = width1 - 1; | |
4495 if (curwin->w_virtcol > curwin->w_curswant) | |
4496 curwin->w_curswant += ((curwin->w_virtcol | |
4497 - curwin->w_curswant - 1) / width2 + 1) * width2; | |
4498 } | |
4499 } | |
4500 else | |
4501 { | |
4502 if (linelen > width1) | |
4503 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
4504 else | |
4505 n = width1; | |
4506 if (curwin->w_curswant > (colnr_T)n + 1) | |
4507 curwin->w_curswant -= ((curwin->w_curswant - n) / width2 + 1) | |
4508 * width2; | |
4509 } | |
4510 | |
4511 while (dist--) | |
4512 { | |
4513 if (dir == BACKWARD) | |
4514 { | |
4515 if ((long)curwin->w_curswant >= width2) | |
4516 /* move back within line */ | |
4517 curwin->w_curswant -= width2; | |
4518 else | |
4519 { | |
4520 /* to previous line */ | |
4521 if (curwin->w_cursor.lnum == 1) | |
4522 { | |
4523 retval = FAIL; | |
4524 break; | |
4525 } | |
4526 --curwin->w_cursor.lnum; | |
4527 #ifdef FEAT_FOLDING | |
4528 /* Move to the start of a closed fold. Don't do that when | |
4529 * 'foldopen' contains "all": it will open in a moment. */ | |
4530 if (!(fdo_flags & FDO_ALL)) | |
4531 (void)hasFolding(curwin->w_cursor.lnum, | |
4532 &curwin->w_cursor.lnum, NULL); | |
4533 #endif | |
4534 linelen = linetabsize(ml_get_curline()); | |
4535 if (linelen > width1) | |
4536 curwin->w_curswant += (((linelen - width1 - 1) / width2) | |
4537 + 1) * width2; | |
4538 } | |
4539 } | |
4540 else /* dir == FORWARD */ | |
4541 { | |
4542 if (linelen > width1) | |
4543 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
4544 else | |
4545 n = width1; | |
4546 if (curwin->w_curswant + width2 < (colnr_T)n) | |
4547 /* move forward within line */ | |
4548 curwin->w_curswant += width2; | |
4549 else | |
4550 { | |
4551 /* to next line */ | |
4552 #ifdef FEAT_FOLDING | |
4553 /* Move to the end of a closed fold. */ | |
4554 (void)hasFolding(curwin->w_cursor.lnum, NULL, | |
4555 &curwin->w_cursor.lnum); | |
4556 #endif | |
4557 if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
4558 { | |
4559 retval = FAIL; | |
4560 break; | |
4561 } | |
4562 curwin->w_cursor.lnum++; | |
4563 curwin->w_curswant %= width2; | |
2911 | 4564 linelen = linetabsize(ml_get_curline()); |
7 | 4565 } |
4566 } | |
4567 } | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4568 } |
7 | 4569 |
5600 | 4570 if (virtual_active() && atend) |
4571 coladvance(MAXCOL); | |
4572 else | |
4573 coladvance(curwin->w_curswant); | |
7 | 4574 |
4575 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE) | |
4576 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
4577 { | |
6178 | 4578 colnr_T virtcol; |
4579 | |
7 | 4580 /* |
4581 * Check for landing on a character that got split at the end of the | |
4582 * last line. We want to advance a screenline, not end up in the same | |
4583 * screenline or move two screenlines. | |
4584 */ | |
4585 validate_virtcol(); | |
6178 | 4586 virtcol = curwin->w_virtcol; |
6187 | 4587 # if defined(FEAT_LINEBREAK) |
6178 | 4588 if (virtcol > (colnr_T)width1 && *p_sbr != NUL) |
4589 virtcol -= vim_strsize(p_sbr); | |
6187 | 4590 # endif |
6178 | 4591 |
4592 if (virtcol > curwin->w_curswant | |
7 | 4593 && (curwin->w_curswant < (colnr_T)width1 |
4594 ? (curwin->w_curswant > (colnr_T)width1 / 2) | |
4595 : ((curwin->w_curswant - width1) % width2 | |
4596 > (colnr_T)width2 / 2))) | |
4597 --curwin->w_cursor.col; | |
4598 } | |
4599 #endif | |
4600 | |
4601 if (atend) | |
4602 curwin->w_curswant = MAXCOL; /* stick in the last column */ | |
4603 | |
4604 return retval; | |
4605 } | |
4606 | |
4607 #ifdef FEAT_MOUSE | |
4608 /* | |
4609 * Mouse scroll wheel: Default action is to scroll three lines, or one page | |
4610 * when Shift or Ctrl is used. | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4611 * K_MOUSEUP (cap->arg == 1) or K_MOUSEDOWN (cap->arg == 0) or |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4612 * K_MOUSELEFT (cap->arg == -1) or K_MOUSERIGHT (cap->arg == -2) |
7 | 4613 */ |
4614 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4615 nv_mousescroll(cmdarg_T *cap) |
7 | 4616 { |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4617 win_T *old_curwin = curwin, *wp; |
7 | 4618 |
4162 | 4619 if (mouse_row >= 0 && mouse_col >= 0) |
7 | 4620 { |
4621 int row, col; | |
4622 | |
4623 row = mouse_row; | |
4624 col = mouse_col; | |
4625 | |
4626 /* find the window at the pointer coordinates */ | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4627 wp = mouse_find_win(&row, &col); |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4628 if (wp == NULL) |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4629 return; |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4630 curwin = wp; |
7 | 4631 curbuf = curwin->w_buffer; |
4632 } | |
4633 | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4634 if (cap->arg == MSCR_UP || cap->arg == MSCR_DOWN) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4635 { |
11983
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4636 # ifdef FEAT_TERMINAL |
11993
92a86fe8adc0
patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
11987
diff
changeset
|
4637 if (term_use_loop()) |
12893
40ae30bc2691
patch 8.0.1323: mouse events in a terminal window may cause endless loop
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
4638 /* This window is a terminal window, send the mouse event there. |
40ae30bc2691
patch 8.0.1323: mouse events in a terminal window may cause endless loop
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
4639 * Set "typed" to FALSE to avoid an endless loop. */ |
40ae30bc2691
patch 8.0.1323: mouse events in a terminal window may cause endless loop
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
4640 send_keys_to_term(curbuf->b_term, cap->cmdchar, FALSE); |
11983
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4641 else |
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4642 # endif |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4643 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4644 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4645 (void)onepage(cap->arg ? FORWARD : BACKWARD, 1L); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4646 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4647 else |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4648 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4649 cap->count1 = 3; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4650 cap->count0 = 3; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4651 nv_scroll_line(cap); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4652 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4653 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4654 # ifdef FEAT_GUI |
7 | 4655 else |
4656 { | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4657 /* Horizontal scroll - only allowed when 'wrap' is disabled */ |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4658 if (!curwin->w_p_wrap) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4659 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4660 int val, step = 6; |
2416
1a9c16dd76d4
Fix compiler warnings on 64 bit systems.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4661 |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4662 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
4663 step = curwin->w_width; |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4664 val = curwin->w_leftcol + (cap->arg == MSCR_RIGHT ? -step : +step); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4665 if (val < 0) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4666 val = 0; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4667 |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4668 gui_do_horiz_scroll(val, TRUE); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4669 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4670 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4671 # endif |
7 | 4672 |
4673 curwin->w_redr_status = TRUE; | |
4674 | |
4675 curwin = old_curwin; | |
4676 curbuf = curwin->w_buffer; | |
4677 } | |
4678 | |
4679 /* | |
4680 * Mouse clicks and drags. | |
4681 */ | |
4682 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4683 nv_mouse(cmdarg_T *cap) |
7 | 4684 { |
4685 (void)do_mouse(cap->oap, cap->cmdchar, BACKWARD, cap->count1, 0); | |
4686 } | |
4687 #endif | |
4688 | |
4689 /* | |
4690 * Handle CTRL-E and CTRL-Y commands: scroll a line up or down. | |
4691 * cap->arg must be TRUE for CTRL-E. | |
4692 */ | |
4693 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4694 nv_scroll_line(cmdarg_T *cap) |
7 | 4695 { |
4696 if (!checkclearop(cap->oap)) | |
4697 scroll_redraw(cap->arg, cap->count1); | |
4698 } | |
4699 | |
4700 /* | |
4701 * Scroll "count" lines up or down, and redraw. | |
4702 */ | |
4703 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4704 scroll_redraw(int up, long count) |
7 | 4705 { |
4706 linenr_T prev_topline = curwin->w_topline; | |
4707 #ifdef FEAT_DIFF | |
4708 int prev_topfill = curwin->w_topfill; | |
4709 #endif | |
4710 linenr_T prev_lnum = curwin->w_cursor.lnum; | |
4711 | |
4712 if (up) | |
4713 scrollup(count, TRUE); | |
4714 else | |
4715 scrolldown(count, TRUE); | |
4716 if (p_so) | |
4717 { | |
4718 /* Adjust the cursor position for 'scrolloff'. Mark w_topline as | |
4719 * valid, otherwise the screen jumps back at the end of the file. */ | |
4720 cursor_correct(); | |
4721 check_cursor_moved(curwin); | |
4722 curwin->w_valid |= VALID_TOPLINE; | |
4723 | |
4724 /* If moved back to where we were, at least move the cursor, otherwise | |
4725 * we get stuck at one position. Don't move the cursor up if the | |
4726 * first line of the buffer is already on the screen */ | |
4727 while (curwin->w_topline == prev_topline | |
4728 #ifdef FEAT_DIFF | |
4729 && curwin->w_topfill == prev_topfill | |
4730 #endif | |
4731 ) | |
4732 { | |
4733 if (up) | |
4734 { | |
4735 if (curwin->w_cursor.lnum > prev_lnum | |
4736 || cursor_down(1L, FALSE) == FAIL) | |
4737 break; | |
4738 } | |
4739 else | |
4740 { | |
4741 if (curwin->w_cursor.lnum < prev_lnum | |
4742 || prev_topline == 1L | |
4743 || cursor_up(1L, FALSE) == FAIL) | |
4744 break; | |
4745 } | |
4746 /* Mark w_topline as valid, otherwise the screen jumps back at the | |
4747 * end of the file. */ | |
4748 check_cursor_moved(curwin); | |
4749 curwin->w_valid |= VALID_TOPLINE; | |
4750 } | |
4751 } | |
4752 if (curwin->w_cursor.lnum != prev_lnum) | |
4753 coladvance(curwin->w_curswant); | |
4754 redraw_later(VALID); | |
4755 } | |
4756 | |
4757 /* | |
4758 * Commands that start with "z". | |
4759 */ | |
4760 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4761 nv_zet(cmdarg_T *cap) |
7 | 4762 { |
4763 long n; | |
4764 colnr_T col; | |
4765 int nchar = cap->nchar; | |
4766 #ifdef FEAT_FOLDING | |
4767 long old_fdl = curwin->w_p_fdl; | |
4768 int old_fen = curwin->w_p_fen; | |
4769 #endif | |
737 | 4770 #ifdef FEAT_SPELL |
710 | 4771 int undo = FALSE; |
4772 #endif | |
7 | 4773 |
4774 if (VIM_ISDIGIT(nchar)) | |
4775 { | |
4776 /* | |
4777 * "z123{nchar}": edit the count before obtaining {nchar} | |
4778 */ | |
4779 if (checkclearop(cap->oap)) | |
4780 return; | |
4781 n = nchar - '0'; | |
4782 for (;;) | |
4783 { | |
4784 #ifdef USE_ON_FLY_SCROLL | |
4785 dont_scroll = TRUE; /* disallow scrolling here */ | |
4786 #endif | |
4787 ++no_mapping; | |
4788 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 4789 nchar = plain_vgetc(); |
7 | 4790 LANGMAP_ADJUST(nchar, TRUE); |
4791 --no_mapping; | |
4792 --allow_keys; | |
4793 #ifdef FEAT_CMDL_INFO | |
4794 (void)add_to_showcmd(nchar); | |
4795 #endif | |
4796 if (nchar == K_DEL || nchar == K_KDEL) | |
4797 n /= 10; | |
4798 else if (VIM_ISDIGIT(nchar)) | |
4799 n = n * 10 + (nchar - '0'); | |
4800 else if (nchar == CAR) | |
4801 { | |
4802 #ifdef FEAT_GUI | |
4803 need_mouse_correct = TRUE; | |
4804 #endif | |
4805 win_setheight((int)n); | |
4806 break; | |
4807 } | |
4808 else if (nchar == 'l' | |
4809 || nchar == 'h' | |
4810 || nchar == K_LEFT | |
229 | 4811 || nchar == K_RIGHT) |
7 | 4812 { |
4813 cap->count1 = n ? n * cap->count1 : cap->count1; | |
4814 goto dozet; | |
4815 } | |
4816 else | |
4817 { | |
4818 clearopbeep(cap->oap); | |
4819 break; | |
4820 } | |
4821 } | |
4822 cap->oap->op_type = OP_NOP; | |
4823 return; | |
4824 } | |
4825 | |
4826 dozet: | |
4827 if ( | |
4828 #ifdef FEAT_FOLDING | |
4829 /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" | |
4830 * and "zC" only in Visual mode. "zj" and "zk" are motion | |
4831 * commands. */ | |
4832 cap->nchar != 'f' && cap->nchar != 'F' | |
4833 && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) | |
4834 && cap->nchar != 'j' && cap->nchar != 'k' | |
4835 && | |
4836 #endif | |
4837 checkclearop(cap->oap)) | |
4838 return; | |
4839 | |
4840 /* | |
4841 * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb": | |
4842 * If line number given, set cursor. | |
4843 */ | |
4844 if ((vim_strchr((char_u *)"+\r\nt.z^-b", nchar) != NULL) | |
4845 && cap->count0 | |
4846 && cap->count0 != curwin->w_cursor.lnum) | |
4847 { | |
4848 setpcmark(); | |
4849 if (cap->count0 > curbuf->b_ml.ml_line_count) | |
4850 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4851 else | |
4852 curwin->w_cursor.lnum = cap->count0; | |
22 | 4853 check_cursor_col(); |
7 | 4854 } |
4855 | |
4856 switch (nchar) | |
4857 { | |
4858 /* "z+", "z<CR>" and "zt": put cursor at top of screen */ | |
4859 case '+': | |
4860 if (cap->count0 == 0) | |
4861 { | |
4862 /* No count given: put cursor at the line below screen */ | |
4863 validate_botline(); /* make sure w_botline is valid */ | |
4864 if (curwin->w_botline > curbuf->b_ml.ml_line_count) | |
4865 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4866 else | |
4867 curwin->w_cursor.lnum = curwin->w_botline; | |
4868 } | |
4869 /* FALLTHROUGH */ | |
4870 case NL: | |
4871 case CAR: | |
4872 case K_KENTER: | |
4873 beginline(BL_WHITE | BL_FIX); | |
4874 /* FALLTHROUGH */ | |
4875 | |
4876 case 't': scroll_cursor_top(0, TRUE); | |
4877 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4878 set_fraction(curwin); |
7 | 4879 break; |
4880 | |
4881 /* "z." and "zz": put cursor in middle of screen */ | |
4882 case '.': beginline(BL_WHITE | BL_FIX); | |
4883 /* FALLTHROUGH */ | |
4884 | |
4885 case 'z': scroll_cursor_halfway(TRUE); | |
4886 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4887 set_fraction(curwin); |
7 | 4888 break; |
4889 | |
4890 /* "z^", "z-" and "zb": put cursor at bottom of screen */ | |
4891 case '^': /* Strange Vi behavior: <count>z^ finds line at top of window | |
4892 * when <count> is at bottom of window, and puts that one at | |
4893 * bottom of window. */ | |
4894 if (cap->count0 != 0) | |
4895 { | |
4896 scroll_cursor_bot(0, TRUE); | |
4897 curwin->w_cursor.lnum = curwin->w_topline; | |
4898 } | |
4899 else if (curwin->w_topline == 1) | |
4900 curwin->w_cursor.lnum = 1; | |
4901 else | |
4902 curwin->w_cursor.lnum = curwin->w_topline - 1; | |
4903 /* FALLTHROUGH */ | |
4904 case '-': | |
4905 beginline(BL_WHITE | BL_FIX); | |
4906 /* FALLTHROUGH */ | |
4907 | |
4908 case 'b': scroll_cursor_bot(0, TRUE); | |
4909 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4910 set_fraction(curwin); |
7 | 4911 break; |
4912 | |
4913 /* "zH" - scroll screen right half-page */ | |
4914 case 'H': | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
4915 cap->count1 *= curwin->w_width / 2; |
7 | 4916 /* FALLTHROUGH */ |
4917 | |
4918 /* "zh" - scroll screen to the right */ | |
4919 case 'h': | |
4920 case K_LEFT: | |
4921 if (!curwin->w_p_wrap) | |
4922 { | |
4923 if ((colnr_T)cap->count1 > curwin->w_leftcol) | |
4924 curwin->w_leftcol = 0; | |
4925 else | |
4926 curwin->w_leftcol -= (colnr_T)cap->count1; | |
4927 leftcol_changed(); | |
4928 } | |
4929 break; | |
4930 | |
4931 /* "zL" - scroll screen left half-page */ | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
4932 case 'L': cap->count1 *= curwin->w_width / 2; |
7 | 4933 /* FALLTHROUGH */ |
4934 | |
4935 /* "zl" - scroll screen to the left */ | |
4936 case 'l': | |
4937 case K_RIGHT: | |
4938 if (!curwin->w_p_wrap) | |
4939 { | |
4940 /* scroll the window left */ | |
4941 curwin->w_leftcol += (colnr_T)cap->count1; | |
4942 leftcol_changed(); | |
4943 } | |
4944 break; | |
4945 | |
4946 /* "zs" - scroll screen, cursor at the start */ | |
4947 case 's': if (!curwin->w_p_wrap) | |
4948 { | |
4949 #ifdef FEAT_FOLDING | |
4950 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4951 col = 0; /* like the cursor is in col 0 */ | |
4952 else | |
4953 #endif | |
4954 getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL); | |
4955 if ((long)col > p_siso) | |
4956 col -= p_siso; | |
4957 else | |
4958 col = 0; | |
4959 if (curwin->w_leftcol != col) | |
4960 { | |
4961 curwin->w_leftcol = col; | |
4962 redraw_later(NOT_VALID); | |
4963 } | |
4964 } | |
4965 break; | |
4966 | |
4967 /* "ze" - scroll screen, cursor at the end */ | |
4968 case 'e': if (!curwin->w_p_wrap) | |
4969 { | |
4970 #ifdef FEAT_FOLDING | |
4971 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4972 col = 0; /* like the cursor is in col 0 */ | |
4973 else | |
4974 #endif | |
4975 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
4976 n = curwin->w_width - curwin_col_off(); |
7 | 4977 if ((long)col + p_siso < n) |
4978 col = 0; | |
4979 else | |
4980 col = col + p_siso - n + 1; | |
4981 if (curwin->w_leftcol != col) | |
4982 { | |
4983 curwin->w_leftcol = col; | |
4984 redraw_later(NOT_VALID); | |
4985 } | |
4986 } | |
4987 break; | |
4988 | |
4989 #ifdef FEAT_FOLDING | |
4990 /* "zF": create fold command */ | |
4991 /* "zf": create fold operator */ | |
4992 case 'F': | |
4993 case 'f': if (foldManualAllowed(TRUE)) | |
4994 { | |
4995 cap->nchar = 'f'; | |
4996 nv_operator(cap); | |
4997 curwin->w_p_fen = TRUE; | |
4998 | |
4999 /* "zF" is like "zfzf" */ | |
5000 if (nchar == 'F' && cap->oap->op_type == OP_FOLD) | |
5001 { | |
5002 nv_operator(cap); | |
5003 finish_op = TRUE; | |
5004 } | |
5005 } | |
5006 else | |
5007 clearopbeep(cap->oap); | |
5008 break; | |
5009 | |
5010 /* "zd": delete fold at cursor */ | |
5011 /* "zD": delete fold at cursor recursively */ | |
5012 case 'd': | |
5013 case 'D': if (foldManualAllowed(FALSE)) | |
5014 { | |
5015 if (VIsual_active) | |
5016 nv_operator(cap); | |
5017 else | |
5018 deleteFold(curwin->w_cursor.lnum, | |
5019 curwin->w_cursor.lnum, nchar == 'D', FALSE); | |
5020 } | |
5021 break; | |
5022 | |
4352 | 5023 /* "zE": erase all folds */ |
7 | 5024 case 'E': if (foldmethodIsManual(curwin)) |
5025 { | |
5026 clearFolding(curwin); | |
5027 changed_window_setting(); | |
5028 } | |
5029 else if (foldmethodIsMarker(curwin)) | |
5030 deleteFold((linenr_T)1, curbuf->b_ml.ml_line_count, | |
5031 TRUE, FALSE); | |
5032 else | |
5033 EMSG(_("E352: Cannot erase folds with current 'foldmethod'")); | |
5034 break; | |
5035 | |
5036 /* "zn": fold none: reset 'foldenable' */ | |
5037 case 'n': curwin->w_p_fen = FALSE; | |
5038 break; | |
5039 | |
5040 /* "zN": fold Normal: set 'foldenable' */ | |
5041 case 'N': curwin->w_p_fen = TRUE; | |
5042 break; | |
5043 | |
5044 /* "zi": invert folding: toggle 'foldenable' */ | |
5045 case 'i': curwin->w_p_fen = !curwin->w_p_fen; | |
5046 break; | |
5047 | |
5048 /* "za": open closed fold or close open fold at cursor */ | |
5049 case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
5050 openFold(curwin->w_cursor.lnum, cap->count1); | |
5051 else | |
5052 { | |
5053 closeFold(curwin->w_cursor.lnum, cap->count1); | |
5054 curwin->w_p_fen = TRUE; | |
5055 } | |
5056 break; | |
5057 | |
5058 /* "zA": open fold at cursor recursively */ | |
5059 case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
5060 openFoldRecurse(curwin->w_cursor.lnum); | |
5061 else | |
5062 { | |
5063 closeFoldRecurse(curwin->w_cursor.lnum); | |
5064 curwin->w_p_fen = TRUE; | |
5065 } | |
5066 break; | |
5067 | |
5068 /* "zo": open fold at cursor or Visual area */ | |
5069 case 'o': if (VIsual_active) | |
5070 nv_operator(cap); | |
5071 else | |
5072 openFold(curwin->w_cursor.lnum, cap->count1); | |
5073 break; | |
5074 | |
5075 /* "zO": open fold recursively */ | |
5076 case 'O': if (VIsual_active) | |
5077 nv_operator(cap); | |
5078 else | |
5079 openFoldRecurse(curwin->w_cursor.lnum); | |
5080 break; | |
5081 | |
5082 /* "zc": close fold at cursor or Visual area */ | |
5083 case 'c': if (VIsual_active) | |
5084 nv_operator(cap); | |
5085 else | |
5086 closeFold(curwin->w_cursor.lnum, cap->count1); | |
5087 curwin->w_p_fen = TRUE; | |
5088 break; | |
5089 | |
5090 /* "zC": close fold recursively */ | |
5091 case 'C': if (VIsual_active) | |
5092 nv_operator(cap); | |
5093 else | |
5094 closeFoldRecurse(curwin->w_cursor.lnum); | |
5095 curwin->w_p_fen = TRUE; | |
5096 break; | |
5097 | |
5098 /* "zv": open folds at the cursor */ | |
5099 case 'v': foldOpenCursor(); | |
5100 break; | |
5101 | |
5102 /* "zx": re-apply 'foldlevel' and open folds at the cursor */ | |
5103 case 'x': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5104 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5105 newFoldLevel(); /* update right now */ |
7 | 5106 foldOpenCursor(); |
5107 break; | |
5108 | |
5109 /* "zX": undo manual opens/closes, re-apply 'foldlevel' */ | |
5110 case 'X': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5111 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5112 old_fdl = -1; /* force an update */ |
7 | 5113 break; |
5114 | |
5115 /* "zm": fold more */ | |
5116 case 'm': if (curwin->w_p_fdl > 0) | |
6725 | 5117 { |
5118 curwin->w_p_fdl -= cap->count1; | |
5119 if (curwin->w_p_fdl < 0) | |
5120 curwin->w_p_fdl = 0; | |
5121 } | |
7 | 5122 old_fdl = -1; /* force an update */ |
5123 curwin->w_p_fen = TRUE; | |
5124 break; | |
5125 | |
5126 /* "zM": close all folds */ | |
5127 case 'M': curwin->w_p_fdl = 0; | |
5128 old_fdl = -1; /* force an update */ | |
5129 curwin->w_p_fen = TRUE; | |
5130 break; | |
5131 | |
5132 /* "zr": reduce folding */ | |
6725 | 5133 case 'r': curwin->w_p_fdl += cap->count1; |
5134 { | |
5135 int d = getDeepestNesting(); | |
5136 | |
5137 if (curwin->w_p_fdl >= d) | |
5138 curwin->w_p_fdl = d; | |
5139 } | |
7 | 5140 break; |
5141 | |
5142 /* "zR": open all folds */ | |
5143 case 'R': curwin->w_p_fdl = getDeepestNesting(); | |
5144 old_fdl = -1; /* force an update */ | |
5145 break; | |
5146 | |
5147 case 'j': /* "zj" move to next fold downwards */ | |
5148 case 'k': /* "zk" move to next fold upwards */ | |
5149 if (foldMoveTo(TRUE, nchar == 'j' ? FORWARD : BACKWARD, | |
5150 cap->count1) == FAIL) | |
5151 clearopbeep(cap->oap); | |
5152 break; | |
5153 | |
5154 #endif /* FEAT_FOLDING */ | |
5155 | |
737 | 5156 #ifdef FEAT_SPELL |
710 | 5157 case 'u': /* "zug" and "zuw": undo "zg" and "zw" */ |
5158 ++no_mapping; | |
5159 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 5160 nchar = plain_vgetc(); |
710 | 5161 LANGMAP_ADJUST(nchar, TRUE); |
5162 --no_mapping; | |
5163 --allow_keys; | |
5164 #ifdef FEAT_CMDL_INFO | |
5165 (void)add_to_showcmd(nchar); | |
5166 #endif | |
5167 if (vim_strchr((char_u *)"gGwW", nchar) == NULL) | |
5168 { | |
5169 clearopbeep(cap->oap); | |
5170 break; | |
5171 } | |
5172 undo = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
5173 /* FALLTHROUGH */ |
710 | 5174 |
310 | 5175 case 'g': /* "zg": add good word to word list */ |
5176 case 'w': /* "zw": add wrong word to word list */ | |
381 | 5177 case 'G': /* "zG": add good word to temp word list */ |
5178 case 'W': /* "zW": add wrong word to temp word list */ | |
310 | 5179 { |
5180 char_u *ptr = NULL; | |
5181 int len; | |
5182 | |
5183 if (checkclearop(cap->oap)) | |
5184 break; | |
5185 if (VIsual_active && get_visual_text(cap, &ptr, &len) | |
5186 == FAIL) | |
5187 return; | |
501 | 5188 if (ptr == NULL) |
5189 { | |
5190 pos_T pos = curwin->w_cursor; | |
5191 | |
5374 | 5192 /* Find bad word under the cursor. When 'spell' is |
5193 * off this fails and find_ident_under_cursor() is | |
5194 * used below. */ | |
5195 emsg_off++; | |
534 | 5196 len = spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL); |
5374 | 5197 emsg_off--; |
501 | 5198 if (len != 0 && curwin->w_cursor.col <= pos.col) |
5199 ptr = ml_get_pos(&curwin->w_cursor); | |
5200 curwin->w_cursor = pos; | |
5201 } | |
5202 | |
310 | 5203 if (ptr == NULL && (len = find_ident_under_cursor(&ptr, |
5204 FIND_IDENT)) == 0) | |
5205 return; | |
381 | 5206 spell_add_word(ptr, len, nchar == 'w' || nchar == 'W', |
710 | 5207 (nchar == 'G' || nchar == 'W') |
5208 ? 0 : (int)cap->count1, | |
5209 undo); | |
310 | 5210 } |
316 | 5211 break; |
323 | 5212 |
584 | 5213 case '=': /* "z=": suggestions for a badly spelled word */ |
638 | 5214 if (!checkclearop(cap->oap)) |
485 | 5215 spell_suggest((int)cap->count0); |
323 | 5216 break; |
310 | 5217 #endif |
5218 | |
7 | 5219 default: clearopbeep(cap->oap); |
5220 } | |
5221 | |
5222 #ifdef FEAT_FOLDING | |
5223 /* Redraw when 'foldenable' changed */ | |
5224 if (old_fen != curwin->w_p_fen) | |
5225 { | |
5226 # ifdef FEAT_DIFF | |
5227 win_T *wp; | |
5228 | |
5229 if (foldmethodIsDiff(curwin) && curwin->w_p_scb) | |
5230 { | |
5231 /* Adjust 'foldenable' in diff-synced windows. */ | |
5232 FOR_ALL_WINDOWS(wp) | |
5233 { | |
5234 if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) | |
5235 { | |
5236 wp->w_p_fen = curwin->w_p_fen; | |
5237 changed_window_setting_win(wp); | |
5238 } | |
5239 } | |
5240 } | |
5241 # endif | |
5242 changed_window_setting(); | |
5243 } | |
5244 | |
5245 /* Redraw when 'foldlevel' changed. */ | |
5246 if (old_fdl != curwin->w_p_fdl) | |
5247 newFoldLevel(); | |
5248 #endif | |
5249 } | |
5250 | |
5251 #ifdef FEAT_GUI | |
5252 /* | |
5253 * Vertical scrollbar movement. | |
5254 */ | |
5255 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5256 nv_ver_scrollbar(cmdarg_T *cap) |
7 | 5257 { |
5258 if (cap->oap->op_type != OP_NOP) | |
5259 clearopbeep(cap->oap); | |
5260 | |
5261 /* Even if an operator was pending, we still want to scroll */ | |
5262 gui_do_scroll(); | |
5263 } | |
5264 | |
5265 /* | |
5266 * Horizontal scrollbar movement. | |
5267 */ | |
5268 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5269 nv_hor_scrollbar(cmdarg_T *cap) |
7 | 5270 { |
5271 if (cap->oap->op_type != OP_NOP) | |
5272 clearopbeep(cap->oap); | |
5273 | |
5274 /* Even if an operator was pending, we still want to scroll */ | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
5275 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 5276 } |
5277 #endif | |
5278 | |
690 | 5279 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
685 | 5280 /* |
5281 * Click in GUI tab. | |
5282 */ | |
5283 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5284 nv_tabline(cmdarg_T *cap) |
685 | 5285 { |
5286 if (cap->oap->op_type != OP_NOP) | |
5287 clearopbeep(cap->oap); | |
5288 | |
5289 /* Even if an operator was pending, we still want to jump tabs. */ | |
5290 goto_tabpage(current_tab); | |
5291 } | |
686 | 5292 |
5293 /* | |
5294 * Selected item in tab line menu. | |
5295 */ | |
5296 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5297 nv_tabmenu(cmdarg_T *cap) |
686 | 5298 { |
5299 if (cap->oap->op_type != OP_NOP) | |
5300 clearopbeep(cap->oap); | |
5301 | |
5302 /* Even if an operator was pending, we still want to jump tabs. */ | |
690 | 5303 handle_tabmenu(); |
5304 } | |
5305 | |
5306 /* | |
5307 * Handle selecting an item of the GUI tab line menu. | |
5308 * Used in Normal and Insert mode. | |
5309 */ | |
5310 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5311 handle_tabmenu(void) |
690 | 5312 { |
686 | 5313 switch (current_tabmenu) |
5314 { | |
5315 case TABLINE_MENU_CLOSE: | |
5316 if (current_tab == 0) | |
5317 do_cmdline_cmd((char_u *)"tabclose"); | |
5318 else | |
5319 { | |
5320 vim_snprintf((char *)IObuff, IOSIZE, "tabclose %d", | |
5321 current_tab); | |
5322 do_cmdline_cmd(IObuff); | |
5323 } | |
5324 break; | |
5325 | |
5326 case TABLINE_MENU_NEW: | |
6631 | 5327 if (current_tab == 0) |
5328 do_cmdline_cmd((char_u *)"$tabnew"); | |
5329 else | |
5330 { | |
5331 vim_snprintf((char *)IObuff, IOSIZE, "%dtabnew", | |
5332 current_tab - 1); | |
5333 do_cmdline_cmd(IObuff); | |
5334 } | |
686 | 5335 break; |
5336 | |
5337 case TABLINE_MENU_OPEN: | |
6631 | 5338 if (current_tab == 0) |
5339 do_cmdline_cmd((char_u *)"browse $tabnew"); | |
5340 else | |
5341 { | |
5342 vim_snprintf((char *)IObuff, IOSIZE, "browse %dtabnew", | |
5343 current_tab - 1); | |
5344 do_cmdline_cmd(IObuff); | |
5345 } | |
686 | 5346 break; |
5347 } | |
5348 } | |
685 | 5349 #endif |
5350 | |
7 | 5351 /* |
5352 * "Q" command. | |
5353 */ | |
5354 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5355 nv_exmode(cmdarg_T *cap) |
7 | 5356 { |
5357 /* | |
5358 * Ignore 'Q' in Visual mode, just give a beep. | |
5359 */ | |
5360 if (VIsual_active) | |
6949 | 5361 vim_beep(BO_EX); |
5735 | 5362 else if (!checkclearop(cap->oap)) |
7 | 5363 do_exmode(FALSE); |
5364 } | |
5365 | |
5366 /* | |
5367 * Handle a ":" command. | |
5368 */ | |
5369 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5370 nv_colon(cmdarg_T *cap) |
7 | 5371 { |
5372 int old_p_im; | |
4256 | 5373 int cmd_result; |
7 | 5374 |
5375 if (VIsual_active) | |
5376 nv_operator(cap); | |
5377 else | |
5378 { | |
5379 if (cap->oap->op_type != OP_NOP) | |
5380 { | |
5381 /* Using ":" as a movement is characterwise exclusive. */ | |
5382 cap->oap->motion_type = MCHAR; | |
5383 cap->oap->inclusive = FALSE; | |
5384 } | |
5385 else if (cap->count0) | |
5386 { | |
5387 /* translate "count:" into ":.,.+(count - 1)" */ | |
5388 stuffcharReadbuff('.'); | |
5389 if (cap->count0 > 1) | |
5390 { | |
5391 stuffReadbuff((char_u *)",.+"); | |
5392 stuffnumReadbuff((long)cap->count0 - 1L); | |
5393 } | |
5394 } | |
5395 | |
5396 /* When typing, don't type below an old message */ | |
5397 if (KeyTyped) | |
5398 compute_cmdrow(); | |
5399 | |
5400 old_p_im = p_im; | |
5401 | |
5402 /* get a command line and execute it */ | |
4256 | 5403 cmd_result = do_cmdline(NULL, getexline, NULL, |
7 | 5404 cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0); |
5405 | |
5406 /* If 'insertmode' changed, enter or exit Insert mode */ | |
5407 if (p_im != old_p_im) | |
5408 { | |
5409 if (p_im) | |
5410 restart_edit = 'i'; | |
5411 else | |
5412 restart_edit = 0; | |
5413 } | |
5414 | |
4256 | 5415 if (cmd_result == FAIL) |
5416 /* The Ex command failed, do not execute the operator. */ | |
5417 clearop(cap->oap); | |
5418 else if (cap->oap->op_type != OP_NOP | |
7 | 5419 && (cap->oap->start.lnum > curbuf->b_ml.ml_line_count |
5420 || cap->oap->start.col > | |
4256 | 5421 (colnr_T)STRLEN(ml_get(cap->oap->start.lnum)) |
5422 || did_emsg | |
5423 )) | |
5424 /* The start of the operator has become invalid by the Ex command. | |
5425 */ | |
7 | 5426 clearopbeep(cap->oap); |
5427 } | |
5428 } | |
5429 | |
5430 /* | |
5431 * Handle CTRL-G command. | |
5432 */ | |
5433 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5434 nv_ctrlg(cmdarg_T *cap) |
7 | 5435 { |
5436 if (VIsual_active) /* toggle Selection/Visual mode */ | |
5437 { | |
5438 VIsual_select = !VIsual_select; | |
5439 showmode(); | |
5440 } | |
5735 | 5441 else if (!checkclearop(cap->oap)) |
7 | 5442 /* print full name if count given or :cd used */ |
5443 fileinfo((int)cap->count0, FALSE, TRUE); | |
5444 } | |
5445 | |
5446 /* | |
5447 * Handle CTRL-H <Backspace> command. | |
5448 */ | |
5449 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5450 nv_ctrlh(cmdarg_T *cap) |
7 | 5451 { |
5452 if (VIsual_active && VIsual_select) | |
5453 { | |
5454 cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */ | |
5455 v_visop(cap); | |
5456 } | |
5457 else | |
5458 nv_left(cap); | |
5459 } | |
5460 | |
5461 /* | |
5462 * CTRL-L: clear screen and redraw. | |
5463 */ | |
5464 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5465 nv_clear(cmdarg_T *cap) |
7 | 5466 { |
5467 if (!checkclearop(cap->oap)) | |
5468 { | |
5469 #if defined(__BEOS__) && !USE_THREAD_FOR_INPUT_WITH_TIMEOUT | |
5470 /* | |
5471 * Right now, the BeBox doesn't seem to have an easy way to detect | |
5472 * window resizing, so we cheat and make the user detect it | |
5473 * manually with CTRL-L instead | |
5474 */ | |
5475 ui_get_shellsize(); | |
5476 #endif | |
5477 #ifdef FEAT_SYN_HL | |
5478 /* Clear all syntax states to force resyncing. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
5479 syn_stack_free_all(curwin->w_s); |
11529
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5480 # ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5481 { |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5482 win_T *wp; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5483 |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5484 FOR_ALL_WINDOWS(wp) |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5485 wp->w_s->b_syn_slow = FALSE; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5486 } |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5487 # endif |
7 | 5488 #endif |
5489 redraw_later(CLEAR); | |
5490 } | |
5491 } | |
5492 | |
5493 /* | |
5494 * CTRL-O: In Select mode: switch to Visual mode for one command. | |
5495 * Otherwise: Go to older pcmark. | |
5496 */ | |
5497 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5498 nv_ctrlo(cmdarg_T *cap) |
7 | 5499 { |
5500 if (VIsual_active && VIsual_select) | |
5501 { | |
5502 VIsual_select = FALSE; | |
5503 showmode(); | |
5504 restart_VIsual_select = 2; /* restart Select mode later */ | |
5505 } | |
5506 else | |
5507 { | |
5508 cap->count1 = -cap->count1; | |
5509 nv_pcmark(cap); | |
5510 } | |
5511 } | |
5512 | |
5513 /* | |
5514 * CTRL-^ command, short for ":e #" | |
5515 */ | |
5516 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5517 nv_hat(cmdarg_T *cap) |
7 | 5518 { |
5519 if (!checkclearopq(cap->oap)) | |
5520 (void)buflist_getfile((int)cap->count0, (linenr_T)0, | |
5521 GETF_SETMARK|GETF_ALT, FALSE); | |
5522 } | |
5523 | |
5524 /* | |
5525 * "Z" commands. | |
5526 */ | |
5527 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5528 nv_Zet(cmdarg_T *cap) |
7 | 5529 { |
5530 if (!checkclearopq(cap->oap)) | |
5531 { | |
5532 switch (cap->nchar) | |
5533 { | |
5534 /* "ZZ": equivalent to ":x". */ | |
5535 case 'Z': do_cmdline_cmd((char_u *)"x"); | |
5536 break; | |
5537 | |
5538 /* "ZQ": equivalent to ":q!" (Elvis compatible). */ | |
5539 case 'Q': do_cmdline_cmd((char_u *)"q!"); | |
5540 break; | |
5541 | |
5542 default: clearopbeep(cap->oap); | |
5543 } | |
5544 } | |
5545 } | |
5546 | |
5547 /* | |
5548 * Call nv_ident() as if "c1" was used, with "c2" as next character. | |
5549 */ | |
5550 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5551 do_nv_ident(int c1, int c2) |
7 | 5552 { |
5553 oparg_T oa; | |
5554 cmdarg_T ca; | |
5555 | |
5556 clear_oparg(&oa); | |
5557 vim_memset(&ca, 0, sizeof(ca)); | |
5558 ca.oap = &oa; | |
5559 ca.cmdchar = c1; | |
5560 ca.nchar = c2; | |
5561 nv_ident(&ca); | |
5562 } | |
5563 | |
5564 /* | |
5565 * Handle the commands that use the word under the cursor. | |
5566 * [g] CTRL-] :ta to current identifier | |
5567 * [g] 'K' run program for current identifier | |
5568 * [g] '*' / to current identifier or string | |
5569 * [g] '#' ? to current identifier or string | |
5570 * g ']' :tselect for current identifier | |
5571 */ | |
5572 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5573 nv_ident(cmdarg_T *cap) |
7 | 5574 { |
5575 char_u *ptr = NULL; | |
5576 char_u *buf; | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5577 unsigned buflen; |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5578 char_u *newbuf; |
7 | 5579 char_u *p; |
5580 char_u *kp; /* value of 'keywordprg' */ | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5581 int kp_help; /* 'keywordprg' is ":he" */ |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5582 int kp_ex; /* 'keywordprg' starts with ":" */ |
7 | 5583 int n = 0; /* init for GCC */ |
5584 int cmdchar; | |
5585 int g_cmd; /* "g" command */ | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5586 int tag_cmd = FALSE; |
7 | 5587 char_u *aux_ptr; |
5588 int isman; | |
5589 int isman_s; | |
5590 | |
5591 if (cap->cmdchar == 'g') /* "g*", "g#", "g]" and "gCTRL-]" */ | |
5592 { | |
5593 cmdchar = cap->nchar; | |
5594 g_cmd = TRUE; | |
5595 } | |
5596 else | |
5597 { | |
5598 cmdchar = cap->cmdchar; | |
5599 g_cmd = FALSE; | |
5600 } | |
5601 | |
5602 if (cmdchar == POUND) /* the pound sign, '#' for English keyboards */ | |
5603 cmdchar = '#'; | |
5604 | |
5605 /* | |
5606 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode. | |
5607 */ | |
5608 if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') | |
5609 { | |
5610 if (VIsual_active && get_visual_text(cap, &ptr, &n) == FAIL) | |
5611 return; | |
5612 if (checkclearopq(cap->oap)) | |
5613 return; | |
5614 } | |
5615 | |
5616 if (ptr == NULL && (n = find_ident_under_cursor(&ptr, | |
5617 (cmdchar == '*' || cmdchar == '#') | |
5618 ? FIND_IDENT|FIND_STRING : FIND_IDENT)) == 0) | |
5619 { | |
5620 clearop(cap->oap); | |
5621 return; | |
5622 } | |
5623 | |
5624 /* Allocate buffer to put the command in. Inserting backslashes can | |
5625 * double the length of the word. p_kp / curbuf->b_p_kp could be added | |
5626 * and some numbers. */ | |
5627 kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); | |
5628 kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 | |
5629 || STRCMP(kp, ":help") == 0); | |
12236
55cf556d8ce1
patch 8.0.0998: strange error when using K while only spaces are selected
Christian Brabandt <cb@256bit.org>
parents:
12164
diff
changeset
|
5630 if (kp_help && *skipwhite(ptr) == NUL) |
55cf556d8ce1
patch 8.0.0998: strange error when using K while only spaces are selected
Christian Brabandt <cb@256bit.org>
parents:
12164
diff
changeset
|
5631 { |
55cf556d8ce1
patch 8.0.0998: strange error when using K while only spaces are selected
Christian Brabandt <cb@256bit.org>
parents:
12164
diff
changeset
|
5632 EMSG(_(e_noident)); /* found white space only */ |
55cf556d8ce1
patch 8.0.0998: strange error when using K while only spaces are selected
Christian Brabandt <cb@256bit.org>
parents:
12164
diff
changeset
|
5633 return; |
55cf556d8ce1
patch 8.0.0998: strange error when using K while only spaces are selected
Christian Brabandt <cb@256bit.org>
parents:
12164
diff
changeset
|
5634 } |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5635 kp_ex = (*kp == ':'); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5636 buflen = (unsigned)(n * 2 + 30 + STRLEN(kp)); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5637 buf = alloc(buflen); |
7 | 5638 if (buf == NULL) |
5639 return; | |
5640 buf[0] = NUL; | |
5641 | |
5642 switch (cmdchar) | |
5643 { | |
5644 case '*': | |
5645 case '#': | |
5646 /* | |
5647 * Put cursor at start of word, makes search skip the word | |
5648 * under the cursor. | |
5649 * Call setpcmark() first, so "*``" puts the cursor back where | |
5650 * it was. | |
5651 */ | |
5652 setpcmark(); | |
5653 curwin->w_cursor.col = (colnr_T) (ptr - ml_get_curline()); | |
5654 | |
5655 if (!g_cmd && vim_iswordp(ptr)) | |
5656 STRCPY(buf, "\\<"); | |
5657 no_smartcase = TRUE; /* don't use 'smartcase' now */ | |
5658 break; | |
5659 | |
5660 case 'K': | |
5661 if (kp_help) | |
5662 STRCPY(buf, "he! "); | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5663 else if (kp_ex) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5664 { |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5665 if (cap->count0 != 0) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5666 vim_snprintf((char *)buf, buflen, "%s %ld", |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5667 kp, cap->count0); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5668 else |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5669 STRCPY(buf, kp); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5670 STRCAT(buf, " "); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5671 } |
7 | 5672 else |
5673 { | |
1712 | 5674 /* An external command will probably use an argument starting |
5675 * with "-" as an option. To avoid trouble we skip the "-". */ | |
1728 | 5676 while (*ptr == '-' && n > 0) |
5677 { | |
1712 | 5678 ++ptr; |
1728 | 5679 --n; |
5680 } | |
5681 if (n == 0) | |
5682 { | |
5683 EMSG(_(e_noident)); /* found dashes only */ | |
5684 vim_free(buf); | |
5685 return; | |
5686 } | |
1712 | 5687 |
7 | 5688 /* When a count is given, turn it into a range. Is this |
5689 * really what we want? */ | |
5690 isman = (STRCMP(kp, "man") == 0); | |
5691 isman_s = (STRCMP(kp, "man -s") == 0); | |
5692 if (cap->count0 != 0 && !(isman || isman_s)) | |
5693 sprintf((char *)buf, ".,.+%ld", cap->count0 - 1); | |
5694 | |
5695 STRCAT(buf, "! "); | |
5696 if (cap->count0 == 0 && isman_s) | |
5697 STRCAT(buf, "man"); | |
5698 else | |
5699 STRCAT(buf, kp); | |
5700 STRCAT(buf, " "); | |
5701 if (cap->count0 != 0 && (isman || isman_s)) | |
5702 { | |
5703 sprintf((char *)buf + STRLEN(buf), "%ld", cap->count0); | |
5704 STRCAT(buf, " "); | |
5705 } | |
5706 } | |
5707 break; | |
5708 | |
5709 case ']': | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5710 tag_cmd = TRUE; |
7 | 5711 #ifdef FEAT_CSCOPE |
5712 if (p_cst) | |
5713 STRCPY(buf, "cstag "); | |
5714 else | |
5715 #endif | |
5716 STRCPY(buf, "ts "); | |
5717 break; | |
5718 | |
5719 default: | |
2112
6b5d641bcdd4
updated for version 7.2.395
Bram Moolenaar <bram@zimbu.org>
parents:
2049
diff
changeset
|
5720 tag_cmd = TRUE; |
7 | 5721 if (curbuf->b_help) |
5722 STRCPY(buf, "he! "); | |
5723 else | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5724 { |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5725 if (g_cmd) |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5726 STRCPY(buf, "tj "); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5727 else |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5728 sprintf((char *)buf, "%ldta ", cap->count0); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5729 } |
7 | 5730 } |
5731 | |
5732 /* | |
5733 * Now grab the chars in the identifier | |
5734 */ | |
1712 | 5735 if (cmdchar == 'K' && !kp_help) |
5736 { | |
1728 | 5737 ptr = vim_strnsave(ptr, n); |
10330
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5738 if (kp_ex) |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5739 /* Escape the argument properly for an Ex command */ |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5740 p = vim_strsave_fnameescape(ptr, FALSE); |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5741 else |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5742 /* Escape the argument properly for a shell command */ |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5743 p = vim_strsave_shellescape(ptr, TRUE, TRUE); |
1728 | 5744 vim_free(ptr); |
1712 | 5745 if (p == NULL) |
5746 { | |
5747 vim_free(buf); | |
5748 return; | |
5749 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5750 newbuf = (char_u *)vim_realloc(buf, STRLEN(buf) + STRLEN(p) + 1); |
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5751 if (newbuf == NULL) |
1712 | 5752 { |
5753 vim_free(buf); | |
5754 vim_free(p); | |
5755 return; | |
5756 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5757 buf = newbuf; |
1712 | 5758 STRCAT(buf, p); |
5759 vim_free(p); | |
5760 } | |
7 | 5761 else |
1712 | 5762 { |
5763 if (cmdchar == '*') | |
5764 aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\"); | |
5765 else if (cmdchar == '#') | |
5766 aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\"); | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5767 else if (tag_cmd) |
2603 | 5768 { |
5769 if (curbuf->b_help) | |
5770 /* ":help" handles unescaped argument */ | |
5771 aux_ptr = (char_u *)""; | |
5772 else | |
5773 aux_ptr = (char_u *)"\\|\"\n["; | |
5774 } | |
1712 | 5775 else |
5776 aux_ptr = (char_u *)"\\|\"\n*?["; | |
5777 | |
5778 p = buf + STRLEN(buf); | |
5779 while (n-- > 0) | |
5780 { | |
5781 /* put a backslash before \ and some others */ | |
5782 if (vim_strchr(aux_ptr, *ptr) != NULL) | |
5783 *p++ = '\\'; | |
7 | 5784 #ifdef FEAT_MBYTE |
1712 | 5785 /* When current byte is a part of multibyte character, copy all |
5786 * bytes of that character. */ | |
5787 if (has_mbyte) | |
5788 { | |
5789 int i; | |
5790 int len = (*mb_ptr2len)(ptr) - 1; | |
5791 | |
5792 for (i = 0; i < len && n >= 1; ++i, --n) | |
5793 *p++ = *ptr++; | |
5794 } | |
5795 #endif | |
5796 *p++ = *ptr++; | |
5797 } | |
5798 *p = NUL; | |
5799 } | |
7 | 5800 |
5801 /* | |
5802 * Execute the command. | |
5803 */ | |
5804 if (cmdchar == '*' || cmdchar == '#') | |
5805 { | |
5806 if (!g_cmd && ( | |
5807 #ifdef FEAT_MBYTE | |
5808 has_mbyte ? vim_iswordp(mb_prevptr(ml_get_curline(), ptr)) : | |
5809 #endif | |
5810 vim_iswordc(ptr[-1]))) | |
5811 STRCAT(buf, "\\>"); | |
5812 #ifdef FEAT_CMDHIST | |
5813 /* put pattern in search history */ | |
2024 | 5814 init_history(); |
7 | 5815 add_to_history(HIST_SEARCH, buf, TRUE, NUL); |
5816 #endif | |
6620 | 5817 (void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0); |
7 | 5818 } |
5819 else | |
5820 do_cmdline_cmd(buf); | |
5821 | |
5822 vim_free(buf); | |
5823 } | |
5824 | |
5825 /* | |
5826 * Get visually selected text, within one line only. | |
5827 * Returns FAIL if more than one line selected. | |
5828 */ | |
344 | 5829 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5830 get_visual_text( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5831 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5832 char_u **pp, /* return: start of selected text */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5833 int *lenp) /* return: length of selected text */ |
7 | 5834 { |
5835 if (VIsual_mode != 'V') | |
5836 unadjust_for_sel(); | |
5837 if (VIsual.lnum != curwin->w_cursor.lnum) | |
5838 { | |
344 | 5839 if (cap != NULL) |
5840 clearopbeep(cap->oap); | |
7 | 5841 return FAIL; |
5842 } | |
5843 if (VIsual_mode == 'V') | |
5844 { | |
5845 *pp = ml_get_curline(); | |
5846 *lenp = (int)STRLEN(*pp); | |
5847 } | |
5848 else | |
5849 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5850 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 5851 { |
5852 *pp = ml_get_pos(&curwin->w_cursor); | |
5853 *lenp = VIsual.col - curwin->w_cursor.col + 1; | |
5854 } | |
5855 else | |
5856 { | |
5857 *pp = ml_get_pos(&VIsual); | |
5858 *lenp = curwin->w_cursor.col - VIsual.col + 1; | |
5859 } | |
5860 #ifdef FEAT_MBYTE | |
5861 if (has_mbyte) | |
5862 /* Correct the length to include the whole last character. */ | |
474 | 5863 *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; |
7 | 5864 #endif |
5865 } | |
5866 reset_VIsual_and_resel(); | |
5867 return OK; | |
5868 } | |
5869 | |
5870 /* | |
5871 * CTRL-T: backwards in tag stack | |
5872 */ | |
5873 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5874 nv_tagpop(cmdarg_T *cap) |
7 | 5875 { |
5876 if (!checkclearopq(cap->oap)) | |
5877 do_tag((char_u *)"", DT_POP, (int)cap->count1, FALSE, TRUE); | |
5878 } | |
5879 | |
5880 /* | |
5881 * Handle scrolling command 'H', 'L' and 'M'. | |
5882 */ | |
5883 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5884 nv_scroll(cmdarg_T *cap) |
7 | 5885 { |
5886 int used = 0; | |
5887 long n; | |
5888 #ifdef FEAT_FOLDING | |
5889 linenr_T lnum; | |
5890 #endif | |
5891 int half; | |
5892 | |
5893 cap->oap->motion_type = MLINE; | |
5894 setpcmark(); | |
5895 | |
5896 if (cap->cmdchar == 'L') | |
5897 { | |
5898 validate_botline(); /* make sure curwin->w_botline is valid */ | |
5899 curwin->w_cursor.lnum = curwin->w_botline - 1; | |
5900 if (cap->count1 - 1 >= curwin->w_cursor.lnum) | |
5901 curwin->w_cursor.lnum = 1; | |
5902 else | |
9 | 5903 { |
5904 #ifdef FEAT_FOLDING | |
5905 if (hasAnyFolding(curwin)) | |
5906 { | |
5907 /* Count a fold for one screen line. */ | |
5908 for (n = cap->count1 - 1; n > 0 | |
5909 && curwin->w_cursor.lnum > curwin->w_topline; --n) | |
5910 { | |
5911 (void)hasFolding(curwin->w_cursor.lnum, | |
5912 &curwin->w_cursor.lnum, NULL); | |
5913 --curwin->w_cursor.lnum; | |
5914 } | |
5915 } | |
5916 else | |
5917 #endif | |
5918 curwin->w_cursor.lnum -= cap->count1 - 1; | |
5919 } | |
7 | 5920 } |
5921 else | |
5922 { | |
5923 if (cap->cmdchar == 'M') | |
5924 { | |
5925 #ifdef FEAT_DIFF | |
5926 /* Don't count filler lines above the window. */ | |
5927 used -= diff_check_fill(curwin, curwin->w_topline) | |
5928 - curwin->w_topfill; | |
5929 #endif | |
5930 validate_botline(); /* make sure w_empty_rows is valid */ | |
5931 half = (curwin->w_height - curwin->w_empty_rows + 1) / 2; | |
5932 for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) | |
5933 { | |
5934 #ifdef FEAT_DIFF | |
5935 /* Count half he number of filler lines to be "below this | |
5936 * line" and half to be "above the next line". */ | |
5937 if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline | |
5938 + n) / 2 >= half) | |
5939 { | |
5940 --n; | |
5941 break; | |
5942 } | |
5943 #endif | |
5944 used += plines(curwin->w_topline + n); | |
5945 if (used >= half) | |
5946 break; | |
5947 #ifdef FEAT_FOLDING | |
5948 if (hasFolding(curwin->w_topline + n, NULL, &lnum)) | |
5949 n = lnum - curwin->w_topline; | |
5950 #endif | |
5951 } | |
5952 if (n > 0 && used > curwin->w_height) | |
5953 --n; | |
5954 } | |
9 | 5955 else /* (cap->cmdchar == 'H') */ |
5956 { | |
7 | 5957 n = cap->count1 - 1; |
9 | 5958 #ifdef FEAT_FOLDING |
5959 if (hasAnyFolding(curwin)) | |
5960 { | |
5961 /* Count a fold for one screen line. */ | |
5962 lnum = curwin->w_topline; | |
5963 while (n-- > 0 && lnum < curwin->w_botline - 1) | |
5964 { | |
7009 | 5965 (void)hasFolding(lnum, NULL, &lnum); |
9 | 5966 ++lnum; |
5967 } | |
5968 n = lnum - curwin->w_topline; | |
5969 } | |
5970 #endif | |
5971 } | |
7 | 5972 curwin->w_cursor.lnum = curwin->w_topline + n; |
5973 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
5974 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
5975 } | |
5976 | |
12646
b908a3682f6e
patch 8.0.1201: "yL" is affected by 'scrolloff'
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
5977 /* Correct for 'so', except when an operator is pending. */ |
b908a3682f6e
patch 8.0.1201: "yL" is affected by 'scrolloff'
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
5978 if (cap->oap->op_type == OP_NOP) |
b908a3682f6e
patch 8.0.1201: "yL" is affected by 'scrolloff'
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
5979 cursor_correct(); |
7 | 5980 beginline(BL_SOL | BL_FIX); |
5981 } | |
5982 | |
5983 /* | |
5984 * Cursor right commands. | |
5985 */ | |
5986 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5987 nv_right(cmdarg_T *cap) |
7 | 5988 { |
5989 long n; | |
5735 | 5990 int past_line; |
7 | 5991 |
180 | 5992 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
5993 { | |
5994 /* <C-Right> and <S-Right> move a word or WORD right */ | |
5995 if (mod_mask & MOD_MASK_CTRL) | |
5996 cap->arg = TRUE; | |
5997 nv_wordcmd(cap); | |
5998 return; | |
5999 } | |
6000 | |
7 | 6001 cap->oap->motion_type = MCHAR; |
6002 cap->oap->inclusive = FALSE; | |
5735 | 6003 past_line = (VIsual_active && *p_sel != 'o'); |
6004 | |
6005 #ifdef FEAT_VIRTUALEDIT | |
7 | 6006 /* |
5735 | 6007 * In virtual edit mode, there's no such thing as "past_line", as lines |
6008 * are (theoretically) infinitely long. | |
7 | 6009 */ |
6010 if (virtual_active()) | |
5735 | 6011 past_line = 0; |
7 | 6012 #endif |
6013 | |
6014 for (n = cap->count1; n > 0; --n) | |
6015 { | |
5735 | 6016 if ((!past_line && oneright() == FAIL) |
6017 || (past_line && *ml_get_cursor() == NUL) | |
1877 | 6018 ) |
7 | 6019 { |
6020 /* | |
714 | 6021 * <Space> wraps to next line if 'whichwrap' has 's'. |
6022 * 'l' wraps to next line if 'whichwrap' has 'l'. | |
6023 * CURS_RIGHT wraps to next line if 'whichwrap' has '>'. | |
7 | 6024 */ |
6025 if ( ((cap->cmdchar == ' ' | |
6026 && vim_strchr(p_ww, 's') != NULL) | |
6027 || (cap->cmdchar == 'l' | |
6028 && vim_strchr(p_ww, 'l') != NULL) | |
229 | 6029 || (cap->cmdchar == K_RIGHT |
7 | 6030 && vim_strchr(p_ww, '>') != NULL)) |
6031 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
6032 { | |
6033 /* When deleting we also count the NL as a character. | |
6034 * Set cap->oap->inclusive when last char in the line is | |
6035 * included, move to next line after that */ | |
714 | 6036 if ( cap->oap->op_type != OP_NOP |
7 | 6037 && !cap->oap->inclusive |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6038 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6039 cap->oap->inclusive = TRUE; |
6040 else | |
6041 { | |
6042 ++curwin->w_cursor.lnum; | |
6043 curwin->w_cursor.col = 0; | |
6044 #ifdef FEAT_VIRTUALEDIT | |
6045 curwin->w_cursor.coladd = 0; | |
6046 #endif | |
6047 curwin->w_set_curswant = TRUE; | |
6048 cap->oap->inclusive = FALSE; | |
6049 } | |
6050 continue; | |
6051 } | |
6052 if (cap->oap->op_type == OP_NOP) | |
6053 { | |
6054 /* Only beep and flush if not moved at all */ | |
6055 if (n == cap->count1) | |
6056 beep_flush(); | |
6057 } | |
6058 else | |
6059 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6060 if (!LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6061 cap->oap->inclusive = TRUE; |
6062 } | |
6063 break; | |
6064 } | |
5735 | 6065 else if (past_line) |
7 | 6066 { |
6067 curwin->w_set_curswant = TRUE; | |
5735 | 6068 #ifdef FEAT_VIRTUALEDIT |
7 | 6069 if (virtual_active()) |
6070 oneright(); | |
6071 else | |
5735 | 6072 #endif |
6073 { | |
6074 #ifdef FEAT_MBYTE | |
7 | 6075 if (has_mbyte) |
6076 curwin->w_cursor.col += | |
474 | 6077 (*mb_ptr2len)(ml_get_cursor()); |
7 | 6078 else |
5735 | 6079 #endif |
7 | 6080 ++curwin->w_cursor.col; |
6081 } | |
6082 } | |
6083 } | |
6084 #ifdef FEAT_FOLDING | |
6085 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
6086 && cap->oap->op_type == OP_NOP) | |
6087 foldOpenCursor(); | |
6088 #endif | |
6089 } | |
6090 | |
6091 /* | |
6092 * Cursor left commands. | |
6093 * | |
6094 * Returns TRUE when operator end should not be adjusted. | |
6095 */ | |
6096 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6097 nv_left(cmdarg_T *cap) |
7 | 6098 { |
6099 long n; | |
6100 | |
180 | 6101 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
6102 { | |
6103 /* <C-Left> and <S-Left> move a word or WORD left */ | |
6104 if (mod_mask & MOD_MASK_CTRL) | |
6105 cap->arg = 1; | |
6106 nv_bck_word(cap); | |
6107 return; | |
6108 } | |
6109 | |
7 | 6110 cap->oap->motion_type = MCHAR; |
6111 cap->oap->inclusive = FALSE; | |
6112 for (n = cap->count1; n > 0; --n) | |
6113 { | |
6114 if (oneleft() == FAIL) | |
6115 { | |
6116 /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'. | |
6117 * 'h' wraps to previous line if 'whichwrap' has 'h'. | |
6118 * CURS_LEFT wraps to previous line if 'whichwrap' has '<'. | |
6119 */ | |
6120 if ( (((cap->cmdchar == K_BS | |
6121 || cap->cmdchar == Ctrl_H) | |
6122 && vim_strchr(p_ww, 'b') != NULL) | |
6123 || (cap->cmdchar == 'h' | |
6124 && vim_strchr(p_ww, 'h') != NULL) | |
229 | 6125 || (cap->cmdchar == K_LEFT |
7 | 6126 && vim_strchr(p_ww, '<') != NULL)) |
6127 && curwin->w_cursor.lnum > 1) | |
6128 { | |
6129 --(curwin->w_cursor.lnum); | |
6130 coladvance((colnr_T)MAXCOL); | |
6131 curwin->w_set_curswant = TRUE; | |
6132 | |
6133 /* When the NL before the first char has to be deleted we | |
6134 * put the cursor on the NUL after the previous line. | |
6135 * This is a very special case, be careful! | |
1469 | 6136 * Don't adjust op_end now, otherwise it won't work. */ |
7 | 6137 if ( (cap->oap->op_type == OP_DELETE |
6138 || cap->oap->op_type == OP_CHANGE) | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6139 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6140 { |
5682 | 6141 char_u *cp = ml_get_cursor(); |
6142 | |
6143 if (*cp != NUL) | |
6144 { | |
6145 #ifdef FEAT_MBYTE | |
6146 if (has_mbyte) | |
6147 curwin->w_cursor.col += (*mb_ptr2len)(cp); | |
6148 else | |
6149 #endif | |
6150 ++curwin->w_cursor.col; | |
6151 } | |
7 | 6152 cap->retval |= CA_NO_ADJ_OP_END; |
6153 } | |
6154 continue; | |
6155 } | |
6156 /* Only beep and flush if not moved at all */ | |
6157 else if (cap->oap->op_type == OP_NOP && n == cap->count1) | |
6158 beep_flush(); | |
6159 break; | |
6160 } | |
6161 } | |
6162 #ifdef FEAT_FOLDING | |
6163 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
6164 && cap->oap->op_type == OP_NOP) | |
6165 foldOpenCursor(); | |
6166 #endif | |
6167 } | |
6168 | |
6169 /* | |
6170 * Cursor up commands. | |
6171 * cap->arg is TRUE for "-": Move cursor to first non-blank. | |
6172 */ | |
6173 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6174 nv_up(cmdarg_T *cap) |
7 | 6175 { |
180 | 6176 if (mod_mask & MOD_MASK_SHIFT) |
6177 { | |
6178 /* <S-Up> is page up */ | |
6179 cap->arg = BACKWARD; | |
6180 nv_page(cap); | |
6181 } | |
6182 else | |
6183 { | |
6184 cap->oap->motion_type = MLINE; | |
6185 if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
6186 clearopbeep(cap->oap); | |
6187 else if (cap->arg) | |
6188 beginline(BL_WHITE | BL_FIX); | |
6189 } | |
7 | 6190 } |
6191 | |
6192 /* | |
6193 * Cursor down commands. | |
6194 * cap->arg is TRUE for CR and "+": Move cursor to first non-blank. | |
6195 */ | |
6196 static void | |
10192
758f3d5a463d
commit https://github.com/vim/vim/commit/1b010058235fb803c1d4f42a02d2883921be8ef4
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
6197 nv_down(cmdarg_T *cap) |
7 | 6198 { |
180 | 6199 if (mod_mask & MOD_MASK_SHIFT) |
6200 { | |
6201 /* <S-Down> is page down */ | |
6202 cap->arg = FORWARD; | |
6203 nv_page(cap); | |
6204 } | |
6205 else | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
6206 #if defined(FEAT_QUICKFIX) |
7 | 6207 /* In a quickfix window a <CR> jumps to the error under the cursor. */ |
170 | 6208 if (bt_quickfix(curbuf) && cap->cmdchar == CAR) |
10980
5362b4b6042c
patch 8.0.0379: CTRL-Z and mouse click use CTRL-O unnecessary
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
6209 { |
643 | 6210 if (curwin->w_llist_ref == NULL) |
6211 do_cmdline_cmd((char_u *)".cc"); /* quickfix window */ | |
6212 else | |
6213 do_cmdline_cmd((char_u *)".ll"); /* location list window */ | |
10980
5362b4b6042c
patch 8.0.0379: CTRL-Z and mouse click use CTRL-O unnecessary
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
6214 } |
7 | 6215 else |
6216 #endif | |
6217 { | |
6218 #ifdef FEAT_CMDWIN | |
6219 /* In the cmdline window a <CR> executes the command. */ | |
170 | 6220 if (cmdwin_type != 0 && cap->cmdchar == CAR) |
7 | 6221 cmdwin_result = CAR; |
6222 else | |
6223 #endif | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6224 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6225 /* In a prompt buffer a <CR> in the last line invokes the callback. */ |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6226 if (bt_prompt(curbuf) && cap->cmdchar == CAR |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6227 && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6228 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6229 invoke_prompt_callback(); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6230 if (restart_edit == 0) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6231 restart_edit = 'a'; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6232 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6233 else |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6234 #endif |
7 | 6235 { |
6236 cap->oap->motion_type = MLINE; | |
6237 if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
6238 clearopbeep(cap->oap); | |
6239 else if (cap->arg) | |
6240 beginline(BL_WHITE | BL_FIX); | |
6241 } | |
6242 } | |
6243 } | |
6244 | |
6245 #ifdef FEAT_SEARCHPATH | |
6246 /* | |
6247 * Grab the file name under the cursor and edit it. | |
6248 */ | |
6249 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6250 nv_gotofile(cmdarg_T *cap) |
7 | 6251 { |
6252 char_u *ptr; | |
681 | 6253 linenr_T lnum = -1; |
7 | 6254 |
633 | 6255 if (text_locked()) |
7 | 6256 { |
6257 clearopbeep(cap->oap); | |
633 | 6258 text_locked_msg(); |
7 | 6259 return; |
6260 } | |
819 | 6261 if (curbuf_locked()) |
6262 { | |
6263 clearop(cap->oap); | |
6264 return; | |
6265 } | |
7 | 6266 |
681 | 6267 ptr = grab_file_name(cap->count1, &lnum); |
7 | 6268 |
6269 if (ptr != NULL) | |
6270 { | |
6271 /* do autowrite if necessary */ | |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11892
diff
changeset
|
6272 if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !buf_hide(curbuf)) |
7009 | 6273 (void)autowrite(curbuf, FALSE); |
7 | 6274 setpcmark(); |
11436
69b52a770b29
patch 8.0.0602: when gF fails to edit the file the cursor still moves
Christian Brabandt <cb@256bit.org>
parents:
11366
diff
changeset
|
6275 if (do_ecmd(0, ptr, NULL, NULL, ECMD_LAST, |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11892
diff
changeset
|
6276 buf_hide(curbuf) ? ECMD_HIDE : 0, curwin) == OK |
11436
69b52a770b29
patch 8.0.0602: when gF fails to edit the file the cursor still moves
Christian Brabandt <cb@256bit.org>
parents:
11366
diff
changeset
|
6277 && cap->nchar == 'F' && lnum >= 0) |
681 | 6278 { |
6279 curwin->w_cursor.lnum = lnum; | |
6280 check_cursor_lnum(); | |
6281 beginline(BL_SOL | BL_FIX); | |
6282 } | |
7 | 6283 vim_free(ptr); |
6284 } | |
6285 else | |
6286 clearop(cap->oap); | |
6287 } | |
6288 #endif | |
6289 | |
6290 /* | |
6291 * <End> command: to end of current line or last line. | |
6292 */ | |
6293 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6294 nv_end(cmdarg_T *cap) |
7 | 6295 { |
180 | 6296 if (cap->arg || (mod_mask & MOD_MASK_CTRL)) /* CTRL-END = goto last line */ |
6297 { | |
6298 cap->arg = TRUE; | |
7 | 6299 nv_goto(cap); |
6300 cap->count1 = 1; /* to end of current line */ | |
6301 } | |
6302 nv_dollar(cap); | |
6303 } | |
6304 | |
6305 /* | |
6306 * Handle the "$" command. | |
6307 */ | |
6308 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6309 nv_dollar(cmdarg_T *cap) |
7 | 6310 { |
6311 cap->oap->motion_type = MCHAR; | |
6312 cap->oap->inclusive = TRUE; | |
6313 #ifdef FEAT_VIRTUALEDIT | |
6314 /* In virtual mode when off the edge of a line and an operator | |
6315 * is pending (whew!) keep the cursor where it is. | |
6316 * Otherwise, send it to the end of the line. */ | |
6317 if (!virtual_active() || gchar_cursor() != NUL | |
6318 || cap->oap->op_type == OP_NOP) | |
6319 #endif | |
6320 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
6321 if (cursor_down((long)(cap->count1 - 1), | |
6322 cap->oap->op_type == OP_NOP) == FAIL) | |
6323 clearopbeep(cap->oap); | |
6324 #ifdef FEAT_FOLDING | |
6325 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6326 foldOpenCursor(); | |
6327 #endif | |
6328 } | |
6329 | |
6330 /* | |
6331 * Implementation of '?' and '/' commands. | |
6332 * If cap->arg is TRUE don't set PC mark. | |
6333 */ | |
6334 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6335 nv_search(cmdarg_T *cap) |
7 | 6336 { |
6337 oparg_T *oap = cap->oap; | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6338 pos_T save_cursor = curwin->w_cursor; |
7 | 6339 |
6340 if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13) | |
6341 { | |
6342 /* Translate "g??" to "g?g?" */ | |
6343 cap->cmdchar = 'g'; | |
6344 cap->nchar = '?'; | |
6345 nv_operator(cap); | |
6346 return; | |
6347 } | |
6348 | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6349 /* When using 'incsearch' the cursor may be moved to set a different search |
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6350 * start position. */ |
7 | 6351 cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0); |
6352 | |
6353 if (cap->searchbuf == NULL) | |
6354 { | |
6355 clearop(oap); | |
6356 return; | |
6357 } | |
6358 | |
6620 | 6359 (void)normal_search(cap, cap->cmdchar, cap->searchbuf, |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6360 (cap->arg || !EQUAL_POS(save_cursor, curwin->w_cursor)) |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6361 ? 0 : SEARCH_MARK); |
7 | 6362 } |
6363 | |
6364 /* | |
6365 * Handle "N" and "n" commands. | |
6366 * cap->arg is SEARCH_REV for "N", 0 for "n". | |
6367 */ | |
6368 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6369 nv_next(cmdarg_T *cap) |
7 | 6370 { |
6620 | 6371 pos_T old = curwin->w_cursor; |
6372 int i = normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
6373 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6374 if (i == 1 && EQUAL_POS(old, curwin->w_cursor)) |
6620 | 6375 { |
6376 /* Avoid getting stuck on the current cursor position, which can | |
6377 * happen when an offset is given and the cursor is on the last char | |
6378 * in the buffer: Repeat with count + 1. */ | |
6379 cap->count1 += 1; | |
6380 (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
6381 cap->count1 -= 1; | |
6382 } | |
7 | 6383 } |
6384 | |
6385 /* | |
6386 * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat). | |
6387 * Uses only cap->count1 and cap->oap from "cap". | |
6620 | 6388 * Return 0 for failure, 1 for found, 2 for found and line offset added. |
6389 */ | |
6390 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6391 normal_search( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6392 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6393 int dir, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6394 char_u *pat, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6395 int opt) /* extra flags for do_search() */ |
7 | 6396 { |
6397 int i; | |
6398 | |
6399 cap->oap->motion_type = MCHAR; | |
6400 cap->oap->inclusive = FALSE; | |
6401 cap->oap->use_reg_one = TRUE; | |
6402 curwin->w_set_curswant = TRUE; | |
6403 | |
6404 i = do_search(cap->oap, dir, pat, cap->count1, | |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11451
diff
changeset
|
6405 opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL, NULL); |
7 | 6406 if (i == 0) |
6407 clearop(cap->oap); | |
6408 else | |
6409 { | |
6410 if (i == 2) | |
6411 cap->oap->motion_type = MLINE; | |
6412 #ifdef FEAT_VIRTUALEDIT | |
6413 curwin->w_cursor.coladd = 0; | |
6414 #endif | |
6415 #ifdef FEAT_FOLDING | |
6416 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
6417 foldOpenCursor(); | |
6418 #endif | |
6419 } | |
6420 | |
6421 /* "/$" will put the cursor after the end of the line, may need to | |
6422 * correct that here */ | |
6423 check_cursor(); | |
6620 | 6424 return i; |
7 | 6425 } |
6426 | |
6427 /* | |
6428 * Character search commands. | |
6429 * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for | |
6430 * ',' and FALSE for ';'. | |
6431 * cap->nchar is NUL for ',' and ';' (repeat the search) | |
6432 */ | |
6433 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6434 nv_csearch(cmdarg_T *cap) |
7 | 6435 { |
6436 int t_cmd; | |
6437 | |
6438 if (cap->cmdchar == 't' || cap->cmdchar == 'T') | |
6439 t_cmd = TRUE; | |
6440 else | |
6441 t_cmd = FALSE; | |
6442 | |
6443 cap->oap->motion_type = MCHAR; | |
6444 if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL) | |
6445 clearopbeep(cap->oap); | |
6446 else | |
6447 { | |
6448 curwin->w_set_curswant = TRUE; | |
6449 #ifdef FEAT_VIRTUALEDIT | |
6450 /* Include a Tab for "tx" and for "dfx". */ | |
6451 if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD | |
6452 && (t_cmd || cap->oap->op_type != OP_NOP)) | |
6453 { | |
6454 colnr_T scol, ecol; | |
6455 | |
6456 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
6457 curwin->w_cursor.coladd = ecol - scol; | |
6458 } | |
6459 else | |
6460 curwin->w_cursor.coladd = 0; | |
6461 #endif | |
6462 adjust_for_sel(cap); | |
6463 #ifdef FEAT_FOLDING | |
6464 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6465 foldOpenCursor(); | |
6466 #endif | |
6467 } | |
6468 } | |
6469 | |
6470 /* | |
6471 * "[" and "]" commands. | |
6472 * cap->arg is BACKWARD for "[" and FORWARD for "]". | |
6473 */ | |
6474 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6475 nv_brackets(cmdarg_T *cap) |
7 | 6476 { |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
6477 pos_T new_pos = INIT_POS_T(0, 0, 0); |
7 | 6478 pos_T prev_pos; |
6479 pos_T *pos = NULL; /* init for GCC */ | |
6480 pos_T old_pos; /* cursor position before command */ | |
6481 int flag; | |
6482 long n; | |
6483 int findc; | |
6484 int c; | |
6485 | |
6486 cap->oap->motion_type = MCHAR; | |
6487 cap->oap->inclusive = FALSE; | |
6488 old_pos = curwin->w_cursor; | |
6489 #ifdef FEAT_VIRTUALEDIT | |
6490 curwin->w_cursor.coladd = 0; /* TODO: don't do this for an error. */ | |
6491 #endif | |
6492 | |
6493 #ifdef FEAT_SEARCHPATH | |
6494 /* | |
6495 * "[f" or "]f" : Edit file under the cursor (same as "gf") | |
6496 */ | |
6497 if (cap->nchar == 'f') | |
6498 nv_gotofile(cap); | |
6499 else | |
6500 #endif | |
6501 | |
6502 #ifdef FEAT_FIND_ID | |
6503 /* | |
1188 | 6504 * Find the occurrence(s) of the identifier or define under cursor |
6505 * in current and included files or jump to the first occurrence. | |
7 | 6506 * |
6507 * search list jump | |
6508 * fwd bwd fwd bwd fwd bwd | |
6509 * identifier "]i" "[i" "]I" "[I" "]^I" "[^I" | |
6510 * define "]d" "[d" "]D" "[D" "]^D" "[^D" | |
6511 */ | |
6512 if (vim_strchr((char_u *) | |
6513 #ifdef EBCDIC | |
6514 "iI\005dD\067", | |
6515 #else | |
6516 "iI\011dD\004", | |
6517 #endif | |
6518 cap->nchar) != NULL) | |
6519 { | |
6520 char_u *ptr; | |
6521 int len; | |
6522 | |
6523 if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) | |
6524 clearop(cap->oap); | |
6525 else | |
6526 { | |
6527 find_pattern_in_path(ptr, 0, len, TRUE, | |
6528 cap->count0 == 0 ? !isupper(cap->nchar) : FALSE, | |
6529 ((cap->nchar & 0xf) == ('d' & 0xf)) ? FIND_DEFINE : FIND_ANY, | |
6530 cap->count1, | |
6531 isupper(cap->nchar) ? ACTION_SHOW_ALL : | |
6532 islower(cap->nchar) ? ACTION_SHOW : ACTION_GOTO, | |
6533 cap->cmdchar == ']' ? curwin->w_cursor.lnum + 1 : (linenr_T)1, | |
6534 (linenr_T)MAXLNUM); | |
6535 curwin->w_set_curswant = TRUE; | |
6536 } | |
6537 } | |
6538 else | |
6539 #endif | |
6540 | |
6541 /* | |
6542 * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')' | |
6543 * "[#", "]#": go to start/end of Nth innermost #if..#endif construct. | |
6544 * "[/", "[*", "]/", "]*": go to Nth comment start/end. | |
6545 * "[m" or "]m" search for prev/next start of (Java) method. | |
6546 * "[M" or "]M" search for prev/next end of (Java) method. | |
6547 */ | |
6548 if ( (cap->cmdchar == '[' | |
6549 && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL) | |
6550 || (cap->cmdchar == ']' | |
6551 && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) | |
6552 { | |
6553 if (cap->nchar == '*') | |
6554 cap->nchar = '/'; | |
6555 prev_pos.lnum = 0; | |
6556 if (cap->nchar == 'm' || cap->nchar == 'M') | |
6557 { | |
6558 if (cap->cmdchar == '[') | |
6559 findc = '{'; | |
6560 else | |
6561 findc = '}'; | |
6562 n = 9999; | |
6563 } | |
6564 else | |
6565 { | |
6566 findc = cap->nchar; | |
6567 n = cap->count1; | |
6568 } | |
6569 for ( ; n > 0; --n) | |
6570 { | |
6571 if ((pos = findmatchlimit(cap->oap, findc, | |
6572 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) | |
6573 { | |
6574 if (new_pos.lnum == 0) /* nothing found */ | |
6575 { | |
6576 if (cap->nchar != 'm' && cap->nchar != 'M') | |
6577 clearopbeep(cap->oap); | |
6578 } | |
6579 else | |
6580 pos = &new_pos; /* use last one found */ | |
6581 break; | |
6582 } | |
6583 prev_pos = new_pos; | |
6584 curwin->w_cursor = *pos; | |
6585 new_pos = *pos; | |
6586 } | |
6587 curwin->w_cursor = old_pos; | |
6588 | |
6589 /* | |
6590 * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only | |
6591 * brought us to the match for "[m" and "]M" when inside a method. | |
6592 * Try finding the '{' or '}' we want to be at. | |
6593 * Also repeat for the given count. | |
6594 */ | |
6595 if (cap->nchar == 'm' || cap->nchar == 'M') | |
6596 { | |
6597 /* norm is TRUE for "]M" and "[m" */ | |
6598 int norm = ((findc == '{') == (cap->nchar == 'm')); | |
6599 | |
6600 n = cap->count1; | |
6601 /* found a match: we were inside a method */ | |
6602 if (prev_pos.lnum != 0) | |
6603 { | |
6604 pos = &prev_pos; | |
6605 curwin->w_cursor = prev_pos; | |
6606 if (norm) | |
6607 --n; | |
6608 } | |
6609 else | |
6610 pos = NULL; | |
6611 while (n > 0) | |
6612 { | |
6613 for (;;) | |
6614 { | |
6615 if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0) | |
6616 { | |
6617 /* if not found anything, that's an error */ | |
6618 if (pos == NULL) | |
6619 clearopbeep(cap->oap); | |
6620 n = 0; | |
6621 break; | |
6622 } | |
6623 c = gchar_cursor(); | |
6624 if (c == '{' || c == '}') | |
6625 { | |
6626 /* Must have found end/start of class: use it. | |
6627 * Or found the place to be at. */ | |
6628 if ((c == findc && norm) || (n == 1 && !norm)) | |
6629 { | |
6630 new_pos = curwin->w_cursor; | |
6631 pos = &new_pos; | |
6632 n = 0; | |
6633 } | |
6634 /* if no match found at all, we started outside of the | |
6635 * class and we're inside now. Just go on. */ | |
6636 else if (new_pos.lnum == 0) | |
6637 { | |
6638 new_pos = curwin->w_cursor; | |
6639 pos = &new_pos; | |
6640 } | |
6641 /* found start/end of other method: go to match */ | |
6642 else if ((pos = findmatchlimit(cap->oap, findc, | |
6643 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, | |
6644 0)) == NULL) | |
6645 n = 0; | |
6646 else | |
6647 curwin->w_cursor = *pos; | |
6648 break; | |
6649 } | |
6650 } | |
6651 --n; | |
6652 } | |
6653 curwin->w_cursor = old_pos; | |
6654 if (pos == NULL && new_pos.lnum != 0) | |
6655 clearopbeep(cap->oap); | |
6656 } | |
6657 if (pos != NULL) | |
6658 { | |
6659 setpcmark(); | |
6660 curwin->w_cursor = *pos; | |
6661 curwin->w_set_curswant = TRUE; | |
6662 #ifdef FEAT_FOLDING | |
6663 if ((fdo_flags & FDO_BLOCK) && KeyTyped | |
6664 && cap->oap->op_type == OP_NOP) | |
6665 foldOpenCursor(); | |
6666 #endif | |
6667 } | |
6668 } | |
6669 | |
6670 /* | |
6671 * "[[", "[]", "]]" and "][": move to start or end of function | |
6672 */ | |
6673 else if (cap->nchar == '[' || cap->nchar == ']') | |
6674 { | |
6675 if (cap->nchar == cap->cmdchar) /* "]]" or "[[" */ | |
6676 flag = '{'; | |
6677 else | |
6678 flag = '}'; /* "][" or "[]" */ | |
6679 | |
6680 curwin->w_set_curswant = TRUE; | |
6681 /* | |
6682 * Imitate strange Vi behaviour: When using "]]" with an operator | |
6683 * we also stop at '}'. | |
6684 */ | |
503 | 6685 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, flag, |
7 | 6686 (cap->oap->op_type != OP_NOP |
6687 && cap->arg == FORWARD && flag == '{'))) | |
6688 clearopbeep(cap->oap); | |
6689 else | |
6690 { | |
6691 if (cap->oap->op_type == OP_NOP) | |
6692 beginline(BL_WHITE | BL_FIX); | |
6693 #ifdef FEAT_FOLDING | |
6694 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6695 foldOpenCursor(); | |
6696 #endif | |
6697 } | |
6698 } | |
6699 | |
6700 /* | |
6701 * "[p", "[P", "]P" and "]p": put with indent adjustment | |
6702 */ | |
6703 else if (cap->nchar == 'p' || cap->nchar == 'P') | |
6704 { | |
1312 | 6705 if (!checkclearop(cap->oap)) |
7 | 6706 { |
5708 | 6707 int dir = (cap->cmdchar == ']' && cap->nchar == 'p') |
6708 ? FORWARD : BACKWARD; | |
6709 int regname = cap->oap->regname; | |
6710 int was_visual = VIsual_active; | |
6711 int line_count = curbuf->b_ml.ml_line_count; | |
6712 pos_T start, end; | |
6713 | |
6714 if (VIsual_active) | |
6715 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6716 start = LTOREQ_POS(VIsual, curwin->w_cursor) |
5708 | 6717 ? VIsual : curwin->w_cursor; |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6718 end = EQUAL_POS(start,VIsual) ? curwin->w_cursor : VIsual; |
5708 | 6719 curwin->w_cursor = (dir == BACKWARD ? start : end); |
6720 } | |
6721 # ifdef FEAT_CLIPBOARD | |
6722 adjust_clip_reg(®name); | |
6723 # endif | |
7 | 6724 prep_redo_cmd(cap); |
5708 | 6725 |
6726 do_put(regname, dir, cap->count1, PUT_FIXINDENT); | |
6727 if (was_visual) | |
6728 { | |
6729 VIsual = start; | |
6730 curwin->w_cursor = end; | |
6731 if (dir == BACKWARD) | |
6732 { | |
6733 /* adjust lines */ | |
6734 VIsual.lnum += curbuf->b_ml.ml_line_count - line_count; | |
6735 curwin->w_cursor.lnum += | |
6736 curbuf->b_ml.ml_line_count - line_count; | |
6737 } | |
6738 | |
6739 VIsual_active = TRUE; | |
6740 if (VIsual_mode == 'V') | |
6741 { | |
6742 /* delete visually selected lines */ | |
6743 cap->cmdchar = 'd'; | |
6744 cap->nchar = NUL; | |
6745 cap->oap->regname = regname; | |
6746 nv_operator(cap); | |
6747 do_pending_operator(cap, 0, FALSE); | |
6748 } | |
6749 if (VIsual_active) | |
6750 { | |
6751 end_visual_mode(); | |
6752 redraw_later(SOME_VALID); | |
6753 } | |
6754 } | |
7 | 6755 } |
6756 } | |
6757 | |
6758 /* | |
6759 * "['", "[`", "]'" and "]`": jump to next mark | |
6760 */ | |
6761 else if (cap->nchar == '\'' || cap->nchar == '`') | |
6762 { | |
6763 pos = &curwin->w_cursor; | |
6764 for (n = cap->count1; n > 0; --n) | |
6765 { | |
6766 prev_pos = *pos; | |
6767 pos = getnextmark(pos, cap->cmdchar == '[' ? BACKWARD : FORWARD, | |
6768 cap->nchar == '\''); | |
6769 if (pos == NULL) | |
6770 break; | |
6771 } | |
6772 if (pos == NULL) | |
6773 pos = &prev_pos; | |
6774 nv_cursormark(cap, cap->nchar == '\'', pos); | |
6775 } | |
6776 | |
6777 #ifdef FEAT_MOUSE | |
6778 /* | |
6779 * [ or ] followed by a middle mouse click: put selected text with | |
6780 * indent adjustment. Any other button just does as usual. | |
6781 */ | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
6782 else if (cap->nchar >= K_RIGHTRELEASE && cap->nchar <= K_LEFTMOUSE) |
7 | 6783 { |
6784 (void)do_mouse(cap->oap, cap->nchar, | |
6785 (cap->cmdchar == ']') ? FORWARD : BACKWARD, | |
6786 cap->count1, PUT_FIXINDENT); | |
6787 } | |
6788 #endif /* FEAT_MOUSE */ | |
6789 | |
6790 #ifdef FEAT_FOLDING | |
6791 /* | |
6792 * "[z" and "]z": move to start or end of open fold. | |
6793 */ | |
6794 else if (cap->nchar == 'z') | |
6795 { | |
6796 if (foldMoveTo(FALSE, cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
6797 cap->count1) == FAIL) | |
6798 clearopbeep(cap->oap); | |
6799 } | |
6800 #endif | |
6801 | |
6802 #ifdef FEAT_DIFF | |
6803 /* | |
6804 * "[c" and "]c": move to next or previous diff-change. | |
6805 */ | |
6806 else if (cap->nchar == 'c') | |
6807 { | |
6808 if (diff_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
6809 cap->count1) == FAIL) | |
6810 clearopbeep(cap->oap); | |
6811 } | |
6812 #endif | |
6813 | |
737 | 6814 #ifdef FEAT_SPELL |
236 | 6815 /* |
6816 * "[s", "[S", "]s" and "]S": move to next spell error. | |
6817 */ | |
6818 else if (cap->nchar == 's' || cap->nchar == 'S') | |
6819 { | |
249 | 6820 setpcmark(); |
6821 for (n = 0; n < cap->count1; ++n) | |
498 | 6822 if (spell_move_to(curwin, cap->cmdchar == ']' ? FORWARD : BACKWARD, |
6823 cap->nchar == 's' ? TRUE : FALSE, FALSE, NULL) == 0) | |
249 | 6824 { |
6825 clearopbeep(cap->oap); | |
6826 break; | |
6827 } | |
13088
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
6828 else |
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
6829 curwin->w_set_curswant = TRUE; |
819 | 6830 # ifdef FEAT_FOLDING |
6831 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
6832 foldOpenCursor(); | |
6833 # endif | |
236 | 6834 } |
6835 #endif | |
6836 | |
7 | 6837 /* Not a valid cap->nchar. */ |
6838 else | |
6839 clearopbeep(cap->oap); | |
6840 } | |
6841 | |
6842 /* | |
6843 * Handle Normal mode "%" command. | |
6844 */ | |
6845 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6846 nv_percent(cmdarg_T *cap) |
7 | 6847 { |
6848 pos_T *pos; | |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2281
diff
changeset
|
6849 #if defined(FEAT_FOLDING) |
7 | 6850 linenr_T lnum = curwin->w_cursor.lnum; |
6851 #endif | |
6852 | |
6853 cap->oap->inclusive = TRUE; | |
6854 if (cap->count0) /* {cnt}% : goto {cnt} percentage in file */ | |
6855 { | |
6856 if (cap->count0 > 100) | |
6857 clearopbeep(cap->oap); | |
6858 else | |
6859 { | |
6860 cap->oap->motion_type = MLINE; | |
6861 setpcmark(); | |
6862 /* Round up, so CTRL-G will give same value. Watch out for a | |
6863 * large line count, the line number must not go negative! */ | |
6864 if (curbuf->b_ml.ml_line_count > 1000000) | |
6865 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) | |
6866 / 100L * cap->count0; | |
6867 else | |
6868 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count * | |
6869 cap->count0 + 99L) / 100L; | |
6870 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
6871 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
6872 beginline(BL_SOL | BL_FIX); | |
6873 } | |
6874 } | |
6875 else /* "%" : go to matching paren */ | |
6876 { | |
6877 cap->oap->motion_type = MCHAR; | |
6878 cap->oap->use_reg_one = TRUE; | |
6879 if ((pos = findmatch(cap->oap, NUL)) == NULL) | |
6880 clearopbeep(cap->oap); | |
6881 else | |
6882 { | |
6883 setpcmark(); | |
6884 curwin->w_cursor = *pos; | |
6885 curwin->w_set_curswant = TRUE; | |
6886 #ifdef FEAT_VIRTUALEDIT | |
6887 curwin->w_cursor.coladd = 0; | |
6888 #endif | |
6889 adjust_for_sel(cap); | |
6890 } | |
6891 } | |
6892 #ifdef FEAT_FOLDING | |
6893 if (cap->oap->op_type == OP_NOP | |
6894 && lnum != curwin->w_cursor.lnum | |
6895 && (fdo_flags & FDO_PERCENT) | |
6896 && KeyTyped) | |
6897 foldOpenCursor(); | |
6898 #endif | |
6899 } | |
6900 | |
6901 /* | |
6902 * Handle "(" and ")" commands. | |
6903 * cap->arg is BACKWARD for "(" and FORWARD for ")". | |
6904 */ | |
6905 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6906 nv_brace(cmdarg_T *cap) |
7 | 6907 { |
6908 cap->oap->motion_type = MCHAR; | |
6909 cap->oap->use_reg_one = TRUE; | |
620 | 6910 /* The motion used to be inclusive for "(", but that is not what Vi does. */ |
6911 cap->oap->inclusive = FALSE; | |
7 | 6912 curwin->w_set_curswant = TRUE; |
6913 | |
6914 if (findsent(cap->arg, cap->count1) == FAIL) | |
6915 clearopbeep(cap->oap); | |
6916 else | |
6917 { | |
1505 | 6918 /* Don't leave the cursor on the NUL past end of line. */ |
6919 adjust_cursor(cap->oap); | |
7 | 6920 #ifdef FEAT_VIRTUALEDIT |
6921 curwin->w_cursor.coladd = 0; | |
6922 #endif | |
6923 #ifdef FEAT_FOLDING | |
6924 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6925 foldOpenCursor(); | |
6926 #endif | |
6927 } | |
6928 } | |
6929 | |
6930 /* | |
6931 * "m" command: Mark a position. | |
6932 */ | |
6933 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6934 nv_mark(cmdarg_T *cap) |
7 | 6935 { |
6936 if (!checkclearop(cap->oap)) | |
6937 { | |
6938 if (setmark(cap->nchar) == FAIL) | |
6939 clearopbeep(cap->oap); | |
6940 } | |
6941 } | |
6942 | |
6943 /* | |
6944 * "{" and "}" commands. | |
6945 * cmd->arg is BACKWARD for "{" and FORWARD for "}". | |
6946 */ | |
6947 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6948 nv_findpar(cmdarg_T *cap) |
7 | 6949 { |
6950 cap->oap->motion_type = MCHAR; | |
6951 cap->oap->inclusive = FALSE; | |
6952 cap->oap->use_reg_one = TRUE; | |
6953 curwin->w_set_curswant = TRUE; | |
503 | 6954 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, FALSE)) |
7 | 6955 clearopbeep(cap->oap); |
6956 else | |
6957 { | |
6958 #ifdef FEAT_VIRTUALEDIT | |
6959 curwin->w_cursor.coladd = 0; | |
6960 #endif | |
6961 #ifdef FEAT_FOLDING | |
6962 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6963 foldOpenCursor(); | |
6964 #endif | |
6965 } | |
6966 } | |
6967 | |
6968 /* | |
6969 * "u" command: Undo or make lower case. | |
6970 */ | |
6971 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6972 nv_undo(cmdarg_T *cap) |
7 | 6973 { |
5735 | 6974 if (cap->oap->op_type == OP_LOWER || VIsual_active) |
7 | 6975 { |
6976 /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */ | |
6977 cap->cmdchar = 'g'; | |
6978 cap->nchar = 'u'; | |
6979 nv_operator(cap); | |
6980 } | |
6981 else | |
6982 nv_kundo(cap); | |
6983 } | |
6984 | |
6985 /* | |
6986 * <Undo> command. | |
6987 */ | |
6988 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6989 nv_kundo(cmdarg_T *cap) |
7 | 6990 { |
6991 if (!checkclearopq(cap->oap)) | |
6992 { | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6993 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6994 if (bt_prompt(curbuf)) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6995 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6996 clearopbeep(cap->oap); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6997 return; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6998 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
6999 #endif |
7 | 7000 u_undo((int)cap->count1); |
7001 curwin->w_set_curswant = TRUE; | |
7002 } | |
7003 } | |
7004 | |
7005 /* | |
7006 * Handle the "r" command. | |
7007 */ | |
7008 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7009 nv_replace(cmdarg_T *cap) |
7 | 7010 { |
7011 char_u *ptr; | |
7012 int had_ctrl_v; | |
7013 long n; | |
7014 | |
7015 if (checkclearop(cap->oap)) | |
7016 return; | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7017 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7018 if (bt_prompt(curbuf) && !prompt_curpos_editable()) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7019 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7020 clearopbeep(cap->oap); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7021 return; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7022 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7023 #endif |
7 | 7024 |
7025 /* get another character */ | |
7026 if (cap->nchar == Ctrl_V) | |
7027 { | |
7028 had_ctrl_v = Ctrl_V; | |
7029 cap->nchar = get_literal(); | |
7030 /* Don't redo a multibyte character with CTRL-V. */ | |
7031 if (cap->nchar > DEL) | |
7032 had_ctrl_v = NUL; | |
7033 } | |
7034 else | |
7035 had_ctrl_v = NUL; | |
7036 | |
1343 | 7037 /* Abort if the character is a special key. */ |
7038 if (IS_SPECIAL(cap->nchar)) | |
7039 { | |
7040 clearopbeep(cap->oap); | |
7041 return; | |
7042 } | |
7043 | |
7 | 7044 /* Visual mode "r" */ |
7045 if (VIsual_active) | |
7046 { | |
1797 | 7047 if (got_int) |
7048 reset_VIsual(); | |
5428 | 7049 if (had_ctrl_v) |
7050 { | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
7051 /* Use a special (negative) number to make a difference between a |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
7052 * literal CR or NL and a line break. */ |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
7053 if (cap->nchar == CAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
7054 cap->nchar = REPLACE_CR_NCHAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
7055 else if (cap->nchar == NL) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
7056 cap->nchar = REPLACE_NL_NCHAR; |
5428 | 7057 } |
7 | 7058 nv_operator(cap); |
7059 return; | |
7060 } | |
7061 | |
7062 #ifdef FEAT_VIRTUALEDIT | |
7063 /* Break tabs, etc. */ | |
7064 if (virtual_active()) | |
7065 { | |
7066 if (u_save_cursor() == FAIL) | |
7067 return; | |
7068 if (gchar_cursor() == NUL) | |
7069 { | |
7070 /* Add extra space and put the cursor on the first one. */ | |
7071 coladvance_force((colnr_T)(getviscol() + cap->count1)); | |
7072 curwin->w_cursor.col -= cap->count1; | |
7073 } | |
7074 else if (gchar_cursor() == TAB) | |
7075 coladvance_force(getviscol()); | |
7076 } | |
7077 #endif | |
7078 | |
1343 | 7079 /* Abort if not enough characters to replace. */ |
7 | 7080 ptr = ml_get_cursor(); |
1343 | 7081 if (STRLEN(ptr) < (unsigned)cap->count1 |
7 | 7082 #ifdef FEAT_MBYTE |
7083 || (has_mbyte && mb_charlen(ptr) < cap->count1) | |
7084 #endif | |
7085 ) | |
7086 { | |
7087 clearopbeep(cap->oap); | |
7088 return; | |
7089 } | |
7090 | |
7091 /* | |
7092 * Replacing with a TAB is done by edit() when it is complicated because | |
7093 * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB. | |
7094 * Other characters are done below to avoid problems with things like | |
7095 * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC). | |
7096 */ | |
7097 if (had_ctrl_v != Ctrl_V && cap->nchar == '\t' && (curbuf->b_p_et || p_sta)) | |
7098 { | |
7099 stuffnumReadbuff(cap->count1); | |
7100 stuffcharReadbuff('R'); | |
7101 stuffcharReadbuff('\t'); | |
7102 stuffcharReadbuff(ESC); | |
7103 return; | |
7104 } | |
7105 | |
7106 /* save line for undo */ | |
7107 if (u_save_cursor() == FAIL) | |
7108 return; | |
7109 | |
7110 if (had_ctrl_v != Ctrl_V && (cap->nchar == '\r' || cap->nchar == '\n')) | |
7111 { | |
7112 /* | |
7113 * Replace character(s) by a single newline. | |
7114 * Strange vi behaviour: Only one newline is inserted. | |
7115 * Delete the characters here. | |
7116 * Insert the newline with an insert command, takes care of | |
7117 * autoindent. The insert command depends on being on the last | |
7118 * character of a line or not. | |
7119 */ | |
7120 #ifdef FEAT_MBYTE | |
7121 (void)del_chars(cap->count1, FALSE); /* delete the characters */ | |
7122 #else | |
608 | 7123 (void)del_bytes(cap->count1, FALSE, FALSE); /* delete the characters */ |
7 | 7124 #endif |
7125 stuffcharReadbuff('\r'); | |
7126 stuffcharReadbuff(ESC); | |
7127 | |
7128 /* Give 'r' to edit(), to get the redo command right. */ | |
7129 invoke_edit(cap, TRUE, 'r', FALSE); | |
7130 } | |
7131 else | |
7132 { | |
7133 prep_redo(cap->oap->regname, cap->count1, | |
7134 NUL, 'r', NUL, had_ctrl_v, cap->nchar); | |
7135 | |
7136 curbuf->b_op_start = curwin->w_cursor; | |
7137 #ifdef FEAT_MBYTE | |
7138 if (has_mbyte) | |
7139 { | |
7140 int old_State = State; | |
7141 | |
7142 if (cap->ncharC1 != 0) | |
7143 AppendCharToRedobuff(cap->ncharC1); | |
7144 if (cap->ncharC2 != 0) | |
7145 AppendCharToRedobuff(cap->ncharC2); | |
7146 | |
7147 /* This is slow, but it handles replacing a single-byte with a | |
7148 * multi-byte and the other way around. Also handles adding | |
7149 * composing characters for utf-8. */ | |
7150 for (n = cap->count1; n > 0; --n) | |
7151 { | |
7152 State = REPLACE; | |
3501 | 7153 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7154 { | |
7155 int c = ins_copychar(curwin->w_cursor.lnum | |
7156 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7157 if (c != NUL) | |
7158 ins_char(c); | |
7159 else | |
7160 /* will be decremented further down */ | |
7161 ++curwin->w_cursor.col; | |
7162 } | |
7163 else | |
7164 ins_char(cap->nchar); | |
7 | 7165 State = old_State; |
7166 if (cap->ncharC1 != 0) | |
7167 ins_char(cap->ncharC1); | |
7168 if (cap->ncharC2 != 0) | |
7169 ins_char(cap->ncharC2); | |
7170 } | |
7171 } | |
7172 else | |
7173 #endif | |
7174 { | |
7175 /* | |
7176 * Replace the characters within one line. | |
7177 */ | |
7178 for (n = cap->count1; n > 0; --n) | |
7179 { | |
7180 /* | |
7181 * Get ptr again, because u_save and/or showmatch() will have | |
7182 * released the line. At the same time we let know that the | |
7183 * line will be changed. | |
7184 */ | |
7185 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); | |
3501 | 7186 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7187 { | |
7188 int c = ins_copychar(curwin->w_cursor.lnum | |
7189 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7190 if (c != NUL) | |
7191 ptr[curwin->w_cursor.col] = c; | |
7192 } | |
7193 else | |
7194 ptr[curwin->w_cursor.col] = cap->nchar; | |
7 | 7195 if (p_sm && msg_silent == 0) |
7196 showmatch(cap->nchar); | |
7197 ++curwin->w_cursor.col; | |
7198 } | |
7199 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7200 if (netbeans_active()) |
7 | 7201 { |
2210 | 7202 colnr_T start = (colnr_T)(curwin->w_cursor.col - cap->count1); |
7 | 7203 |
33 | 7204 netbeans_removed(curbuf, curwin->w_cursor.lnum, start, |
2210 | 7205 (long)cap->count1); |
7 | 7206 netbeans_inserted(curbuf, curwin->w_cursor.lnum, start, |
33 | 7207 &ptr[start], (int)cap->count1); |
7 | 7208 } |
7209 #endif | |
7210 | |
7211 /* mark the buffer as changed and prepare for displaying */ | |
7212 changed_bytes(curwin->w_cursor.lnum, | |
7213 (colnr_T)(curwin->w_cursor.col - cap->count1)); | |
7214 } | |
7215 --curwin->w_cursor.col; /* cursor on the last replaced char */ | |
7216 #ifdef FEAT_MBYTE | |
7217 /* if the character on the left of the current cursor is a multi-byte | |
7218 * character, move two characters left */ | |
7219 if (has_mbyte) | |
7220 mb_adjust_cursor(); | |
7221 #endif | |
7222 curbuf->b_op_end = curwin->w_cursor; | |
7223 curwin->w_set_curswant = TRUE; | |
7224 set_last_insert(cap->nchar); | |
7225 } | |
7226 } | |
7227 | |
7228 /* | |
7229 * 'o': Exchange start and end of Visual area. | |
7230 * 'O': same, but in block mode exchange left and right corners. | |
7231 */ | |
7232 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7233 v_swap_corners(int cmdchar) |
7 | 7234 { |
7235 pos_T old_cursor; | |
7236 colnr_T left, right; | |
7237 | |
7238 if (cmdchar == 'O' && VIsual_mode == Ctrl_V) | |
7239 { | |
7240 old_cursor = curwin->w_cursor; | |
7241 getvcols(curwin, &old_cursor, &VIsual, &left, &right); | |
7242 curwin->w_cursor.lnum = VIsual.lnum; | |
7243 coladvance(left); | |
7244 VIsual = curwin->w_cursor; | |
7245 | |
7246 curwin->w_cursor.lnum = old_cursor.lnum; | |
7247 curwin->w_curswant = right; | |
7248 /* 'selection "exclusive" and cursor at right-bottom corner: move it | |
7249 * right one column */ | |
7250 if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') | |
7251 ++curwin->w_curswant; | |
7252 coladvance(curwin->w_curswant); | |
7253 if (curwin->w_cursor.col == old_cursor.col | |
7254 #ifdef FEAT_VIRTUALEDIT | |
7255 && (!virtual_active() | |
7256 || curwin->w_cursor.coladd == old_cursor.coladd) | |
7257 #endif | |
7258 ) | |
7259 { | |
7260 curwin->w_cursor.lnum = VIsual.lnum; | |
7261 if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') | |
7262 ++right; | |
7263 coladvance(right); | |
7264 VIsual = curwin->w_cursor; | |
7265 | |
7266 curwin->w_cursor.lnum = old_cursor.lnum; | |
7267 coladvance(left); | |
7268 curwin->w_curswant = left; | |
7269 } | |
7270 } | |
7271 else | |
7272 { | |
7273 old_cursor = curwin->w_cursor; | |
7274 curwin->w_cursor = VIsual; | |
7275 VIsual = old_cursor; | |
7276 curwin->w_set_curswant = TRUE; | |
7277 } | |
7278 } | |
7279 | |
7280 /* | |
7281 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE). | |
7282 */ | |
7283 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7284 nv_Replace(cmdarg_T *cap) |
7 | 7285 { |
7286 if (VIsual_active) /* "R" is replace lines */ | |
7287 { | |
7288 cap->cmdchar = 'c'; | |
7289 cap->nchar = NUL; | |
4213 | 7290 VIsual_mode_orig = VIsual_mode; /* remember original area for gv */ |
7 | 7291 VIsual_mode = 'V'; |
7292 nv_operator(cap); | |
7293 } | |
5735 | 7294 else if (!checkclearopq(cap->oap)) |
7 | 7295 { |
7296 if (!curbuf->b_p_ma) | |
7297 EMSG(_(e_modifiable)); | |
7298 else | |
7299 { | |
7300 #ifdef FEAT_VIRTUALEDIT | |
7301 if (virtual_active()) | |
7302 coladvance(getviscol()); | |
7303 #endif | |
7304 invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE); | |
7305 } | |
7306 } | |
7307 } | |
7308 | |
7309 #ifdef FEAT_VREPLACE | |
7310 /* | |
7311 * "gr". | |
7312 */ | |
7313 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7314 nv_vreplace(cmdarg_T *cap) |
7 | 7315 { |
7316 if (VIsual_active) | |
7317 { | |
7318 cap->cmdchar = 'r'; | |
7319 cap->nchar = cap->extra_char; | |
7320 nv_replace(cap); /* Do same as "r" in Visual mode for now */ | |
7321 } | |
5735 | 7322 else if (!checkclearopq(cap->oap)) |
7 | 7323 { |
7324 if (!curbuf->b_p_ma) | |
7325 EMSG(_(e_modifiable)); | |
7326 else | |
7327 { | |
7328 if (cap->extra_char == Ctrl_V) /* get another character */ | |
7329 cap->extra_char = get_literal(); | |
7330 stuffcharReadbuff(cap->extra_char); | |
7331 stuffcharReadbuff(ESC); | |
7332 # ifdef FEAT_VIRTUALEDIT | |
7333 if (virtual_active()) | |
7334 coladvance(getviscol()); | |
7335 # endif | |
7336 invoke_edit(cap, TRUE, 'v', FALSE); | |
7337 } | |
7338 } | |
7339 } | |
7340 #endif | |
7341 | |
7342 /* | |
7343 * Swap case for "~" command, when it does not work like an operator. | |
7344 */ | |
7345 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7346 n_swapchar(cmdarg_T *cap) |
7 | 7347 { |
7348 long n; | |
7349 pos_T startpos; | |
7350 int did_change = 0; | |
7351 #ifdef FEAT_NETBEANS_INTG | |
7352 pos_T pos; | |
7353 char_u *ptr; | |
7354 int count; | |
7355 #endif | |
7356 | |
7357 if (checkclearopq(cap->oap)) | |
7358 return; | |
7359 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7360 if (LINEEMPTY(curwin->w_cursor.lnum) && vim_strchr(p_ww, '~') == NULL) |
7 | 7361 { |
7362 clearopbeep(cap->oap); | |
7363 return; | |
7364 } | |
7365 | |
7366 prep_redo_cmd(cap); | |
7367 | |
7368 if (u_save_cursor() == FAIL) | |
7369 return; | |
7370 | |
7371 startpos = curwin->w_cursor; | |
7372 #ifdef FEAT_NETBEANS_INTG | |
7373 pos = startpos; | |
7374 #endif | |
7375 for (n = cap->count1; n > 0; --n) | |
7376 { | |
7377 did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor); | |
7378 inc_cursor(); | |
7379 if (gchar_cursor() == NUL) | |
7380 { | |
7381 if (vim_strchr(p_ww, '~') != NULL | |
7382 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
7383 { | |
7384 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7385 if (netbeans_active()) |
7 | 7386 { |
7387 if (did_change) | |
7388 { | |
7389 ptr = ml_get(pos.lnum); | |
835 | 7390 count = (int)STRLEN(ptr) - pos.col; |
33 | 7391 netbeans_removed(curbuf, pos.lnum, pos.col, |
7392 (long)count); | |
7 | 7393 netbeans_inserted(curbuf, pos.lnum, pos.col, |
33 | 7394 &ptr[pos.col], count); |
7 | 7395 } |
7396 pos.col = 0; | |
7397 pos.lnum++; | |
7398 } | |
7399 #endif | |
7400 ++curwin->w_cursor.lnum; | |
7401 curwin->w_cursor.col = 0; | |
7402 if (n > 1) | |
7403 { | |
7404 if (u_savesub(curwin->w_cursor.lnum) == FAIL) | |
7405 break; | |
7406 u_clearline(); | |
7407 } | |
7408 } | |
7409 else | |
7410 break; | |
7411 } | |
7412 } | |
7413 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7414 if (did_change && netbeans_active()) |
7 | 7415 { |
7416 ptr = ml_get(pos.lnum); | |
7417 count = curwin->w_cursor.col - pos.col; | |
33 | 7418 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7419 netbeans_inserted(curbuf, pos.lnum, pos.col, &ptr[pos.col], count); | |
7 | 7420 } |
7421 #endif | |
7422 | |
7423 | |
7424 check_cursor(); | |
7425 curwin->w_set_curswant = TRUE; | |
7426 if (did_change) | |
7427 { | |
7428 changed_lines(startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1, | |
7429 0L); | |
7430 curbuf->b_op_start = startpos; | |
7431 curbuf->b_op_end = curwin->w_cursor; | |
7432 if (curbuf->b_op_end.col > 0) | |
7433 --curbuf->b_op_end.col; | |
7434 } | |
7435 } | |
7436 | |
7437 /* | |
7438 * Move cursor to mark. | |
7439 */ | |
7440 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7441 nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos) |
7 | 7442 { |
7443 if (check_mark(pos) == FAIL) | |
7444 clearop(cap->oap); | |
7445 else | |
7446 { | |
7447 if (cap->cmdchar == '\'' | |
7448 || cap->cmdchar == '`' | |
7449 || cap->cmdchar == '[' | |
7450 || cap->cmdchar == ']') | |
7451 setpcmark(); | |
7452 curwin->w_cursor = *pos; | |
7453 if (flag) | |
7454 beginline(BL_WHITE | BL_FIX); | |
7455 else | |
7456 check_cursor(); | |
7457 } | |
7458 cap->oap->motion_type = flag ? MLINE : MCHAR; | |
7459 if (cap->cmdchar == '`') | |
7460 cap->oap->use_reg_one = TRUE; | |
7461 cap->oap->inclusive = FALSE; /* ignored if not MCHAR */ | |
7462 curwin->w_set_curswant = TRUE; | |
7463 } | |
7464 | |
7465 /* | |
7466 * Handle commands that are operators in Visual mode. | |
7467 */ | |
7468 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7469 v_visop(cmdarg_T *cap) |
7 | 7470 { |
7471 static char_u trans[] = "YyDdCcxdXdAAIIrr"; | |
7472 | |
7473 /* Uppercase means linewise, except in block mode, then "D" deletes till | |
4352 | 7474 * the end of the line, and "C" replaces till EOL */ |
7 | 7475 if (isupper(cap->cmdchar)) |
7476 { | |
7477 if (VIsual_mode != Ctrl_V) | |
4213 | 7478 { |
7479 VIsual_mode_orig = VIsual_mode; | |
7 | 7480 VIsual_mode = 'V'; |
4213 | 7481 } |
7 | 7482 else if (cap->cmdchar == 'C' || cap->cmdchar == 'D') |
7483 curwin->w_curswant = MAXCOL; | |
7484 } | |
7485 cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1); | |
7486 nv_operator(cap); | |
7487 } | |
7488 | |
7489 /* | |
7490 * "s" and "S" commands. | |
7491 */ | |
7492 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7493 nv_subst(cmdarg_T *cap) |
7 | 7494 { |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7495 #ifdef FEAT_TERMINAL |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7496 /* When showing output of term_dumpdiff() swap the top and botom. */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7497 if (term_swap_diff() == OK) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7498 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7499 #endif |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7500 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7501 if (bt_prompt(curbuf) && !prompt_curpos_editable()) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7502 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7503 clearopbeep(cap->oap); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7504 return; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7505 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
7506 #endif |
7 | 7507 if (VIsual_active) /* "vs" and "vS" are the same as "vc" */ |
7508 { | |
7509 if (cap->cmdchar == 'S') | |
4213 | 7510 { |
7511 VIsual_mode_orig = VIsual_mode; | |
7 | 7512 VIsual_mode = 'V'; |
4213 | 7513 } |
7 | 7514 cap->cmdchar = 'c'; |
7515 nv_operator(cap); | |
7516 } | |
7517 else | |
7518 nv_optrans(cap); | |
7519 } | |
7520 | |
7521 /* | |
7522 * Abbreviated commands. | |
7523 */ | |
7524 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7525 nv_abbrev(cmdarg_T *cap) |
7 | 7526 { |
7527 if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) | |
7528 cap->cmdchar = 'x'; /* DEL key behaves like 'x' */ | |
7529 | |
7530 /* in Visual mode these commands are operators */ | |
7531 if (VIsual_active) | |
7532 v_visop(cap); | |
7533 else | |
7534 nv_optrans(cap); | |
7535 } | |
7536 | |
7537 /* | |
7538 * Translate a command into another command. | |
7539 */ | |
7540 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7541 nv_optrans(cmdarg_T *cap) |
7 | 7542 { |
7543 static char_u *(ar[8]) = {(char_u *)"dl", (char_u *)"dh", | |
7544 (char_u *)"d$", (char_u *)"c$", | |
7545 (char_u *)"cl", (char_u *)"cc", | |
7546 (char_u *)"yy", (char_u *)":s\r"}; | |
7547 static char_u *str = (char_u *)"xXDCsSY&"; | |
7548 | |
7549 if (!checkclearopq(cap->oap)) | |
7550 { | |
164 | 7551 /* In Vi "2D" doesn't delete the next line. Can't translate it |
7552 * either, because "2." should also not use the count. */ | |
7553 if (cap->cmdchar == 'D' && vim_strchr(p_cpo, CPO_HASH) != NULL) | |
7554 { | |
7555 cap->oap->start = curwin->w_cursor; | |
7556 cap->oap->op_type = OP_DELETE; | |
1490 | 7557 #ifdef FEAT_EVAL |
7558 set_op_var(OP_DELETE); | |
7559 #endif | |
164 | 7560 cap->count1 = 1; |
7561 nv_dollar(cap); | |
7562 finish_op = TRUE; | |
7563 ResetRedobuff(); | |
7564 AppendCharToRedobuff('D'); | |
7565 } | |
7566 else | |
7567 { | |
7568 if (cap->count0) | |
7569 stuffnumReadbuff(cap->count0); | |
7570 stuffReadbuff(ar[(int)(vim_strchr(str, cap->cmdchar) - str)]); | |
7571 } | |
7 | 7572 } |
7573 cap->opcount = 0; | |
7574 } | |
7575 | |
7576 /* | |
7577 * "'" and "`" commands. Also for "g'" and "g`". | |
7578 * cap->arg is TRUE for "'" and "g'". | |
7579 */ | |
7580 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7581 nv_gomark(cmdarg_T *cap) |
7 | 7582 { |
7583 pos_T *pos; | |
7584 int c; | |
7585 #ifdef FEAT_FOLDING | |
4017 | 7586 pos_T old_cursor = curwin->w_cursor; |
7 | 7587 int old_KeyTyped = KeyTyped; /* getting file may reset it */ |
7588 #endif | |
7589 | |
7590 if (cap->cmdchar == 'g') | |
7591 c = cap->extra_char; | |
7592 else | |
7593 c = cap->nchar; | |
7594 pos = getmark(c, (cap->oap->op_type == OP_NOP)); | |
7595 if (pos == (pos_T *)-1) /* jumped to other file */ | |
7596 { | |
7597 if (cap->arg) | |
7598 { | |
7599 check_cursor_lnum(); | |
7600 beginline(BL_WHITE | BL_FIX); | |
7601 } | |
7602 else | |
7603 check_cursor(); | |
7604 } | |
7605 else | |
7606 nv_cursormark(cap, cap->arg, pos); | |
7607 | |
7608 #ifdef FEAT_VIRTUALEDIT | |
7609 /* May need to clear the coladd that a mark includes. */ | |
7610 if (!virtual_active()) | |
7611 curwin->w_cursor.coladd = 0; | |
7612 #endif | |
12164
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
7613 check_cursor_col(); |
7 | 7614 #ifdef FEAT_FOLDING |
7615 if (cap->oap->op_type == OP_NOP | |
4057 | 7616 && pos != NULL |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7617 && (pos == (pos_T *)-1 || !EQUAL_POS(old_cursor, *pos)) |
7 | 7618 && (fdo_flags & FDO_MARK) |
7619 && old_KeyTyped) | |
7620 foldOpenCursor(); | |
7621 #endif | |
7622 } | |
7623 | |
7624 /* | |
7625 * Handle CTRL-O, CTRL-I, "g;" and "g," commands. | |
7626 */ | |
7627 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7628 nv_pcmark(cmdarg_T *cap) |
7 | 7629 { |
7630 #ifdef FEAT_JUMPLIST | |
7631 pos_T *pos; | |
7632 # ifdef FEAT_FOLDING | |
7633 linenr_T lnum = curwin->w_cursor.lnum; | |
7634 int old_KeyTyped = KeyTyped; /* getting file may reset it */ | |
7635 # endif | |
7636 | |
7637 if (!checkclearopq(cap->oap)) | |
7638 { | |
7639 if (cap->cmdchar == 'g') | |
7640 pos = movechangelist((int)cap->count1); | |
7641 else | |
7642 pos = movemark((int)cap->count1); | |
7643 if (pos == (pos_T *)-1) /* jump to other file */ | |
7644 { | |
7645 curwin->w_set_curswant = TRUE; | |
7646 check_cursor(); | |
7647 } | |
7648 else if (pos != NULL) /* can jump */ | |
7649 nv_cursormark(cap, FALSE, pos); | |
7650 else if (cap->cmdchar == 'g') | |
7651 { | |
7652 if (curbuf->b_changelistlen == 0) | |
7653 EMSG(_("E664: changelist is empty")); | |
7654 else if (cap->count1 < 0) | |
7655 EMSG(_("E662: At start of changelist")); | |
7656 else | |
7657 EMSG(_("E663: At end of changelist")); | |
7658 } | |
7659 else | |
7660 clearopbeep(cap->oap); | |
7661 # ifdef FEAT_FOLDING | |
7662 if (cap->oap->op_type == OP_NOP | |
7663 && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum) | |
7664 && (fdo_flags & FDO_MARK) | |
7665 && old_KeyTyped) | |
7666 foldOpenCursor(); | |
7667 # endif | |
7668 } | |
7669 #else | |
7670 clearopbeep(cap->oap); | |
7671 #endif | |
7672 } | |
7673 | |
7674 /* | |
7675 * Handle '"' command. | |
7676 */ | |
7677 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7678 nv_regname(cmdarg_T *cap) |
7 | 7679 { |
7680 if (checkclearop(cap->oap)) | |
7681 return; | |
7682 #ifdef FEAT_EVAL | |
7683 if (cap->nchar == '=') | |
7684 cap->nchar = get_expr_register(); | |
7685 #endif | |
7686 if (cap->nchar != NUL && valid_yank_reg(cap->nchar, FALSE)) | |
7687 { | |
7688 cap->oap->regname = cap->nchar; | |
7689 cap->opcount = cap->count0; /* remember count before '"' */ | |
7690 #ifdef FEAT_EVAL | |
7691 set_reg_var(cap->oap->regname); | |
7692 #endif | |
7693 } | |
7694 else | |
7695 clearopbeep(cap->oap); | |
7696 } | |
7697 | |
7698 /* | |
7699 * Handle "v", "V" and "CTRL-V" commands. | |
7700 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg | |
7701 * is TRUE. | |
167 | 7702 * Handle CTRL-Q just like CTRL-V. |
7 | 7703 */ |
7704 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7705 nv_visual(cmdarg_T *cap) |
7 | 7706 { |
167 | 7707 if (cap->cmdchar == Ctrl_Q) |
7708 cap->cmdchar = Ctrl_V; | |
7709 | |
7 | 7710 /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it |
7711 * characterwise, linewise, or blockwise. */ | |
7712 if (cap->oap->op_type != OP_NOP) | |
7713 { | |
7714 cap->oap->motion_force = cap->cmdchar; | |
7715 finish_op = FALSE; /* operator doesn't finish now but later */ | |
7716 return; | |
7717 } | |
7718 | |
7719 VIsual_select = cap->arg; | |
7720 if (VIsual_active) /* change Visual mode */ | |
7721 { | |
7722 if (VIsual_mode == cap->cmdchar) /* stop visual mode */ | |
7723 end_visual_mode(); | |
7724 else /* toggle char/block mode */ | |
7725 { /* or char/line mode */ | |
7726 VIsual_mode = cap->cmdchar; | |
7727 showmode(); | |
7728 } | |
7729 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
7730 } | |
7731 else /* start Visual mode */ | |
7732 { | |
7733 check_visual_highlight(); | |
3537 | 7734 if (cap->count0 > 0 && resel_VIsual_mode != NUL) |
7735 { | |
7736 /* use previously selected part */ | |
7 | 7737 VIsual = curwin->w_cursor; |
7738 | |
7739 VIsual_active = TRUE; | |
7740 VIsual_reselect = TRUE; | |
7741 if (!cap->arg) | |
7742 /* start Select mode when 'selectmode' contains "cmd" */ | |
7743 may_start_select('c'); | |
7744 #ifdef FEAT_MOUSE | |
7745 setmouse(); | |
7746 #endif | |
641 | 7747 if (p_smd && msg_silent == 0) |
7 | 7748 redraw_cmdline = TRUE; /* show visual mode later */ |
7749 /* | |
7750 * For V and ^V, we multiply the number of lines even if there | |
7751 * was only one -- webb | |
7752 */ | |
7753 if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) | |
7754 { | |
7755 curwin->w_cursor.lnum += | |
7756 resel_VIsual_line_count * cap->count0 - 1; | |
7757 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
7758 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7759 } | |
7760 VIsual_mode = resel_VIsual_mode; | |
7761 if (VIsual_mode == 'v') | |
7762 { | |
7763 if (resel_VIsual_line_count <= 1) | |
3125 | 7764 { |
7765 validate_virtcol(); | |
7766 curwin->w_curswant = curwin->w_virtcol | |
7767 + resel_VIsual_vcol * cap->count0 - 1; | |
7768 } | |
7 | 7769 else |
3125 | 7770 curwin->w_curswant = resel_VIsual_vcol; |
7771 coladvance(curwin->w_curswant); | |
7 | 7772 } |
3125 | 7773 if (resel_VIsual_vcol == MAXCOL) |
7 | 7774 { |
7775 curwin->w_curswant = MAXCOL; | |
7776 coladvance((colnr_T)MAXCOL); | |
7777 } | |
7778 else if (VIsual_mode == Ctrl_V) | |
7779 { | |
7780 validate_virtcol(); | |
7781 curwin->w_curswant = curwin->w_virtcol | |
3125 | 7782 + resel_VIsual_vcol * cap->count0 - 1; |
7 | 7783 coladvance(curwin->w_curswant); |
7784 } | |
7785 else | |
7786 curwin->w_set_curswant = TRUE; | |
7787 redraw_curbuf_later(INVERTED); /* show the inversion */ | |
7788 } | |
7789 else | |
7790 { | |
7791 if (!cap->arg) | |
7792 /* start Select mode when 'selectmode' contains "cmd" */ | |
7793 may_start_select('c'); | |
7794 n_start_visual_mode(cap->cmdchar); | |
3537 | 7795 if (VIsual_mode != 'V' && *p_sel == 'e') |
7796 ++cap->count1; /* include one more char */ | |
7797 if (cap->count0 > 0 && --cap->count1 > 0) | |
7798 { | |
7799 /* With a count select that many characters or lines. */ | |
7800 if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) | |
7801 nv_right(cap); | |
7802 else if (VIsual_mode == 'V') | |
7803 nv_down(cap); | |
7804 } | |
7 | 7805 } |
7806 } | |
7807 } | |
7808 | |
7809 /* | |
7810 * Start selection for Shift-movement keys. | |
7811 */ | |
7812 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7813 start_selection(void) |
7 | 7814 { |
7815 /* if 'selectmode' contains "key", start Select mode */ | |
7816 may_start_select('k'); | |
7817 n_start_visual_mode('v'); | |
7818 } | |
7819 | |
7820 /* | |
7821 * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu. | |
7822 */ | |
7823 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7824 may_start_select(int c) |
7 | 7825 { |
7826 VIsual_select = (stuff_empty() && typebuf_typed() | |
7827 && (vim_strchr(p_slm, c) != NULL)); | |
7828 } | |
7829 | |
7830 /* | |
7831 * Start Visual mode "c". | |
7832 * Should set VIsual_select before calling this. | |
7833 */ | |
7834 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7835 n_start_visual_mode(int c) |
7 | 7836 { |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7837 #ifdef FEAT_CONCEAL |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7838 /* Check for redraw before changing the state. */ |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13772
diff
changeset
|
7839 conceal_check_cursor_line(); |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7840 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7841 |
7 | 7842 VIsual_mode = c; |
7843 VIsual_active = TRUE; | |
7844 VIsual_reselect = TRUE; | |
7845 #ifdef FEAT_VIRTUALEDIT | |
7846 /* Corner case: the 0 position in a tab may change when going into | |
7847 * virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting. | |
7848 */ | |
7849 if (c == Ctrl_V && (ve_flags & VE_BLOCK) && gchar_cursor() == TAB) | |
3742 | 7850 { |
7851 validate_virtcol(); | |
7 | 7852 coladvance(curwin->w_virtcol); |
3742 | 7853 } |
7 | 7854 #endif |
7855 VIsual = curwin->w_cursor; | |
7856 | |
7857 #ifdef FEAT_FOLDING | |
7858 foldAdjustVisual(); | |
7859 #endif | |
7860 | |
7861 #ifdef FEAT_MOUSE | |
7862 setmouse(); | |
7863 #endif | |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7864 #ifdef FEAT_CONCEAL |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7865 /* Check for redraw after changing the state. */ |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13772
diff
changeset
|
7866 conceal_check_cursor_line(); |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7867 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7868 |
641 | 7869 if (p_smd && msg_silent == 0) |
7 | 7870 redraw_cmdline = TRUE; /* show visual mode later */ |
7871 #ifdef FEAT_CLIPBOARD | |
7872 /* Make sure the clipboard gets updated. Needed because start and | |
7873 * end may still be the same, and the selection needs to be owned */ | |
7874 clip_star.vmode = NUL; | |
7875 #endif | |
7876 | |
7877 /* Only need to redraw this line, unless still need to redraw an old | |
7878 * Visual area (when 'lazyredraw' is set). */ | |
7879 if (curwin->w_redr_type < INVERTED) | |
7880 { | |
7881 curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
7882 curwin->w_old_visual_lnum = curwin->w_cursor.lnum; | |
7883 } | |
7884 } | |
7885 | |
7886 | |
7887 /* | |
7888 * CTRL-W: Window commands | |
7889 */ | |
7890 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7891 nv_window(cmdarg_T *cap) |
7 | 7892 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7893 if (cap->nchar == ':') |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7894 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7895 /* "CTRL-W :" is the same as typing ":"; useful in a terminal window */ |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7896 cap->cmdchar = ':'; |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7897 cap->nchar = NUL; |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7898 nv_colon(cap); |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7899 } |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7900 else if (!checkclearop(cap->oap)) |
7 | 7901 do_window(cap->nchar, cap->count0, NUL); /* everything is in window.c */ |
7902 } | |
7903 | |
7904 /* | |
7905 * CTRL-Z: Suspend | |
7906 */ | |
7907 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7908 nv_suspend(cmdarg_T *cap) |
7 | 7909 { |
7910 clearop(cap->oap); | |
7911 if (VIsual_active) | |
7912 end_visual_mode(); /* stop Visual mode */ | |
7913 do_cmdline_cmd((char_u *)"st"); | |
7914 } | |
7915 | |
7916 /* | |
7917 * Commands starting with "g". | |
7918 */ | |
7919 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7920 nv_g_cmd(cmdarg_T *cap) |
7 | 7921 { |
7922 oparg_T *oap = cap->oap; | |
7923 pos_T tpos; | |
7924 int i; | |
7925 int flag = FALSE; | |
7926 | |
7927 switch (cap->nchar) | |
7928 { | |
6868 | 7929 case Ctrl_A: |
7930 case Ctrl_X: | |
7 | 7931 #ifdef MEM_PROFILE |
7932 /* | |
7933 * "g^A": dump log of used memory. | |
7934 */ | |
6868 | 7935 if (!VIsual_active && cap->nchar == Ctrl_A) |
7936 vim_mem_profile_dump(); | |
7937 else | |
7938 #endif | |
7939 /* | |
7940 * "g^A/g^X": sequentially increment visually selected region | |
7941 */ | |
7942 if (VIsual_active) | |
7943 { | |
7944 cap->arg = TRUE; | |
7945 cap->cmdchar = cap->nchar; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
7946 cap->nchar = NUL; |
6868 | 7947 nv_addsub(cap); |
7948 } | |
7949 else | |
7950 clearopbeep(oap); | |
7 | 7951 break; |
7952 | |
7953 #ifdef FEAT_VREPLACE | |
7954 /* | |
7955 * "gR": Enter virtual replace mode. | |
7956 */ | |
7957 case 'R': | |
7958 cap->arg = TRUE; | |
7959 nv_Replace(cap); | |
7960 break; | |
7961 | |
7962 case 'r': | |
7963 nv_vreplace(cap); | |
7964 break; | |
7965 #endif | |
7966 | |
7967 case '&': | |
7968 do_cmdline_cmd((char_u *)"%s//~/&"); | |
7969 break; | |
7970 | |
7971 /* | |
7972 * "gv": Reselect the previous Visual area. If Visual already active, | |
7973 * exchange previous and current Visual area. | |
7974 */ | |
7975 case 'v': | |
7976 if (checkclearop(oap)) | |
7977 break; | |
7978 | |
690 | 7979 if ( curbuf->b_visual.vi_start.lnum == 0 |
7980 || curbuf->b_visual.vi_start.lnum > curbuf->b_ml.ml_line_count | |
7981 || curbuf->b_visual.vi_end.lnum == 0) | |
7 | 7982 beep_flush(); |
7983 else | |
7984 { | |
7985 /* set w_cursor to the start of the Visual area, tpos to the end */ | |
7986 if (VIsual_active) | |
7987 { | |
7988 i = VIsual_mode; | |
690 | 7989 VIsual_mode = curbuf->b_visual.vi_mode; |
7990 curbuf->b_visual.vi_mode = i; | |
7 | 7991 # ifdef FEAT_EVAL |
7992 curbuf->b_visual_mode_eval = i; | |
7993 # endif | |
7994 i = curwin->w_curswant; | |
690 | 7995 curwin->w_curswant = curbuf->b_visual.vi_curswant; |
7996 curbuf->b_visual.vi_curswant = i; | |
7997 | |
7998 tpos = curbuf->b_visual.vi_end; | |
7999 curbuf->b_visual.vi_end = curwin->w_cursor; | |
8000 curwin->w_cursor = curbuf->b_visual.vi_start; | |
8001 curbuf->b_visual.vi_start = VIsual; | |
7 | 8002 } |
8003 else | |
8004 { | |
690 | 8005 VIsual_mode = curbuf->b_visual.vi_mode; |
8006 curwin->w_curswant = curbuf->b_visual.vi_curswant; | |
8007 tpos = curbuf->b_visual.vi_end; | |
8008 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7 | 8009 } |
8010 | |
8011 VIsual_active = TRUE; | |
8012 VIsual_reselect = TRUE; | |
8013 | |
8014 /* Set Visual to the start and w_cursor to the end of the Visual | |
8015 * area. Make sure they are on an existing character. */ | |
8016 check_cursor(); | |
8017 VIsual = curwin->w_cursor; | |
8018 curwin->w_cursor = tpos; | |
8019 check_cursor(); | |
8020 update_topline(); | |
8021 /* | |
8022 * When called from normal "g" command: start Select mode when | |
8023 * 'selectmode' contains "cmd". When called for K_SELECT, always | |
8024 * start Select mode. | |
8025 */ | |
8026 if (cap->arg) | |
8027 VIsual_select = TRUE; | |
8028 else | |
8029 may_start_select('c'); | |
8030 #ifdef FEAT_MOUSE | |
8031 setmouse(); | |
8032 #endif | |
8033 #ifdef FEAT_CLIPBOARD | |
8034 /* Make sure the clipboard gets updated. Needed because start and | |
8035 * end are still the same, and the selection needs to be owned */ | |
8036 clip_star.vmode = NUL; | |
8037 #endif | |
8038 redraw_curbuf_later(INVERTED); | |
8039 showmode(); | |
8040 } | |
8041 break; | |
8042 /* | |
8043 * "gV": Don't reselect the previous Visual area after a Select mode | |
8044 * mapping of menu. | |
8045 */ | |
8046 case 'V': | |
8047 VIsual_reselect = FALSE; | |
8048 break; | |
8049 | |
8050 /* | |
8051 * "gh": start Select mode. | |
8052 * "gH": start Select line mode. | |
8053 * "g^H": start Select block mode. | |
8054 */ | |
8055 case K_BS: | |
8056 cap->nchar = Ctrl_H; | |
8057 /* FALLTHROUGH */ | |
8058 case 'h': | |
8059 case 'H': | |
8060 case Ctrl_H: | |
8061 # ifdef EBCDIC | |
8062 /* EBCDIC: 'v'-'h' != '^v'-'^h' */ | |
8063 if (cap->nchar == Ctrl_H) | |
8064 cap->cmdchar = Ctrl_V; | |
8065 else | |
8066 # endif | |
8067 cap->cmdchar = cap->nchar + ('v' - 'h'); | |
8068 cap->arg = TRUE; | |
8069 nv_visual(cap); | |
8070 break; | |
3701 | 8071 |
8072 /* "gn", "gN" visually select next/previous search match | |
8073 * "gn" selects next match | |
8074 * "gN" selects previous match | |
8075 */ | |
8076 case 'N': | |
8077 case 'n': | |
8078 if (!current_search(cap->count1, cap->nchar == 'n')) | |
3896 | 8079 clearopbeep(oap); |
3701 | 8080 break; |
7 | 8081 |
8082 /* | |
8083 * "gj" and "gk" two new funny movement keys -- up and down | |
8084 * movement based on *screen* line rather than *file* line. | |
8085 */ | |
8086 case 'j': | |
8087 case K_DOWN: | |
8088 /* with 'nowrap' it works just like the normal "j" command; also when | |
8089 * in a closed fold */ | |
8090 if (!curwin->w_p_wrap | |
8091 #ifdef FEAT_FOLDING | |
8092 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
8093 #endif | |
8094 ) | |
8095 { | |
8096 oap->motion_type = MLINE; | |
8097 i = cursor_down(cap->count1, oap->op_type == OP_NOP); | |
8098 } | |
8099 else | |
8100 i = nv_screengo(oap, FORWARD, cap->count1); | |
8101 if (i == FAIL) | |
8102 clearopbeep(oap); | |
8103 break; | |
8104 | |
8105 case 'k': | |
8106 case K_UP: | |
8107 /* with 'nowrap' it works just like the normal "k" command; also when | |
8108 * in a closed fold */ | |
8109 if (!curwin->w_p_wrap | |
8110 #ifdef FEAT_FOLDING | |
8111 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
8112 #endif | |
8113 ) | |
8114 { | |
8115 oap->motion_type = MLINE; | |
8116 i = cursor_up(cap->count1, oap->op_type == OP_NOP); | |
8117 } | |
8118 else | |
8119 i = nv_screengo(oap, BACKWARD, cap->count1); | |
8120 if (i == FAIL) | |
8121 clearopbeep(oap); | |
8122 break; | |
8123 | |
8124 /* | |
8125 * "gJ": join two lines without inserting a space. | |
8126 */ | |
8127 case 'J': | |
8128 nv_join(cap); | |
8129 break; | |
8130 | |
8131 /* | |
8132 * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines. | |
8133 * "gm": middle of "g0" and "g$". | |
8134 */ | |
8135 case '^': | |
8136 flag = TRUE; | |
8137 /* FALLTHROUGH */ | |
8138 | |
8139 case '0': | |
8140 case 'm': | |
8141 case K_HOME: | |
8142 case K_KHOME: | |
8143 oap->motion_type = MCHAR; | |
8144 oap->inclusive = FALSE; | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
8145 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 8146 { |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8147 int width1 = curwin->w_width - curwin_col_off(); |
7 | 8148 int width2 = width1 + curwin_col_off2(); |
8149 | |
8150 validate_virtcol(); | |
8151 i = 0; | |
8152 if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0) | |
8153 i = (curwin->w_virtcol - width1) / width2 * width2 + width1; | |
8154 } | |
8155 else | |
8156 i = curwin->w_leftcol; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2139
diff
changeset
|
8157 /* Go to the middle of the screen line. When 'number' or |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2139
diff
changeset
|
8158 * 'relativenumber' is on and lines are wrapping the middle can be more |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2139
diff
changeset
|
8159 * to the left. */ |
7 | 8160 if (cap->nchar == 'm') |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8161 i += (curwin->w_width - curwin_col_off() |
7 | 8162 + ((curwin->w_p_wrap && i > 0) |
8163 ? curwin_col_off2() : 0)) / 2; | |
8164 coladvance((colnr_T)i); | |
8165 if (flag) | |
8166 { | |
8167 do | |
8168 i = gchar_cursor(); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
8169 while (VIM_ISWHITE(i) && oneright() == OK); |
7 | 8170 } |
8171 curwin->w_set_curswant = TRUE; | |
8172 break; | |
8173 | |
8174 case '_': | |
8175 /* "g_": to the last non-blank character in the line or <count> lines | |
8176 * downward. */ | |
8177 cap->oap->motion_type = MCHAR; | |
8178 cap->oap->inclusive = TRUE; | |
8179 curwin->w_curswant = MAXCOL; | |
8180 if (cursor_down((long)(cap->count1 - 1), | |
8181 cap->oap->op_type == OP_NOP) == FAIL) | |
8182 clearopbeep(cap->oap); | |
8183 else | |
8184 { | |
8185 char_u *ptr = ml_get_curline(); | |
8186 | |
8187 /* In Visual mode we may end up after the line. */ | |
8188 if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) | |
8189 --curwin->w_cursor.col; | |
8190 | |
8191 /* Decrease the cursor column until it's on a non-blank. */ | |
8192 while (curwin->w_cursor.col > 0 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
8193 && VIM_ISWHITE(ptr[curwin->w_cursor.col])) |
7 | 8194 --curwin->w_cursor.col; |
8195 curwin->w_set_curswant = TRUE; | |
2040
70c67b1bb1f1
updated for version 7.2.329
Bram Moolenaar <bram@zimbu.org>
parents:
2024
diff
changeset
|
8196 adjust_for_sel(cap); |
7 | 8197 } |
8198 break; | |
8199 | |
8200 case '$': | |
8201 case K_END: | |
8202 case K_KEND: | |
8203 { | |
8204 int col_off = curwin_col_off(); | |
8205 | |
8206 oap->motion_type = MCHAR; | |
8207 oap->inclusive = TRUE; | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
8208 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 8209 { |
8210 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
8211 if (cap->count1 == 1) | |
8212 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8213 int width1 = curwin->w_width - col_off; |
7 | 8214 int width2 = width1 + curwin_col_off2(); |
8215 | |
8216 validate_virtcol(); | |
8217 i = width1 - 1; | |
8218 if (curwin->w_virtcol >= (colnr_T)width1) | |
8219 i += ((curwin->w_virtcol - width1) / width2 + 1) | |
8220 * width2; | |
8221 coladvance((colnr_T)i); | |
5162
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8222 |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8223 /* Make sure we stick in this column. */ |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8224 validate_virtcol(); |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8225 curwin->w_curswant = curwin->w_virtcol; |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8226 curwin->w_set_curswant = FALSE; |
7 | 8227 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE) |
8228 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
8229 { | |
8230 /* | |
8231 * Check for landing on a character that got split at | |
8232 * the end of the line. We do not want to advance to | |
8233 * the next screen line. | |
8234 */ | |
8235 if (curwin->w_virtcol > (colnr_T)i) | |
8236 --curwin->w_cursor.col; | |
8237 } | |
8238 #endif | |
8239 } | |
8240 else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == FAIL) | |
8241 clearopbeep(oap); | |
8242 } | |
8243 else | |
8244 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8245 i = curwin->w_leftcol + curwin->w_width - col_off - 1; |
7 | 8246 coladvance((colnr_T)i); |
40 | 8247 |
8248 /* Make sure we stick in this column. */ | |
8249 validate_virtcol(); | |
8250 curwin->w_curswant = curwin->w_virtcol; | |
8251 curwin->w_set_curswant = FALSE; | |
7 | 8252 } |
8253 } | |
8254 break; | |
8255 | |
8256 /* | |
8257 * "g*" and "g#", like "*" and "#" but without using "\<" and "\>" | |
8258 */ | |
8259 case '*': | |
8260 case '#': | |
8261 #if POUND != '#' | |
8262 case POUND: /* pound sign (sometimes equal to '#') */ | |
8263 #endif | |
8264 case Ctrl_RSB: /* :tag or :tselect for current identifier */ | |
8265 case ']': /* :tselect for current identifier */ | |
8266 nv_ident(cap); | |
8267 break; | |
8268 | |
8269 /* | |
8270 * ge and gE: go back to end of word | |
8271 */ | |
8272 case 'e': | |
8273 case 'E': | |
8274 oap->motion_type = MCHAR; | |
8275 curwin->w_set_curswant = TRUE; | |
8276 oap->inclusive = TRUE; | |
8277 if (bckend_word(cap->count1, cap->nchar == 'E', FALSE) == FAIL) | |
8278 clearopbeep(oap); | |
8279 break; | |
8280 | |
8281 /* | |
8282 * "g CTRL-G": display info about cursor position | |
8283 */ | |
8284 case Ctrl_G: | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7311
diff
changeset
|
8285 cursor_pos_info(NULL); |
7 | 8286 break; |
8287 | |
8288 /* | |
8289 * "gi": start Insert at the last position. | |
8290 */ | |
8291 case 'i': | |
8292 if (curbuf->b_last_insert.lnum != 0) | |
8293 { | |
8294 curwin->w_cursor = curbuf->b_last_insert; | |
8295 check_cursor_lnum(); | |
8296 i = (int)STRLEN(ml_get_curline()); | |
8297 if (curwin->w_cursor.col > (colnr_T)i) | |
8298 { | |
8299 #ifdef FEAT_VIRTUALEDIT | |
8300 if (virtual_active()) | |
8301 curwin->w_cursor.coladd += curwin->w_cursor.col - i; | |
8302 #endif | |
8303 curwin->w_cursor.col = i; | |
8304 } | |
8305 } | |
8306 cap->cmdchar = 'i'; | |
8307 nv_edit(cap); | |
8308 break; | |
8309 | |
8310 /* | |
8311 * "gI": Start insert in column 1. | |
8312 */ | |
8313 case 'I': | |
8314 beginline(0); | |
8315 if (!checkclearopq(oap)) | |
8316 invoke_edit(cap, FALSE, 'g', FALSE); | |
8317 break; | |
8318 | |
8319 #ifdef FEAT_SEARCHPATH | |
8320 /* | |
8321 * "gf": goto file, edit file under cursor | |
8322 * "]f" and "[f": can also be used. | |
8323 */ | |
8324 case 'f': | |
681 | 8325 case 'F': |
7 | 8326 nv_gotofile(cap); |
8327 break; | |
8328 #endif | |
8329 | |
8330 /* "g'm" and "g`m": jump to mark without setting pcmark */ | |
8331 case '\'': | |
8332 cap->arg = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
8333 /* FALLTHROUGH */ |
7 | 8334 case '`': |
8335 nv_gomark(cap); | |
8336 break; | |
8337 | |
8338 /* | |
8339 * "gs": Goto sleep. | |
8340 */ | |
8341 case 's': | |
8342 do_sleep(cap->count1 * 1000L); | |
8343 break; | |
8344 | |
8345 /* | |
8346 * "ga": Display the ascii value of the character under the | |
8347 * cursor. It is displayed in decimal, hex, and octal. -- webb | |
8348 */ | |
8349 case 'a': | |
8350 do_ascii(NULL); | |
8351 break; | |
8352 | |
8353 #ifdef FEAT_MBYTE | |
8354 /* | |
8355 * "g8": Display the bytes used for the UTF-8 character under the | |
8356 * cursor. It is displayed in hex. | |
775 | 8357 * "8g8" finds illegal byte sequence. |
7 | 8358 */ |
8359 case '8': | |
775 | 8360 if (cap->count0 == 8) |
8361 utf_find_illegal(); | |
8362 else | |
8363 show_utf8(); | |
7 | 8364 break; |
8365 #endif | |
8366 | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
8367 /* "g<": show scrollback text */ |
447 | 8368 case '<': |
8369 show_sb_text(); | |
8370 break; | |
8371 | |
7 | 8372 /* |
8373 * "gg": Goto the first line in file. With a count it goes to | |
8374 * that line number like for "G". -- webb | |
8375 */ | |
8376 case 'g': | |
8377 cap->arg = FALSE; | |
8378 nv_goto(cap); | |
8379 break; | |
8380 | |
8381 /* | |
8382 * Two-character operators: | |
8383 * "gq" Format text | |
8384 * "gw" Format text and keep cursor position | |
8385 * "g~" Toggle the case of the text. | |
8386 * "gu" Change text to lower case. | |
8387 * "gU" Change text to upper case. | |
8388 * "g?" rot13 encoding | |
602 | 8389 * "g@" call 'operatorfunc' |
7 | 8390 */ |
8391 case 'q': | |
8392 case 'w': | |
8393 oap->cursor_start = curwin->w_cursor; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
8394 /* FALLTHROUGH */ |
7 | 8395 case '~': |
8396 case 'u': | |
8397 case 'U': | |
8398 case '?': | |
602 | 8399 case '@': |
7 | 8400 nv_operator(cap); |
8401 break; | |
8402 | |
8403 /* | |
1188 | 8404 * "gd": Find first occurrence of pattern under the cursor in the |
7 | 8405 * current function |
8406 * "gD": idem, but in the current file. | |
8407 */ | |
8408 case 'd': | |
8409 case 'D': | |
523 | 8410 nv_gd(oap, cap->nchar, (int)cap->count0); |
7 | 8411 break; |
8412 | |
8413 #ifdef FEAT_MOUSE | |
8414 /* | |
8415 * g<*Mouse> : <C-*mouse> | |
8416 */ | |
8417 case K_MIDDLEMOUSE: | |
8418 case K_MIDDLEDRAG: | |
8419 case K_MIDDLERELEASE: | |
8420 case K_LEFTMOUSE: | |
8421 case K_LEFTDRAG: | |
8422 case K_LEFTRELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
8423 case K_MOUSEMOVE: |
7 | 8424 case K_RIGHTMOUSE: |
8425 case K_RIGHTDRAG: | |
8426 case K_RIGHTRELEASE: | |
8427 case K_X1MOUSE: | |
8428 case K_X1DRAG: | |
8429 case K_X1RELEASE: | |
8430 case K_X2MOUSE: | |
8431 case K_X2DRAG: | |
8432 case K_X2RELEASE: | |
8433 mod_mask = MOD_MASK_CTRL; | |
8434 (void)do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0); | |
8435 break; | |
8436 #endif | |
8437 | |
8438 case K_IGNORE: | |
8439 break; | |
8440 | |
8441 /* | |
8442 * "gP" and "gp": same as "P" and "p" but leave cursor just after new text | |
8443 */ | |
8444 case 'p': | |
8445 case 'P': | |
8446 nv_put(cap); | |
8447 break; | |
8448 | |
8449 #ifdef FEAT_BYTEOFF | |
8450 /* "go": goto byte count from start of buffer */ | |
8451 case 'o': | |
8452 goto_byte(cap->count0); | |
8453 break; | |
8454 #endif | |
8455 | |
8456 /* "gQ": improved Ex mode */ | |
8457 case 'Q': | |
633 | 8458 if (text_locked()) |
7 | 8459 { |
8460 clearopbeep(cap->oap); | |
633 | 8461 text_locked_msg(); |
7 | 8462 break; |
8463 } | |
631 | 8464 |
7 | 8465 if (!checkclearopq(oap)) |
8466 do_exmode(TRUE); | |
8467 break; | |
8468 | |
8469 #ifdef FEAT_JUMPLIST | |
8470 case ',': | |
8471 nv_pcmark(cap); | |
8472 break; | |
8473 | |
8474 case ';': | |
8475 cap->count1 = -cap->count1; | |
8476 nv_pcmark(cap); | |
8477 break; | |
8478 #endif | |
8479 | |
667 | 8480 case 't': |
3630 | 8481 if (!checkclearop(oap)) |
8482 goto_tabpage((int)cap->count0); | |
667 | 8483 break; |
682 | 8484 case 'T': |
3630 | 8485 if (!checkclearop(oap)) |
8486 goto_tabpage(-(int)cap->count1); | |
682 | 8487 break; |
667 | 8488 |
750 | 8489 case '+': |
8490 case '-': /* "g+" and "g-": undo or redo along the timeline */ | |
8491 if (!checkclearopq(oap)) | |
771 | 8492 undo_time(cap->nchar == '-' ? -cap->count1 : cap->count1, |
2281
e41433ea71df
Added ":earlier 1f" and ":later 1f".
Bram Moolenaar <bram@vim.org>
parents:
2259
diff
changeset
|
8493 FALSE, FALSE, FALSE); |
750 | 8494 break; |
8495 | |
7 | 8496 default: |
8497 clearopbeep(oap); | |
8498 break; | |
8499 } | |
8500 } | |
8501 | |
8502 /* | |
8503 * Handle "o" and "O" commands. | |
8504 */ | |
8505 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8506 n_opencmd(cmdarg_T *cap) |
7 | 8507 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8508 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8509 linenr_T oldline = curwin->w_cursor.lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8510 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8511 |
7 | 8512 if (!checkclearopq(cap->oap)) |
8513 { | |
8514 #ifdef FEAT_FOLDING | |
8515 if (cap->cmdchar == 'O') | |
8516 /* Open above the first line of a folded sequence of lines */ | |
8517 (void)hasFolding(curwin->w_cursor.lnum, | |
8518 &curwin->w_cursor.lnum, NULL); | |
8519 else | |
8520 /* Open below the last line of a folded sequence of lines */ | |
8521 (void)hasFolding(curwin->w_cursor.lnum, | |
8522 NULL, &curwin->w_cursor.lnum); | |
8523 #endif | |
8524 if (u_save((linenr_T)(curwin->w_cursor.lnum - | |
8525 (cap->cmdchar == 'O' ? 1 : 0)), | |
8526 (linenr_T)(curwin->w_cursor.lnum + | |
8527 (cap->cmdchar == 'o' ? 1 : 0)) | |
8528 ) == OK | |
8529 && open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD, | |
8530 #ifdef FEAT_COMMENTS | |
8531 has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM : | |
8532 #endif | |
13772
cc21507ee4b1
patch 8.0.1758: open_line() returns TRUE/FALSE for success/failure
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
8533 0, 0) == OK) |
7 | 8534 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8535 #ifdef FEAT_CONCEAL |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
8536 if (curwin->w_p_cole > 0 && oldline != curwin->w_cursor.lnum) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8537 update_single_line(curwin, oldline); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8538 #endif |
164 | 8539 /* When '#' is in 'cpoptions' ignore the count. */ |
8540 if (vim_strchr(p_cpo, CPO_HASH) != NULL) | |
8541 cap->count1 = 1; | |
6834 | 8542 #ifdef FEAT_SYN_HL |
6821 | 8543 if (curwin->w_p_cul) |
8544 /* force redraw of cursorline */ | |
8545 curwin->w_valid &= ~VALID_CROW; | |
6834 | 8546 #endif |
7 | 8547 invoke_edit(cap, FALSE, cap->cmdchar, TRUE); |
8548 } | |
8549 } | |
8550 } | |
8551 | |
8552 /* | |
8553 * "." command: redo last change. | |
8554 */ | |
8555 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8556 nv_dot(cmdarg_T *cap) |
7 | 8557 { |
8558 if (!checkclearopq(cap->oap)) | |
8559 { | |
8560 /* | |
8561 * If "restart_edit" is TRUE, the last but one command is repeated | |
8562 * instead of the last command (inserting text). This is used for | |
8563 * CTRL-O <.> in insert mode. | |
8564 */ | |
8565 if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == FAIL) | |
8566 clearopbeep(cap->oap); | |
8567 } | |
8568 } | |
8569 | |
8570 /* | |
8571 * CTRL-R: undo undo | |
8572 */ | |
8573 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8574 nv_redo(cmdarg_T *cap) |
7 | 8575 { |
8576 if (!checkclearopq(cap->oap)) | |
8577 { | |
8578 u_redo((int)cap->count1); | |
8579 curwin->w_set_curswant = TRUE; | |
8580 } | |
8581 } | |
8582 | |
8583 /* | |
8584 * Handle "U" command. | |
8585 */ | |
8586 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8587 nv_Undo(cmdarg_T *cap) |
7 | 8588 { |
8589 /* In Visual mode and typing "gUU" triggers an operator */ | |
5735 | 8590 if (cap->oap->op_type == OP_UPPER || VIsual_active) |
7 | 8591 { |
8592 /* translate "gUU" to "gUgU" */ | |
8593 cap->cmdchar = 'g'; | |
8594 cap->nchar = 'U'; | |
8595 nv_operator(cap); | |
8596 } | |
8597 else if (!checkclearopq(cap->oap)) | |
8598 { | |
8599 u_undoline(); | |
8600 curwin->w_set_curswant = TRUE; | |
8601 } | |
8602 } | |
8603 | |
8604 /* | |
8605 * '~' command: If tilde is not an operator and Visual is off: swap case of a | |
8606 * single character. | |
8607 */ | |
8608 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8609 nv_tilde(cmdarg_T *cap) |
7 | 8610 { |
5735 | 8611 if (!p_to && !VIsual_active && cap->oap->op_type != OP_TILDE) |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
8612 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
8613 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
8614 if (bt_prompt(curbuf) && !prompt_curpos_editable()) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
8615 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
8616 clearopbeep(cap->oap); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
8617 return; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
8618 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
8619 #endif |
7 | 8620 n_swapchar(cap); |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
8621 } |
7 | 8622 else |
8623 nv_operator(cap); | |
8624 } | |
8625 | |
8626 /* | |
8627 * Handle an operator command. | |
8628 * The actual work is done by do_pending_operator(). | |
8629 */ | |
8630 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8631 nv_operator(cmdarg_T *cap) |
7 | 8632 { |
8633 int op_type; | |
8634 | |
8635 op_type = get_op_type(cap->cmdchar, cap->nchar); | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
8636 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
8637 if (bt_prompt(curbuf) && op_is_change(op_type) && !prompt_curpos_editable()) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
8638 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
8639 clearopbeep(cap->oap); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
8640 return; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
8641 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
8642 #endif |
7 | 8643 |
8644 if (op_type == cap->oap->op_type) /* double operator works on lines */ | |
8645 nv_lineop(cap); | |
8646 else if (!checkclearop(cap->oap)) | |
8647 { | |
8648 cap->oap->start = curwin->w_cursor; | |
8649 cap->oap->op_type = op_type; | |
1490 | 8650 #ifdef FEAT_EVAL |
8651 set_op_var(op_type); | |
8652 #endif | |
8653 } | |
8654 } | |
8655 | |
8656 #ifdef FEAT_EVAL | |
8657 /* | |
8658 * Set v:operator to the characters for "optype". | |
8659 */ | |
8660 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8661 set_op_var(int optype) |
1490 | 8662 { |
8663 char_u opchars[3]; | |
8664 | |
8665 if (optype == OP_NOP) | |
8666 set_vim_var_string(VV_OP, NULL, 0); | |
8667 else | |
8668 { | |
8669 opchars[0] = get_op_char(optype); | |
8670 opchars[1] = get_extra_op_char(optype); | |
8671 opchars[2] = NUL; | |
8672 set_vim_var_string(VV_OP, opchars, -1); | |
8673 } | |
8674 } | |
8675 #endif | |
7 | 8676 |
8677 /* | |
8678 * Handle linewise operator "dd", "yy", etc. | |
8679 * | |
8680 * "_" is is a strange motion command that helps make operators more logical. | |
8681 * It is actually implemented, but not documented in the real Vi. This motion | |
8682 * command actually refers to "the current line". Commands like "dd" and "yy" | |
8683 * are really an alternate form of "d_" and "y_". It does accept a count, so | |
8684 * "d3_" works to delete 3 lines. | |
8685 */ | |
8686 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8687 nv_lineop(cmdarg_T *cap) |
7 | 8688 { |
8689 cap->oap->motion_type = MLINE; | |
8690 if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL) | |
8691 clearopbeep(cap->oap); | |
4011 | 8692 else if ( (cap->oap->op_type == OP_DELETE /* only with linewise motions */ |
8693 && cap->oap->motion_force != 'v' | |
8694 && cap->oap->motion_force != Ctrl_V) | |
7 | 8695 || cap->oap->op_type == OP_LSHIFT |
8696 || cap->oap->op_type == OP_RSHIFT) | |
8697 beginline(BL_SOL | BL_FIX); | |
8698 else if (cap->oap->op_type != OP_YANK) /* 'Y' does not move cursor */ | |
8699 beginline(BL_WHITE | BL_FIX); | |
8700 } | |
8701 | |
8702 /* | |
8703 * <Home> command. | |
8704 */ | |
8705 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8706 nv_home(cmdarg_T *cap) |
7 | 8707 { |
180 | 8708 /* CTRL-HOME is like "gg" */ |
8709 if (mod_mask & MOD_MASK_CTRL) | |
8710 nv_goto(cap); | |
8711 else | |
8712 { | |
8713 cap->count0 = 1; | |
8714 nv_pipe(cap); | |
8715 } | |
229 | 8716 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8717 one-character line). */ | |
7 | 8718 } |
8719 | |
8720 /* | |
8721 * "|" command. | |
8722 */ | |
8723 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8724 nv_pipe(cmdarg_T *cap) |
7 | 8725 { |
8726 cap->oap->motion_type = MCHAR; | |
8727 cap->oap->inclusive = FALSE; | |
8728 beginline(0); | |
8729 if (cap->count0 > 0) | |
8730 { | |
8731 coladvance((colnr_T)(cap->count0 - 1)); | |
8732 curwin->w_curswant = (colnr_T)(cap->count0 - 1); | |
8733 } | |
8734 else | |
8735 curwin->w_curswant = 0; | |
8736 /* keep curswant at the column where we wanted to go, not where | |
2667 | 8737 * we ended; differs if line is too short */ |
7 | 8738 curwin->w_set_curswant = FALSE; |
8739 } | |
8740 | |
8741 /* | |
8742 * Handle back-word command "b" and "B". | |
8743 * cap->arg is 1 for "B" | |
8744 */ | |
8745 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8746 nv_bck_word(cmdarg_T *cap) |
7 | 8747 { |
8748 cap->oap->motion_type = MCHAR; | |
8749 cap->oap->inclusive = FALSE; | |
8750 curwin->w_set_curswant = TRUE; | |
8751 if (bck_word(cap->count1, cap->arg, FALSE) == FAIL) | |
8752 clearopbeep(cap->oap); | |
8753 #ifdef FEAT_FOLDING | |
8754 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8755 foldOpenCursor(); | |
8756 #endif | |
8757 } | |
8758 | |
8759 /* | |
8760 * Handle word motion commands "e", "E", "w" and "W". | |
8761 * cap->arg is TRUE for "E" and "W". | |
8762 */ | |
8763 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8764 nv_wordcmd(cmdarg_T *cap) |
7 | 8765 { |
8766 int n; | |
8767 int word_end; | |
8768 int flag = FALSE; | |
1573 | 8769 pos_T startpos = curwin->w_cursor; |
7 | 8770 |
8771 /* | |
8772 * Set inclusive for the "E" and "e" command. | |
8773 */ | |
8774 if (cap->cmdchar == 'e' || cap->cmdchar == 'E') | |
8775 word_end = TRUE; | |
8776 else | |
8777 word_end = FALSE; | |
8778 cap->oap->inclusive = word_end; | |
8779 | |
8780 /* | |
8781 * "cw" and "cW" are a special case. | |
8782 */ | |
8783 if (!word_end && cap->oap->op_type == OP_CHANGE) | |
8784 { | |
8785 n = gchar_cursor(); | |
8786 if (n != NUL) /* not an empty line */ | |
8787 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
8788 if (VIM_ISWHITE(n)) |
7 | 8789 { |
8790 /* | |
8791 * Reproduce a funny Vi behaviour: "cw" on a blank only | |
8792 * changes one character, not all blanks until the start of | |
8793 * the next word. Only do this when the 'w' flag is included | |
8794 * in 'cpoptions'. | |
8795 */ | |
8796 if (cap->count1 == 1 && vim_strchr(p_cpo, CPO_CW) != NULL) | |
8797 { | |
8798 cap->oap->inclusive = TRUE; | |
8799 cap->oap->motion_type = MCHAR; | |
8800 return; | |
8801 } | |
8802 } | |
8803 else | |
8804 { | |
8805 /* | |
8806 * This is a little strange. To match what the real Vi does, | |
8807 * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided | |
8808 * that we are not on a space or a TAB. This seems impolite | |
8809 * at first, but it's really more what we mean when we say | |
8810 * 'cw'. | |
8811 * Another strangeness: When standing on the end of a word | |
4352 | 8812 * "ce" will change until the end of the next word, but "cw" |
7 | 8813 * will change only one character! This is done by setting |
8814 * flag. | |
8815 */ | |
8816 cap->oap->inclusive = TRUE; | |
8817 word_end = TRUE; | |
8818 flag = TRUE; | |
8819 } | |
8820 } | |
8821 } | |
8822 | |
8823 cap->oap->motion_type = MCHAR; | |
8824 curwin->w_set_curswant = TRUE; | |
8825 if (word_end) | |
8826 n = end_word(cap->count1, cap->arg, flag, FALSE); | |
8827 else | |
8828 n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP); | |
8829 | |
1573 | 8830 /* Don't leave the cursor on the NUL past the end of line. Unless we |
8831 * didn't move it forward. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8832 if (LT_POS(startpos, curwin->w_cursor)) |
1505 | 8833 adjust_cursor(cap->oap); |
7 | 8834 |
8835 if (n == FAIL && cap->oap->op_type == OP_NOP) | |
8836 clearopbeep(cap->oap); | |
8837 else | |
8838 { | |
8839 adjust_for_sel(cap); | |
8840 #ifdef FEAT_FOLDING | |
8841 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8842 foldOpenCursor(); | |
8843 #endif | |
8844 } | |
8845 } | |
8846 | |
8847 /* | |
1505 | 8848 * Used after a movement command: If the cursor ends up on the NUL after the |
8849 * end of the line, may move it back to the last character and make the motion | |
8850 * inclusive. | |
8851 */ | |
8852 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8853 adjust_cursor(oparg_T *oap) |
1505 | 8854 { |
8855 /* The cursor cannot remain on the NUL when: | |
8856 * - the column is > 0 | |
8857 * - not in Visual mode or 'selection' is "o" | |
8858 * - 'virtualedit' is not "all" and not "onemore". | |
8859 */ | |
8860 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL | |
8861 && (!VIsual_active || *p_sel == 'o') | |
8862 #ifdef FEAT_VIRTUALEDIT | |
8863 && !virtual_active() && (ve_flags & VE_ONEMORE) == 0 | |
8864 #endif | |
8865 ) | |
8866 { | |
8867 --curwin->w_cursor.col; | |
8868 #ifdef FEAT_MBYTE | |
8869 /* prevent cursor from moving on the trail byte */ | |
8870 if (has_mbyte) | |
8871 mb_adjust_cursor(); | |
8872 #endif | |
8873 oap->inclusive = TRUE; | |
8874 } | |
8875 } | |
8876 | |
8877 /* | |
7 | 8878 * "0" and "^" commands. |
8879 * cap->arg is the argument for beginline(). | |
8880 */ | |
8881 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8882 nv_beginline(cmdarg_T *cap) |
7 | 8883 { |
8884 cap->oap->motion_type = MCHAR; | |
8885 cap->oap->inclusive = FALSE; | |
8886 beginline(cap->arg); | |
8887 #ifdef FEAT_FOLDING | |
8888 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8889 foldOpenCursor(); | |
8890 #endif | |
557 | 8891 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8892 one-character line). */ | |
7 | 8893 } |
8894 | |
8895 /* | |
8896 * In exclusive Visual mode, may include the last character. | |
8897 */ | |
8898 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8899 adjust_for_sel(cmdarg_T *cap) |
7 | 8900 { |
8901 if (VIsual_active && cap->oap->inclusive && *p_sel == 'e' | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8902 && gchar_cursor() != NUL && LT_POS(VIsual, curwin->w_cursor)) |
7 | 8903 { |
5735 | 8904 #ifdef FEAT_MBYTE |
7 | 8905 if (has_mbyte) |
8906 inc_cursor(); | |
8907 else | |
5735 | 8908 #endif |
7 | 8909 ++curwin->w_cursor.col; |
8910 cap->oap->inclusive = FALSE; | |
8911 } | |
8912 } | |
8913 | |
8914 /* | |
8915 * Exclude last character at end of Visual area for 'selection' == "exclusive". | |
8916 * Should check VIsual_mode before calling this. | |
8917 * Returns TRUE when backed up to the previous line. | |
8918 */ | |
8919 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8920 unadjust_for_sel(void) |
7 | 8921 { |
8922 pos_T *pp; | |
8923 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8924 if (*p_sel == 'e' && !EQUAL_POS(VIsual, curwin->w_cursor)) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8925 { |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8926 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 8927 pp = &curwin->w_cursor; |
8928 else | |
8929 pp = &VIsual; | |
8930 #ifdef FEAT_VIRTUALEDIT | |
8931 if (pp->coladd > 0) | |
8932 --pp->coladd; | |
8933 else | |
8934 #endif | |
8935 if (pp->col > 0) | |
8936 { | |
8937 --pp->col; | |
8938 #ifdef FEAT_MBYTE | |
2933 | 8939 mb_adjustpos(curbuf, pp); |
7 | 8940 #endif |
8941 } | |
8942 else if (pp->lnum > 1) | |
8943 { | |
8944 --pp->lnum; | |
8945 pp->col = (colnr_T)STRLEN(ml_get(pp->lnum)); | |
8946 return TRUE; | |
8947 } | |
8948 } | |
8949 return FALSE; | |
8950 } | |
8951 | |
8952 /* | |
8953 * SELECT key in Normal or Visual mode: end of Select mode mapping. | |
8954 */ | |
8955 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8956 nv_select(cmdarg_T *cap) |
7 | 8957 { |
8958 if (VIsual_active) | |
8959 VIsual_select = TRUE; | |
8960 else if (VIsual_reselect) | |
8961 { | |
8962 cap->nchar = 'v'; /* fake "gv" command */ | |
8963 cap->arg = TRUE; | |
8964 nv_g_cmd(cap); | |
8965 } | |
8966 } | |
8967 | |
8968 | |
8969 /* | |
8970 * "G", "gg", CTRL-END, CTRL-HOME. | |
8971 * cap->arg is TRUE for "G". | |
8972 */ | |
8973 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8974 nv_goto(cmdarg_T *cap) |
7 | 8975 { |
8976 linenr_T lnum; | |
8977 | |
8978 if (cap->arg) | |
8979 lnum = curbuf->b_ml.ml_line_count; | |
8980 else | |
8981 lnum = 1L; | |
8982 cap->oap->motion_type = MLINE; | |
8983 setpcmark(); | |
8984 | |
8985 /* When a count is given, use it instead of the default lnum */ | |
8986 if (cap->count0 != 0) | |
8987 lnum = cap->count0; | |
8988 if (lnum < 1L) | |
8989 lnum = 1L; | |
8990 else if (lnum > curbuf->b_ml.ml_line_count) | |
8991 lnum = curbuf->b_ml.ml_line_count; | |
8992 curwin->w_cursor.lnum = lnum; | |
8993 beginline(BL_SOL | BL_FIX); | |
8994 #ifdef FEAT_FOLDING | |
8995 if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8996 foldOpenCursor(); | |
8997 #endif | |
8998 } | |
8999 | |
9000 /* | |
9001 * CTRL-\ in Normal mode. | |
9002 */ | |
9003 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9004 nv_normal(cmdarg_T *cap) |
7 | 9005 { |
9006 if (cap->nchar == Ctrl_N || cap->nchar == Ctrl_G) | |
9007 { | |
9008 clearop(cap->oap); | |
643 | 9009 if (restart_edit != 0 && mode_displayed) |
7 | 9010 clear_cmdline = TRUE; /* unshow mode later */ |
9011 restart_edit = 0; | |
9012 #ifdef FEAT_CMDWIN | |
9013 if (cmdwin_type != 0) | |
9014 cmdwin_result = Ctrl_C; | |
9015 #endif | |
9016 if (VIsual_active) | |
9017 { | |
9018 end_visual_mode(); /* stop Visual */ | |
9019 redraw_curbuf_later(INVERTED); | |
9020 } | |
9021 /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */ | |
9022 if (cap->nchar == Ctrl_G && p_im) | |
9023 restart_edit = 'a'; | |
9024 } | |
9025 else | |
9026 clearopbeep(cap->oap); | |
9027 } | |
9028 | |
9029 /* | |
9030 * ESC in Normal mode: beep, but don't flush buffers. | |
9031 * Don't even beep if we are canceling a command. | |
9032 */ | |
9033 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9034 nv_esc(cmdarg_T *cap) |
7 | 9035 { |
9036 int no_reason; | |
9037 | |
9038 no_reason = (cap->oap->op_type == OP_NOP | |
9039 && cap->opcount == 0 | |
9040 && cap->count0 == 0 | |
9041 && cap->oap->regname == 0 | |
9042 && !p_im); | |
9043 | |
9044 if (cap->arg) /* TRUE for CTRL-C */ | |
9045 { | |
9046 if (restart_edit == 0 | |
9047 #ifdef FEAT_CMDWIN | |
9048 && cmdwin_type == 0 | |
9049 #endif | |
9050 && !VIsual_active | |
9051 && no_reason) | |
11451
be76f4eca0d7
patch 8.0.0609: some people still don't know how to quit
Christian Brabandt <cb@256bit.org>
parents:
11436
diff
changeset
|
9052 MSG(_("Type :qa! and press <Enter> to abandon all changes and exit Vim")); |
7 | 9053 |
9054 /* Don't reset "restart_edit" when 'insertmode' is set, it won't be | |
9055 * set again below when halfway a mapping. */ | |
9056 if (!p_im) | |
9057 restart_edit = 0; | |
9058 #ifdef FEAT_CMDWIN | |
9059 if (cmdwin_type != 0) | |
9060 { | |
9061 cmdwin_result = K_IGNORE; | |
9062 got_int = FALSE; /* don't stop executing autocommands et al. */ | |
9063 return; | |
9064 } | |
9065 #endif | |
9066 } | |
9067 | |
9068 if (VIsual_active) | |
9069 { | |
9070 end_visual_mode(); /* stop Visual */ | |
9071 check_cursor_col(); /* make sure cursor is not beyond EOL */ | |
9072 curwin->w_set_curswant = TRUE; | |
9073 redraw_curbuf_later(INVERTED); | |
9074 } | |
5735 | 9075 else if (no_reason) |
6949 | 9076 vim_beep(BO_ESC); |
7 | 9077 clearop(cap->oap); |
9078 | |
9079 /* A CTRL-C is often used at the start of a menu. When 'insertmode' is | |
9080 * set return to Insert mode afterwards. */ | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
9081 if (restart_edit == 0 && goto_im() && ex_normal_busy == 0) |
7 | 9082 restart_edit = 'a'; |
9083 } | |
9084 | |
9085 /* | |
9086 * Handle "A", "a", "I", "i" and <Insert> commands. | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9087 * Also handle K_PS, start bracketed paste. |
7 | 9088 */ |
9089 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9090 nv_edit(cmdarg_T *cap) |
7 | 9091 { |
9092 /* <Insert> is equal to "i" */ | |
9093 if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) | |
9094 cap->cmdchar = 'i'; | |
9095 | |
9096 /* in Visual mode "A" and "I" are an operator */ | |
9097 if (VIsual_active && (cap->cmdchar == 'A' || cap->cmdchar == 'I')) | |
12467
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9098 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9099 #ifdef FEAT_TERMINAL |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9100 if (term_in_normal_mode()) |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9101 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9102 end_visual_mode(); |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9103 clearop(cap->oap); |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9104 term_enter_job_mode(); |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9105 return; |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9106 } |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9107 #endif |
7 | 9108 v_visop(cap); |
12467
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9109 } |
7 | 9110 |
9111 /* in Visual mode and after an operator "a" and "i" are for text objects */ | |
5735 | 9112 else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') |
9113 && (cap->oap->op_type != OP_NOP || VIsual_active)) | |
7 | 9114 { |
9115 #ifdef FEAT_TEXTOBJ | |
9116 nv_object(cap); | |
9117 #else | |
9118 clearopbeep(cap->oap); | |
9119 #endif | |
9120 } | |
11892
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9121 #ifdef FEAT_TERMINAL |
11993
92a86fe8adc0
patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
11987
diff
changeset
|
9122 else if (term_in_normal_mode()) |
11892
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9123 { |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9124 clearop(cap->oap); |
11993
92a86fe8adc0
patch 8.0.0877: using CTRL- CTRL-N in terminal is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
11987
diff
changeset
|
9125 term_enter_job_mode(); |
11892
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9126 return; |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9127 } |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9128 #endif |
7 | 9129 else if (!curbuf->b_p_ma && !p_im) |
9130 { | |
9131 /* Only give this error when 'insertmode' is off. */ | |
9132 EMSG(_(e_modifiable)); | |
9133 clearop(cap->oap); | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9134 if (cap->cmdchar == K_PS) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9135 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9136 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 9137 } |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9138 else if (cap->cmdchar == K_PS && VIsual_active) |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9139 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9140 pos_T old_pos = curwin->w_cursor; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9141 pos_T old_visual = VIsual; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9142 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9143 /* In Visual mode the selected text is deleted. */ |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9144 if (VIsual_mode == 'V' || curwin->w_cursor.lnum != VIsual.lnum) |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9145 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9146 shift_delete_registers(); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9147 cap->oap->regname = '1'; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9148 } |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9149 else |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9150 cap->oap->regname = '-'; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9151 cap->cmdchar = 'd'; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9152 cap->nchar = NUL; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9153 nv_operator(cap); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9154 do_pending_operator(cap, 0, FALSE); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9155 cap->cmdchar = K_PS; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9156 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9157 /* When the last char in the line was deleted then append. Detect this |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9158 * by checking if the cursor moved to before the Visual area. */ |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
9159 if (*ml_get_cursor() != NUL && LT_POS(curwin->w_cursor, old_pos) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
9160 && LT_POS(curwin->w_cursor, old_visual)) |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9161 inc_cursor(); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9162 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9163 /* Insert to replace the deleted text with the pasted text. */ |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9164 invoke_edit(cap, FALSE, cap->cmdchar, FALSE); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9165 } |
7 | 9166 else if (!checkclearopq(cap->oap)) |
9167 { | |
9168 switch (cap->cmdchar) | |
9169 { | |
9170 case 'A': /* "A"ppend after the line */ | |
9171 curwin->w_set_curswant = TRUE; | |
9172 #ifdef FEAT_VIRTUALEDIT | |
9173 if (ve_flags == VE_ALL) | |
9174 { | |
9175 int save_State = State; | |
9176 | |
4352 | 9177 /* Pretend Insert mode here to allow the cursor on the |
7 | 9178 * character past the end of the line */ |
9179 State = INSERT; | |
9180 coladvance((colnr_T)MAXCOL); | |
9181 State = save_State; | |
9182 } | |
9183 else | |
9184 #endif | |
9185 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor()); | |
9186 break; | |
9187 | |
9188 case 'I': /* "I"nsert before the first non-blank */ | |
164 | 9189 if (vim_strchr(p_cpo, CPO_INSEND) == NULL) |
9190 beginline(BL_WHITE); | |
9191 else | |
9192 beginline(BL_WHITE|BL_FIX); | |
7 | 9193 break; |
9194 | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9195 case K_PS: |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9196 /* Bracketed paste works like "a"ppend, unless the cursor is in |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9197 * the first column, then it inserts. */ |
10813
09eb5fd275e0
patch 8.0.0296: bracketed paste can only append, not insert
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
9198 if (curwin->w_cursor.col == 0) |
09eb5fd275e0
patch 8.0.0296: bracketed paste can only append, not insert
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
9199 break; |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
9200 /* FALLTHROUGH */ |
10813
09eb5fd275e0
patch 8.0.0296: bracketed paste can only append, not insert
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
9201 |
7 | 9202 case 'a': /* "a"ppend is like "i"nsert on the next character. */ |
9203 #ifdef FEAT_VIRTUALEDIT | |
9204 /* increment coladd when in virtual space, increment the | |
9205 * column otherwise, also to append after an unprintable char */ | |
9206 if (virtual_active() | |
9207 && (curwin->w_cursor.coladd > 0 | |
9208 || *ml_get_cursor() == NUL | |
9209 || *ml_get_cursor() == TAB)) | |
9210 curwin->w_cursor.coladd++; | |
9211 else | |
9212 #endif | |
9213 if (*ml_get_cursor() != NUL) | |
9214 inc_cursor(); | |
9215 break; | |
9216 } | |
9217 | |
9218 #ifdef FEAT_VIRTUALEDIT | |
9219 if (curwin->w_cursor.coladd && cap->cmdchar != 'A') | |
9220 { | |
9221 int save_State = State; | |
9222 | |
4352 | 9223 /* Pretend Insert mode here to allow the cursor on the |
7 | 9224 * character past the end of the line */ |
9225 State = INSERT; | |
9226 coladvance(getviscol()); | |
9227 State = save_State; | |
9228 } | |
9229 #endif | |
9230 | |
9231 invoke_edit(cap, FALSE, cap->cmdchar, FALSE); | |
9232 } | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9233 else if (cap->cmdchar == K_PS) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9234 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9235 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 9236 } |
9237 | |
9238 /* | |
9239 * Invoke edit() and take care of "restart_edit" and the return value. | |
9240 */ | |
9241 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9242 invoke_edit( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9243 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9244 int repl, /* "r" or "gr" command */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9245 int cmd, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9246 int startln) |
7 | 9247 { |
9248 int restart_edit_save = 0; | |
9249 | |
9250 /* Complicated: When the user types "a<C-O>a" we don't want to do Insert | |
9251 * mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow | |
9252 * it. */ | |
9253 if (repl || !stuff_empty()) | |
9254 restart_edit_save = restart_edit; | |
9255 else | |
9256 restart_edit_save = 0; | |
9257 | |
9258 /* Always reset "restart_edit", this is not a restarted edit. */ | |
9259 restart_edit = 0; | |
9260 | |
9261 if (edit(cmd, startln, cap->count1)) | |
9262 cap->retval |= CA_COMMAND_BUSY; | |
9263 | |
9264 if (restart_edit == 0) | |
9265 restart_edit = restart_edit_save; | |
9266 } | |
9267 | |
9268 #ifdef FEAT_TEXTOBJ | |
9269 /* | |
9270 * "a" or "i" while an operator is pending or in Visual mode: object motion. | |
9271 */ | |
9272 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9273 nv_object( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9274 cmdarg_T *cap) |
7 | 9275 { |
9276 int flag; | |
9277 int include; | |
9278 char_u *mps_save; | |
9279 | |
9280 if (cap->cmdchar == 'i') | |
9281 include = FALSE; /* "ix" = inner object: exclude white space */ | |
9282 else | |
9283 include = TRUE; /* "ax" = an object: include white space */ | |
9284 | |
9285 /* Make sure (), [], {} and <> are in 'matchpairs' */ | |
9286 mps_save = curbuf->b_p_mps; | |
9287 curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>"; | |
9288 | |
9289 switch (cap->nchar) | |
9290 { | |
9291 case 'w': /* "aw" = a word */ | |
9292 flag = current_word(cap->oap, cap->count1, include, FALSE); | |
9293 break; | |
9294 case 'W': /* "aW" = a WORD */ | |
9295 flag = current_word(cap->oap, cap->count1, include, TRUE); | |
9296 break; | |
9297 case 'b': /* "ab" = a braces block */ | |
9298 case '(': | |
9299 case ')': | |
9300 flag = current_block(cap->oap, cap->count1, include, '(', ')'); | |
9301 break; | |
9302 case 'B': /* "aB" = a Brackets block */ | |
9303 case '{': | |
9304 case '}': | |
9305 flag = current_block(cap->oap, cap->count1, include, '{', '}'); | |
9306 break; | |
9307 case '[': /* "a[" = a [] block */ | |
9308 case ']': | |
9309 flag = current_block(cap->oap, cap->count1, include, '[', ']'); | |
9310 break; | |
9311 case '<': /* "a<" = a <> block */ | |
9312 case '>': | |
9313 flag = current_block(cap->oap, cap->count1, include, '<', '>'); | |
9314 break; | |
420 | 9315 case 't': /* "at" = a tag block (xml and html) */ |
6661 | 9316 /* Do not adjust oap->end in do_pending_operator() |
9317 * otherwise there are different results for 'dit' | |
9318 * (note leading whitespace in last line): | |
9319 * 1) <b> 2) <b> | |
9320 * foobar foobar | |
9321 * </b> </b> | |
9322 */ | |
9323 cap->retval |= CA_NO_ADJ_OP_END; | |
420 | 9324 flag = current_tagblock(cap->oap, cap->count1, include); |
9325 break; | |
7 | 9326 case 'p': /* "ap" = a paragraph */ |
9327 flag = current_par(cap->oap, cap->count1, include, 'p'); | |
9328 break; | |
9329 case 's': /* "as" = a sentence */ | |
9330 flag = current_sent(cap->oap, cap->count1, include); | |
9331 break; | |
12 | 9332 case '"': /* "a"" = a double quoted string */ |
9333 case '\'': /* "a'" = a single quoted string */ | |
9334 case '`': /* "a`" = a backtick quoted string */ | |
9335 flag = current_quote(cap->oap, cap->count1, include, | |
9336 cap->nchar); | |
9337 break; | |
7 | 9338 #if 0 /* TODO */ |
9339 case 'S': /* "aS" = a section */ | |
9340 case 'f': /* "af" = a filename */ | |
9341 case 'u': /* "au" = a URL */ | |
9342 #endif | |
9343 default: | |
9344 flag = FAIL; | |
9345 break; | |
9346 } | |
9347 | |
9348 curbuf->b_p_mps = mps_save; | |
9349 if (flag == FAIL) | |
9350 clearopbeep(cap->oap); | |
9351 adjust_cursor_col(); | |
9352 curwin->w_set_curswant = TRUE; | |
9353 } | |
9354 #endif | |
9355 | |
9356 /* | |
9357 * "q" command: Start/stop recording. | |
9358 * "q:", "q/", "q?": edit command-line in command-line window. | |
9359 */ | |
9360 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9361 nv_record(cmdarg_T *cap) |
7 | 9362 { |
9363 if (cap->oap->op_type == OP_FORMAT) | |
9364 { | |
9365 /* "gqq" is the same as "gqgq": format line */ | |
9366 cap->cmdchar = 'g'; | |
9367 cap->nchar = 'q'; | |
9368 nv_operator(cap); | |
9369 } | |
9370 else if (!checkclearop(cap->oap)) | |
9371 { | |
9372 #ifdef FEAT_CMDWIN | |
9373 if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?') | |
9374 { | |
9375 stuffcharReadbuff(cap->nchar); | |
9376 stuffcharReadbuff(K_CMDWIN); | |
9377 } | |
9378 else | |
9379 #endif | |
9380 /* (stop) recording into a named register, unless executing a | |
9381 * register */ | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13876
diff
changeset
|
9382 if (reg_executing == 0 && do_record(cap->nchar) == FAIL) |
7 | 9383 clearopbeep(cap->oap); |
9384 } | |
9385 } | |
9386 | |
9387 /* | |
9388 * Handle the "@r" command. | |
9389 */ | |
9390 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9391 nv_at(cmdarg_T *cap) |
7 | 9392 { |
9393 if (checkclearop(cap->oap)) | |
9394 return; | |
9395 #ifdef FEAT_EVAL | |
9396 if (cap->nchar == '=') | |
9397 { | |
9398 if (get_expr_register() == NUL) | |
9399 return; | |
9400 } | |
9401 #endif | |
9402 while (cap->count1-- && !got_int) | |
9403 { | |
1034 | 9404 if (do_execreg(cap->nchar, FALSE, FALSE, FALSE) == FAIL) |
7 | 9405 { |
9406 clearopbeep(cap->oap); | |
9407 break; | |
9408 } | |
9409 line_breakcheck(); | |
9410 } | |
9411 } | |
9412 | |
9413 /* | |
9414 * Handle the CTRL-U and CTRL-D commands. | |
9415 */ | |
9416 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9417 nv_halfpage(cmdarg_T *cap) |
7 | 9418 { |
9419 if ((cap->cmdchar == Ctrl_U && curwin->w_cursor.lnum == 1) | |
9420 || (cap->cmdchar == Ctrl_D | |
9421 && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)) | |
9422 clearopbeep(cap->oap); | |
9423 else if (!checkclearop(cap->oap)) | |
9424 halfpage(cap->cmdchar == Ctrl_D, cap->count0); | |
9425 } | |
9426 | |
9427 /* | |
9428 * Handle "J" or "gJ" command. | |
9429 */ | |
9430 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9431 nv_join(cmdarg_T *cap) |
7 | 9432 { |
9433 if (VIsual_active) /* join the visual lines */ | |
9434 nv_operator(cap); | |
5735 | 9435 else if (!checkclearop(cap->oap)) |
7 | 9436 { |
9437 if (cap->count0 <= 1) | |
9438 cap->count0 = 2; /* default for join is two lines! */ | |
9439 if (curwin->w_cursor.lnum + cap->count0 - 1 > | |
9440 curbuf->b_ml.ml_line_count) | |
8445
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9441 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9442 /* can't join when on the last line */ |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9443 if (cap->count0 <= 2) |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9444 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9445 clearopbeep(cap->oap); |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9446 return; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9447 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9448 cap->count0 = curbuf->b_ml.ml_line_count |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9449 - curwin->w_cursor.lnum + 1; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9450 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9451 |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9452 prep_redo(cap->oap->regname, cap->count0, |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9453 NUL, cap->cmdchar, NUL, NUL, cap->nchar); |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9454 (void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE, TRUE); |
7 | 9455 } |
9456 } | |
9457 | |
9458 /* | |
9459 * "P", "gP", "p" and "gp" commands. | |
9460 */ | |
9461 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9462 nv_put(cmdarg_T *cap) |
7 | 9463 { |
9464 int regname = 0; | |
9465 void *reg1 = NULL, *reg2 = NULL; | |
84 | 9466 int empty = FALSE; |
236 | 9467 int was_visual = FALSE; |
7 | 9468 int dir; |
9469 int flags = 0; | |
9470 | |
9471 if (cap->oap->op_type != OP_NOP) | |
9472 { | |
9473 #ifdef FEAT_DIFF | |
9474 /* "dp" is ":diffput" */ | |
9475 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') | |
9476 { | |
9477 clearop(cap->oap); | |
6314 | 9478 nv_diffgetput(TRUE, cap->opcount); |
7 | 9479 } |
9480 else | |
9481 #endif | |
9482 clearopbeep(cap->oap); | |
9483 } | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
9484 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
9485 else if (bt_prompt(curbuf) && !prompt_curpos_editable()) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
9486 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
9487 clearopbeep(cap->oap); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
9488 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
9489 #endif |
7 | 9490 else |
9491 { | |
9492 dir = (cap->cmdchar == 'P' | |
9493 || (cap->cmdchar == 'g' && cap->nchar == 'P')) | |
9494 ? BACKWARD : FORWARD; | |
9495 prep_redo_cmd(cap); | |
9496 if (cap->cmdchar == 'g') | |
9497 flags |= PUT_CURSEND; | |
9498 | |
9499 if (VIsual_active) | |
9500 { | |
9501 /* Putting in Visual mode: The put text replaces the selected | |
9502 * text. First delete the selected text, then put the new text. | |
9503 * Need to save and restore the registers that the delete | |
9504 * overwrites if the old contents is being put. | |
9505 */ | |
236 | 9506 was_visual = TRUE; |
7 | 9507 regname = cap->oap->regname; |
5735 | 9508 #ifdef FEAT_CLIPBOARD |
7 | 9509 adjust_clip_reg(®name); |
5735 | 9510 #endif |
5682 | 9511 if (regname == 0 || regname == '"' |
4013 | 9512 || VIM_ISDIGIT(regname) || regname == '-' |
5735 | 9513 #ifdef FEAT_CLIPBOARD |
7 | 9514 || (clip_unnamed && (regname == '*' || regname == '+')) |
5735 | 9515 #endif |
7 | 9516 |
9517 ) | |
9518 { | |
4013 | 9519 /* The delete is going to overwrite the register we want to |
7 | 9520 * put, save it first. */ |
9521 reg1 = get_register(regname, TRUE); | |
9522 } | |
9523 | |
9524 /* Now delete the selected text. */ | |
9525 cap->cmdchar = 'd'; | |
9526 cap->nchar = NUL; | |
9527 cap->oap->regname = NUL; | |
9528 nv_operator(cap); | |
9529 do_pending_operator(cap, 0, FALSE); | |
84 | 9530 empty = (curbuf->b_ml.ml_flags & ML_EMPTY); |
7 | 9531 |
9532 /* delete PUT_LINE_BACKWARD; */ | |
9533 cap->oap->regname = regname; | |
9534 | |
9535 if (reg1 != NULL) | |
9536 { | |
9537 /* Delete probably changed the register we want to put, save | |
9538 * it first. Then put back what was there before the delete. */ | |
9539 reg2 = get_register(regname, FALSE); | |
9540 put_register(regname, reg1); | |
9541 } | |
9542 | |
9543 /* When deleted a linewise Visual area, put the register as | |
9544 * lines to avoid it joined with the next line. When deletion was | |
9545 * characterwise, split a line when putting lines. */ | |
9546 if (VIsual_mode == 'V') | |
9547 flags |= PUT_LINE; | |
9548 else if (VIsual_mode == 'v') | |
9549 flags |= PUT_LINE_SPLIT; | |
9550 if (VIsual_mode == Ctrl_V && dir == FORWARD) | |
9551 flags |= PUT_LINE_FORWARD; | |
9552 dir = BACKWARD; | |
9553 if ((VIsual_mode != 'V' | |
9554 && curwin->w_cursor.col < curbuf->b_op_start.col) | |
9555 || (VIsual_mode == 'V' | |
9556 && curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) | |
9557 /* cursor is at the end of the line or end of file, put | |
9558 * forward. */ | |
9559 dir = FORWARD; | |
5365 | 9560 /* May have been reset in do_put(). */ |
9561 VIsual_active = TRUE; | |
7 | 9562 } |
9563 do_put(cap->oap->regname, dir, cap->count1, flags); | |
9564 | |
9565 /* If a register was saved, put it back now. */ | |
9566 if (reg2 != NULL) | |
9567 put_register(regname, reg2); | |
236 | 9568 |
9569 /* What to reselect with "gv"? Selecting the just put text seems to | |
9570 * be the most useful, since the original text was removed. */ | |
9571 if (was_visual) | |
9572 { | |
690 | 9573 curbuf->b_visual.vi_start = curbuf->b_op_start; |
9574 curbuf->b_visual.vi_end = curbuf->b_op_end; | |
7241
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
9575 /* need to adjust cursor position */ |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
9576 if (*p_sel == 'e') |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
9577 inc(&curbuf->b_visual.vi_end); |
236 | 9578 } |
9579 | |
84 | 9580 /* When all lines were selected and deleted do_put() leaves an empty |
236 | 9581 * line that needs to be deleted now. */ |
84 | 9582 if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) |
817 | 9583 { |
84 | 9584 ml_delete(curbuf->b_ml.ml_line_count, TRUE); |
817 | 9585 |
9586 /* If the cursor was in that line, move it to the end of the last | |
9587 * line. */ | |
9588 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
9589 { | |
9590 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
9591 coladvance((colnr_T)MAXCOL); | |
9592 } | |
9593 } | |
7 | 9594 auto_format(FALSE, TRUE); |
9595 } | |
9596 } | |
9597 | |
9598 /* | |
9599 * "o" and "O" commands. | |
9600 */ | |
9601 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9602 nv_open(cmdarg_T *cap) |
7 | 9603 { |
9604 #ifdef FEAT_DIFF | |
9605 /* "do" is ":diffget" */ | |
9606 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') | |
9607 { | |
9608 clearop(cap->oap); | |
6314 | 9609 nv_diffgetput(FALSE, cap->opcount); |
7 | 9610 } |
9611 else | |
9612 #endif | |
9613 if (VIsual_active) /* switch start and end of visual */ | |
9614 v_swap_corners(cap->cmdchar); | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
9615 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
9616 else if (bt_prompt(curbuf)) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
9617 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
9618 clearopbeep(cap->oap); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
9619 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
9620 #endif |
7 | 9621 else |
9622 n_opencmd(cap); | |
9623 } | |
9624 | |
9625 #ifdef FEAT_NETBEANS_INTG | |
9626 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9627 nv_nbcmd(cmdarg_T *cap) |
7 | 9628 { |
9629 netbeans_keycommand(cap->nchar); | |
9630 } | |
9631 #endif | |
9632 | |
9633 #ifdef FEAT_DND | |
9634 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9635 nv_drop(cmdarg_T *cap UNUSED) |
7 | 9636 { |
9637 do_put('~', BACKWARD, 1L, PUT_CURSEND); | |
9638 } | |
9639 #endif | |
203 | 9640 |
9641 /* | |
9642 * Trigger CursorHold event. | |
9643 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the | |
9644 * input buffer. "did_cursorhold" is set to avoid retriggering. | |
9645 */ | |
9646 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9647 nv_cursorhold(cmdarg_T *cap) |
203 | 9648 { |
9649 apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); | |
9650 did_cursorhold = TRUE; | |
226 | 9651 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
9652 } | |
6866 | 9653 |
9654 /* | |
7001 | 9655 * Calculate start/end virtual columns for operating in block mode. |
6866 | 9656 */ |
9657 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9658 get_op_vcol( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9659 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9660 colnr_T redo_VIsual_vcol, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9661 int initial) /* when TRUE adjust position for 'selectmode' */ |
6866 | 9662 { |
9663 colnr_T start, end; | |
9664 | |
7001 | 9665 if (VIsual_mode != Ctrl_V |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
9666 || (!initial && oap->end.col < curwin->w_width)) |
6866 | 9667 return; |
9668 | |
7143
fe6d525d12f4
commit https://github.com/vim/vim/commit/10ad1d90da8c464e1bf08bf23d92d4888378a8a1
Christian Brabandt <cb@256bit.org>
parents:
7090
diff
changeset
|
9669 oap->block_mode = TRUE; |
6866 | 9670 |
9671 #ifdef FEAT_MBYTE | |
9672 /* prevent from moving onto a trail byte */ | |
9673 if (has_mbyte) | |
9674 mb_adjustpos(curwin->w_buffer, &oap->end); | |
9675 #endif | |
9676 | |
9677 getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol); | |
6961 | 9678 |
9679 if (!redo_VIsual_busy) | |
9680 { | |
9681 getvvcol(curwin, &(oap->end), &start, NULL, &end); | |
9682 | |
9683 if (start < oap->start_vcol) | |
9684 oap->start_vcol = start; | |
9685 if (end > oap->end_vcol) | |
9686 { | |
9687 if (initial && *p_sel == 'e' && start >= 1 | |
9688 && start - 1 >= oap->end_vcol) | |
9689 oap->end_vcol = start - 1; | |
9690 else | |
9691 oap->end_vcol = end; | |
9692 } | |
9693 } | |
9694 | |
6866 | 9695 /* if '$' was used, get oap->end_vcol from longest line */ |
9696 if (curwin->w_curswant == MAXCOL) | |
9697 { | |
9698 curwin->w_cursor.col = MAXCOL; | |
9699 oap->end_vcol = 0; | |
9700 for (curwin->w_cursor.lnum = oap->start.lnum; | |
9701 curwin->w_cursor.lnum <= oap->end.lnum; | |
9702 ++curwin->w_cursor.lnum) | |
9703 { | |
9704 getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end); | |
9705 if (end > oap->end_vcol) | |
9706 oap->end_vcol = end; | |
9707 } | |
9708 } | |
9709 else if (redo_VIsual_busy) | |
9710 oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1; | |
9711 /* | |
9712 * Correct oap->end.col and oap->start.col to be the | |
9713 * upper-left and lower-right corner of the block area. | |
9714 * | |
9715 * (Actually, this does convert column positions into character | |
9716 * positions) | |
9717 */ | |
9718 curwin->w_cursor.lnum = oap->end.lnum; | |
9719 coladvance(oap->end_vcol); | |
9720 oap->end = curwin->w_cursor; | |
9721 | |
9722 curwin->w_cursor = oap->start; | |
9723 coladvance(oap->start_vcol); | |
9724 oap->start = curwin->w_cursor; | |
9725 } |