Mercurial > vim
annotate src/normal.c @ 15495:617ca1eb76f8
Added tag v8.1.0755 for changeset 74a8f44b53220af449f838ad7dc476ee98d9f488
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 15 Jan 2019 22:30:06 +0100 |
parents | 55ccc2d353bd |
children | dd725a8ab112 |
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 void op_colon(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
36 static void op_function(oparg_T *oap); |
5735 | 37 #if defined(FEAT_MOUSE) |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
42 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
|
43 static void clearop(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
44 static void clearopbeep(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
45 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
|
46 static void may_clear_cmdline(void); |
7 | 47 #ifdef FEAT_CMDL_INFO |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
48 static void del_from_showcmd(int); |
7 | 49 #endif |
50 | |
51 /* | |
52 * nv_*(): functions called to handle Normal and Visual mode commands. | |
53 * n_*(): functions called to handle Normal mode commands. | |
54 * v_*(): functions called to handle Visual mode commands. | |
55 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 static void nv_page(cmdarg_T *cap); |
7 | 62 #ifdef FEAT_MOUSE |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
63 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
|
64 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
|
65 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
66 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
|
67 static void nv_zet(cmdarg_T *cap); |
7 | 68 #ifdef FEAT_GUI |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
69 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
|
70 static void nv_hor_scrollbar(cmdarg_T *cap); |
7 | 71 #endif |
685 | 72 #ifdef FEAT_GUI_TABLINE |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
73 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
|
74 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
|
75 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 static void nv_down(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_end(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_dollar(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_search(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_next(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 static void nv_operator(cmdarg_T *cap); |
1490 | 124 #ifdef FEAT_EVAL |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
125 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
|
126 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 static int unadjust_for_sel(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 static void invoke_edit(cmdarg_T *cap, int repl, int cmd, int startln); |
7 | 142 #ifdef FEAT_TEXTOBJ |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
143 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
|
144 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 static void nv_open(cmdarg_T *cap); |
7 | 151 #ifdef FEAT_NETBEANS_INTG |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
152 static void nv_nbcmd(cmdarg_T *cap); |
7 | 153 #endif |
154 #ifdef FEAT_DND | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
155 static void nv_drop(cmdarg_T *cap); |
7 | 156 #endif |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
157 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
|
158 static void get_op_vcol(oparg_T *oap, colnr_T col, int initial); |
7 | 159 |
1728 | 160 static char *e_noident = N_("E349: No identifier under cursor"); |
161 | |
7 | 162 /* |
163 * Function to be called for a Normal or Visual mode command. | |
164 * The argument is a cmdarg_T. | |
165 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
166 typedef void (*nv_func_T)(cmdarg_T *cap); |
7 | 167 |
168 /* Values for cmd_flags. */ | |
169 #define NV_NCH 0x01 /* may need to get a second char */ | |
170 #define NV_NCH_NOP (0x02|NV_NCH) /* get second char when no operator pending */ | |
171 #define NV_NCH_ALW (0x04|NV_NCH) /* always get a second char */ | |
172 #define NV_LANG 0x08 /* second char needs language adjustment */ | |
173 | |
174 #define NV_SS 0x10 /* may start selection */ | |
175 #define NV_SSS 0x20 /* may start selection with shift modifier */ | |
176 #define NV_STS 0x40 /* may stop selection without shift modif. */ | |
177 #define NV_RL 0x80 /* 'rightleft' modifies command */ | |
178 #define NV_KEEPREG 0x100 /* don't clear regname */ | |
179 #define NV_NCW 0x200 /* not allowed in command-line window */ | |
180 | |
181 /* | |
182 * Generally speaking, every Normal mode command should either clear any | |
183 * pending operator (with *clearop*()), or set the motion type variable | |
184 * oap->motion_type. | |
185 * | |
186 * When a cursor motion command is made, it is marked as being a character or | |
187 * line oriented motion. Then, if an operator is in effect, the operation | |
188 * becomes character or line oriented accordingly. | |
189 */ | |
190 | |
191 /* | |
192 * This table contains one entry for every Normal or Visual mode command. | |
193 * The order doesn't matter, init_normal_cmds() will create a sorted index. | |
194 * It is faster when all keys from zero to '~' are present. | |
195 */ | |
196 static const struct nv_cmd | |
197 { | |
198 int cmd_char; /* (first) command character */ | |
199 nv_func_T cmd_func; /* function for this command */ | |
200 short_u cmd_flags; /* NV_ flags */ | |
201 short cmd_arg; /* value for ca.arg */ | |
202 } nv_cmds[] = | |
203 { | |
204 {NUL, nv_error, 0, 0}, | |
205 {Ctrl_A, nv_addsub, 0, 0}, | |
206 {Ctrl_B, nv_page, NV_STS, BACKWARD}, | |
207 {Ctrl_C, nv_esc, 0, TRUE}, | |
208 {Ctrl_D, nv_halfpage, 0, 0}, | |
209 {Ctrl_E, nv_scroll_line, 0, TRUE}, | |
210 {Ctrl_F, nv_page, NV_STS, FORWARD}, | |
211 {Ctrl_G, nv_ctrlg, 0, 0}, | |
212 {Ctrl_H, nv_ctrlh, 0, 0}, | |
213 {Ctrl_I, nv_pcmark, 0, 0}, | |
214 {NL, nv_down, 0, FALSE}, | |
215 {Ctrl_K, nv_error, 0, 0}, | |
216 {Ctrl_L, nv_clear, 0, 0}, | |
376 | 217 {Ctrl_M, nv_down, 0, TRUE}, |
7 | 218 {Ctrl_N, nv_down, NV_STS, FALSE}, |
219 {Ctrl_O, nv_ctrlo, 0, 0}, | |
220 {Ctrl_P, nv_up, NV_STS, FALSE}, | |
167 | 221 {Ctrl_Q, nv_visual, 0, FALSE}, |
7 | 222 {Ctrl_R, nv_redo, 0, 0}, |
223 {Ctrl_S, nv_ignore, 0, 0}, | |
224 {Ctrl_T, nv_tagpop, NV_NCW, 0}, | |
225 {Ctrl_U, nv_halfpage, 0, 0}, | |
226 {Ctrl_V, nv_visual, 0, FALSE}, | |
227 {'V', nv_visual, 0, FALSE}, | |
228 {'v', nv_visual, 0, FALSE}, | |
229 {Ctrl_W, nv_window, 0, 0}, | |
230 {Ctrl_X, nv_addsub, 0, 0}, | |
231 {Ctrl_Y, nv_scroll_line, 0, FALSE}, | |
232 {Ctrl_Z, nv_suspend, 0, 0}, | |
233 {ESC, nv_esc, 0, FALSE}, | |
234 {Ctrl_BSL, nv_normal, NV_NCH_ALW, 0}, | |
235 {Ctrl_RSB, nv_ident, NV_NCW, 0}, | |
236 {Ctrl_HAT, nv_hat, NV_NCW, 0}, | |
237 {Ctrl__, nv_error, 0, 0}, | |
238 {' ', nv_right, 0, 0}, | |
239 {'!', nv_operator, 0, 0}, | |
240 {'"', nv_regname, NV_NCH_NOP|NV_KEEPREG, 0}, | |
241 {'#', nv_ident, 0, 0}, | |
242 {'$', nv_dollar, 0, 0}, | |
243 {'%', nv_percent, 0, 0}, | |
244 {'&', nv_optrans, 0, 0}, | |
245 {'\'', nv_gomark, NV_NCH_ALW, TRUE}, | |
246 {'(', nv_brace, 0, BACKWARD}, | |
247 {')', nv_brace, 0, FORWARD}, | |
248 {'*', nv_ident, 0, 0}, | |
249 {'+', nv_down, 0, TRUE}, | |
250 {',', nv_csearch, 0, TRUE}, | |
251 {'-', nv_up, 0, TRUE}, | |
252 {'.', nv_dot, NV_KEEPREG, 0}, | |
253 {'/', nv_search, 0, FALSE}, | |
254 {'0', nv_beginline, 0, 0}, | |
255 {'1', nv_ignore, 0, 0}, | |
256 {'2', nv_ignore, 0, 0}, | |
257 {'3', nv_ignore, 0, 0}, | |
258 {'4', nv_ignore, 0, 0}, | |
259 {'5', nv_ignore, 0, 0}, | |
260 {'6', nv_ignore, 0, 0}, | |
261 {'7', nv_ignore, 0, 0}, | |
262 {'8', nv_ignore, 0, 0}, | |
263 {'9', nv_ignore, 0, 0}, | |
264 {':', nv_colon, 0, 0}, | |
265 {';', nv_csearch, 0, FALSE}, | |
266 {'<', nv_operator, NV_RL, 0}, | |
267 {'=', nv_operator, 0, 0}, | |
268 {'>', nv_operator, NV_RL, 0}, | |
269 {'?', nv_search, 0, FALSE}, | |
270 {'@', nv_at, NV_NCH_NOP, FALSE}, | |
271 {'A', nv_edit, 0, 0}, | |
272 {'B', nv_bck_word, 0, 1}, | |
273 {'C', nv_abbrev, NV_KEEPREG, 0}, | |
274 {'D', nv_abbrev, NV_KEEPREG, 0}, | |
275 {'E', nv_wordcmd, 0, TRUE}, | |
276 {'F', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
277 {'G', nv_goto, 0, TRUE}, | |
278 {'H', nv_scroll, 0, 0}, | |
279 {'I', nv_edit, 0, 0}, | |
280 {'J', nv_join, 0, 0}, | |
281 {'K', nv_ident, 0, 0}, | |
282 {'L', nv_scroll, 0, 0}, | |
283 {'M', nv_scroll, 0, 0}, | |
284 {'N', nv_next, 0, SEARCH_REV}, | |
285 {'O', nv_open, 0, 0}, | |
286 {'P', nv_put, 0, 0}, | |
287 {'Q', nv_exmode, NV_NCW, 0}, | |
288 {'R', nv_Replace, 0, FALSE}, | |
289 {'S', nv_subst, NV_KEEPREG, 0}, | |
290 {'T', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
291 {'U', nv_Undo, 0, 0}, | |
292 {'W', nv_wordcmd, 0, TRUE}, | |
293 {'X', nv_abbrev, NV_KEEPREG, 0}, | |
294 {'Y', nv_abbrev, NV_KEEPREG, 0}, | |
295 {'Z', nv_Zet, NV_NCH_NOP|NV_NCW, 0}, | |
296 {'[', nv_brackets, NV_NCH_ALW, BACKWARD}, | |
297 {'\\', nv_error, 0, 0}, | |
298 {']', nv_brackets, NV_NCH_ALW, FORWARD}, | |
299 {'^', nv_beginline, 0, BL_WHITE | BL_FIX}, | |
300 {'_', nv_lineop, 0, 0}, | |
301 {'`', nv_gomark, NV_NCH_ALW, FALSE}, | |
302 {'a', nv_edit, NV_NCH, 0}, | |
303 {'b', nv_bck_word, 0, 0}, | |
304 {'c', nv_operator, 0, 0}, | |
305 {'d', nv_operator, 0, 0}, | |
306 {'e', nv_wordcmd, 0, FALSE}, | |
307 {'f', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
308 {'g', nv_g_cmd, NV_NCH_ALW, FALSE}, | |
309 {'h', nv_left, NV_RL, 0}, | |
310 {'i', nv_edit, NV_NCH, 0}, | |
311 {'j', nv_down, 0, FALSE}, | |
312 {'k', nv_up, 0, FALSE}, | |
313 {'l', nv_right, NV_RL, 0}, | |
314 {'m', nv_mark, NV_NCH_NOP, 0}, | |
315 {'n', nv_next, 0, 0}, | |
316 {'o', nv_open, 0, 0}, | |
317 {'p', nv_put, 0, 0}, | |
318 {'q', nv_record, NV_NCH, 0}, | |
319 {'r', nv_replace, NV_NCH_NOP|NV_LANG, 0}, | |
320 {'s', nv_subst, NV_KEEPREG, 0}, | |
321 {'t', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
322 {'u', nv_undo, 0, 0}, | |
323 {'w', nv_wordcmd, 0, FALSE}, | |
324 {'x', nv_abbrev, NV_KEEPREG, 0}, | |
325 {'y', nv_operator, 0, 0}, | |
326 {'z', nv_zet, NV_NCH_ALW, 0}, | |
327 {'{', nv_findpar, 0, BACKWARD}, | |
328 {'|', nv_pipe, 0, 0}, | |
329 {'}', nv_findpar, 0, FORWARD}, | |
330 {'~', nv_tilde, 0, 0}, | |
331 | |
332 /* pound sign */ | |
333 {POUND, nv_ident, 0, 0}, | |
334 #ifdef FEAT_MOUSE | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
335 {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
|
336 {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
|
337 {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
|
338 {K_MOUSERIGHT, nv_mousescroll, 0, MSCR_RIGHT}, |
7 | 339 {K_LEFTMOUSE, nv_mouse, 0, 0}, |
340 {K_LEFTMOUSE_NM, nv_mouse, 0, 0}, | |
341 {K_LEFTDRAG, nv_mouse, 0, 0}, | |
342 {K_LEFTRELEASE, nv_mouse, 0, 0}, | |
343 {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
|
344 {K_MOUSEMOVE, nv_mouse, 0, 0}, |
7 | 345 {K_MIDDLEMOUSE, nv_mouse, 0, 0}, |
346 {K_MIDDLEDRAG, nv_mouse, 0, 0}, | |
347 {K_MIDDLERELEASE, nv_mouse, 0, 0}, | |
348 {K_RIGHTMOUSE, nv_mouse, 0, 0}, | |
349 {K_RIGHTDRAG, nv_mouse, 0, 0}, | |
350 {K_RIGHTRELEASE, nv_mouse, 0, 0}, | |
351 {K_X1MOUSE, nv_mouse, 0, 0}, | |
352 {K_X1DRAG, nv_mouse, 0, 0}, | |
353 {K_X1RELEASE, nv_mouse, 0, 0}, | |
354 {K_X2MOUSE, nv_mouse, 0, 0}, | |
355 {K_X2DRAG, nv_mouse, 0, 0}, | |
356 {K_X2RELEASE, nv_mouse, 0, 0}, | |
357 #endif | |
819 | 358 {K_IGNORE, nv_ignore, NV_KEEPREG, 0}, |
620 | 359 {K_NOP, nv_nop, 0, 0}, |
7 | 360 {K_INS, nv_edit, 0, 0}, |
361 {K_KINS, nv_edit, 0, 0}, | |
362 {K_BS, nv_ctrlh, 0, 0}, | |
363 {K_UP, nv_up, NV_SSS|NV_STS, FALSE}, | |
364 {K_S_UP, nv_page, NV_SS, BACKWARD}, | |
365 {K_DOWN, nv_down, NV_SSS|NV_STS, FALSE}, | |
366 {K_S_DOWN, nv_page, NV_SS, FORWARD}, | |
367 {K_LEFT, nv_left, NV_SSS|NV_STS|NV_RL, 0}, | |
368 {K_S_LEFT, nv_bck_word, NV_SS|NV_RL, 0}, | |
369 {K_C_LEFT, nv_bck_word, NV_SSS|NV_RL|NV_STS, 1}, | |
370 {K_RIGHT, nv_right, NV_SSS|NV_STS|NV_RL, 0}, | |
371 {K_S_RIGHT, nv_wordcmd, NV_SS|NV_RL, FALSE}, | |
372 {K_C_RIGHT, nv_wordcmd, NV_SSS|NV_RL|NV_STS, TRUE}, | |
373 {K_PAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
374 {K_KPAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
375 {K_PAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
376 {K_KPAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
377 {K_END, nv_end, NV_SSS|NV_STS, FALSE}, | |
378 {K_KEND, nv_end, NV_SSS|NV_STS, FALSE}, | |
379 {K_S_END, nv_end, NV_SS, FALSE}, | |
380 {K_C_END, nv_end, NV_SSS|NV_STS, TRUE}, | |
381 {K_HOME, nv_home, NV_SSS|NV_STS, 0}, | |
382 {K_KHOME, nv_home, NV_SSS|NV_STS, 0}, | |
383 {K_S_HOME, nv_home, NV_SS, 0}, | |
384 {K_C_HOME, nv_goto, NV_SSS|NV_STS, FALSE}, | |
385 {K_DEL, nv_abbrev, 0, 0}, | |
386 {K_KDEL, nv_abbrev, 0, 0}, | |
387 {K_UNDO, nv_kundo, 0, 0}, | |
388 {K_HELP, nv_help, NV_NCW, 0}, | |
389 {K_F1, nv_help, NV_NCW, 0}, | |
390 {K_XF1, nv_help, NV_NCW, 0}, | |
391 {K_SELECT, nv_select, 0, 0}, | |
392 #ifdef FEAT_GUI | |
393 {K_VER_SCROLLBAR, nv_ver_scrollbar, 0, 0}, | |
394 {K_HOR_SCROLLBAR, nv_hor_scrollbar, 0, 0}, | |
395 #endif | |
685 | 396 #ifdef FEAT_GUI_TABLINE |
397 {K_TABLINE, nv_tabline, 0, 0}, | |
686 | 398 {K_TABMENU, nv_tabmenu, 0, 0}, |
685 | 399 #endif |
7 | 400 #ifdef FEAT_FKMAP |
9399
43b8570abbec
commit https://github.com/vim/vim/commit/ee2615af64fdcee87d8e4b13b65356e77fbd969b
Christian Brabandt <cb@256bit.org>
parents:
9315
diff
changeset
|
401 {K_F8, farsi_f8, 0, 0}, |
43b8570abbec
commit https://github.com/vim/vim/commit/ee2615af64fdcee87d8e4b13b65356e77fbd969b
Christian Brabandt <cb@256bit.org>
parents:
9315
diff
changeset
|
402 {K_F9, farsi_f9, 0, 0}, |
7 | 403 #endif |
404 #ifdef FEAT_NETBEANS_INTG | |
405 {K_F21, nv_nbcmd, NV_NCH_ALW, 0}, | |
406 #endif | |
407 #ifdef FEAT_DND | |
408 {K_DROP, nv_drop, NV_STS, 0}, | |
409 #endif | |
819 | 410 {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
|
411 {K_PS, nv_edit, 0, 0}, |
7 | 412 }; |
413 | |
414 /* Number of commands in nv_cmds[]. */ | |
415 #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd)) | |
416 | |
417 /* Sorted index of commands in nv_cmds[]. */ | |
418 static short nv_cmd_idx[NV_CMDS_SIZE]; | |
419 | |
420 /* The highest index for which | |
421 * nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] */ | |
422 static int nv_max_linear; | |
423 | |
424 /* | |
425 * Compare functions for qsort() below, that checks the command character | |
426 * through the index in nv_cmd_idx[]. | |
427 */ | |
428 static int | |
429 #ifdef __BORLANDC__ | |
430 _RTLENTRYF | |
431 #endif | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
432 nv_compare(const void *s1, const void *s2) |
7 | 433 { |
434 int c1, c2; | |
435 | |
436 /* The commands are sorted on absolute value. */ | |
437 c1 = nv_cmds[*(const short *)s1].cmd_char; | |
438 c2 = nv_cmds[*(const short *)s2].cmd_char; | |
439 if (c1 < 0) | |
440 c1 = -c1; | |
441 if (c2 < 0) | |
442 c2 = -c2; | |
443 return c1 - c2; | |
444 } | |
445 | |
446 /* | |
447 * Initialize the nv_cmd_idx[] table. | |
448 */ | |
449 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
450 init_normal_cmds(void) |
7 | 451 { |
452 int i; | |
453 | |
454 /* Fill the index table with a one to one relation. */ | |
1877 | 455 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 456 nv_cmd_idx[i] = i; |
457 | |
458 /* Sort the commands by the command character. */ | |
459 qsort((void *)&nv_cmd_idx, (size_t)NV_CMDS_SIZE, sizeof(short), nv_compare); | |
460 | |
461 /* Find the first entry that can't be indexed by the command character. */ | |
1877 | 462 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 463 if (i != nv_cmds[nv_cmd_idx[i]].cmd_char) |
464 break; | |
465 nv_max_linear = i - 1; | |
466 } | |
467 | |
468 /* | |
469 * Search for a command in the commands table. | |
470 * Returns -1 for invalid command. | |
471 */ | |
472 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
473 find_command(int cmdchar) |
7 | 474 { |
475 int i; | |
476 int idx; | |
477 int top, bot; | |
478 int c; | |
479 | |
480 #ifdef FEAT_MBYTE | |
481 /* A multi-byte character is never a command. */ | |
482 if (cmdchar >= 0x100) | |
483 return -1; | |
484 #endif | |
485 | |
486 /* We use the absolute value of the character. Special keys have a | |
487 * negative value, but are sorted on their absolute value. */ | |
488 if (cmdchar < 0) | |
489 cmdchar = -cmdchar; | |
490 | |
491 /* If the character is in the first part: The character is the index into | |
492 * nv_cmd_idx[]. */ | |
493 if (cmdchar <= nv_max_linear) | |
494 return nv_cmd_idx[cmdchar]; | |
495 | |
496 /* Perform a binary search. */ | |
497 bot = nv_max_linear + 1; | |
498 top = NV_CMDS_SIZE - 1; | |
499 idx = -1; | |
500 while (bot <= top) | |
501 { | |
502 i = (top + bot) / 2; | |
503 c = nv_cmds[nv_cmd_idx[i]].cmd_char; | |
504 if (c < 0) | |
505 c = -c; | |
506 if (cmdchar == c) | |
507 { | |
508 idx = nv_cmd_idx[i]; | |
509 break; | |
510 } | |
511 if (cmdchar > c) | |
512 bot = i + 1; | |
513 else | |
514 top = i - 1; | |
515 } | |
516 return idx; | |
517 } | |
518 | |
519 /* | |
520 * Execute a command in Normal mode. | |
521 */ | |
522 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
523 normal_cmd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
524 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
525 int toplevel UNUSED) /* TRUE when called from main() */ |
7 | 526 { |
527 cmdarg_T ca; /* command arguments */ | |
528 int c; | |
529 int ctrl_w = FALSE; /* got CTRL-W command */ | |
530 int old_col = curwin->w_curswant; | |
531 #ifdef FEAT_CMDL_INFO | |
532 int need_flushbuf; /* need to call out_flush() */ | |
533 #endif | |
534 pos_T old_pos; /* cursor position before command */ | |
535 int mapped_len; | |
536 static int old_mapped_len = 0; | |
537 int idx; | |
1751 | 538 #ifdef FEAT_EVAL |
539 int set_prevcount = FALSE; | |
540 #endif | |
7 | 541 |
542 vim_memset(&ca, 0, sizeof(ca)); /* also resets ca.retval */ | |
543 ca.oap = oap; | |
1692 | 544 |
545 /* Use a count remembered from before entering an operator. After typing | |
546 * "3d" we return from normal_cmd() and come back here, the "3" is | |
547 * remembered in "opcount". */ | |
7 | 548 ca.opcount = opcount; |
549 | |
550 /* | |
551 * If there is an operator pending, then the command we take this time | |
552 * will terminate it. Finish_op tells us to finish the operation before | |
553 * returning this time (unless the operation was cancelled). | |
554 */ | |
555 #ifdef CURSOR_SHAPE | |
556 c = finish_op; | |
557 #endif | |
558 finish_op = (oap->op_type != OP_NOP); | |
559 #ifdef CURSOR_SHAPE | |
560 if (finish_op != c) | |
561 { | |
562 ui_cursor_shape(); /* may show different cursor shape */ | |
563 # ifdef FEAT_MOUSESHAPE | |
564 update_mouseshape(-1); | |
565 # endif | |
566 } | |
567 #endif | |
568 | |
1692 | 569 /* When not finishing an operator and no register name typed, reset the |
570 * count. */ | |
7 | 571 if (!finish_op && !oap->regname) |
1751 | 572 { |
7 | 573 ca.opcount = 0; |
1751 | 574 #ifdef FEAT_EVAL |
575 set_prevcount = TRUE; | |
576 #endif | |
577 } | |
7 | 578 |
1692 | 579 /* Restore counts from before receiving K_CURSORHOLD. This means after |
580 * typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not | |
581 * "3 * 2". */ | |
582 if (oap->prev_opcount > 0 || oap->prev_count0 > 0) | |
583 { | |
584 ca.opcount = oap->prev_opcount; | |
585 ca.count0 = oap->prev_count0; | |
586 oap->prev_opcount = 0; | |
587 oap->prev_count0 = 0; | |
588 } | |
589 | |
7 | 590 mapped_len = typebuf_maplen(); |
591 | |
592 State = NORMAL_BUSY; | |
593 #ifdef USE_ON_FLY_SCROLL | |
594 dont_scroll = FALSE; /* allow scrolling here */ | |
595 #endif | |
596 | |
2667 | 597 #ifdef FEAT_EVAL |
598 /* Set v:count here, when called from main() and not a stuffed | |
599 * command, so that v:count can be used in an expression mapping | |
5649 | 600 * when there is no count. Do set it for redo. */ |
601 if (toplevel && readbuf1_empty()) | |
2667 | 602 set_vcount_ca(&ca, &set_prevcount); |
603 #endif | |
604 | |
7 | 605 /* |
606 * Get the command character from the user. | |
607 */ | |
608 c = safe_vgetc(); | |
7703
39251e981d1f
commit https://github.com/vim/vim/commit/25281634cda03ce302aaf9f906a9520b5f81f91e
Christian Brabandt <cb@256bit.org>
parents:
7578
diff
changeset
|
609 LANGMAP_ADJUST(c, get_real_state() != SELECTMODE); |
7 | 610 |
611 /* | |
612 * If a mapping was started in Visual or Select mode, remember the length | |
613 * of the mapping. This is used below to not return to Insert mode for as | |
614 * long as the mapping is being executed. | |
615 */ | |
616 if (restart_edit == 0) | |
617 old_mapped_len = 0; | |
618 else if (old_mapped_len | |
819 | 619 || (VIsual_active && mapped_len == 0 && typebuf_maplen() > 0)) |
7 | 620 old_mapped_len = typebuf_maplen(); |
621 | |
622 if (c == NUL) | |
623 c = K_ZERO; | |
624 | |
625 /* | |
626 * In Select mode, typed text replaces the selection. | |
627 */ | |
628 if (VIsual_active | |
629 && VIsual_select | |
630 && (vim_isprintc(c) || c == NL || c == CAR || c == K_KENTER)) | |
631 { | |
275 | 632 /* Fake a "c"hange command. When "restart_edit" is set (e.g., because |
633 * 'insertmode' is set) fake a "d"elete command, Insert mode will | |
634 * restart automatically. | |
1051 | 635 * Insert the typed character in the typeahead buffer, so that it can |
636 * be mapped in Insert mode. Required for ":lmap" to work. */ | |
852 | 637 ins_char_typebuf(c); |
275 | 638 if (restart_edit != 0) |
639 c = 'd'; | |
640 else | |
641 c = 'c'; | |
695 | 642 msg_nowait = TRUE; /* don't delay going to insert mode */ |
4472 | 643 old_mapped_len = 0; /* do go to Insert mode */ |
7 | 644 } |
645 | |
646 #ifdef FEAT_CMDL_INFO | |
647 need_flushbuf = add_to_showcmd(c); | |
648 #endif | |
649 | |
650 getcount: | |
651 if (!(VIsual_active && VIsual_select)) | |
652 { | |
653 /* | |
654 * Handle a count before a command and compute ca.count0. | |
655 * Note that '0' is a command and not the start of a count, but it's | |
656 * part of a count after other digits. | |
657 */ | |
658 while ( (c >= '1' && c <= '9') | |
659 || (ca.count0 != 0 && (c == K_DEL || c == K_KDEL || c == '0'))) | |
660 { | |
661 if (c == K_DEL || c == K_KDEL) | |
662 { | |
663 ca.count0 /= 10; | |
664 #ifdef FEAT_CMDL_INFO | |
665 del_from_showcmd(4); /* delete the digit and ~@% */ | |
666 #endif | |
667 } | |
668 else | |
669 ca.count0 = ca.count0 * 10 + (c - '0'); | |
670 if (ca.count0 < 0) /* got too large! */ | |
671 ca.count0 = 999999999L; | |
1425 | 672 #ifdef FEAT_EVAL |
673 /* Set v:count here, when called from main() and not a stuffed | |
674 * command, so that v:count can be used in an expression mapping | |
5649 | 675 * right after the count. Do set it for redo. */ |
676 if (toplevel && readbuf1_empty()) | |
2667 | 677 set_vcount_ca(&ca, &set_prevcount); |
1425 | 678 #endif |
7 | 679 if (ctrl_w) |
680 { | |
681 ++no_mapping; | |
682 ++allow_keys; /* no mapping for nchar, but keys */ | |
683 } | |
684 ++no_zero_mapping; /* don't map zero here */ | |
1389 | 685 c = plain_vgetc(); |
7 | 686 LANGMAP_ADJUST(c, TRUE); |
687 --no_zero_mapping; | |
688 if (ctrl_w) | |
689 { | |
690 --no_mapping; | |
691 --allow_keys; | |
692 } | |
693 #ifdef FEAT_CMDL_INFO | |
694 need_flushbuf |= add_to_showcmd(c); | |
695 #endif | |
696 } | |
697 | |
698 /* | |
699 * If we got CTRL-W there may be a/another count | |
700 */ | |
701 if (c == Ctrl_W && !ctrl_w && oap->op_type == OP_NOP) | |
702 { | |
703 ctrl_w = TRUE; | |
704 ca.opcount = ca.count0; /* remember first count */ | |
705 ca.count0 = 0; | |
706 ++no_mapping; | |
707 ++allow_keys; /* no mapping for nchar, but keys */ | |
1389 | 708 c = plain_vgetc(); /* get next character */ |
7 | 709 LANGMAP_ADJUST(c, TRUE); |
710 --no_mapping; | |
711 --allow_keys; | |
712 #ifdef FEAT_CMDL_INFO | |
713 need_flushbuf |= add_to_showcmd(c); | |
714 #endif | |
715 goto getcount; /* jump back */ | |
716 } | |
717 } | |
718 | |
1692 | 719 if (c == K_CURSORHOLD) |
720 { | |
721 /* Save the count values so that ca.opcount and ca.count0 are exactly | |
722 * the same when coming back here after handling K_CURSORHOLD. */ | |
723 oap->prev_opcount = ca.opcount; | |
724 oap->prev_count0 = ca.count0; | |
725 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
726 else if (ca.opcount != 0) |
1692 | 727 { |
728 /* | |
729 * If we're in the middle of an operator (including after entering a | |
730 * yank buffer with '"') AND we had a count before the operator, then | |
731 * that count overrides the current value of ca.count0. | |
732 * What this means effectively, is that commands like "3dw" get turned | |
733 * into "d3w" which makes things fall into place pretty neatly. | |
734 * If you give a count before AND after the operator, they are | |
735 * multiplied. | |
736 */ | |
7 | 737 if (ca.count0) |
738 ca.count0 *= ca.opcount; | |
739 else | |
740 ca.count0 = ca.opcount; | |
741 } | |
742 | |
743 /* | |
744 * Always remember the count. It will be set to zero (on the next call, | |
745 * above) when there is no pending operator. | |
746 * When called from main(), save the count for use by the "count" built-in | |
747 * variable. | |
748 */ | |
749 ca.opcount = ca.count0; | |
750 ca.count1 = (ca.count0 == 0 ? 1 : ca.count0); | |
751 | |
752 #ifdef FEAT_EVAL | |
753 /* | |
754 * Only set v:count when called from main() and not a stuffed command. | |
5649 | 755 * Do set it for redo. |
7 | 756 */ |
5649 | 757 if (toplevel && readbuf1_empty()) |
1751 | 758 set_vcount(ca.count0, ca.count1, set_prevcount); |
7 | 759 #endif |
760 | |
761 /* | |
762 * Find the command character in the table of commands. | |
763 * For CTRL-W we already got nchar when looking for a count. | |
764 */ | |
765 if (ctrl_w) | |
766 { | |
767 ca.nchar = c; | |
768 ca.cmdchar = Ctrl_W; | |
769 } | |
770 else | |
771 ca.cmdchar = c; | |
772 idx = find_command(ca.cmdchar); | |
773 if (idx < 0) | |
774 { | |
775 /* Not a known command: beep. */ | |
776 clearopbeep(oap); | |
777 goto normal_end; | |
778 } | |
631 | 779 |
633 | 780 if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW)) |
631 | 781 { |
5848 | 782 /* This command is not allowed while editing a cmdline: beep. */ |
7 | 783 clearopbeep(oap); |
633 | 784 text_locked_msg(); |
7 | 785 goto normal_end; |
786 } | |
819 | 787 if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked()) |
788 goto normal_end; | |
7 | 789 |
790 /* | |
791 * In Visual/Select mode, a few keys are handled in a special way. | |
792 */ | |
793 if (VIsual_active) | |
794 { | |
795 /* when 'keymodel' contains "stopsel" may stop Select/Visual mode */ | |
796 if (km_stopsel | |
797 && (nv_cmds[idx].cmd_flags & NV_STS) | |
798 && !(mod_mask & MOD_MASK_SHIFT)) | |
799 { | |
800 end_visual_mode(); | |
801 redraw_curbuf_later(INVERTED); | |
802 } | |
803 | |
804 /* Keys that work different when 'keymodel' contains "startsel" */ | |
805 if (km_startsel) | |
806 { | |
807 if (nv_cmds[idx].cmd_flags & NV_SS) | |
808 { | |
809 unshift_special(&ca); | |
810 idx = find_command(ca.cmdchar); | |
840 | 811 if (idx < 0) |
812 { | |
813 /* Just in case */ | |
814 clearopbeep(oap); | |
815 goto normal_end; | |
816 } | |
7 | 817 } |
818 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
819 && (mod_mask & MOD_MASK_SHIFT)) | |
820 { | |
821 mod_mask &= ~MOD_MASK_SHIFT; | |
822 } | |
823 } | |
824 } | |
825 | |
826 #ifdef FEAT_RIGHTLEFT | |
827 if (curwin->w_p_rl && KeyTyped && !KeyStuffed | |
828 && (nv_cmds[idx].cmd_flags & NV_RL)) | |
829 { | |
830 /* Invert horizontal movements and operations. Only when typed by the | |
831 * user directly, not when the result of a mapping or "x" translated | |
832 * to "dl". */ | |
833 switch (ca.cmdchar) | |
834 { | |
835 case 'l': ca.cmdchar = 'h'; break; | |
836 case K_RIGHT: ca.cmdchar = K_LEFT; break; | |
837 case K_S_RIGHT: ca.cmdchar = K_S_LEFT; break; | |
838 case K_C_RIGHT: ca.cmdchar = K_C_LEFT; break; | |
839 case 'h': ca.cmdchar = 'l'; break; | |
840 case K_LEFT: ca.cmdchar = K_RIGHT; break; | |
841 case K_S_LEFT: ca.cmdchar = K_S_RIGHT; break; | |
842 case K_C_LEFT: ca.cmdchar = K_C_RIGHT; break; | |
843 case '>': ca.cmdchar = '<'; break; | |
844 case '<': ca.cmdchar = '>'; break; | |
845 } | |
846 idx = find_command(ca.cmdchar); | |
847 } | |
848 #endif | |
849 | |
850 /* | |
851 * Get an additional character if we need one. | |
852 */ | |
853 if ((nv_cmds[idx].cmd_flags & NV_NCH) | |
854 && (((nv_cmds[idx].cmd_flags & NV_NCH_NOP) == NV_NCH_NOP | |
855 && oap->op_type == OP_NOP) | |
856 || (nv_cmds[idx].cmd_flags & NV_NCH_ALW) == NV_NCH_ALW | |
857 || (ca.cmdchar == 'q' | |
858 && 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
|
859 && 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
|
860 && reg_executing == 0) |
7 | 861 || ((ca.cmdchar == 'a' || ca.cmdchar == 'i') |
5735 | 862 && (oap->op_type != OP_NOP || VIsual_active)))) |
7 | 863 { |
864 int *cp; | |
865 int repl = FALSE; /* get character for replace mode */ | |
866 int lit = FALSE; /* get extra character literally */ | |
867 int langmap_active = FALSE; /* using :lmap mappings */ | |
868 int lang; /* getting a text character */ | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
869 #ifdef HAVE_INPUT_METHOD |
7 | 870 int save_smd; /* saved value of p_smd */ |
871 #endif | |
872 | |
873 ++no_mapping; | |
874 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1343 | 875 /* Don't generate a CursorHold event here, most commands can't handle |
876 * it, e.g., nv_replace(), nv_csearch(). */ | |
877 did_cursorhold = TRUE; | |
7 | 878 if (ca.cmdchar == 'g') |
879 { | |
880 /* | |
881 * For 'g' get the next character now, so that we can check for | |
882 * "gr", "g'" and "g`". | |
883 */ | |
1389 | 884 ca.nchar = plain_vgetc(); |
7 | 885 LANGMAP_ADJUST(ca.nchar, TRUE); |
886 #ifdef FEAT_CMDL_INFO | |
887 need_flushbuf |= add_to_showcmd(ca.nchar); | |
888 #endif | |
889 if (ca.nchar == 'r' || ca.nchar == '\'' || ca.nchar == '`' | |
5523 | 890 || ca.nchar == Ctrl_BSL) |
7 | 891 { |
892 cp = &ca.extra_char; /* need to get a third character */ | |
893 if (ca.nchar != 'r') | |
894 lit = TRUE; /* get it literally */ | |
895 else | |
896 repl = TRUE; /* get it in replace mode */ | |
897 } | |
898 else | |
899 cp = NULL; /* no third character needed */ | |
900 } | |
901 else | |
902 { | |
903 if (ca.cmdchar == 'r') /* get it in replace mode */ | |
904 repl = TRUE; | |
905 cp = &ca.nchar; | |
906 } | |
907 lang = (repl || (nv_cmds[idx].cmd_flags & NV_LANG)); | |
908 | |
909 /* | |
910 * Get a second or third character. | |
911 */ | |
912 if (cp != NULL) | |
913 { | |
914 #ifdef CURSOR_SHAPE | |
915 if (repl) | |
916 { | |
917 State = REPLACE; /* pretend Replace mode */ | |
918 ui_cursor_shape(); /* show different cursor shape */ | |
919 } | |
920 #endif | |
921 if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) | |
922 { | |
923 /* Allow mappings defined with ":lmap". */ | |
924 --no_mapping; | |
925 --allow_keys; | |
926 if (repl) | |
927 State = LREPLACE; | |
928 else | |
929 State = LANGMAP; | |
930 langmap_active = TRUE; | |
931 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
932 #ifdef HAVE_INPUT_METHOD |
7 | 933 save_smd = p_smd; |
934 p_smd = FALSE; /* Don't let the IM code show the mode here */ | |
935 if (lang && curbuf->b_p_iminsert == B_IMODE_IM) | |
936 im_set_active(TRUE); | |
937 #endif | |
938 | |
1389 | 939 *cp = plain_vgetc(); |
7 | 940 |
941 if (langmap_active) | |
942 { | |
943 /* Undo the decrement done above */ | |
944 ++no_mapping; | |
945 ++allow_keys; | |
946 State = NORMAL_BUSY; | |
947 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
948 #ifdef HAVE_INPUT_METHOD |
7 | 949 if (lang) |
950 { | |
951 if (curbuf->b_p_iminsert != B_IMODE_LMAP) | |
952 im_save_status(&curbuf->b_p_iminsert); | |
953 im_set_active(FALSE); | |
954 } | |
955 p_smd = save_smd; | |
956 #endif | |
957 #ifdef CURSOR_SHAPE | |
958 State = NORMAL_BUSY; | |
959 #endif | |
960 #ifdef FEAT_CMDL_INFO | |
961 need_flushbuf |= add_to_showcmd(*cp); | |
962 #endif | |
963 | |
964 if (!lit) | |
965 { | |
966 #ifdef FEAT_DIGRAPHS | |
967 /* Typing CTRL-K gets a digraph. */ | |
968 if (*cp == Ctrl_K | |
969 && ((nv_cmds[idx].cmd_flags & NV_LANG) | |
970 || cp == &ca.extra_char) | |
971 && vim_strchr(p_cpo, CPO_DIGRAPH) == NULL) | |
972 { | |
973 c = get_digraph(FALSE); | |
974 if (c > 0) | |
975 { | |
976 *cp = c; | |
977 # ifdef FEAT_CMDL_INFO | |
978 /* Guessing how to update showcmd here... */ | |
979 del_from_showcmd(3); | |
980 need_flushbuf |= add_to_showcmd(*cp); | |
981 # endif | |
982 } | |
983 } | |
984 #endif | |
985 | |
986 /* adjust chars > 127, except after "tTfFr" commands */ | |
987 LANGMAP_ADJUST(*cp, !lang); | |
988 #ifdef FEAT_RIGHTLEFT | |
989 /* adjust Hebrew mapped char */ | |
990 if (p_hkmap && lang && KeyTyped) | |
991 *cp = hkmap(*cp); | |
992 # ifdef FEAT_FKMAP | |
993 /* adjust Farsi mapped char */ | |
994 if (p_fkmap && lang && KeyTyped) | |
995 *cp = fkmap(*cp); | |
996 # endif | |
997 #endif | |
998 } | |
999 | |
1000 /* | |
1001 * When the next character is CTRL-\ a following CTRL-N means the | |
1002 * command is aborted and we go to Normal mode. | |
1003 */ | |
1004 if (cp == &ca.extra_char | |
1005 && ca.nchar == Ctrl_BSL | |
1006 && (ca.extra_char == Ctrl_N || ca.extra_char == Ctrl_G)) | |
1007 { | |
1008 ca.cmdchar = Ctrl_BSL; | |
1009 ca.nchar = ca.extra_char; | |
1010 idx = find_command(ca.cmdchar); | |
1011 } | |
3908 | 1012 else if ((ca.nchar == 'n' || ca.nchar == 'N') && ca.cmdchar == 'g') |
3896 | 1013 ca.oap->op_type = get_op_type(*cp, NUL); |
7 | 1014 else if (*cp == Ctrl_BSL) |
1015 { | |
1016 long towait = (p_ttm >= 0 ? p_ttm : p_tm); | |
1017 | |
1018 /* There is a busy wait here when typing "f<C-\>" and then | |
1019 * something different from CTRL-N. Can't be avoided. */ | |
1020 while ((c = vpeekc()) <= 0 && towait > 0L) | |
1021 { | |
1022 do_sleep(towait > 50L ? 50L : towait); | |
1023 towait -= 50L; | |
1024 } | |
1025 if (c > 0) | |
1026 { | |
1389 | 1027 c = plain_vgetc(); |
7 | 1028 if (c != Ctrl_N && c != Ctrl_G) |
1029 vungetc(c); | |
1030 else | |
1031 { | |
1032 ca.cmdchar = Ctrl_BSL; | |
1033 ca.nchar = c; | |
1034 idx = find_command(ca.cmdchar); | |
1035 } | |
1036 } | |
1037 } | |
1038 | |
1039 #ifdef FEAT_MBYTE | |
1040 /* When getting a text character and the next character is a | |
1041 * multi-byte character, it could be a composing character. | |
6071 | 1042 * However, don't wait for it to arrive. Also, do enable mapping, |
1043 * because if it's put back with vungetc() it's too late to apply | |
1044 * mapping. */ | |
1045 --no_mapping; | |
7 | 1046 while (enc_utf8 && lang && (c = vpeekc()) > 0 |
1047 && (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) | |
1048 { | |
1389 | 1049 c = plain_vgetc(); |
7 | 1050 if (!utf_iscomposing(c)) |
1051 { | |
1052 vungetc(c); /* it wasn't, put it back */ | |
1053 break; | |
1054 } | |
1055 else if (ca.ncharC1 == 0) | |
1056 ca.ncharC1 = c; | |
1057 else | |
1058 ca.ncharC2 = c; | |
1059 } | |
6071 | 1060 ++no_mapping; |
7 | 1061 #endif |
1062 } | |
1063 --no_mapping; | |
1064 --allow_keys; | |
1065 } | |
1066 | |
1067 #ifdef FEAT_CMDL_INFO | |
1068 /* | |
1069 * Flush the showcmd characters onto the screen so we can see them while | |
1070 * the command is being executed. Only do this when the shown command was | |
1071 * actually displayed, otherwise this will slow down a lot when executing | |
1072 * mappings. | |
1073 */ | |
1074 if (need_flushbuf) | |
1075 out_flush(); | |
1076 #endif | |
1727 | 1077 if (ca.cmdchar != K_IGNORE) |
1078 did_cursorhold = FALSE; | |
7 | 1079 |
1080 State = NORMAL; | |
1081 | |
1082 if (ca.nchar == ESC) | |
1083 { | |
1084 clearop(oap); | |
1085 if (restart_edit == 0 && goto_im()) | |
1086 restart_edit = 'a'; | |
1087 goto normal_end; | |
1088 } | |
1089 | |
24 | 1090 if (ca.cmdchar != K_IGNORE) |
1091 { | |
1092 msg_didout = FALSE; /* don't scroll screen up for normal command */ | |
1093 msg_col = 0; | |
1094 } | |
7 | 1095 |
1096 old_pos = curwin->w_cursor; /* remember where cursor was */ | |
1097 | |
1098 /* When 'keymodel' contains "startsel" some keys start Select/Visual | |
1099 * mode. */ | |
1100 if (!VIsual_active && km_startsel) | |
1101 { | |
1102 if (nv_cmds[idx].cmd_flags & NV_SS) | |
1103 { | |
1104 start_selection(); | |
1105 unshift_special(&ca); | |
1106 idx = find_command(ca.cmdchar); | |
1107 } | |
1108 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
1109 && (mod_mask & MOD_MASK_SHIFT)) | |
1110 { | |
1111 start_selection(); | |
1112 mod_mask &= ~MOD_MASK_SHIFT; | |
1113 } | |
1114 } | |
1115 | |
1116 /* | |
1117 * Execute the command! | |
1118 * Call the command function found in the commands table. | |
1119 */ | |
1120 ca.arg = nv_cmds[idx].cmd_arg; | |
1121 (nv_cmds[idx].cmd_func)(&ca); | |
1122 | |
1123 /* | |
1124 * If we didn't start or finish an operator, reset oap->regname, unless we | |
1125 * need it later. | |
1126 */ | |
1127 if (!finish_op | |
1128 && !oap->op_type | |
1129 && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) | |
1130 { | |
1131 clearop(oap); | |
1132 #ifdef FEAT_EVAL | |
2821 | 1133 { |
1134 int regname = 0; | |
2829 | 1135 |
2821 | 1136 /* Adjust the register according to 'clipboard', so that when |
1137 * "unnamed" is present it becomes '*' or '+' instead of '"'. */ | |
2829 | 1138 # ifdef FEAT_CLIPBOARD |
2821 | 1139 adjust_clip_reg(®name); |
2829 | 1140 # endif |
2821 | 1141 set_reg_var(regname); |
1142 } | |
7 | 1143 #endif |
1144 } | |
1145 | |
570 | 1146 /* Get the length of mapped chars again after typing a count, second |
36 | 1147 * character or "z333<cr>". */ |
1148 if (old_mapped_len > 0) | |
1149 old_mapped_len = typebuf_maplen(); | |
1150 | |
7 | 1151 /* |
1152 * If an operation is pending, handle it... | |
1153 */ | |
1154 do_pending_operator(&ca, old_col, FALSE); | |
1155 | |
1156 /* | |
1157 * Wait for a moment when a message is displayed that will be overwritten | |
1158 * by the mode message. | |
1159 * In Visual mode and with "^O" in Insert mode, a short message will be | |
1160 * overwritten by the mode message. Wait a bit, until a key is hit. | |
1161 * In Visual mode, it's more important to keep the Visual area updated | |
1162 * than keeping a message (e.g. from a /pat search). | |
1163 * Only do this if the command was typed, not from a mapping. | |
1164 * Don't wait when emsg_silent is non-zero. | |
1165 * Also wait a bit after an error message, e.g. for "^O:". | |
1166 * Don't redraw the screen, it would remove the message. | |
1167 */ | |
1168 if ( ((p_smd | |
641 | 1169 && msg_silent == 0 |
7 | 1170 && (restart_edit != 0 |
1171 || (VIsual_active | |
1172 && old_pos.lnum == curwin->w_cursor.lnum | |
1173 && old_pos.col == curwin->w_cursor.col) | |
1174 ) | |
1175 && (clear_cmdline | |
1176 || redraw_cmdline) | |
1177 && (msg_didout || (msg_didany && msg_scroll)) | |
1178 && !msg_nowait | |
1179 && KeyTyped) | |
1180 || (restart_edit != 0 | |
1181 && !VIsual_active | |
1182 && (msg_scroll | |
1183 || emsg_on_display))) | |
1184 && oap->regname == 0 | |
1185 && !(ca.retval & CA_COMMAND_BUSY) | |
1186 && stuff_empty() | |
1187 && typebuf_typed() | |
1188 && emsg_silent == 0 | |
1189 && !did_wait_return | |
1190 && oap->op_type == OP_NOP) | |
1191 { | |
1192 int save_State = State; | |
1193 | |
1194 /* Draw the cursor with the right shape here */ | |
1195 if (restart_edit != 0) | |
1196 State = INSERT; | |
1197 | |
1198 /* If need to redraw, and there is a "keep_msg", redraw before the | |
1199 * delay */ | |
1200 if (must_redraw && keep_msg != NULL && !emsg_on_display) | |
1201 { | |
1202 char_u *kmsg; | |
1203 | |
1204 kmsg = keep_msg; | |
1205 keep_msg = NULL; | |
1206 /* showmode() will clear keep_msg, but we want to use it anyway */ | |
1207 update_screen(0); | |
1208 /* now reset it, otherwise it's put in the history again */ | |
1209 keep_msg = kmsg; | |
1210 msg_attr(kmsg, keep_msg_attr); | |
1211 vim_free(kmsg); | |
1212 } | |
1213 setcursor(); | |
1214 cursor_on(); | |
1215 out_flush(); | |
1216 if (msg_scroll || emsg_on_display) | |
1217 ui_delay(1000L, TRUE); /* wait at least one second */ | |
1218 ui_delay(3000L, FALSE); /* wait up to three seconds */ | |
1219 State = save_State; | |
1220 | |
1221 msg_scroll = FALSE; | |
1222 emsg_on_display = FALSE; | |
1223 } | |
1224 | |
1225 /* | |
1226 * Finish up after executing a Normal mode command. | |
1227 */ | |
1228 normal_end: | |
1229 | |
1230 msg_nowait = FALSE; | |
1231 | |
1232 /* Reset finish_op, in case it was set */ | |
1233 #ifdef CURSOR_SHAPE | |
1234 c = finish_op; | |
1235 #endif | |
1236 finish_op = FALSE; | |
1237 #ifdef CURSOR_SHAPE | |
1238 /* Redraw the cursor with another shape, if we were in Operator-pending | |
1239 * mode or did a replace command. */ | |
1240 if (c || ca.cmdchar == 'r') | |
1241 { | |
1242 ui_cursor_shape(); /* may show different cursor shape */ | |
1243 # ifdef FEAT_MOUSESHAPE | |
1244 update_mouseshape(-1); | |
1245 # endif | |
1246 } | |
1247 #endif | |
1248 | |
1249 #ifdef FEAT_CMDL_INFO | |
1692 | 1250 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
|
1251 && ca.cmdchar != K_CURSORHOLD) |
7 | 1252 clear_showcmd(); |
1253 #endif | |
1254 | |
1255 checkpcmark(); /* check if we moved since setting pcmark */ | |
1256 vim_free(ca.searchbuf); | |
1257 | |
1258 #ifdef FEAT_MBYTE | |
1259 if (has_mbyte) | |
1260 mb_adjust_cursor(); | |
1261 #endif | |
1262 | |
1263 if (curwin->w_p_scb && toplevel) | |
1264 { | |
1265 validate_cursor(); /* may need to update w_leftcol */ | |
1266 do_check_scrollbind(TRUE); | |
1267 } | |
13384
6740c499de13
patch 8.0.1566: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1268 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1269 if (curwin->w_p_crb && toplevel) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1270 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1271 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
|
1272 do_check_cursorbind(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1273 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1274 |
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
|
1275 #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
|
1276 /* 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
|
1277 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
|
1278 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
|
1279 #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
|
1280 |
7 | 1281 /* |
1282 * May restart edit(), if we got here with CTRL-O in Insert mode (but not | |
1283 * if still inside a mapping that started in Visual mode). | |
1284 * May switch from Visual to Select mode after CTRL-O command. | |
1285 */ | |
1286 if ( oap->op_type == OP_NOP | |
1287 && ((restart_edit != 0 && !VIsual_active && old_mapped_len == 0) | |
1288 || restart_VIsual_select == 1) | |
1289 && !(ca.retval & CA_COMMAND_BUSY) | |
1290 && stuff_empty() | |
1291 && oap->regname == 0) | |
1292 { | |
1293 if (restart_VIsual_select == 1) | |
1294 { | |
1295 VIsual_select = TRUE; | |
1296 showmode(); | |
1297 restart_VIsual_select = 0; | |
1298 } | |
5735 | 1299 if (restart_edit != 0 && !VIsual_active && old_mapped_len == 0) |
7 | 1300 (void)edit(restart_edit, FALSE, 1L); |
1301 } | |
1302 | |
1303 if (restart_VIsual_select == 2) | |
1304 restart_VIsual_select = 1; | |
1305 | |
1306 /* Save count before an operator for next time. */ | |
1307 opcount = ca.opcount; | |
1308 } | |
1309 | |
2667 | 1310 #ifdef FEAT_EVAL |
1311 /* | |
1312 * Set v:count and v:count1 according to "cap". | |
1313 * Set v:prevcount only when "set_prevcount" is TRUE. | |
1314 */ | |
1315 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1316 set_vcount_ca(cmdarg_T *cap, int *set_prevcount) |
2667 | 1317 { |
1318 long count = cap->count0; | |
1319 | |
1320 /* multiply with cap->opcount the same way as above */ | |
1321 if (cap->opcount != 0) | |
1322 count = cap->opcount * (count == 0 ? 1 : count); | |
1323 set_vcount(count, count == 0 ? 1 : count, *set_prevcount); | |
1324 *set_prevcount = FALSE; /* only set v:prevcount once */ | |
1325 } | |
1326 #endif | |
1327 | |
7 | 1328 /* |
15357
15e6f35b4223
patch 8.1.0686: when 'y' is in 'cpoptions' yanking for the clipboard changes redo
Bram Moolenaar <Bram@vim.org>
parents:
15279
diff
changeset
|
1329 * Handle an operator after Visual mode or when the movement is finished. |
15e6f35b4223
patch 8.1.0686: when 'y' is in 'cpoptions' yanking for the clipboard changes redo
Bram Moolenaar <Bram@vim.org>
parents:
15279
diff
changeset
|
1330 * "gui_yank" is true when yanking text for the clipboard. |
7 | 1331 */ |
1332 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1333 do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank) |
7 | 1334 { |
1335 oparg_T *oap = cap->oap; | |
1336 pos_T old_cursor; | |
1337 int empty_region_error; | |
1338 int restart_edit_save; | |
6266 | 1339 #ifdef FEAT_LINEBREAK |
1340 int lbr_saved = curwin->w_p_lbr; | |
1341 #endif | |
7 | 1342 |
1343 /* The visual area is remembered for redo */ | |
1344 static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ | |
1345 static linenr_T redo_VIsual_line_count; /* number of lines */ | |
3125 | 1346 static colnr_T redo_VIsual_vcol; /* number of cols or end column */ |
7 | 1347 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
|
1348 static int redo_VIsual_arg; /* extra argument */ |
5735 | 1349 #ifdef FEAT_VIRTUALEDIT |
7 | 1350 int include_line_break = FALSE; |
1351 #endif | |
1352 | |
1353 #if defined(FEAT_CLIPBOARD) | |
1354 /* | |
1355 * Yank the visual area into the GUI selection register before we operate | |
1356 * on it and lose it forever. | |
1357 * Don't do it if a specific register was specified, so that ""x"*P works. | |
1358 * This could call do_pending_operator() recursively, but that's OK | |
1359 * because gui_yank will be TRUE for the nested call. | |
1360 */ | |
3674 | 1361 if ((clip_star.available || clip_plus.available) |
7 | 1362 && oap->op_type != OP_NOP |
1363 && !gui_yank | |
1364 && VIsual_active | |
1365 && !redo_VIsual_busy | |
1366 && oap->regname == 0) | |
1367 clip_auto_select(); | |
1368 #endif | |
1369 old_cursor = curwin->w_cursor; | |
1370 | |
1371 /* | |
1372 * If an operation is pending, handle it... | |
1373 */ | |
5735 | 1374 if ((finish_op || VIsual_active) && oap->op_type != OP_NOP) |
1375 { | |
15357
15e6f35b4223
patch 8.1.0686: when 'y' is in 'cpoptions' yanking for the clipboard changes redo
Bram Moolenaar <Bram@vim.org>
parents:
15279
diff
changeset
|
1376 // Yank can be redone when 'y' is in 'cpoptions', but not when yanking |
15e6f35b4223
patch 8.1.0686: when 'y' is in 'cpoptions' yanking for the clipboard changes redo
Bram Moolenaar <Bram@vim.org>
parents:
15279
diff
changeset
|
1377 // for the clipboard. |
15e6f35b4223
patch 8.1.0686: when 'y' is in 'cpoptions' yanking for the clipboard changes redo
Bram Moolenaar <Bram@vim.org>
parents:
15279
diff
changeset
|
1378 int redo_yank = vim_strchr(p_cpo, CPO_YANK) != NULL && !gui_yank; |
15e6f35b4223
patch 8.1.0686: when 'y' is in 'cpoptions' yanking for the clipboard changes redo
Bram Moolenaar <Bram@vim.org>
parents:
15279
diff
changeset
|
1379 |
6497 | 1380 #ifdef FEAT_LINEBREAK |
1381 /* Avoid a problem with unwanted linebreaks in block mode. */ | |
6866 | 1382 if (curwin->w_p_lbr) |
1383 curwin->w_valid &= ~VALID_VIRTCOL; | |
6497 | 1384 curwin->w_p_lbr = FALSE; |
1385 #endif | |
7 | 1386 oap->is_VIsual = VIsual_active; |
1387 if (oap->motion_force == 'V') | |
1388 oap->motion_type = MLINE; | |
1389 else if (oap->motion_force == 'v') | |
1390 { | |
1391 /* If the motion was linewise, "inclusive" will not have been set. | |
1392 * Use "exclusive" to be consistent. Makes "dvj" work nice. */ | |
1393 if (oap->motion_type == MLINE) | |
1394 oap->inclusive = FALSE; | |
1395 /* If the motion already was characterwise, toggle "inclusive" */ | |
1396 else if (oap->motion_type == MCHAR) | |
1397 oap->inclusive = !oap->inclusive; | |
1398 oap->motion_type = MCHAR; | |
1399 } | |
1400 else if (oap->motion_force == Ctrl_V) | |
1401 { | |
1402 /* Change line- or characterwise motion into Visual block mode. */ | |
15279
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1403 if (!VIsual_active) |
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1404 { |
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1405 VIsual_active = TRUE; |
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1406 VIsual = oap->start; |
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1407 } |
7 | 1408 VIsual_mode = Ctrl_V; |
1409 VIsual_select = FALSE; | |
1410 VIsual_reselect = FALSE; | |
1411 } | |
1412 | |
4337 | 1413 /* Only redo yank when 'y' flag is in 'cpoptions'. */ |
1414 /* Never redo "zf" (define fold). */ | |
15357
15e6f35b4223
patch 8.1.0686: when 'y' is in 'cpoptions' yanking for the clipboard changes redo
Bram Moolenaar <Bram@vim.org>
parents:
15279
diff
changeset
|
1415 if ((redo_yank || oap->op_type != OP_YANK) |
4337 | 1416 && ((!VIsual_active || oap->motion_force) |
1417 /* Also redo Operator-pending Visual mode mappings */ | |
1418 || (VIsual_active && cap->cmdchar == ':' | |
1419 && oap->op_type != OP_COLON)) | |
164 | 1420 && cap->cmdchar != 'D' |
7 | 1421 #ifdef FEAT_FOLDING |
1422 && oap->op_type != OP_FOLD | |
1423 && oap->op_type != OP_FOLDOPEN | |
1424 && oap->op_type != OP_FOLDOPENREC | |
1425 && oap->op_type != OP_FOLDCLOSE | |
1426 && oap->op_type != OP_FOLDCLOSEREC | |
1427 && oap->op_type != OP_FOLDDEL | |
1428 && oap->op_type != OP_FOLDDELREC | |
1429 #endif | |
1430 ) | |
1431 { | |
1432 prep_redo(oap->regname, cap->count0, | |
1433 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1434 oap->motion_force, cap->cmdchar, cap->nchar); | |
1435 if (cap->cmdchar == '/' || cap->cmdchar == '?') /* was a search */ | |
1436 { | |
1437 /* | |
1438 * If 'cpoptions' does not contain 'r', insert the search | |
1439 * pattern to really repeat the same command. | |
1440 */ | |
1441 if (vim_strchr(p_cpo, CPO_REDO) == NULL) | |
620 | 1442 AppendToRedobuffLit(cap->searchbuf, -1); |
7 | 1443 AppendToRedobuff(NL_STR); |
1444 } | |
1445 else if (cap->cmdchar == ':') | |
1446 { | |
1447 /* do_cmdline() has stored the first typed line in | |
1448 * "repeat_cmdline". When several lines are typed repeating | |
1449 * won't be possible. */ | |
1450 if (repeat_cmdline == NULL) | |
1451 ResetRedobuff(); | |
1452 else | |
1453 { | |
620 | 1454 AppendToRedobuffLit(repeat_cmdline, -1); |
7 | 1455 AppendToRedobuff(NL_STR); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
1456 VIM_CLEAR(repeat_cmdline); |
7 | 1457 } |
1458 } | |
1459 } | |
1460 | |
1461 if (redo_VIsual_busy) | |
1462 { | |
3125 | 1463 /* Redo of an operation on a Visual area. Use the same size from |
1464 * redo_VIsual_line_count and redo_VIsual_vcol. */ | |
7 | 1465 oap->start = curwin->w_cursor; |
1466 curwin->w_cursor.lnum += redo_VIsual_line_count - 1; | |
1467 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
1468 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
1469 VIsual_mode = redo_VIsual_mode; | |
3125 | 1470 if (redo_VIsual_vcol == MAXCOL || VIsual_mode == 'v') |
7 | 1471 { |
3125 | 1472 if (VIsual_mode == 'v') |
1473 { | |
1474 if (redo_VIsual_line_count <= 1) | |
1475 { | |
1476 validate_virtcol(); | |
1477 curwin->w_curswant = | |
1478 curwin->w_virtcol + redo_VIsual_vcol - 1; | |
1479 } | |
1480 else | |
1481 curwin->w_curswant = redo_VIsual_vcol; | |
1482 } | |
7 | 1483 else |
3125 | 1484 { |
1485 curwin->w_curswant = MAXCOL; | |
1486 } | |
1487 coladvance(curwin->w_curswant); | |
7 | 1488 } |
1489 cap->count0 = redo_VIsual_count; | |
1490 if (redo_VIsual_count != 0) | |
1491 cap->count1 = redo_VIsual_count; | |
1492 else | |
1493 cap->count1 = 1; | |
1494 } | |
1495 else if (VIsual_active) | |
1496 { | |
999 | 1497 if (!gui_yank) |
1498 { | |
1499 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
1500 curbuf->b_visual.vi_start = VIsual; | |
1501 curbuf->b_visual.vi_end = curwin->w_cursor; | |
1502 curbuf->b_visual.vi_mode = VIsual_mode; | |
4213 | 1503 if (VIsual_mode_orig != NUL) |
1504 { | |
1505 curbuf->b_visual.vi_mode = VIsual_mode_orig; | |
1506 VIsual_mode_orig = NUL; | |
1507 } | |
999 | 1508 curbuf->b_visual.vi_curswant = curwin->w_curswant; |
7 | 1509 # ifdef FEAT_EVAL |
999 | 1510 curbuf->b_visual_mode_eval = VIsual_mode; |
7 | 1511 # endif |
999 | 1512 } |
7 | 1513 |
1514 /* In Select mode, a linewise selection is operated upon like a | |
6826 | 1515 * characterwise selection. |
1516 * Special case: gH<Del> deletes the last line. */ | |
1517 if (VIsual_select && VIsual_mode == 'V' | |
1518 && cap->oap->op_type != OP_DELETE) | |
7 | 1519 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1520 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 1521 { |
1522 VIsual.col = 0; | |
1523 curwin->w_cursor.col = | |
1524 (colnr_T)STRLEN(ml_get(curwin->w_cursor.lnum)); | |
1525 } | |
1526 else | |
1527 { | |
1528 curwin->w_cursor.col = 0; | |
1529 VIsual.col = (colnr_T)STRLEN(ml_get(VIsual.lnum)); | |
1530 } | |
1531 VIsual_mode = 'v'; | |
1532 } | |
1533 /* If 'selection' is "exclusive", backup one character for | |
1534 * charwise selections. */ | |
1535 else if (VIsual_mode == 'v') | |
1536 { | |
1537 # ifdef FEAT_VIRTUALEDIT | |
1538 include_line_break = | |
1539 # endif | |
1540 unadjust_for_sel(); | |
1541 } | |
1542 | |
1543 oap->start = VIsual; | |
1544 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
|
1545 { |
7 | 1546 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
|
1547 # ifdef FEAT_VIRTUALEDIT |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1548 oap->start.coladd = 0; |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1549 # endif |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1550 } |
7 | 1551 } |
1552 | |
1553 /* | |
1554 * Set oap->start to the first position of the operated text, oap->end | |
1555 * to the end of the operated text. w_cursor is equal to oap->start. | |
1556 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1557 if (LT_POS(oap->start, curwin->w_cursor)) |
7 | 1558 { |
1559 #ifdef FEAT_FOLDING | |
1560 /* Include folded lines completely. */ | |
1561 if (!VIsual_active) | |
1562 { | |
1563 if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL)) | |
1564 oap->start.col = 0; | |
1565 if (hasFolding(curwin->w_cursor.lnum, NULL, | |
1566 &curwin->w_cursor.lnum)) | |
1567 curwin->w_cursor.col = (colnr_T)STRLEN(ml_get_curline()); | |
1568 } | |
1569 #endif | |
1570 oap->end = curwin->w_cursor; | |
1571 curwin->w_cursor = oap->start; | |
1572 | |
1573 /* w_virtcol may have been updated; if the cursor goes back to its | |
1574 * previous position w_virtcol becomes invalid and isn't updated | |
1575 * automatically. */ | |
1576 curwin->w_valid &= ~VALID_VIRTCOL; | |
1577 } | |
1578 else | |
1579 { | |
1580 #ifdef FEAT_FOLDING | |
1581 /* Include folded lines completely. */ | |
1582 if (!VIsual_active && oap->motion_type == MLINE) | |
1583 { | |
1584 if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, | |
1585 NULL)) | |
1586 curwin->w_cursor.col = 0; | |
1587 if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) | |
1588 oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum)); | |
1589 } | |
1590 #endif | |
1591 oap->end = oap->start; | |
1592 oap->start = curwin->w_cursor; | |
1593 } | |
1594 | |
10154
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10110
diff
changeset
|
1595 /* 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
|
1596 check_pos(curwin->w_buffer, &oap->end); |
7 | 1597 oap->line_count = oap->end.lnum - oap->start.lnum + 1; |
1598 | |
1599 #ifdef FEAT_VIRTUALEDIT | |
1600 /* Set "virtual_op" before resetting VIsual_active. */ | |
1601 virtual_op = virtual_active(); | |
1602 #endif | |
1603 | |
1604 if (VIsual_active || redo_VIsual_busy) | |
1605 { | |
6866 | 1606 get_op_vcol(oap, redo_VIsual_vcol, TRUE); |
7 | 1607 |
1608 if (!redo_VIsual_busy && !gui_yank) | |
1609 { | |
1610 /* | |
1611 * Prepare to reselect and redo Visual: this is based on the | |
1612 * size of the Visual text | |
1613 */ | |
1614 resel_VIsual_mode = VIsual_mode; | |
1615 if (curwin->w_curswant == MAXCOL) | |
3125 | 1616 resel_VIsual_vcol = MAXCOL; |
7 | 1617 else |
3125 | 1618 { |
1619 if (VIsual_mode != Ctrl_V) | |
1620 getvvcol(curwin, &(oap->end), | |
1621 NULL, NULL, &oap->end_vcol); | |
1622 if (VIsual_mode == Ctrl_V || oap->line_count <= 1) | |
1623 { | |
1624 if (VIsual_mode != Ctrl_V) | |
1625 getvvcol(curwin, &(oap->start), | |
1626 &oap->start_vcol, NULL, NULL); | |
1627 resel_VIsual_vcol = oap->end_vcol - oap->start_vcol + 1; | |
1628 } | |
1629 else | |
1630 resel_VIsual_vcol = oap->end_vcol; | |
1631 } | |
7 | 1632 resel_VIsual_line_count = oap->line_count; |
1633 } | |
1634 | |
1635 /* can't redo yank (unless 'y' is in 'cpoptions') and ":" */ | |
15357
15e6f35b4223
patch 8.1.0686: when 'y' is in 'cpoptions' yanking for the clipboard changes redo
Bram Moolenaar <Bram@vim.org>
parents:
15279
diff
changeset
|
1636 if ((redo_yank || oap->op_type != OP_YANK) |
7 | 1637 && oap->op_type != OP_COLON |
1638 #ifdef FEAT_FOLDING | |
1639 && oap->op_type != OP_FOLD | |
1640 && oap->op_type != OP_FOLDOPEN | |
1641 && oap->op_type != OP_FOLDOPENREC | |
1642 && oap->op_type != OP_FOLDCLOSE | |
1643 && oap->op_type != OP_FOLDCLOSEREC | |
1644 && oap->op_type != OP_FOLDDEL | |
1645 && oap->op_type != OP_FOLDDELREC | |
1646 #endif | |
1647 && oap->motion_force == NUL | |
1648 ) | |
1649 { | |
1650 /* Prepare for redoing. Only use the nchar field for "r", | |
1651 * otherwise it might be the second char of the operator. */ | |
3701 | 1652 if (cap->cmdchar == 'g' && (cap->nchar == 'n' |
1653 || cap->nchar == 'N')) | |
5523 | 1654 prep_redo(oap->regname, cap->count0, |
1655 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1656 oap->motion_force, cap->cmdchar, cap->nchar); | |
4337 | 1657 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
|
1658 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1659 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
|
1660 |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1661 /* 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
|
1662 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
|
1663 nchar = CAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1664 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
|
1665 nchar = NL; |
3701 | 1666 prep_redo(oap->regname, 0L, NUL, 'v', |
1667 get_op_char(oap->op_type), | |
1668 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
|
1669 nchar); |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1670 } |
7 | 1671 if (!redo_VIsual_busy) |
1672 { | |
1673 redo_VIsual_mode = resel_VIsual_mode; | |
3125 | 1674 redo_VIsual_vcol = resel_VIsual_vcol; |
7 | 1675 redo_VIsual_line_count = resel_VIsual_line_count; |
1676 redo_VIsual_count = cap->count0; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
1677 redo_VIsual_arg = cap->arg; |
7 | 1678 } |
1679 } | |
1680 | |
1681 /* | |
1682 * oap->inclusive defaults to TRUE. | |
1683 * If oap->end is on a NUL (empty line) oap->inclusive becomes | |
1684 * FALSE. This makes "d}P" and "v}dP" work the same. | |
1685 */ | |
1686 if (oap->motion_force == NUL || oap->motion_type == MLINE) | |
1687 oap->inclusive = TRUE; | |
1688 if (VIsual_mode == 'V') | |
1689 oap->motion_type = MLINE; | |
1690 else | |
1691 { | |
1692 oap->motion_type = MCHAR; | |
1693 if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL | |
5735 | 1694 #ifdef FEAT_VIRTUALEDIT |
7 | 1695 && (include_line_break || !virtual_op) |
5735 | 1696 #endif |
7 | 1697 ) |
1698 { | |
1699 oap->inclusive = FALSE; | |
1700 /* Try to include the newline, unless it's an operator | |
2957 | 1701 * that works on lines only. */ |
6826 | 1702 if (*p_sel != 'o' |
1703 && !op_on_lines(oap->op_type) | |
1704 && oap->end.lnum < curbuf->b_ml.ml_line_count) | |
7 | 1705 { |
6826 | 1706 ++oap->end.lnum; |
1707 oap->end.col = 0; | |
5735 | 1708 #ifdef FEAT_VIRTUALEDIT |
6826 | 1709 oap->end.coladd = 0; |
1710 #endif | |
1711 ++oap->line_count; | |
7 | 1712 } |
1713 } | |
1714 } | |
1715 | |
1716 redo_VIsual_busy = FALSE; | |
592 | 1717 |
7 | 1718 /* |
1719 * Switch Visual off now, so screen updating does | |
1720 * not show inverted text when the screen is redrawn. | |
1721 * With OP_YANK and sometimes with OP_COLON and OP_FILTER there is | |
1722 * no screen redraw, so it is done here to remove the inverted | |
1723 * part. | |
1724 */ | |
1725 if (!gui_yank) | |
1726 { | |
1727 VIsual_active = FALSE; | |
5735 | 1728 #ifdef FEAT_MOUSE |
7 | 1729 setmouse(); |
1730 mouse_dragging = 0; | |
5735 | 1731 #endif |
6979 | 1732 may_clear_cmdline(); |
7 | 1733 if ((oap->op_type == OP_YANK |
1734 || oap->op_type == OP_COLON | |
592 | 1735 || oap->op_type == OP_FUNCTION |
7 | 1736 || oap->op_type == OP_FILTER) |
1737 && oap->motion_force == NUL) | |
6497 | 1738 { |
1739 #ifdef FEAT_LINEBREAK | |
1740 /* make sure redrawing is correct */ | |
1741 curwin->w_p_lbr = lbr_saved; | |
1742 #endif | |
7 | 1743 redraw_curbuf_later(INVERTED); |
6497 | 1744 } |
7 | 1745 } |
1746 } | |
1747 | |
1748 #ifdef FEAT_MBYTE | |
1749 /* Include the trailing byte of a multi-byte char. */ | |
1750 if (has_mbyte && oap->inclusive) | |
1751 { | |
1752 int l; | |
1753 | |
474 | 1754 l = (*mb_ptr2len)(ml_get_pos(&oap->end)); |
7 | 1755 if (l > 1) |
1756 oap->end.col += l - 1; | |
1757 } | |
1758 #endif | |
1759 curwin->w_set_curswant = TRUE; | |
1760 | |
1761 /* | |
1762 * oap->empty is set when start and end are the same. The inclusive | |
1763 * flag affects this too, unless yanking and the end is on a NUL. | |
1764 */ | |
1765 oap->empty = (oap->motion_type == MCHAR | |
1766 && (!oap->inclusive | |
1767 || (oap->op_type == OP_YANK | |
1768 && 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
|
1769 && EQUAL_POS(oap->start, oap->end) |
7 | 1770 #ifdef FEAT_VIRTUALEDIT |
1771 && !(virtual_op && oap->start.coladd != oap->end.coladd) | |
1772 #endif | |
1773 ); | |
1774 /* | |
1775 * For delete, change and yank, it's an error to operate on an | |
1776 * empty region, when 'E' included in 'cpoptions' (Vi compatible). | |
1777 */ | |
1778 empty_region_error = (oap->empty | |
1779 && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL); | |
1780 | |
1781 /* Force a redraw when operating on an empty Visual region, when | |
1782 * 'modifiable is off or creating a fold. */ | |
1783 if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma | |
5735 | 1784 #ifdef FEAT_FOLDING |
7 | 1785 || oap->op_type == OP_FOLD |
5735 | 1786 #endif |
7 | 1787 )) |
6497 | 1788 { |
1789 #ifdef FEAT_LINEBREAK | |
1790 curwin->w_p_lbr = lbr_saved; | |
1791 #endif | |
7 | 1792 redraw_curbuf_later(INVERTED); |
6497 | 1793 } |
7 | 1794 |
1795 /* | |
1796 * If the end of an operator is in column one while oap->motion_type | |
1797 * is MCHAR and oap->inclusive is FALSE, we put op_end after the last | |
1798 * character in the previous line. If op_start is on or before the | |
1799 * first non-blank in the line, the operator becomes linewise | |
1800 * (strange, but that's the way vi does it). | |
1801 */ | |
1802 if ( oap->motion_type == MCHAR | |
1803 && oap->inclusive == FALSE | |
1804 && !(cap->retval & CA_NO_ADJ_OP_END) | |
1805 && oap->end.col == 0 | |
1806 && (!oap->is_VIsual || *p_sel == 'o') | |
47 | 1807 && !oap->block_mode |
7 | 1808 && oap->line_count > 1) |
1809 { | |
1810 oap->end_adjusted = TRUE; /* remember that we did this */ | |
1811 --oap->line_count; | |
1812 --oap->end.lnum; | |
1813 if (inindent(0)) | |
1814 oap->motion_type = MLINE; | |
1815 else | |
1816 { | |
1817 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
1818 if (oap->end.col) | |
1819 { | |
1820 --oap->end.col; | |
1821 oap->inclusive = TRUE; | |
1822 } | |
1823 } | |
1824 } | |
1825 else | |
1826 oap->end_adjusted = FALSE; | |
1827 | |
1828 switch (oap->op_type) | |
1829 { | |
1830 case OP_LSHIFT: | |
1831 case OP_RSHIFT: | |
5735 | 1832 op_shift(oap, TRUE, oap->is_VIsual ? (int)cap->count1 : 1); |
7 | 1833 auto_format(FALSE, TRUE); |
1834 break; | |
1835 | |
1836 case OP_JOIN_NS: | |
1837 case OP_JOIN: | |
1838 if (oap->line_count < 2) | |
1839 oap->line_count = 2; | |
1840 if (curwin->w_cursor.lnum + oap->line_count - 1 > | |
1841 curbuf->b_ml.ml_line_count) | |
1842 beep_flush(); | |
1843 else | |
1844 { | |
5735 | 1845 (void)do_join(oap->line_count, oap->op_type == OP_JOIN, |
5848 | 1846 TRUE, TRUE, TRUE); |
7 | 1847 auto_format(FALSE, TRUE); |
1848 } | |
1849 break; | |
1850 | |
1851 case OP_DELETE: | |
1852 VIsual_reselect = FALSE; /* don't reselect now */ | |
1853 if (empty_region_error) | |
3324 | 1854 { |
6949 | 1855 vim_beep(BO_OPER); |
3324 | 1856 CancelRedo(); |
1857 } | |
7 | 1858 else |
1859 { | |
1860 (void)op_delete(oap); | |
1861 if (oap->motion_type == MLINE && has_format_option(FO_AUTO)) | |
1862 u_save_cursor(); /* cursor line wasn't saved yet */ | |
1863 auto_format(FALSE, TRUE); | |
1864 } | |
1865 break; | |
1866 | |
1867 case OP_YANK: | |
1868 if (empty_region_error) | |
1869 { | |
1870 if (!gui_yank) | |
3324 | 1871 { |
6949 | 1872 vim_beep(BO_OPER); |
3324 | 1873 CancelRedo(); |
1874 } | |
7 | 1875 } |
1876 else | |
6497 | 1877 { |
1878 #ifdef FEAT_LINEBREAK | |
1879 curwin->w_p_lbr = lbr_saved; | |
1880 #endif | |
7 | 1881 (void)op_yank(oap, FALSE, !gui_yank); |
6497 | 1882 } |
7 | 1883 check_cursor_col(); |
1884 break; | |
1885 | |
1886 case OP_CHANGE: | |
1887 VIsual_reselect = FALSE; /* don't reselect now */ | |
1888 if (empty_region_error) | |
3324 | 1889 { |
6949 | 1890 vim_beep(BO_OPER); |
3324 | 1891 CancelRedo(); |
1892 } | |
7 | 1893 else |
1894 { | |
1895 /* This is a new edit command, not a restart. Need to | |
1896 * remember it to make 'insertmode' work with mappings for | |
1897 * Visual mode. But do this only once and not when typed and | |
1898 * 'insertmode' isn't set. */ | |
1899 if (p_im || !KeyTyped) | |
1900 restart_edit_save = restart_edit; | |
1901 else | |
1902 restart_edit_save = 0; | |
1903 restart_edit = 0; | |
6497 | 1904 #ifdef FEAT_LINEBREAK |
1905 /* Restore linebreak, so that when the user edits it looks as | |
1906 * before. */ | |
6866 | 1907 if (curwin->w_p_lbr != lbr_saved) |
1908 { | |
1909 curwin->w_p_lbr = lbr_saved; | |
1910 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
1911 } | |
6497 | 1912 #endif |
7 | 1913 /* Reset finish_op now, don't want it set inside edit(). */ |
1914 finish_op = FALSE; | |
1915 if (op_change(oap)) /* will call edit() */ | |
1916 cap->retval |= CA_COMMAND_BUSY; | |
1917 if (restart_edit == 0) | |
1918 restart_edit = restart_edit_save; | |
1919 } | |
1920 break; | |
1921 | |
1922 case OP_FILTER: | |
1923 if (vim_strchr(p_cpo, CPO_FILTER) != NULL) | |
1924 AppendToRedobuff((char_u *)"!\r"); /* use any last used !cmd */ | |
1925 else | |
1926 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
|
1927 /* FALLTHROUGH */ |
7 | 1928 |
1929 case OP_INDENT: | |
1930 case OP_COLON: | |
1931 | |
1932 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
1933 /* | |
1934 * If 'equalprg' is empty, do the indenting internally. | |
1935 */ | |
1936 if (oap->op_type == OP_INDENT && *get_equalprg() == NUL) | |
1937 { | |
1938 # ifdef FEAT_LISP | |
1939 if (curbuf->b_p_lisp) | |
1940 { | |
1941 op_reindent(oap, get_lisp_indent); | |
1942 break; | |
1943 } | |
1944 # endif | |
1945 # ifdef FEAT_CINDENT | |
1946 op_reindent(oap, | |
1947 # ifdef FEAT_EVAL | |
1948 *curbuf->b_p_inde != NUL ? get_expr_indent : | |
1949 # endif | |
1950 get_c_indent); | |
1951 break; | |
1952 # endif | |
1953 } | |
1954 #endif | |
1955 | |
1956 op_colon(oap); | |
1957 break; | |
1958 | |
1959 case OP_TILDE: | |
1960 case OP_UPPER: | |
1961 case OP_LOWER: | |
1962 case OP_ROT13: | |
1963 if (empty_region_error) | |
3324 | 1964 { |
6949 | 1965 vim_beep(BO_OPER); |
3324 | 1966 CancelRedo(); |
1967 } | |
7 | 1968 else |
1969 op_tilde(oap); | |
1970 check_cursor_col(); | |
1971 break; | |
1972 | |
1973 case OP_FORMAT: | |
667 | 1974 #if defined(FEAT_EVAL) |
1975 if (*curbuf->b_p_fex != NUL) | |
1976 op_formatexpr(oap); /* use expression */ | |
1977 else | |
1978 #endif | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
1979 if (*p_fp != NUL || *curbuf->b_p_fp != NUL) |
7 | 1980 op_colon(oap); /* use external command */ |
1981 else | |
1982 op_format(oap, FALSE); /* use internal function */ | |
1983 break; | |
1984 | |
1985 case OP_FORMAT2: | |
1986 op_format(oap, TRUE); /* use internal function */ | |
1987 break; | |
1988 | |
592 | 1989 case OP_FUNCTION: |
10342
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1990 #ifdef FEAT_LINEBREAK |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1991 /* 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
|
1992 * before. */ |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1993 curwin->w_p_lbr = lbr_saved; |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1994 #endif |
592 | 1995 op_function(oap); /* call 'operatorfunc' */ |
1996 break; | |
1997 | |
7 | 1998 case OP_INSERT: |
1999 case OP_APPEND: | |
2000 VIsual_reselect = FALSE; /* don't reselect now */ | |
2001 if (empty_region_error) | |
3324 | 2002 { |
6949 | 2003 vim_beep(BO_OPER); |
3324 | 2004 CancelRedo(); |
2005 } | |
7 | 2006 else |
2007 { | |
2008 /* This is a new edit command, not a restart. Need to | |
2009 * remember it to make 'insertmode' work with mappings for | |
2010 * Visual mode. But do this only once. */ | |
2011 restart_edit_save = restart_edit; | |
2012 restart_edit = 0; | |
6497 | 2013 #ifdef FEAT_LINEBREAK |
2014 /* Restore linebreak, so that when the user edits it looks as | |
2015 * before. */ | |
6866 | 2016 if (curwin->w_p_lbr != lbr_saved) |
2017 { | |
2018 curwin->w_p_lbr = lbr_saved; | |
2019 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
2020 } | |
6497 | 2021 #endif |
7 | 2022 op_insert(oap, cap->count1); |
6497 | 2023 #ifdef FEAT_LINEBREAK |
2024 /* Reset linebreak, so that formatting works correctly. */ | |
2025 curwin->w_p_lbr = FALSE; | |
2026 #endif | |
7 | 2027 |
2028 /* TODO: when inserting in several lines, should format all | |
2029 * the lines. */ | |
2030 auto_format(FALSE, TRUE); | |
2031 | |
2032 if (restart_edit == 0) | |
2033 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
|
2034 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
|
2035 cap->retval |= CA_COMMAND_BUSY; |
7 | 2036 } |
2037 break; | |
2038 | |
2039 case OP_REPLACE: | |
2040 VIsual_reselect = FALSE; /* don't reselect now */ | |
2041 if (empty_region_error) | |
3324 | 2042 { |
6949 | 2043 vim_beep(BO_OPER); |
3324 | 2044 CancelRedo(); |
2045 } | |
7 | 2046 else |
6497 | 2047 { |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15357
diff
changeset
|
2048 #ifdef FEAT_LINEBREAK |
6497 | 2049 /* Restore linebreak, so that when the user edits it looks as |
2050 * before. */ | |
6866 | 2051 if (curwin->w_p_lbr != lbr_saved) |
2052 { | |
2053 curwin->w_p_lbr = lbr_saved; | |
2054 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
2055 } | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15357
diff
changeset
|
2056 #endif |
7 | 2057 op_replace(oap, cap->nchar); |
6497 | 2058 } |
7 | 2059 break; |
2060 | |
2061 #ifdef FEAT_FOLDING | |
2062 case OP_FOLD: | |
2063 VIsual_reselect = FALSE; /* don't reselect now */ | |
2064 foldCreate(oap->start.lnum, oap->end.lnum); | |
2065 break; | |
2066 | |
2067 case OP_FOLDOPEN: | |
2068 case OP_FOLDOPENREC: | |
2069 case OP_FOLDCLOSE: | |
2070 case OP_FOLDCLOSEREC: | |
2071 VIsual_reselect = FALSE; /* don't reselect now */ | |
2072 opFoldRange(oap->start.lnum, oap->end.lnum, | |
2073 oap->op_type == OP_FOLDOPEN | |
2074 || oap->op_type == OP_FOLDOPENREC, | |
2075 oap->op_type == OP_FOLDOPENREC | |
2076 || oap->op_type == OP_FOLDCLOSEREC, | |
2077 oap->is_VIsual); | |
2078 break; | |
2079 | |
2080 case OP_FOLDDEL: | |
2081 case OP_FOLDDELREC: | |
2082 VIsual_reselect = FALSE; /* don't reselect now */ | |
2083 deleteFold(oap->start.lnum, oap->end.lnum, | |
2084 oap->op_type == OP_FOLDDELREC, oap->is_VIsual); | |
2085 break; | |
2086 #endif | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2087 case OP_NR_ADD: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2088 case OP_NR_SUB: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2089 if (empty_region_error) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2090 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2091 vim_beep(BO_OPER); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2092 CancelRedo(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2093 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2094 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2095 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2096 VIsual_active = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2097 #ifdef FEAT_LINEBREAK |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2098 curwin->w_p_lbr = lbr_saved; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2099 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2100 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
|
2101 VIsual_active = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2102 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2103 check_cursor_col(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2104 break; |
7 | 2105 default: |
2106 clearopbeep(oap); | |
2107 } | |
2108 #ifdef FEAT_VIRTUALEDIT | |
2109 virtual_op = MAYBE; | |
2110 #endif | |
2111 if (!gui_yank) | |
2112 { | |
2113 /* | |
2114 * if 'sol' not set, go back to old column for some commands | |
2115 */ | |
2116 if (!p_sol && oap->motion_type == MLINE && !oap->end_adjusted | |
2117 && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT | |
2118 || oap->op_type == OP_DELETE)) | |
6497 | 2119 { |
2120 #ifdef FEAT_LINEBREAK | |
2121 curwin->w_p_lbr = FALSE; | |
2122 #endif | |
7 | 2123 coladvance(curwin->w_curswant = old_col); |
6497 | 2124 } |
7 | 2125 } |
2126 else | |
2127 { | |
2128 curwin->w_cursor = old_cursor; | |
2129 } | |
2130 oap->block_mode = FALSE; | |
2131 clearop(oap); | |
15279
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
2132 motion_force = NUL; |
7 | 2133 } |
6266 | 2134 #ifdef FEAT_LINEBREAK |
2135 curwin->w_p_lbr = lbr_saved; | |
2136 #endif | |
7 | 2137 } |
2138 | |
2139 /* | |
2140 * Handle indent and format operators and visual mode ":". | |
2141 */ | |
2142 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2143 op_colon(oparg_T *oap) |
7 | 2144 { |
2145 stuffcharReadbuff(':'); | |
2146 if (oap->is_VIsual) | |
2147 stuffReadbuff((char_u *)"'<,'>"); | |
2148 else | |
2149 { | |
2150 /* | |
2151 * Make the range look nice, so it can be repeated. | |
2152 */ | |
2153 if (oap->start.lnum == curwin->w_cursor.lnum) | |
2154 stuffcharReadbuff('.'); | |
2155 else | |
2156 stuffnumReadbuff((long)oap->start.lnum); | |
2157 if (oap->end.lnum != oap->start.lnum) | |
2158 { | |
2159 stuffcharReadbuff(','); | |
2160 if (oap->end.lnum == curwin->w_cursor.lnum) | |
2161 stuffcharReadbuff('.'); | |
2162 else if (oap->end.lnum == curbuf->b_ml.ml_line_count) | |
2163 stuffcharReadbuff('$'); | |
2164 else if (oap->start.lnum == curwin->w_cursor.lnum) | |
2165 { | |
2166 stuffReadbuff((char_u *)".+"); | |
2167 stuffnumReadbuff((long)oap->line_count - 1); | |
2168 } | |
2169 else | |
2170 stuffnumReadbuff((long)oap->end.lnum); | |
2171 } | |
2172 } | |
2173 if (oap->op_type != OP_COLON) | |
2174 stuffReadbuff((char_u *)"!"); | |
2175 if (oap->op_type == OP_INDENT) | |
2176 { | |
2177 #ifndef FEAT_CINDENT | |
2178 if (*get_equalprg() == NUL) | |
2179 stuffReadbuff((char_u *)"indent"); | |
2180 else | |
2181 #endif | |
2182 stuffReadbuff(get_equalprg()); | |
2183 stuffReadbuff((char_u *)"\n"); | |
2184 } | |
2185 else if (oap->op_type == OP_FORMAT) | |
2186 { | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2187 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
|
2188 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
|
2189 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
|
2190 stuffReadbuff(p_fp); |
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2191 else |
7 | 2192 stuffReadbuff((char_u *)"fmt"); |
216 | 2193 stuffReadbuff((char_u *)"\n']"); |
7 | 2194 } |
2195 | |
2196 /* | |
2197 * do_cmdline() does the rest | |
2198 */ | |
2199 } | |
2200 | |
592 | 2201 /* |
602 | 2202 * Handle the "g@" operator: call 'operatorfunc'. |
592 | 2203 */ |
690 | 2204 static void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2205 op_function(oparg_T *oap UNUSED) |
592 | 2206 { |
2207 #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
|
2208 typval_T argv[2]; |
4133 | 2209 # ifdef FEAT_VIRTUALEDIT |
3431 | 2210 int save_virtual_op = virtual_op; |
4133 | 2211 # endif |
592 | 2212 |
2213 if (*p_opfunc == NUL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2214 emsg(_("E774: 'operatorfunc' is empty")); |
592 | 2215 else |
2216 { | |
2217 /* Set '[ and '] marks to text to be operated on. */ | |
2218 curbuf->b_op_start = oap->start; | |
2219 curbuf->b_op_end = oap->end; | |
2220 if (oap->motion_type != MLINE && !oap->inclusive) | |
2221 /* Exclude the end position. */ | |
2222 decl(&curbuf->b_op_end); | |
2223 | |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2224 argv[0].v_type = VAR_STRING; |
592 | 2225 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
|
2226 argv[0].vval.v_string = (char_u *)"block"; |
592 | 2227 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
|
2228 argv[0].vval.v_string = (char_u *)"line"; |
592 | 2229 else |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2230 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
|
2231 argv[1].v_type = VAR_UNKNOWN; |
3431 | 2232 |
4133 | 2233 # ifdef FEAT_VIRTUALEDIT |
3431 | 2234 /* Reset virtual_op so that 'virtualedit' can be changed in the |
2235 * function. */ | |
2236 virtual_op = MAYBE; | |
4133 | 2237 # endif |
3431 | 2238 |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
2239 (void)call_func_retnr(p_opfunc, 1, argv); |
3431 | 2240 |
4133 | 2241 # ifdef FEAT_VIRTUALEDIT |
3431 | 2242 virtual_op = save_virtual_op; |
4133 | 2243 # endif |
592 | 2244 } |
2245 #else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2246 emsg(_("E775: Eval feature not available")); |
592 | 2247 #endif |
2248 } | |
2249 | |
7 | 2250 #if defined(FEAT_MOUSE) || defined(PROTO) |
2251 /* | |
2252 * Do the appropriate action for the current mouse click in the current mode. | |
2253 * Not used for Command-line mode. | |
2254 * | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2255 * Normal and Visual Mode: |
7 | 2256 * event modi- position visual change action |
2257 * fier cursor window | |
2258 * left press - yes end yes | |
2259 * 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
|
2260 * left press S yes end (popup: extend) yes "*" (2) |
7 | 2261 * left drag - yes start if moved no |
2262 * left relse - yes start if moved no | |
2263 * middle press - yes if not active no put register | |
2264 * middle press - yes if active no yank and put | |
2265 * right press - yes start or extend yes | |
2266 * right press S yes no change yes "#" (2) | |
2267 * right drag - yes extend no | |
2268 * right relse - yes extend no | |
2269 * | |
2270 * Insert or Replace Mode: | |
2271 * event modi- position visual change action | |
2272 * fier cursor window | |
2273 * left press - yes (cannot be active) yes | |
2274 * left press C yes (cannot be active) yes "CTRL-O^]" (2) | |
2275 * left press S yes (cannot be active) yes "CTRL-O*" (2) | |
2276 * left drag - yes start or extend (1) no CTRL-O (1) | |
2277 * left relse - yes start or extend (1) no CTRL-O (1) | |
2278 * middle press - no (cannot be active) no put register | |
2279 * right press - yes start or extend yes CTRL-O | |
2280 * right press S yes (cannot be active) yes "CTRL-O#" (2) | |
2281 * | |
2282 * (1) only if mouse pointer moved since press | |
2283 * (2) only if click is in same buffer | |
2284 * | |
2285 * Return TRUE if start_arrow() should be called for edit mode. | |
2286 */ | |
2287 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2288 do_mouse( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2289 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
|
2290 int c, /* K_LEFTMOUSE, etc */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2291 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
|
2292 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2293 int fixindent) /* PUT_FIXINDENT if fixing indent necessary */ |
7 | 2294 { |
2295 static int do_always = FALSE; /* ignore 'mouse' setting next time */ | |
2296 static int got_click = FALSE; /* got a click some time back */ | |
2297 | |
2298 int which_button; /* MOUSE_LEFT, _MIDDLE or _RIGHT */ | |
2299 int is_click; /* If FALSE it's a drag or release event */ | |
2300 int is_drag; /* If TRUE it's a drag event */ | |
2301 int jump_flags = 0; /* flags for jump_to_mouse() */ | |
2302 pos_T start_visual; | |
2303 int moved; /* Has cursor moved? */ | |
2304 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
|
2305 static int in_tab_line = FALSE; /* mouse clicked in tab line */ |
7 | 2306 int in_sep_line; /* mouse in vertical separator line */ |
2307 int c1, c2; | |
2308 #if defined(FEAT_FOLDING) | |
2309 pos_T save_cursor; | |
2310 #endif | |
2311 win_T *old_curwin = curwin; | |
2312 static pos_T orig_cursor; | |
2313 colnr_T leftcol, rightcol; | |
2314 pos_T end_visual; | |
2315 int diff; | |
2316 int old_active = VIsual_active; | |
2317 int old_mode = VIsual_mode; | |
2318 int regname; | |
2319 | |
2320 #if defined(FEAT_FOLDING) | |
2321 save_cursor = curwin->w_cursor; | |
2322 #endif | |
2323 | |
2324 /* | |
2325 * When GUI is active, always recognize mouse events, otherwise: | |
2326 * - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'. | |
2327 * - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'. | |
2328 * - For command line and insert mode 'mouse' is checked before calling | |
2329 * do_mouse(). | |
2330 */ | |
2331 if (do_always) | |
2332 do_always = FALSE; | |
2333 else | |
2334 #ifdef FEAT_GUI | |
2335 if (!gui.in_use) | |
2336 #endif | |
2337 { | |
2338 if (VIsual_active) | |
2339 { | |
2340 if (!mouse_has(MOUSE_VISUAL)) | |
2341 return FALSE; | |
2342 } | |
5735 | 2343 else if (State == NORMAL && !mouse_has(MOUSE_NORMAL)) |
7 | 2344 return FALSE; |
2345 } | |
2346 | |
4221 | 2347 for (;;) |
2348 { | |
2349 which_button = get_mouse_button(KEY2TERMCAP1(c), &is_click, &is_drag); | |
2350 if (is_drag) | |
2351 { | |
2352 /* If the next character is the same mouse event then use that | |
2353 * one. Speeds up dragging the status line. */ | |
2354 if (vpeekc() != NUL) | |
2355 { | |
2356 int nc; | |
2357 int save_mouse_row = mouse_row; | |
2358 int save_mouse_col = mouse_col; | |
2359 | |
2360 /* Need to get the character, peeking doesn't get the actual | |
2361 * one. */ | |
2362 nc = safe_vgetc(); | |
2363 if (c == nc) | |
2364 continue; | |
2365 vungetc(nc); | |
2366 mouse_row = save_mouse_row; | |
2367 mouse_col = save_mouse_col; | |
2368 } | |
2369 } | |
2370 break; | |
2371 } | |
7 | 2372 |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2373 if (c == K_MOUSEMOVE) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2374 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2375 /* 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
|
2376 #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
|
2377 ui_may_remove_balloon(); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2378 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
|
2379 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2380 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
|
2381 bevalexpr_due_set = TRUE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2382 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2383 #endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2384 return FALSE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2385 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2386 |
7 | 2387 #ifdef FEAT_MOUSESHAPE |
2388 /* May have stopped dragging the status or separator line. The pointer is | |
2389 * most likely still on the status or separator line. */ | |
2390 if (!is_drag && drag_status_line) | |
2391 { | |
2392 drag_status_line = FALSE; | |
2393 update_mouseshape(SHAPE_IDX_STATUS); | |
2394 } | |
2395 if (!is_drag && drag_sep_line) | |
2396 { | |
2397 drag_sep_line = FALSE; | |
2398 update_mouseshape(SHAPE_IDX_VSEP); | |
2399 } | |
2400 #endif | |
2401 | |
2402 /* | |
2403 * Ignore drag and release events if we didn't get a click. | |
2404 */ | |
2405 if (is_click) | |
2406 got_click = TRUE; | |
2407 else | |
2408 { | |
2409 if (!got_click) /* didn't get click, ignore */ | |
2410 return FALSE; | |
2411 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
|
2412 { |
7 | 2413 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
|
2414 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
|
2415 { |
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
|
2416 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
|
2417 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
|
2418 } |
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
|
2419 } |
7 | 2420 } |
2421 | |
2422 /* | |
2423 * CTRL right mouse button does CTRL-T | |
2424 */ | |
2425 if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) | |
2426 { | |
2427 if (State & INSERT) | |
2428 stuffcharReadbuff(Ctrl_O); | |
2429 if (count > 1) | |
2430 stuffnumReadbuff(count); | |
2431 stuffcharReadbuff(Ctrl_T); | |
2432 got_click = FALSE; /* ignore drag&release now */ | |
2433 return FALSE; | |
2434 } | |
2435 | |
2436 /* | |
2437 * CTRL only works with left mouse button | |
2438 */ | |
2439 if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT) | |
2440 return FALSE; | |
2441 | |
2442 /* | |
2443 * When a modifier is down, ignore drag and release events, as well as | |
2444 * multiple clicks and the middle mouse button. | |
2445 * Accept shift-leftmouse drags when 'mousemodel' is "popup.*". | |
2446 */ | |
179 | 2447 if ((mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT |
2448 | MOD_MASK_META)) | |
7 | 2449 && (!is_click |
2450 || (mod_mask & MOD_MASK_MULTI_CLICK) | |
2451 || which_button == MOUSE_MIDDLE) | |
598 | 2452 && !((mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT)) |
7 | 2453 && mouse_model_popup() |
2454 && which_button == MOUSE_LEFT) | |
598 | 2455 && !((mod_mask & MOD_MASK_ALT) |
2456 && !mouse_model_popup() | |
2457 && which_button == MOUSE_RIGHT) | |
7 | 2458 ) |
2459 return FALSE; | |
2460 | |
2461 /* | |
2462 * If the button press was used as the movement command for an operator | |
2463 * (eg "d<MOUSE>"), or it is the middle button that is held down, ignore | |
2464 * drag/release events. | |
2465 */ | |
2466 if (!is_click && which_button == MOUSE_MIDDLE) | |
2467 return FALSE; | |
2468 | |
2469 if (oap != NULL) | |
2470 regname = oap->regname; | |
2471 else | |
2472 regname = 0; | |
2473 | |
2474 /* | |
2475 * Middle mouse button does a 'put' of the selected text | |
2476 */ | |
2477 if (which_button == MOUSE_MIDDLE) | |
2478 { | |
2479 if (State == NORMAL) | |
2480 { | |
2481 /* | |
2482 * If an operator was pending, we don't know what the user wanted | |
2483 * to do. Go back to normal mode: Clear the operator and beep(). | |
2484 */ | |
2485 if (oap != NULL && oap->op_type != OP_NOP) | |
2486 { | |
2487 clearopbeep(oap); | |
2488 return FALSE; | |
2489 } | |
2490 | |
2491 /* | |
2492 * If visual was active, yank the highlighted text and put it | |
2493 * before the mouse pointer position. | |
1016 | 2494 * In Select mode replace the highlighted text with the clipboard. |
7 | 2495 */ |
2496 if (VIsual_active) | |
2497 { | |
1016 | 2498 if (VIsual_select) |
2499 { | |
2500 stuffcharReadbuff(Ctrl_G); | |
1019 | 2501 stuffReadbuff((char_u *)"\"+p"); |
1016 | 2502 } |
2503 else | |
2504 { | |
2505 stuffcharReadbuff('y'); | |
2506 stuffcharReadbuff(K_MIDDLEMOUSE); | |
2507 } | |
7 | 2508 do_always = TRUE; /* ignore 'mouse' setting next time */ |
2509 return FALSE; | |
2510 } | |
2511 /* | |
2512 * The rest is below jump_to_mouse() | |
2513 */ | |
2514 } | |
2515 | |
2516 else if ((State & INSERT) == 0) | |
2517 return FALSE; | |
2518 | |
2519 /* | |
2520 * Middle click in insert mode doesn't move the mouse, just insert the | |
2521 * contents of a register. '.' register is special, can't insert that | |
2522 * with do_put(). | |
2523 * Also paste at the cursor if the current mode isn't in 'mouse' (only | |
2524 * happens for the GUI). | |
2525 */ | |
2526 if ((State & INSERT) || !mouse_has(MOUSE_NORMAL)) | |
2527 { | |
2528 if (regname == '.') | |
2529 insert_reg(regname, TRUE); | |
2530 else | |
2531 { | |
2532 #ifdef FEAT_CLIPBOARD | |
2533 if (clip_star.available && regname == 0) | |
2534 regname = '*'; | |
2535 #endif | |
2536 if ((State & REPLACE_FLAG) && !yank_register_mline(regname)) | |
2537 insert_reg(regname, TRUE); | |
2538 else | |
2539 { | |
2540 do_put(regname, BACKWARD, 1L, fixindent | PUT_CURSEND); | |
2541 | |
2542 /* Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r */ | |
2543 AppendCharToRedobuff(Ctrl_R); | |
2544 AppendCharToRedobuff(fixindent ? Ctrl_P : Ctrl_O); | |
2545 AppendCharToRedobuff(regname == 0 ? '"' : regname); | |
2546 } | |
2547 } | |
2548 return FALSE; | |
2549 } | |
2550 } | |
2551 | |
2552 /* When dragging or button-up stay in the same window. */ | |
2553 if (!is_click) | |
2554 jump_flags |= MOUSE_FOCUS | MOUSE_DID_MOVE; | |
2555 | |
2556 start_visual.lnum = 0; | |
2557 | |
671 | 2558 /* Check for clicking in the tab page line. */ |
2559 if (mouse_row == 0 && firstwin->w_winrow > 0) | |
2560 { | |
1619 | 2561 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
|
2562 { |
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
|
2563 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
|
2564 { |
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
|
2565 c1 = TabPageIdxs[mouse_col]; |
7090
052043fc57ab
commit https://github.com/vim/vim/commit/4a4b821085847651b71d8ad9fab9f180635cb453
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2566 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
|
2567 ? 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
|
2568 } |
1619 | 2569 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
|
2570 } |
671 | 2571 |
2572 /* click in a tab selects that tab page */ | |
2573 if (is_click | |
2574 # ifdef FEAT_CMDWIN | |
2575 && cmdwin_type == 0 | |
2576 # endif | |
681 | 2577 && mouse_col < Columns) |
2578 { | |
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
|
2579 in_tab_line = TRUE; |
681 | 2580 c1 = TabPageIdxs[mouse_col]; |
2581 if (c1 >= 0) | |
2582 { | |
682 | 2583 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) |
2584 { | |
2585 /* double click opens new page */ | |
681 | 2586 end_visual_mode(); |
682 | 2587 tabpage_new(); |
2588 tabpage_move(c1 == 0 ? 9999 : c1 - 1); | |
2589 } | |
2590 else | |
2591 { | |
2592 /* Go to specified tab page, or next one if not clicking | |
2593 * on a label. */ | |
2594 goto_tabpage(c1); | |
2595 | |
2596 /* It's like clicking on the status line of a window. */ | |
2597 if (curwin != old_curwin) | |
2598 end_visual_mode(); | |
2599 } | |
681 | 2600 } |
13762
9de2b25932eb
patch 8.0.1753: various warnings from a static analyser
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2601 else |
681 | 2602 { |
2603 tabpage_T *tp; | |
2604 | |
2605 /* Close the current or specified tab page. */ | |
2606 if (c1 == -999) | |
2607 tp = curtab; | |
2608 else | |
2609 tp = find_tabpage(-c1); | |
2610 if (tp == curtab) | |
2611 { | |
2612 if (first_tabpage->tp_next != NULL) | |
2613 tabpage_close(FALSE); | |
2614 } | |
2615 else if (tp != NULL) | |
2616 tabpage_close_other(tp, FALSE); | |
2617 } | |
2618 } | |
2619 return TRUE; | |
671 | 2620 } |
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
|
2621 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
|
2622 { |
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
|
2623 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
|
2624 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
|
2625 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
|
2626 } |
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
|
2627 |
7 | 2628 /* |
2629 * When 'mousemodel' is "popup" or "popup_setpos", translate mouse events: | |
2630 * right button up -> pop-up menu | |
2631 * shift-left button -> right button | |
598 | 2632 * alt-left button -> alt-right button |
7 | 2633 */ |
2634 if (mouse_model_popup()) | |
2635 { | |
2636 if (which_button == MOUSE_RIGHT | |
2637 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | |
2638 { | |
573 | 2639 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \ |
7 | 2640 || 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
|
2641 || 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
|
2642 || 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
|
2643 # ifdef FEAT_GUI |
7 | 2644 if (gui.in_use) |
2645 { | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2646 # 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
|
2647 || 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
|
2648 if (!is_click) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2649 /* 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
|
2650 * 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
|
2651 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2652 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2653 # 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
|
2654 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
|
2655 /* 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
|
2656 * 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
|
2657 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2658 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2659 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2660 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2661 # 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
|
2662 else |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2663 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2664 # 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
|
2665 if (!is_click) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2666 /* 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
|
2667 * 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
|
2668 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2669 #endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2670 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2671 jump_flags = 0; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2672 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
|
2673 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2674 /* 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
|
2675 * menu. */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2676 if (VIsual_active) |
7 | 2677 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2678 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
|
2679 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2680 /* |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2681 * 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
|
2682 * 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
|
2683 * negative here) |
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 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
|
2686 || mouse_row |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2687 > (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
|
2688 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
|
2689 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
|
2690 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
|
2691 else |
7 | 2692 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2693 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
|
2694 && (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
|
2695 || 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
|
2696 || (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
|
2697 && (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
|
2698 || 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
|
2699 { |
7 | 2700 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
|
2701 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2702 else if (VIsual_mode == Ctrl_V) |
7 | 2703 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2704 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
|
2705 &leftcol, &rightcol); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2706 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
|
2707 if (m_pos.col < leftcol || m_pos.col > rightcol) |
7 | 2708 jump_flags = MOUSE_MAY_STOP_VIS; |
2709 } | |
2710 } | |
2711 } | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2712 else |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2713 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
|
2714 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2715 if (jump_flags) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2716 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2717 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
|
2718 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
|
2719 setcursor(); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2720 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
|
2721 } |
7 | 2722 # 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
|
2723 show_popupmenu(); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2724 got_click = FALSE; /* ignore release events */ |
7 | 2725 # endif |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2726 return (jump_flags & CURSOR_MOVED) != 0; |
7 | 2727 #else |
2728 return FALSE; | |
2729 #endif | |
2730 } | |
598 | 2731 if (which_button == MOUSE_LEFT |
2732 && (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT))) | |
7 | 2733 { |
2734 which_button = MOUSE_RIGHT; | |
2735 mod_mask &= ~MOD_MASK_SHIFT; | |
2736 } | |
2737 } | |
2738 | |
2739 if ((State & (NORMAL | INSERT)) | |
2740 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | |
2741 { | |
2742 if (which_button == MOUSE_LEFT) | |
2743 { | |
2744 if (is_click) | |
2745 { | |
2746 /* stop Visual mode for a left click in a window, but not when | |
2747 * on a status line */ | |
2748 if (VIsual_active) | |
2749 jump_flags |= MOUSE_MAY_STOP_VIS; | |
2750 } | |
2751 else if (mouse_has(MOUSE_VISUAL)) | |
2752 jump_flags |= MOUSE_MAY_VIS; | |
2753 } | |
2754 else if (which_button == MOUSE_RIGHT) | |
2755 { | |
2756 if (is_click && VIsual_active) | |
2757 { | |
2758 /* | |
2759 * Remember the start and end of visual before moving the | |
2760 * cursor. | |
2761 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2762 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 2763 { |
2764 start_visual = curwin->w_cursor; | |
2765 end_visual = VIsual; | |
2766 } | |
2767 else | |
2768 { | |
2769 start_visual = VIsual; | |
2770 end_visual = curwin->w_cursor; | |
2771 } | |
2772 } | |
2773 jump_flags |= MOUSE_FOCUS; | |
2774 if (mouse_has(MOUSE_VISUAL)) | |
2775 jump_flags |= MOUSE_MAY_VIS; | |
2776 } | |
2777 } | |
2778 | |
2779 /* | |
2780 * If an operator is pending, ignore all drags and releases until the | |
2781 * next mouse click. | |
2782 */ | |
2783 if (!is_drag && oap != NULL && oap->op_type != OP_NOP) | |
2784 { | |
2785 got_click = FALSE; | |
2786 oap->motion_type = MCHAR; | |
2787 } | |
2788 | |
2789 /* When releasing the button let jump_to_mouse() know. */ | |
2790 if (!is_click && !is_drag) | |
2791 jump_flags |= MOUSE_RELEASED; | |
2792 | |
2793 /* | |
2794 * JUMP! | |
2795 */ | |
2796 jump_flags = jump_to_mouse(jump_flags, | |
2797 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
|
2798 |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2799 #ifdef FEAT_MENU |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2800 /* 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
|
2801 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
|
2802 return FALSE; |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2803 #endif |
7 | 2804 moved = (jump_flags & CURSOR_MOVED); |
2805 in_status_line = (jump_flags & IN_STATUS_LINE); | |
2806 in_sep_line = (jump_flags & IN_SEP_LINE); | |
2807 | |
2808 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2809 if (isNetbeansBuffer(curbuf) |
7 | 2810 && !(jump_flags & (IN_STATUS_LINE | IN_SEP_LINE))) |
2811 { | |
2812 int key = KEY2TERMCAP1(c); | |
2813 | |
2814 if (key == (int)KE_LEFTRELEASE || key == (int)KE_MIDDLERELEASE | |
2815 || key == (int)KE_RIGHTRELEASE) | |
2816 netbeans_button_release(which_button); | |
2817 } | |
2818 #endif | |
2819 | |
2820 /* When jumping to another window, clear a pending operator. That's a bit | |
2821 * friendlier than beeping and not jumping to that window. */ | |
2822 if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP) | |
2823 clearop(oap); | |
2824 | |
2825 #ifdef FEAT_FOLDING | |
2826 if (mod_mask == 0 | |
2827 && !is_drag | |
2828 && (jump_flags & (MOUSE_FOLD_CLOSE | MOUSE_FOLD_OPEN)) | |
2829 && which_button == MOUSE_LEFT) | |
2830 { | |
2831 /* open or close a fold at this line */ | |
2832 if (jump_flags & MOUSE_FOLD_OPEN) | |
2833 openFold(curwin->w_cursor.lnum, 1L); | |
2834 else | |
2835 closeFold(curwin->w_cursor.lnum, 1L); | |
2836 /* don't move the cursor if still in the same window */ | |
2837 if (curwin == old_curwin) | |
2838 curwin->w_cursor = save_cursor; | |
2839 } | |
2840 #endif | |
2841 | |
2842 #if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN) | |
2843 if ((jump_flags & IN_OTHER_WIN) && !VIsual_active && clip_star.available) | |
2844 { | |
2845 clip_modeless(which_button, is_click, is_drag); | |
2846 return FALSE; | |
2847 } | |
2848 #endif | |
2849 | |
2850 /* Set global flag that we are extending the Visual area with mouse | |
1188 | 2851 * dragging; temporarily minimize 'scrolloff'. */ |
7 | 2852 if (VIsual_active && is_drag && p_so) |
2853 { | |
2854 /* In the very first line, allow scrolling one line */ | |
2855 if (mouse_row == 0) | |
2856 mouse_dragging = 2; | |
2857 else | |
2858 mouse_dragging = 1; | |
2859 } | |
2860 | |
2861 /* When dragging the mouse above the window, scroll down. */ | |
2862 if (is_drag && mouse_row < 0 && !in_status_line) | |
2863 { | |
2864 scroll_redraw(FALSE, 1L); | |
2865 mouse_row = 0; | |
2866 } | |
2867 | |
2868 if (start_visual.lnum) /* right click in visual mode */ | |
2869 { | |
598 | 2870 /* When ALT is pressed make Visual mode blockwise. */ |
2871 if (mod_mask & MOD_MASK_ALT) | |
2872 VIsual_mode = Ctrl_V; | |
2873 | |
7 | 2874 /* |
2875 * In Visual-block mode, divide the area in four, pick up the corner | |
2876 * that is in the quarter that the cursor is in. | |
2877 */ | |
2878 if (VIsual_mode == Ctrl_V) | |
2879 { | |
2880 getvcols(curwin, &start_visual, &end_visual, &leftcol, &rightcol); | |
2881 if (curwin->w_curswant > (leftcol + rightcol) / 2) | |
2882 end_visual.col = leftcol; | |
2883 else | |
2884 end_visual.col = rightcol; | |
7009 | 2885 if (curwin->w_cursor.lnum >= |
7 | 2886 (start_visual.lnum + end_visual.lnum) / 2) |
2887 end_visual.lnum = start_visual.lnum; | |
2888 | |
2889 /* move VIsual to the right column */ | |
2890 start_visual = curwin->w_cursor; /* save the cursor pos */ | |
2891 curwin->w_cursor = end_visual; | |
2892 coladvance(end_visual.col); | |
2893 VIsual = curwin->w_cursor; | |
2894 curwin->w_cursor = start_visual; /* restore the cursor */ | |
2895 } | |
2896 else | |
2897 { | |
2898 /* | |
2899 * If the click is before the start of visual, change the start. | |
2900 * If the click is after the end of visual, change the end. If | |
2901 * the click is inside the visual, change the closest side. | |
2902 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2903 if (LT_POS(curwin->w_cursor, start_visual)) |
7 | 2904 VIsual = end_visual; |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2905 else if (LT_POS(end_visual, curwin->w_cursor)) |
7 | 2906 VIsual = start_visual; |
2907 else | |
2908 { | |
2909 /* In the same line, compare column number */ | |
2910 if (end_visual.lnum == start_visual.lnum) | |
2911 { | |
2912 if (curwin->w_cursor.col - start_visual.col > | |
2913 end_visual.col - curwin->w_cursor.col) | |
2914 VIsual = start_visual; | |
2915 else | |
2916 VIsual = end_visual; | |
2917 } | |
2918 | |
2919 /* In different lines, compare line number */ | |
2920 else | |
2921 { | |
2922 diff = (curwin->w_cursor.lnum - start_visual.lnum) - | |
2923 (end_visual.lnum - curwin->w_cursor.lnum); | |
2924 | |
2925 if (diff > 0) /* closest to end */ | |
2926 VIsual = start_visual; | |
2927 else if (diff < 0) /* closest to start */ | |
2928 VIsual = end_visual; | |
2929 else /* in the middle line */ | |
2930 { | |
2931 if (curwin->w_cursor.col < | |
2932 (start_visual.col + end_visual.col) / 2) | |
2933 VIsual = end_visual; | |
2934 else | |
2935 VIsual = start_visual; | |
2936 } | |
2937 } | |
2938 } | |
2939 } | |
2940 } | |
2941 /* | |
2942 * If Visual mode started in insert mode, execute "CTRL-O" | |
2943 */ | |
2944 else if ((State & INSERT) && VIsual_active) | |
2945 stuffcharReadbuff(Ctrl_O); | |
2946 | |
2947 /* | |
2948 * Middle mouse click: Put text before cursor. | |
2949 */ | |
2950 if (which_button == MOUSE_MIDDLE) | |
2951 { | |
2952 #ifdef FEAT_CLIPBOARD | |
2953 if (clip_star.available && regname == 0) | |
2954 regname = '*'; | |
2955 #endif | |
2956 if (yank_register_mline(regname)) | |
2957 { | |
2958 if (mouse_past_bottom) | |
2959 dir = FORWARD; | |
2960 } | |
2961 else if (mouse_past_eol) | |
2962 dir = FORWARD; | |
2963 | |
2964 if (fixindent) | |
2965 { | |
2966 c1 = (dir == BACKWARD) ? '[' : ']'; | |
2967 c2 = 'p'; | |
2968 } | |
2969 else | |
2970 { | |
2971 c1 = (dir == FORWARD) ? 'p' : 'P'; | |
2972 c2 = NUL; | |
2973 } | |
2974 prep_redo(regname, count, NUL, c1, NUL, c2, NUL); | |
2975 | |
2976 /* | |
2977 * Remember where the paste started, so in edit() Insstart can be set | |
2978 * to this position | |
2979 */ | |
2980 if (restart_edit != 0) | |
2981 where_paste_started = curwin->w_cursor; | |
2982 do_put(regname, dir, count, fixindent | PUT_CURSEND); | |
2983 } | |
2984 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
2985 #if defined(FEAT_QUICKFIX) |
7 | 2986 /* |
2987 * Ctrl-Mouse click or double click in a quickfix window jumps to the | |
2988 * error under the mouse pointer. | |
2989 */ | |
2990 else if (((mod_mask & MOD_MASK_CTRL) | |
2991 || (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
2992 && bt_quickfix(curbuf)) | |
2993 { | |
643 | 2994 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
|
2995 do_cmdline_cmd((char_u *)".cc"); |
643 | 2996 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
|
2997 do_cmdline_cmd((char_u *)".ll"); |
7 | 2998 got_click = FALSE; /* ignore drag&release now */ |
2999 } | |
3000 #endif | |
3001 | |
3002 /* | |
3003 * Ctrl-Mouse click (or double click in a help window) jumps to the tag | |
3004 * under the mouse pointer. | |
3005 */ | |
3006 else if ((mod_mask & MOD_MASK_CTRL) || (curbuf->b_help | |
3007 && (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)) | |
3008 { | |
3009 if (State & INSERT) | |
3010 stuffcharReadbuff(Ctrl_O); | |
3011 stuffcharReadbuff(Ctrl_RSB); | |
3012 got_click = FALSE; /* ignore drag&release now */ | |
3013 } | |
3014 | |
3015 /* | |
3016 * Shift-Mouse click searches for the next occurrence of the word under | |
3017 * the mouse pointer | |
3018 */ | |
3019 else if ((mod_mask & MOD_MASK_SHIFT)) | |
3020 { | |
5735 | 3021 if ((State & INSERT) || (VIsual_active && VIsual_select)) |
7 | 3022 stuffcharReadbuff(Ctrl_O); |
3023 if (which_button == MOUSE_LEFT) | |
3024 stuffcharReadbuff('*'); | |
3025 else /* MOUSE_RIGHT */ | |
3026 stuffcharReadbuff('#'); | |
3027 } | |
3028 | |
3029 /* Handle double clicks, unless on status line */ | |
3030 else if (in_status_line) | |
3031 { | |
3032 #ifdef FEAT_MOUSESHAPE | |
3033 if ((is_drag || is_click) && !drag_status_line) | |
3034 { | |
3035 drag_status_line = TRUE; | |
3036 update_mouseshape(-1); | |
3037 } | |
3038 #endif | |
3039 } | |
3040 else if (in_sep_line) | |
3041 { | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3042 #ifdef FEAT_MOUSESHAPE |
7 | 3043 if ((is_drag || is_click) && !drag_sep_line) |
3044 { | |
3045 drag_sep_line = TRUE; | |
3046 update_mouseshape(-1); | |
3047 } | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3048 #endif |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3049 } |
7 | 3050 else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT)) |
3051 && mouse_has(MOUSE_VISUAL)) | |
3052 { | |
3053 if (is_click || !VIsual_active) | |
3054 { | |
3055 if (VIsual_active) | |
3056 orig_cursor = VIsual; | |
3057 else | |
3058 { | |
3059 check_visual_highlight(); | |
3060 VIsual = curwin->w_cursor; | |
3061 orig_cursor = VIsual; | |
3062 VIsual_active = TRUE; | |
3063 VIsual_reselect = TRUE; | |
3064 /* start Select mode if 'selectmode' contains "mouse" */ | |
3065 may_start_select('o'); | |
3066 setmouse(); | |
3067 } | |
3068 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
598 | 3069 { |
3070 /* Double click with ALT pressed makes it blockwise. */ | |
3071 if (mod_mask & MOD_MASK_ALT) | |
3072 VIsual_mode = Ctrl_V; | |
3073 else | |
3074 VIsual_mode = 'v'; | |
3075 } | |
7 | 3076 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK) |
3077 VIsual_mode = 'V'; | |
3078 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK) | |
3079 VIsual_mode = Ctrl_V; | |
3080 #ifdef FEAT_CLIPBOARD | |
3081 /* Make sure the clipboard gets updated. Needed because start and | |
3082 * end may still be the same, and the selection needs to be owned */ | |
3083 clip_star.vmode = NUL; | |
3084 #endif | |
3085 } | |
3086 /* | |
3087 * A double click selects a word or a block. | |
3088 */ | |
3089 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
3090 { | |
3091 pos_T *pos = NULL; | |
300 | 3092 int gc; |
7 | 3093 |
3094 if (is_click) | |
3095 { | |
3096 /* If the character under the cursor (skipping white space) is | |
3097 * not a word character, try finding a match and select a (), | |
3098 * {}, [], #if/#endif, etc. block. */ | |
3099 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
|
3100 while (gc = gchar_pos(&end_visual), VIM_ISWHITE(gc)) |
7 | 3101 inc(&end_visual); |
3102 if (oap != NULL) | |
3103 oap->motion_type = MCHAR; | |
3104 if (oap != NULL | |
3105 && VIsual_mode == 'v' | |
3106 && !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
|
3107 && EQUAL_POS(curwin->w_cursor, VIsual) |
7 | 3108 && (pos = findmatch(oap, NUL)) != NULL) |
3109 { | |
3110 curwin->w_cursor = *pos; | |
3111 if (oap->motion_type == MLINE) | |
3112 VIsual_mode = 'V'; | |
3113 else if (*p_sel == 'e') | |
3114 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3115 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 3116 ++VIsual.col; |
3117 else | |
3118 ++curwin->w_cursor.col; | |
3119 } | |
3120 } | |
3121 } | |
3122 | |
3123 if (pos == NULL && (is_click || is_drag)) | |
3124 { | |
3125 /* When not found a match or when dragging: extend to include | |
3126 * a word. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3127 if (LT_POS(curwin->w_cursor, orig_cursor)) |
7 | 3128 { |
3129 find_start_of_word(&curwin->w_cursor); | |
3130 find_end_of_word(&VIsual); | |
3131 } | |
3132 else | |
3133 { | |
3134 find_start_of_word(&VIsual); | |
3135 if (*p_sel == 'e' && *ml_get_cursor() != NUL) | |
3136 #ifdef FEAT_MBYTE | |
3137 curwin->w_cursor.col += | |
474 | 3138 (*mb_ptr2len)(ml_get_cursor()); |
7 | 3139 #else |
3140 ++curwin->w_cursor.col; | |
3141 #endif | |
3142 find_end_of_word(&curwin->w_cursor); | |
3143 } | |
3144 } | |
3145 curwin->w_set_curswant = TRUE; | |
3146 } | |
3147 if (is_click) | |
3148 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
3149 } | |
3150 else if (VIsual_active && !old_active) | |
598 | 3151 { |
3152 if (mod_mask & MOD_MASK_ALT) | |
3153 VIsual_mode = Ctrl_V; | |
3154 else | |
3155 VIsual_mode = 'v'; | |
3156 } | |
7 | 3157 |
3158 /* If Visual mode changed show it later. */ | |
643 | 3159 if ((!VIsual_active && old_active && mode_displayed) |
3160 || (VIsual_active && p_smd && msg_silent == 0 | |
3161 && (!old_active || VIsual_mode != old_mode))) | |
7 | 3162 redraw_cmdline = TRUE; |
3163 | |
3164 return moved; | |
3165 } | |
3166 | |
3167 /* | |
3168 * Move "pos" back to the start of the word it's in. | |
3169 */ | |
3170 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3171 find_start_of_word(pos_T *pos) |
7 | 3172 { |
3173 char_u *line; | |
3174 int cclass; | |
3175 int col; | |
3176 | |
3177 line = ml_get(pos->lnum); | |
3178 cclass = get_mouse_class(line + pos->col); | |
3179 | |
3180 while (pos->col > 0) | |
3181 { | |
3182 col = pos->col - 1; | |
3183 #ifdef FEAT_MBYTE | |
3184 col -= (*mb_head_off)(line, line + col); | |
3185 #endif | |
3186 if (get_mouse_class(line + col) != cclass) | |
3187 break; | |
3188 pos->col = col; | |
3189 } | |
3190 } | |
3191 | |
3192 /* | |
3193 * Move "pos" forward to the end of the word it's in. | |
3194 * When 'selection' is "exclusive", the position is just after the word. | |
3195 */ | |
3196 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3197 find_end_of_word(pos_T *pos) |
7 | 3198 { |
3199 char_u *line; | |
3200 int cclass; | |
3201 int col; | |
3202 | |
3203 line = ml_get(pos->lnum); | |
3204 if (*p_sel == 'e' && pos->col > 0) | |
3205 { | |
3206 --pos->col; | |
3207 #ifdef FEAT_MBYTE | |
3208 pos->col -= (*mb_head_off)(line, line + pos->col); | |
3209 #endif | |
3210 } | |
3211 cclass = get_mouse_class(line + pos->col); | |
3212 while (line[pos->col] != NUL) | |
3213 { | |
3214 #ifdef FEAT_MBYTE | |
474 | 3215 col = pos->col + (*mb_ptr2len)(line + pos->col); |
7 | 3216 #else |
3217 col = pos->col + 1; | |
3218 #endif | |
3219 if (get_mouse_class(line + col) != cclass) | |
3220 { | |
3221 if (*p_sel == 'e') | |
3222 pos->col = col; | |
3223 break; | |
3224 } | |
3225 pos->col = col; | |
3226 } | |
3227 } | |
3228 | |
3229 /* | |
3230 * Get class of a character for selection: same class means same word. | |
3231 * 0: blank | |
3232 * 1: punctuation groups | |
3233 * 2: normal word character | |
3234 * >2: multi-byte word character. | |
3235 */ | |
3236 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3237 get_mouse_class(char_u *p) |
7 | 3238 { |
3239 int c; | |
3240 | |
3241 #ifdef FEAT_MBYTE | |
3242 if (has_mbyte && MB_BYTE2LEN(p[0]) > 1) | |
3243 return mb_get_class(p); | |
3244 #endif | |
3245 | |
3246 c = *p; | |
3247 if (c == ' ' || c == '\t') | |
3248 return 0; | |
3249 | |
3250 if (vim_iswordc(c)) | |
3251 return 2; | |
3252 | |
3253 /* | |
3254 * There are a few special cases where we want certain combinations of | |
3255 * characters to be considered as a single word. These are things like | |
3256 * "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
3257 * character is in its own class. |
7 | 3258 */ |
3259 if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL) | |
3260 return 1; | |
3261 return c; | |
3262 } | |
3263 #endif /* FEAT_MOUSE */ | |
3264 | |
3265 /* | |
3266 * Check if highlighting for visual mode is possible, give a warning message | |
3267 * if not. | |
3268 */ | |
3269 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3270 check_visual_highlight(void) |
7 | 3271 { |
3272 static int did_check = FALSE; | |
3273 | |
3274 if (full_screen) | |
3275 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3276 if (!did_check && HL_ATTR(HLF_V) == 0) |
7 | 3277 MSG(_("Warning: terminal cannot highlight")); |
3278 did_check = TRUE; | |
3279 } | |
3280 } | |
3281 | |
3282 /* | |
638 | 3283 * End Visual mode. |
7 | 3284 * This function should ALWAYS be called to end Visual mode, except from |
3285 * do_pending_operator(). | |
3286 */ | |
3287 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3288 end_visual_mode(void) |
7 | 3289 { |
3290 #ifdef FEAT_CLIPBOARD | |
3291 /* | |
3292 * If we are using the clipboard, then remember what was selected in case | |
3293 * we need to paste it somewhere while we still own the selection. | |
3294 * Only do this when the clipboard is already owned. Don't want to grab | |
3295 * the selection when hitting ESC. | |
3296 */ | |
3297 if (clip_star.available && clip_star.owned) | |
3298 clip_auto_select(); | |
3299 #endif | |
3300 | |
3301 VIsual_active = FALSE; | |
3302 #ifdef FEAT_MOUSE | |
3303 setmouse(); | |
3304 mouse_dragging = 0; | |
3305 #endif | |
3306 | |
3307 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
690 | 3308 curbuf->b_visual.vi_mode = VIsual_mode; |
3309 curbuf->b_visual.vi_start = VIsual; | |
3310 curbuf->b_visual.vi_end = curwin->w_cursor; | |
3311 curbuf->b_visual.vi_curswant = curwin->w_curswant; | |
7 | 3312 #ifdef FEAT_EVAL |
3313 curbuf->b_visual_mode_eval = VIsual_mode; | |
3314 #endif | |
3315 #ifdef FEAT_VIRTUALEDIT | |
3316 if (!virtual_active()) | |
3317 curwin->w_cursor.coladd = 0; | |
3318 #endif | |
6979 | 3319 may_clear_cmdline(); |
7 | 3320 |
844 | 3321 adjust_cursor_eol(); |
7 | 3322 } |
3323 | |
3324 /* | |
3325 * Reset VIsual_active and VIsual_reselect. | |
3326 */ | |
3327 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3328 reset_VIsual_and_resel(void) |
7 | 3329 { |
3330 if (VIsual_active) | |
3331 { | |
3332 end_visual_mode(); | |
3333 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
3334 } | |
3335 VIsual_reselect = FALSE; | |
3336 } | |
3337 | |
3338 /* | |
3339 * Reset VIsual_active and VIsual_reselect if it's set. | |
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(void) |
7 | 3343 { |
3344 if (VIsual_active) | |
3345 { | |
3346 end_visual_mode(); | |
3347 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
3348 VIsual_reselect = FALSE; | |
3349 } | |
3350 } | |
3351 | |
3352 /* | |
3353 * Check for a balloon-eval special item to include when searching for an | |
3354 * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid! | |
3355 * Returns TRUE if the character at "*ptr" should be included. | |
3356 * "dir" is FORWARD or BACKWARD, the direction of searching. | |
3357 * "*colp" is in/decremented if "ptr[-dir]" should also be included. | |
3358 * "bnp" points to a counter for square brackets. | |
3359 */ | |
3360 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3361 find_is_eval_item( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3362 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3363 int *colp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3364 int *bnp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3365 int dir) |
7 | 3366 { |
3367 /* Accept everything inside []. */ | |
3368 if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) | |
3369 ++*bnp; | |
3370 if (*bnp > 0) | |
3371 { | |
3372 if ((*ptr == '[' && dir == BACKWARD) || (*ptr == ']' && dir == FORWARD)) | |
3373 --*bnp; | |
3374 return TRUE; | |
3375 } | |
3376 | |
3377 /* skip over "s.var" */ | |
3378 if (*ptr == '.') | |
3379 return TRUE; | |
3380 | |
3381 /* two-character item: s->var */ | |
3382 if (ptr[dir == BACKWARD ? 0 : 1] == '>' | |
3383 && ptr[dir == BACKWARD ? -1 : 0] == '-') | |
3384 { | |
3385 *colp += dir; | |
3386 return TRUE; | |
3387 } | |
3388 return FALSE; | |
3389 } | |
3390 | |
3391 /* | |
3392 * Find the identifier under or to the right of the cursor. | |
3393 * "find_type" can have one of three values: | |
3394 * FIND_IDENT: find an identifier (keyword) | |
3395 * FIND_STRING: find any non-white string | |
3396 * FIND_IDENT + FIND_STRING: find any non-white string, identifier preferred. | |
184 | 3397 * FIND_EVAL: find text useful for C program debugging |
7 | 3398 * |
3399 * There are three steps: | |
3400 * 1. Search forward for the start of an identifier/string. Doesn't move if | |
3401 * already on one. | |
3402 * 2. Search backward for the start of this identifier/string. | |
3403 * This doesn't match the real Vi but I like it a little better and it | |
3404 * shouldn't bother anyone. | |
3405 * 3. Search forward to the end of this identifier/string. | |
3406 * When FIND_IDENT isn't defined, we backup until a blank. | |
3407 * | |
3408 * Returns the length of the string, or zero if no string is found. | |
3409 * If a string is found, a pointer to the string is put in "*string". This | |
3410 * string is not always NUL terminated. | |
3411 */ | |
3412 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3413 find_ident_under_cursor(char_u **string, int find_type) |
7 | 3414 { |
3415 return find_ident_at_pos(curwin, curwin->w_cursor.lnum, | |
3416 curwin->w_cursor.col, string, find_type); | |
3417 } | |
3418 | |
3419 /* | |
3420 * Like find_ident_under_cursor(), but for any window and any position. | |
3421 * However: Uses 'iskeyword' from the current window!. | |
3422 */ | |
3423 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3424 find_ident_at_pos( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3425 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3426 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3427 colnr_T startcol, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3428 char_u **string, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3429 int find_type) |
7 | 3430 { |
3431 char_u *ptr; | |
3432 int col = 0; /* init to shut up GCC */ | |
3433 int i; | |
3434 #ifdef FEAT_MBYTE | |
3435 int this_class = 0; | |
3436 int prev_class; | |
3437 int prevcol; | |
3438 #endif | |
3439 int bn = 0; /* bracket nesting */ | |
3440 | |
3441 /* | |
3442 * if i == 0: try to find an identifier | |
3443 * if i == 1: try to find any non-white string | |
3444 */ | |
3445 ptr = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3446 for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; ++i) | |
3447 { | |
3448 /* | |
3449 * 1. skip to start of identifier/string | |
3450 */ | |
3451 col = startcol; | |
3452 #ifdef FEAT_MBYTE | |
3453 if (has_mbyte) | |
3454 { | |
3455 while (ptr[col] != NUL) | |
3456 { | |
3457 /* Stop at a ']' to evaluate "a[x]". */ | |
3458 if ((find_type & FIND_EVAL) && ptr[col] == ']') | |
3459 break; | |
3460 this_class = mb_get_class(ptr + col); | |
3461 if (this_class != 0 && (i == 1 || this_class != 1)) | |
3462 break; | |
474 | 3463 col += (*mb_ptr2len)(ptr + col); |
7 | 3464 } |
3465 } | |
3466 else | |
3467 #endif | |
3468 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
|
3469 && (i == 0 ? !vim_iswordc(ptr[col]) : VIM_ISWHITE(ptr[col])) |
7 | 3470 && (!(find_type & FIND_EVAL) || ptr[col] != ']') |
3471 ) | |
3472 ++col; | |
3473 | |
3474 /* When starting on a ']' count it, so that we include the '['. */ | |
3475 bn = ptr[col] == ']'; | |
3476 | |
3477 /* | |
3478 * 2. Back up to start of identifier/string. | |
3479 */ | |
3480 #ifdef FEAT_MBYTE | |
3481 if (has_mbyte) | |
3482 { | |
3483 /* Remember class of character under cursor. */ | |
3484 if ((find_type & FIND_EVAL) && ptr[col] == ']') | |
3485 this_class = mb_get_class((char_u *)"a"); | |
3486 else | |
3487 this_class = mb_get_class(ptr + col); | |
835 | 3488 while (col > 0 && this_class != 0) |
7 | 3489 { |
3490 prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1); | |
3491 prev_class = mb_get_class(ptr + prevcol); | |
3492 if (this_class != prev_class | |
3493 && (i == 0 | |
3494 || prev_class == 0 | |
3495 || (find_type & FIND_IDENT)) | |
3496 && (!(find_type & FIND_EVAL) | |
3497 || prevcol == 0 | |
3498 || !find_is_eval_item(ptr + prevcol, &prevcol, | |
3499 &bn, BACKWARD)) | |
3500 ) | |
3501 break; | |
3502 col = prevcol; | |
3503 } | |
3504 | |
3505 /* If we don't want just any old string, or we've found an | |
3506 * identifier, stop searching. */ | |
3507 if (this_class > 2) | |
3508 this_class = 2; | |
3509 if (!(find_type & FIND_STRING) || this_class == 2) | |
3510 break; | |
3511 } | |
3512 else | |
3513 #endif | |
3514 { | |
3515 while (col > 0 | |
3516 && ((i == 0 | |
3517 ? 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
|
3518 : (!VIM_ISWHITE(ptr[col - 1]) |
7 | 3519 && (!(find_type & FIND_IDENT) |
3520 || !vim_iswordc(ptr[col - 1])))) | |
3521 || ((find_type & FIND_EVAL) | |
3522 && col > 1 | |
3523 && find_is_eval_item(ptr + col - 1, &col, | |
3524 &bn, BACKWARD)) | |
3525 )) | |
3526 --col; | |
3527 | |
3528 /* If we don't want just any old string, or we've found an | |
3529 * identifier, stop searching. */ | |
3530 if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col])) | |
3531 break; | |
3532 } | |
3533 } | |
3534 | |
3535 if (ptr[col] == NUL || (i == 0 && ( | |
3536 #ifdef FEAT_MBYTE | |
3537 has_mbyte ? this_class != 2 : | |
3538 #endif | |
3539 !vim_iswordc(ptr[col])))) | |
3540 { | |
3541 /* | |
3542 * didn't find an identifier or string | |
3543 */ | |
3544 if (find_type & FIND_STRING) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
3545 emsg(_("E348: No string under cursor")); |
7 | 3546 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
3547 emsg(_(e_noident)); |
7 | 3548 return 0; |
3549 } | |
3550 ptr += col; | |
3551 *string = ptr; | |
3552 | |
3553 /* | |
3554 * 3. Find the end if the identifier/string. | |
3555 */ | |
3556 bn = 0; | |
3557 startcol -= col; | |
3558 col = 0; | |
3559 #ifdef FEAT_MBYTE | |
3560 if (has_mbyte) | |
3561 { | |
3562 /* Search for point of changing multibyte character class. */ | |
3563 this_class = mb_get_class(ptr); | |
3564 while (ptr[col] != NUL | |
3565 && ((i == 0 ? mb_get_class(ptr + col) == this_class | |
3566 : mb_get_class(ptr + col) != 0) | |
3567 || ((find_type & FIND_EVAL) | |
3568 && col <= (int)startcol | |
3569 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
3570 )) | |
474 | 3571 col += (*mb_ptr2len)(ptr + col); |
7 | 3572 } |
3573 else | |
3574 #endif | |
3575 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
|
3576 : (ptr[col] != NUL && !VIM_ISWHITE(ptr[col]))) |
7 | 3577 || ((find_type & FIND_EVAL) |
3578 && col <= (int)startcol | |
3579 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
3580 ) | |
3581 { | |
3582 ++col; | |
3583 } | |
3584 | |
3585 return col; | |
3586 } | |
3587 | |
3588 /* | |
3589 * Prepare for redo of a normal command. | |
3590 */ | |
3591 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3592 prep_redo_cmd(cmdarg_T *cap) |
7 | 3593 { |
3594 prep_redo(cap->oap->regname, cap->count0, | |
3595 NUL, cap->cmdchar, NUL, NUL, cap->nchar); | |
3596 } | |
3597 | |
3598 /* | |
3599 * Prepare for redo of any command. | |
3600 * Note that only the last argument can be a multi-byte char. | |
3601 */ | |
3602 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3603 prep_redo( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3604 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3605 long num, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3606 int cmd1, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3607 int cmd2, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3608 int cmd3, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3609 int cmd4, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3610 int cmd5) |
7 | 3611 { |
3612 ResetRedobuff(); | |
3613 if (regname != 0) /* yank from specified buffer */ | |
3614 { | |
3615 AppendCharToRedobuff('"'); | |
3616 AppendCharToRedobuff(regname); | |
3617 } | |
3618 if (num) | |
3619 AppendNumberToRedobuff(num); | |
3620 | |
3621 if (cmd1 != NUL) | |
3622 AppendCharToRedobuff(cmd1); | |
3623 if (cmd2 != NUL) | |
3624 AppendCharToRedobuff(cmd2); | |
3625 if (cmd3 != NUL) | |
3626 AppendCharToRedobuff(cmd3); | |
3627 if (cmd4 != NUL) | |
3628 AppendCharToRedobuff(cmd4); | |
3629 if (cmd5 != NUL) | |
3630 AppendCharToRedobuff(cmd5); | |
3631 } | |
3632 | |
3633 /* | |
3634 * check for operator active and clear it | |
3635 * | |
3636 * return TRUE if operator was active | |
3637 */ | |
3638 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3639 checkclearop(oparg_T *oap) |
7 | 3640 { |
3641 if (oap->op_type == OP_NOP) | |
3642 return FALSE; | |
3643 clearopbeep(oap); | |
3644 return TRUE; | |
3645 } | |
3646 | |
3647 /* | |
1131 | 3648 * Check for operator or Visual active. Clear active operator. |
7 | 3649 * |
1131 | 3650 * Return TRUE if operator or Visual was active. |
7 | 3651 */ |
3652 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3653 checkclearopq(oparg_T *oap) |
7 | 3654 { |
5735 | 3655 if (oap->op_type == OP_NOP && !VIsual_active) |
7 | 3656 return FALSE; |
3657 clearopbeep(oap); | |
3658 return TRUE; | |
3659 } | |
3660 | |
3661 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3662 clearop(oparg_T *oap) |
7 | 3663 { |
3664 oap->op_type = OP_NOP; | |
3665 oap->regname = 0; | |
3666 oap->motion_force = NUL; | |
3667 oap->use_reg_one = FALSE; | |
3668 } | |
3669 | |
3670 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3671 clearopbeep(oparg_T *oap) |
7 | 3672 { |
3673 clearop(oap); | |
3674 beep_flush(); | |
3675 } | |
3676 | |
3677 /* | |
3678 * Remove the shift modifier from a special key. | |
3679 */ | |
3680 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3681 unshift_special(cmdarg_T *cap) |
7 | 3682 { |
3683 switch (cap->cmdchar) | |
3684 { | |
3685 case K_S_RIGHT: cap->cmdchar = K_RIGHT; break; | |
3686 case K_S_LEFT: cap->cmdchar = K_LEFT; break; | |
3687 case K_S_UP: cap->cmdchar = K_UP; break; | |
3688 case K_S_DOWN: cap->cmdchar = K_DOWN; break; | |
3689 case K_S_HOME: cap->cmdchar = K_HOME; break; | |
3690 case K_S_END: cap->cmdchar = K_END; break; | |
3691 } | |
3692 cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask); | |
3693 } | |
3694 | |
6979 | 3695 /* |
3696 * If the mode is currently displayed clear the command line or update the | |
3697 * command displayed. | |
3698 */ | |
3699 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3700 may_clear_cmdline(void) |
6979 | 3701 { |
3702 if (mode_displayed) | |
3703 clear_cmdline = TRUE; /* unshow visual mode later */ | |
3704 #ifdef FEAT_CMDL_INFO | |
3705 else | |
3706 clear_showcmd(); | |
3707 #endif | |
3708 } | |
3709 | |
7 | 3710 #if defined(FEAT_CMDL_INFO) || defined(PROTO) |
3711 /* | |
3712 * Routines for displaying a partly typed command | |
3713 */ | |
3714 | |
5735 | 3715 #define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 |
7 | 3716 static char_u showcmd_buf[SHOWCMD_BUFLEN]; |
3717 static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */ | |
3718 static int showcmd_is_clear = TRUE; | |
3719 static int showcmd_visual = FALSE; | |
3720 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
3721 static void display_showcmd(void); |
7 | 3722 |
3723 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3724 clear_showcmd(void) |
7 | 3725 { |
3726 if (!p_sc) | |
3727 return; | |
3728 | |
3729 if (VIsual_active && !char_avail()) | |
3730 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3731 int cursor_bot = LT_POS(VIsual, curwin->w_cursor); |
7 | 3732 long lines; |
3733 colnr_T leftcol, rightcol; | |
3734 linenr_T top, bot; | |
3735 | |
3736 /* Show the size of the Visual area. */ | |
1866 | 3737 if (cursor_bot) |
7 | 3738 { |
3739 top = VIsual.lnum; | |
3740 bot = curwin->w_cursor.lnum; | |
3741 } | |
3742 else | |
3743 { | |
3744 top = curwin->w_cursor.lnum; | |
3745 bot = VIsual.lnum; | |
3746 } | |
3747 # ifdef FEAT_FOLDING | |
3748 /* Include closed folds as a whole. */ | |
7009 | 3749 (void)hasFolding(top, &top, NULL); |
3750 (void)hasFolding(bot, NULL, &bot); | |
7 | 3751 # endif |
3752 lines = bot - top + 1; | |
3753 | |
3754 if (VIsual_mode == Ctrl_V) | |
3755 { | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3756 # ifdef FEAT_LINEBREAK |
1866 | 3757 char_u *saved_sbr = p_sbr; |
3758 | |
3759 /* Make 'sbr' empty for a moment to get the correct size. */ | |
3760 p_sbr = empty_option; | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3761 # endif |
7 | 3762 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
|
3763 # ifdef FEAT_LINEBREAK |
1866 | 3764 p_sbr = saved_sbr; |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3765 # endif |
7 | 3766 sprintf((char *)showcmd_buf, "%ldx%ld", lines, |
3767 (long)(rightcol - leftcol + 1)); | |
3768 } | |
3769 else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum) | |
3770 sprintf((char *)showcmd_buf, "%ld", lines); | |
3771 else | |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3772 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3773 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
|
3774 int l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3775 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
|
3776 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
|
3777 |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3778 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
|
3779 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3780 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
|
3781 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
|
3782 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3783 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3784 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3785 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
|
3786 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
|
3787 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3788 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
|
3789 { |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3790 # 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
|
3791 l = (*mb_ptr2len)(s); |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3792 # else |
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3793 l = (*s == NUL) ? 0 : 1; |
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3794 # endif |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3795 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
|
3796 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3797 ++bytes; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3798 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3799 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
|
3800 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3801 bytes += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3802 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3803 s += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3804 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3805 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
|
3806 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
|
3807 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3808 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
|
3809 } |
7 | 3810 showcmd_buf[SHOWCMD_COLS] = NUL; /* truncate */ |
3811 showcmd_visual = TRUE; | |
3812 } | |
3813 else | |
3814 { | |
3815 showcmd_buf[0] = NUL; | |
3816 showcmd_visual = FALSE; | |
3817 | |
3818 /* Don't actually display something if there is nothing to clear. */ | |
3819 if (showcmd_is_clear) | |
3820 return; | |
3821 } | |
3822 | |
3823 display_showcmd(); | |
3824 } | |
3825 | |
3826 /* | |
3827 * Add 'c' to string of shown command chars. | |
3828 * Return TRUE if output has been written (and setcursor() has been called). | |
3829 */ | |
3830 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3831 add_to_showcmd(int c) |
7 | 3832 { |
3833 char_u *p; | |
3834 int old_len; | |
3835 int extra_len; | |
3836 int overflow; | |
3837 #if defined(FEAT_MOUSE) | |
3838 int i; | |
3839 static int ignore[] = | |
3840 { | |
660 | 3841 # ifdef FEAT_GUI |
7 | 3842 K_VER_SCROLLBAR, K_HOR_SCROLLBAR, |
3843 K_LEFTMOUSE_NM, K_LEFTRELEASE_NM, | |
660 | 3844 # endif |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
3845 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
|
3846 K_LEFTMOUSE, K_LEFTDRAG, K_LEFTRELEASE, K_MOUSEMOVE, |
7 | 3847 K_MIDDLEMOUSE, K_MIDDLEDRAG, K_MIDDLERELEASE, |
3848 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
|
3849 K_MOUSEDOWN, K_MOUSEUP, K_MOUSELEFT, K_MOUSERIGHT, |
7 | 3850 K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE, |
631 | 3851 K_CURSORHOLD, |
7 | 3852 0 |
3853 }; | |
3854 #endif | |
3855 | |
641 | 3856 if (!p_sc || msg_silent != 0) |
7 | 3857 return FALSE; |
3858 | |
3859 if (showcmd_visual) | |
3860 { | |
3861 showcmd_buf[0] = NUL; | |
3862 showcmd_visual = FALSE; | |
3863 } | |
3864 | |
3865 #if defined(FEAT_MOUSE) | |
3866 /* Ignore keys that are scrollbar updates and mouse clicks */ | |
3867 if (IS_SPECIAL(c)) | |
3868 for (i = 0; ignore[i] != 0; ++i) | |
3869 if (ignore[i] == c) | |
3870 return FALSE; | |
3871 #endif | |
3872 | |
3873 p = transchar(c); | |
5535 | 3874 if (*p == ' ') |
3875 STRCPY(p, "<20>"); | |
7 | 3876 old_len = (int)STRLEN(showcmd_buf); |
3877 extra_len = (int)STRLEN(p); | |
3878 overflow = old_len + extra_len - SHOWCMD_COLS; | |
3879 if (overflow > 0) | |
1362 | 3880 mch_memmove(showcmd_buf, showcmd_buf + overflow, |
3881 old_len - overflow + 1); | |
7 | 3882 STRCAT(showcmd_buf, p); |
3883 | |
3884 if (char_avail()) | |
3885 return FALSE; | |
3886 | |
3887 display_showcmd(); | |
3888 | |
3889 return TRUE; | |
3890 } | |
3891 | |
3892 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3893 add_to_showcmd_c(int c) |
7 | 3894 { |
3895 if (!add_to_showcmd(c)) | |
3896 setcursor(); | |
3897 } | |
3898 | |
3899 /* | |
3900 * Delete 'len' characters from the end of the shown command. | |
3901 */ | |
3902 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3903 del_from_showcmd(int len) |
7 | 3904 { |
3905 int old_len; | |
3906 | |
3907 if (!p_sc) | |
3908 return; | |
3909 | |
3910 old_len = (int)STRLEN(showcmd_buf); | |
3911 if (len > old_len) | |
3912 len = old_len; | |
3913 showcmd_buf[old_len - len] = NUL; | |
3914 | |
3915 if (!char_avail()) | |
3916 display_showcmd(); | |
3917 } | |
3918 | |
3919 /* | |
3920 * push_showcmd() and pop_showcmd() are used when waiting for the user to type | |
3921 * something and there is a partial mapping. | |
3922 */ | |
3923 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3924 push_showcmd(void) |
7 | 3925 { |
3926 if (p_sc) | |
3927 STRCPY(old_showcmd_buf, showcmd_buf); | |
3928 } | |
3929 | |
3930 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3931 pop_showcmd(void) |
7 | 3932 { |
3933 if (!p_sc) | |
3934 return; | |
3935 | |
3936 STRCPY(showcmd_buf, old_showcmd_buf); | |
3937 | |
3938 display_showcmd(); | |
3939 } | |
3940 | |
3941 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3942 display_showcmd(void) |
7 | 3943 { |
3944 int len; | |
3945 | |
3946 cursor_off(); | |
3947 | |
3948 len = (int)STRLEN(showcmd_buf); | |
3949 if (len == 0) | |
3950 showcmd_is_clear = TRUE; | |
3951 else | |
3952 { | |
3953 screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0); | |
3954 showcmd_is_clear = FALSE; | |
3955 } | |
3956 | |
3957 /* | |
1188 | 3958 * clear the rest of an old message by outputting up to SHOWCMD_COLS |
3959 * spaces | |
7 | 3960 */ |
3961 screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0); | |
3962 | |
3963 setcursor(); /* put cursor back where it belongs */ | |
3964 } | |
3965 #endif | |
3966 | |
3967 /* | |
3968 * When "check" is FALSE, prepare for commands that scroll the window. | |
3969 * When "check" is TRUE, take care of scroll-binding after the window has | |
3970 * scrolled. Called from normal_cmd() and edit(). | |
3971 */ | |
3972 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3973 do_check_scrollbind(int check) |
7 | 3974 { |
3975 static win_T *old_curwin = NULL; | |
3976 static linenr_T old_topline = 0; | |
3977 #ifdef FEAT_DIFF | |
3978 static int old_topfill = 0; | |
3979 #endif | |
3980 static buf_T *old_buf = NULL; | |
3981 static colnr_T old_leftcol = 0; | |
3982 | |
3983 if (check && curwin->w_p_scb) | |
3984 { | |
3985 /* If a ":syncbind" command was just used, don't scroll, only reset | |
3986 * the values. */ | |
3987 if (did_syncbind) | |
3988 did_syncbind = FALSE; | |
3989 else if (curwin == old_curwin) | |
3990 { | |
3991 /* | |
3992 * Synchronize other windows, as necessary according to | |
3993 * 'scrollbind'. Don't do this after an ":edit" command, except | |
3994 * when 'diff' is set. | |
3995 */ | |
3996 if ((curwin->w_buffer == old_buf | |
3997 #ifdef FEAT_DIFF | |
3998 || curwin->w_p_diff | |
3999 #endif | |
4000 ) | |
4001 && (curwin->w_topline != old_topline | |
4002 #ifdef FEAT_DIFF | |
4003 || curwin->w_topfill != old_topfill | |
4004 #endif | |
4005 || curwin->w_leftcol != old_leftcol)) | |
4006 { | |
4007 check_scrollbind(curwin->w_topline - old_topline, | |
4008 (long)(curwin->w_leftcol - old_leftcol)); | |
4009 } | |
4010 } | |
4011 else if (vim_strchr(p_sbo, 'j')) /* jump flag set in 'scrollopt' */ | |
4012 { | |
4013 /* | |
4014 * When switching between windows, make sure that the relative | |
4015 * vertical offset is valid for the new window. The relative | |
4016 * offset is invalid whenever another 'scrollbind' window has | |
4017 * scrolled to a point that would force the current window to | |
4018 * scroll past the beginning or end of its buffer. When the | |
4019 * resync is performed, some of the other 'scrollbind' windows may | |
4020 * need to jump so that the current window's relative position is | |
4021 * visible on-screen. | |
4022 */ | |
4023 check_scrollbind(curwin->w_topline - curwin->w_scbind_pos, 0L); | |
4024 } | |
4025 curwin->w_scbind_pos = curwin->w_topline; | |
4026 } | |
4027 | |
4028 old_curwin = curwin; | |
4029 old_topline = curwin->w_topline; | |
4030 #ifdef FEAT_DIFF | |
4031 old_topfill = curwin->w_topfill; | |
4032 #endif | |
4033 old_buf = curwin->w_buffer; | |
4034 old_leftcol = curwin->w_leftcol; | |
4035 } | |
4036 | |
4037 /* | |
4038 * Synchronize any windows that have "scrollbind" set, based on the | |
4039 * number of rows by which the current window has changed | |
4040 * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>) | |
4041 */ | |
4042 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4043 check_scrollbind(linenr_T topline_diff, long leftcol_diff) |
7 | 4044 { |
4045 int want_ver; | |
4046 int want_hor; | |
4047 win_T *old_curwin = curwin; | |
4048 buf_T *old_curbuf = curbuf; | |
4049 int old_VIsual_select = VIsual_select; | |
4050 int old_VIsual_active = VIsual_active; | |
4051 colnr_T tgt_leftcol = curwin->w_leftcol; | |
4052 long topline; | |
4053 long y; | |
4054 | |
4055 /* | |
4056 * check 'scrollopt' string for vertical and horizontal scroll options | |
4057 */ | |
4058 want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0); | |
4059 #ifdef FEAT_DIFF | |
4060 want_ver |= old_curwin->w_p_diff; | |
4061 #endif | |
4062 want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0)); | |
4063 | |
4064 /* | |
4065 * loop through the scrollbound windows and scroll accordingly | |
4066 */ | |
4067 VIsual_select = VIsual_active = 0; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9399
diff
changeset
|
4068 FOR_ALL_WINDOWS(curwin) |
7 | 4069 { |
4070 curbuf = curwin->w_buffer; | |
4071 /* skip original window and windows with 'noscrollbind' */ | |
4072 if (curwin != old_curwin && curwin->w_p_scb) | |
4073 { | |
4074 /* | |
4075 * do the vertical scroll | |
4076 */ | |
4077 if (want_ver) | |
4078 { | |
4079 #ifdef FEAT_DIFF | |
4080 if (old_curwin->w_p_diff && curwin->w_p_diff) | |
4081 { | |
4082 diff_set_topline(old_curwin, curwin); | |
4083 } | |
4084 else | |
4085 #endif | |
4086 { | |
4087 curwin->w_scbind_pos += topline_diff; | |
4088 topline = curwin->w_scbind_pos; | |
4089 if (topline > curbuf->b_ml.ml_line_count) | |
4090 topline = curbuf->b_ml.ml_line_count; | |
4091 if (topline < 1) | |
4092 topline = 1; | |
4093 | |
4094 y = topline - curwin->w_topline; | |
4095 if (y > 0) | |
4096 scrollup(y, FALSE); | |
4097 else | |
4098 scrolldown(-y, FALSE); | |
4099 } | |
4100 | |
4101 redraw_later(VALID); | |
4102 cursor_correct(); | |
4103 curwin->w_redr_status = TRUE; | |
4104 } | |
4105 | |
4106 /* | |
4107 * do the horizontal scroll | |
4108 */ | |
4109 if (want_hor && curwin->w_leftcol != tgt_leftcol) | |
4110 { | |
4111 curwin->w_leftcol = tgt_leftcol; | |
4112 leftcol_changed(); | |
4113 } | |
4114 } | |
4115 } | |
4116 | |
4117 /* | |
4118 * reset current-window | |
4119 */ | |
4120 VIsual_select = old_VIsual_select; | |
4121 VIsual_active = old_VIsual_active; | |
4122 curwin = old_curwin; | |
4123 curbuf = old_curbuf; | |
4124 } | |
4125 | |
4126 /* | |
4127 * Command character that's ignored. | |
4128 * 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
|
4129 * xon/xoff. |
7 | 4130 */ |
4131 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4132 nv_ignore(cmdarg_T *cap) |
7 | 4133 { |
226 | 4134 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
7 | 4135 } |
4136 | |
4137 /* | |
620 | 4138 * Command character that doesn't do anything, but unlike nv_ignore() does |
4139 * start edit(). Used for "startinsert" executed while starting up. | |
4140 */ | |
4141 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4142 nv_nop(cmdarg_T *cap UNUSED) |
620 | 4143 { |
4144 } | |
4145 | |
4146 /* | |
7 | 4147 * Command character doesn't exist. |
4148 */ | |
4149 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4150 nv_error(cmdarg_T *cap) |
7 | 4151 { |
4152 clearopbeep(cap->oap); | |
4153 } | |
4154 | |
4155 /* | |
4156 * <Help> and <F1> commands. | |
4157 */ | |
4158 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4159 nv_help(cmdarg_T *cap) |
7 | 4160 { |
4161 if (!checkclearopq(cap->oap)) | |
4162 ex_help(NULL); | |
4163 } | |
4164 | |
4165 /* | |
4166 * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor. | |
4167 */ | |
4168 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4169 nv_addsub(cmdarg_T *cap) |
7 | 4170 { |
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
|
4171 #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
|
4172 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
|
4173 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
|
4174 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
|
4175 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4176 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
|
4177 { |
7578
fdae4c496775
commit https://github.com/vim/vim/commit/ef2b5036b3005f1ce15d146dce72379a9834c56d
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
4178 prep_redo_cmd(cap); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4179 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
|
4180 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
|
4181 cap->oap->op_type = OP_NOP; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4182 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4183 else if (VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4184 nv_operator(cap); |
6868 | 4185 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4186 clearop(cap->oap); |
7 | 4187 } |
4188 | |
4189 /* | |
4190 * CTRL-F, CTRL-B, etc: Scroll page up or down. | |
4191 */ | |
4192 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4193 nv_page(cmdarg_T *cap) |
7 | 4194 { |
4195 if (!checkclearop(cap->oap)) | |
819 | 4196 { |
4197 if (mod_mask & MOD_MASK_CTRL) | |
4198 { | |
4199 /* <C-PageUp>: tab page back; <C-PageDown>: tab page forward */ | |
4200 if (cap->arg == BACKWARD) | |
4201 goto_tabpage(-(int)cap->count1); | |
4202 else | |
4203 goto_tabpage((int)cap->count0); | |
4204 } | |
4205 else | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
4206 (void)onepage(cap->arg, cap->count1); |
819 | 4207 } |
7 | 4208 } |
4209 | |
4210 /* | |
4211 * Implementation of "gd" and "gD" command. | |
4212 */ | |
4213 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4214 nv_gd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4215 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4216 int nchar, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4217 int thisblock) /* 1 for "1gd" and "1gD" */ |
7 | 4218 { |
4219 int len; | |
503 | 4220 char_u *ptr; |
4221 | |
4222 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
|
4223 || 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
|
4224 == FAIL) |
503 | 4225 clearopbeep(oap); |
4226 #ifdef FEAT_FOLDING | |
4227 else if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) | |
4228 foldOpenCursor(); | |
4229 #endif | |
4230 } | |
4231 | |
4232 /* | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4233 * 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
|
4234 * otherwise. |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4235 */ |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4236 static int |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4237 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
|
4238 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4239 int i; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4240 int incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4241 int instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4242 int prev = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4243 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4244 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
|
4245 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4246 if (instring != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4247 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4248 if (prev != '\\' && line[i] == instring) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4249 instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4250 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4251 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
|
4252 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4253 instring = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4254 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4255 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4256 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4257 if (incomment) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4258 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4259 if (prev == '*' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4260 incomment = FALSE; |
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 else if (prev == '/' && line[i] == '*') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4263 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4264 incomment = TRUE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4265 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4266 else if (prev == '/' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4267 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4268 return FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4269 } |
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 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4272 prev = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4273 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4274 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4275 return incomment == FALSE && instring == 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4276 } |
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 /* |
523 | 4279 * Search for variable declaration of "ptr[len]". |
4280 * When "locally" is TRUE in the current function ("gd"), otherwise in the | |
4281 * current file ("gD"). | |
4282 * When "thisblock" is TRUE check the {} block scope. | |
503 | 4283 * Return FAIL when not found. |
4284 */ | |
4285 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4286 find_decl( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4287 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4288 int len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4289 int locally, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4290 int thisblock, |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4291 int flags_arg) /* flags passed to searchit() */ |
503 | 4292 { |
7 | 4293 char_u *pat; |
4294 pos_T old_pos; | |
503 | 4295 pos_T par_pos; |
4296 pos_T found_pos; | |
7 | 4297 int t; |
4298 int save_p_ws; | |
4299 int save_p_scs; | |
503 | 4300 int retval = OK; |
944 | 4301 int incll; |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4302 int searchflags = flags_arg; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4303 int valid; |
503 | 4304 |
4305 if ((pat = alloc(len + 7)) == NULL) | |
4306 return FAIL; | |
268 | 4307 |
4308 /* Put "\V" before the pattern to avoid that the special meaning of "." | |
4309 * and "~" causes trouble. */ | |
4310 sprintf((char *)pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", | |
4311 len, ptr); | |
7 | 4312 old_pos = curwin->w_cursor; |
4313 save_p_ws = p_ws; | |
4314 save_p_scs = p_scs; | |
4315 p_ws = FALSE; /* don't wrap around end of file now */ | |
4316 p_scs = FALSE; /* don't switch ignorecase off now */ | |
4317 | |
4318 /* | |
4319 * With "gD" go to line 1. | |
4320 * With "gd" Search back for the start of the current function, then go | |
4321 * back until a blank line. If this fails go to line 1. | |
4322 */ | |
944 | 4323 if (!locally || !findpar(&incll, BACKWARD, 1L, '{', FALSE)) |
7 | 4324 { |
4325 setpcmark(); /* Set in findpar() otherwise */ | |
4326 curwin->w_cursor.lnum = 1; | |
539 | 4327 par_pos = curwin->w_cursor; |
7 | 4328 } |
4329 else | |
4330 { | |
539 | 4331 par_pos = curwin->w_cursor; |
7 | 4332 while (curwin->w_cursor.lnum > 1 && *skipwhite(ml_get_curline()) != NUL) |
4333 --curwin->w_cursor.lnum; | |
4334 } | |
4335 curwin->w_cursor.col = 0; | |
4336 | |
4337 /* 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
|
4338 CLEAR_POS(&found_pos); |
503 | 4339 for (;;) |
4340 { | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4341 valid = FALSE; |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4342 t = searchit(curwin, curbuf, &curwin->w_cursor, NULL, 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
|
4343 pat, 1L, searchflags, RE_LAST, (linenr_T)0, NULL, NULL); |
503 | 4344 if (curwin->w_cursor.lnum >= old_pos.lnum) |
4345 t = FAIL; /* match after start is failure too */ | |
523 | 4346 |
718 | 4347 if (thisblock && t != FAIL) |
523 | 4348 { |
4349 pos_T *pos; | |
4350 | |
4351 /* Check that the block the match is in doesn't end before the | |
4352 * position where we started the search from. */ | |
4353 if ((pos = findmatchlimit(NULL, '}', FM_FORWARD, | |
4354 (int)(old_pos.lnum - curwin->w_cursor.lnum + 1))) != NULL | |
4355 && pos->lnum < old_pos.lnum) | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4356 { |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4357 /* 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
|
4358 * Skip to the end. */ |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4359 curwin->w_cursor = *pos; |
523 | 4360 continue; |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4361 } |
523 | 4362 } |
4363 | |
503 | 4364 if (t == FAIL) |
4365 { | |
4366 /* If we previously found a valid position, use it. */ | |
4367 if (found_pos.lnum != 0) | |
4368 { | |
4369 curwin->w_cursor = found_pos; | |
4370 t = OK; | |
4371 } | |
4372 break; | |
4373 } | |
7 | 4374 #ifdef FEAT_COMMENTS |
3562 | 4375 if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0) |
503 | 4376 { |
4377 /* Ignore this line, continue at start of next line. */ | |
4378 ++curwin->w_cursor.lnum; | |
4379 curwin->w_cursor.col = 0; | |
4380 continue; | |
4381 } | |
4382 #endif | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4383 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
|
4384 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4385 /* 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
|
4386 * 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
|
4387 if (!valid && found_pos.lnum != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4388 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4389 curwin->w_cursor = found_pos; |
503 | 4390 break; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4391 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4392 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4393 /* 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
|
4394 if (valid && !locally) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4395 break; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4396 if (valid && curwin->w_cursor.lnum >= par_pos.lnum) |
503 | 4397 { |
4398 /* If we previously found a valid position, use it. */ | |
4399 if (found_pos.lnum != 0) | |
4400 curwin->w_cursor = found_pos; | |
4401 break; | |
4402 } | |
4403 | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4404 /* 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
|
4405 * 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
|
4406 * 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
|
4407 if (!valid) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4408 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4409 CLEAR_POS(&found_pos); |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4410 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4411 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4412 found_pos = curwin->w_cursor; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4413 /* 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
|
4414 * position. */ |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4415 searchflags &= ~SEARCH_START; |
503 | 4416 } |
4417 | |
4418 if (t == FAIL) | |
4419 { | |
4420 retval = FAIL; | |
7 | 4421 curwin->w_cursor = old_pos; |
4422 } | |
4423 else | |
4424 { | |
4425 curwin->w_set_curswant = TRUE; | |
4426 /* "n" searches forward now */ | |
4427 reset_search_dir(); | |
4428 } | |
4429 | |
4430 vim_free(pat); | |
4431 p_ws = save_p_ws; | |
4432 p_scs = save_p_scs; | |
503 | 4433 |
4434 return retval; | |
7 | 4435 } |
4436 | |
4437 /* | |
4438 * Move 'dist' lines in direction 'dir', counting lines by *screen* | |
4439 * lines rather than lines in the file. | |
4440 * 'dist' must be positive. | |
4441 * | |
4442 * Return OK if able to move cursor, FAIL otherwise. | |
4443 */ | |
4444 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4445 nv_screengo(oparg_T *oap, int dir, long dist) |
7 | 4446 { |
4447 int linelen = linetabsize(ml_get_curline()); | |
4448 int retval = OK; | |
4449 int atend = FALSE; | |
4450 int n; | |
4451 int col_off1; /* margin offset for first screen line */ | |
4452 int col_off2; /* margin offset for wrapped screen line */ | |
4453 int width1; /* text width for first screen line */ | |
4454 int width2; /* test width for wrapped screen line */ | |
4455 | |
4456 oap->motion_type = MCHAR; | |
5192
c28202427d71
updated for version 7.4a.022
Bram Moolenaar <bram@vim.org>
parents:
5162
diff
changeset
|
4457 oap->inclusive = (curwin->w_curswant == MAXCOL); |
7 | 4458 |
4459 col_off1 = curwin_col_off(); | |
4460 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
|
4461 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
|
4462 width2 = curwin->w_width - col_off2; |
6559 | 4463 if (width2 == 0) |
4464 width2 = 1; /* avoid divide by zero */ | |
7 | 4465 |
4466 if (curwin->w_width != 0) | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4467 { |
7 | 4468 /* |
4469 * Instead of sticking at the last character of the buffer line we | |
4470 * try to stick in the last column of the screen. | |
4471 */ | |
4472 if (curwin->w_curswant == MAXCOL) | |
4473 { | |
4474 atend = TRUE; | |
4475 validate_virtcol(); | |
4476 if (width1 <= 0) | |
4477 curwin->w_curswant = 0; | |
4478 else | |
4479 { | |
4480 curwin->w_curswant = width1 - 1; | |
4481 if (curwin->w_virtcol > curwin->w_curswant) | |
4482 curwin->w_curswant += ((curwin->w_virtcol | |
4483 - curwin->w_curswant - 1) / width2 + 1) * width2; | |
4484 } | |
4485 } | |
4486 else | |
4487 { | |
4488 if (linelen > width1) | |
4489 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
4490 else | |
4491 n = width1; | |
4492 if (curwin->w_curswant > (colnr_T)n + 1) | |
4493 curwin->w_curswant -= ((curwin->w_curswant - n) / width2 + 1) | |
4494 * width2; | |
4495 } | |
4496 | |
4497 while (dist--) | |
4498 { | |
4499 if (dir == BACKWARD) | |
4500 { | |
4501 if ((long)curwin->w_curswant >= width2) | |
4502 /* move back within line */ | |
4503 curwin->w_curswant -= width2; | |
4504 else | |
4505 { | |
4506 /* to previous line */ | |
4507 if (curwin->w_cursor.lnum == 1) | |
4508 { | |
4509 retval = FAIL; | |
4510 break; | |
4511 } | |
4512 --curwin->w_cursor.lnum; | |
4513 #ifdef FEAT_FOLDING | |
4514 /* Move to the start of a closed fold. Don't do that when | |
4515 * 'foldopen' contains "all": it will open in a moment. */ | |
4516 if (!(fdo_flags & FDO_ALL)) | |
4517 (void)hasFolding(curwin->w_cursor.lnum, | |
4518 &curwin->w_cursor.lnum, NULL); | |
4519 #endif | |
4520 linelen = linetabsize(ml_get_curline()); | |
4521 if (linelen > width1) | |
4522 curwin->w_curswant += (((linelen - width1 - 1) / width2) | |
4523 + 1) * width2; | |
4524 } | |
4525 } | |
4526 else /* dir == FORWARD */ | |
4527 { | |
4528 if (linelen > width1) | |
4529 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
4530 else | |
4531 n = width1; | |
4532 if (curwin->w_curswant + width2 < (colnr_T)n) | |
4533 /* move forward within line */ | |
4534 curwin->w_curswant += width2; | |
4535 else | |
4536 { | |
4537 /* to next line */ | |
4538 #ifdef FEAT_FOLDING | |
4539 /* Move to the end of a closed fold. */ | |
4540 (void)hasFolding(curwin->w_cursor.lnum, NULL, | |
4541 &curwin->w_cursor.lnum); | |
4542 #endif | |
4543 if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
4544 { | |
4545 retval = FAIL; | |
4546 break; | |
4547 } | |
4548 curwin->w_cursor.lnum++; | |
4549 curwin->w_curswant %= width2; | |
2911 | 4550 linelen = linetabsize(ml_get_curline()); |
7 | 4551 } |
4552 } | |
4553 } | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4554 } |
7 | 4555 |
5600 | 4556 if (virtual_active() && atend) |
4557 coladvance(MAXCOL); | |
4558 else | |
4559 coladvance(curwin->w_curswant); | |
7 | 4560 |
4561 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE) | |
4562 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
4563 { | |
6178 | 4564 colnr_T virtcol; |
4565 | |
7 | 4566 /* |
4567 * Check for landing on a character that got split at the end of the | |
4568 * last line. We want to advance a screenline, not end up in the same | |
4569 * screenline or move two screenlines. | |
4570 */ | |
4571 validate_virtcol(); | |
6178 | 4572 virtcol = curwin->w_virtcol; |
6187 | 4573 # if defined(FEAT_LINEBREAK) |
6178 | 4574 if (virtcol > (colnr_T)width1 && *p_sbr != NUL) |
4575 virtcol -= vim_strsize(p_sbr); | |
6187 | 4576 # endif |
6178 | 4577 |
4578 if (virtcol > curwin->w_curswant | |
7 | 4579 && (curwin->w_curswant < (colnr_T)width1 |
4580 ? (curwin->w_curswant > (colnr_T)width1 / 2) | |
4581 : ((curwin->w_curswant - width1) % width2 | |
4582 > (colnr_T)width2 / 2))) | |
4583 --curwin->w_cursor.col; | |
4584 } | |
4585 #endif | |
4586 | |
4587 if (atend) | |
4588 curwin->w_curswant = MAXCOL; /* stick in the last column */ | |
4589 | |
4590 return retval; | |
4591 } | |
4592 | |
4593 #ifdef FEAT_MOUSE | |
4594 /* | |
4595 * Mouse scroll wheel: Default action is to scroll three lines, or one page | |
4596 * 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
|
4597 * 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
|
4598 * K_MOUSELEFT (cap->arg == -1) or K_MOUSERIGHT (cap->arg == -2) |
7 | 4599 */ |
4600 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4601 nv_mousescroll(cmdarg_T *cap) |
7 | 4602 { |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4603 win_T *old_curwin = curwin, *wp; |
7 | 4604 |
4162 | 4605 if (mouse_row >= 0 && mouse_col >= 0) |
7 | 4606 { |
4607 int row, col; | |
4608 | |
4609 row = mouse_row; | |
4610 col = mouse_col; | |
4611 | |
4612 /* 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
|
4613 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
|
4614 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
|
4615 return; |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4616 curwin = wp; |
7 | 4617 curbuf = curwin->w_buffer; |
4618 } | |
4619 | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4620 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
|
4621 { |
11983
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4622 # 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
|
4623 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
|
4624 /* 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
|
4625 * 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
|
4626 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
|
4627 else |
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4628 # endif |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4629 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
|
4630 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4631 (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
|
4632 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4633 else |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4634 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4635 cap->count1 = 3; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4636 cap->count0 = 3; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4637 nv_scroll_line(cap); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4638 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4639 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4640 # ifdef FEAT_GUI |
7 | 4641 else |
4642 { | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4643 /* 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
|
4644 if (!curwin->w_p_wrap) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4645 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4646 int val, step = 6; |
2416
1a9c16dd76d4
Fix compiler warnings on 64 bit systems.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4647 |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4648 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
|
4649 step = curwin->w_width; |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4650 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
|
4651 if (val < 0) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4652 val = 0; |
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 gui_do_horiz_scroll(val, TRUE); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4655 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4656 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4657 # endif |
7 | 4658 |
4659 curwin->w_redr_status = TRUE; | |
4660 | |
4661 curwin = old_curwin; | |
4662 curbuf = curwin->w_buffer; | |
4663 } | |
4664 | |
4665 /* | |
4666 * Mouse clicks and drags. | |
4667 */ | |
4668 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4669 nv_mouse(cmdarg_T *cap) |
7 | 4670 { |
4671 (void)do_mouse(cap->oap, cap->cmdchar, BACKWARD, cap->count1, 0); | |
4672 } | |
4673 #endif | |
4674 | |
4675 /* | |
4676 * Handle CTRL-E and CTRL-Y commands: scroll a line up or down. | |
4677 * cap->arg must be TRUE for CTRL-E. | |
4678 */ | |
4679 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4680 nv_scroll_line(cmdarg_T *cap) |
7 | 4681 { |
4682 if (!checkclearop(cap->oap)) | |
4683 scroll_redraw(cap->arg, cap->count1); | |
4684 } | |
4685 | |
4686 /* | |
4687 * Scroll "count" lines up or down, and redraw. | |
4688 */ | |
4689 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4690 scroll_redraw(int up, long count) |
7 | 4691 { |
4692 linenr_T prev_topline = curwin->w_topline; | |
4693 #ifdef FEAT_DIFF | |
4694 int prev_topfill = curwin->w_topfill; | |
4695 #endif | |
4696 linenr_T prev_lnum = curwin->w_cursor.lnum; | |
4697 | |
4698 if (up) | |
4699 scrollup(count, TRUE); | |
4700 else | |
4701 scrolldown(count, TRUE); | |
4702 if (p_so) | |
4703 { | |
4704 /* Adjust the cursor position for 'scrolloff'. Mark w_topline as | |
4705 * valid, otherwise the screen jumps back at the end of the file. */ | |
4706 cursor_correct(); | |
4707 check_cursor_moved(curwin); | |
4708 curwin->w_valid |= VALID_TOPLINE; | |
4709 | |
4710 /* If moved back to where we were, at least move the cursor, otherwise | |
4711 * we get stuck at one position. Don't move the cursor up if the | |
4712 * first line of the buffer is already on the screen */ | |
4713 while (curwin->w_topline == prev_topline | |
4714 #ifdef FEAT_DIFF | |
4715 && curwin->w_topfill == prev_topfill | |
4716 #endif | |
4717 ) | |
4718 { | |
4719 if (up) | |
4720 { | |
4721 if (curwin->w_cursor.lnum > prev_lnum | |
4722 || cursor_down(1L, FALSE) == FAIL) | |
4723 break; | |
4724 } | |
4725 else | |
4726 { | |
4727 if (curwin->w_cursor.lnum < prev_lnum | |
4728 || prev_topline == 1L | |
4729 || cursor_up(1L, FALSE) == FAIL) | |
4730 break; | |
4731 } | |
4732 /* Mark w_topline as valid, otherwise the screen jumps back at the | |
4733 * end of the file. */ | |
4734 check_cursor_moved(curwin); | |
4735 curwin->w_valid |= VALID_TOPLINE; | |
4736 } | |
4737 } | |
4738 if (curwin->w_cursor.lnum != prev_lnum) | |
4739 coladvance(curwin->w_curswant); | |
4740 redraw_later(VALID); | |
4741 } | |
4742 | |
4743 /* | |
4744 * Commands that start with "z". | |
4745 */ | |
4746 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4747 nv_zet(cmdarg_T *cap) |
7 | 4748 { |
4749 long n; | |
4750 colnr_T col; | |
4751 int nchar = cap->nchar; | |
4752 #ifdef FEAT_FOLDING | |
4753 long old_fdl = curwin->w_p_fdl; | |
4754 int old_fen = curwin->w_p_fen; | |
4755 #endif | |
737 | 4756 #ifdef FEAT_SPELL |
710 | 4757 int undo = FALSE; |
4758 #endif | |
7 | 4759 |
4760 if (VIM_ISDIGIT(nchar)) | |
4761 { | |
4762 /* | |
4763 * "z123{nchar}": edit the count before obtaining {nchar} | |
4764 */ | |
4765 if (checkclearop(cap->oap)) | |
4766 return; | |
4767 n = nchar - '0'; | |
4768 for (;;) | |
4769 { | |
4770 #ifdef USE_ON_FLY_SCROLL | |
4771 dont_scroll = TRUE; /* disallow scrolling here */ | |
4772 #endif | |
4773 ++no_mapping; | |
4774 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 4775 nchar = plain_vgetc(); |
7 | 4776 LANGMAP_ADJUST(nchar, TRUE); |
4777 --no_mapping; | |
4778 --allow_keys; | |
4779 #ifdef FEAT_CMDL_INFO | |
4780 (void)add_to_showcmd(nchar); | |
4781 #endif | |
4782 if (nchar == K_DEL || nchar == K_KDEL) | |
4783 n /= 10; | |
4784 else if (VIM_ISDIGIT(nchar)) | |
4785 n = n * 10 + (nchar - '0'); | |
4786 else if (nchar == CAR) | |
4787 { | |
4788 #ifdef FEAT_GUI | |
4789 need_mouse_correct = TRUE; | |
4790 #endif | |
4791 win_setheight((int)n); | |
4792 break; | |
4793 } | |
4794 else if (nchar == 'l' | |
4795 || nchar == 'h' | |
4796 || nchar == K_LEFT | |
229 | 4797 || nchar == K_RIGHT) |
7 | 4798 { |
4799 cap->count1 = n ? n * cap->count1 : cap->count1; | |
4800 goto dozet; | |
4801 } | |
4802 else | |
4803 { | |
4804 clearopbeep(cap->oap); | |
4805 break; | |
4806 } | |
4807 } | |
4808 cap->oap->op_type = OP_NOP; | |
4809 return; | |
4810 } | |
4811 | |
4812 dozet: | |
4813 if ( | |
4814 #ifdef FEAT_FOLDING | |
4815 /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" | |
4816 * and "zC" only in Visual mode. "zj" and "zk" are motion | |
4817 * commands. */ | |
4818 cap->nchar != 'f' && cap->nchar != 'F' | |
4819 && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) | |
4820 && cap->nchar != 'j' && cap->nchar != 'k' | |
4821 && | |
4822 #endif | |
4823 checkclearop(cap->oap)) | |
4824 return; | |
4825 | |
4826 /* | |
4827 * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb": | |
4828 * If line number given, set cursor. | |
4829 */ | |
4830 if ((vim_strchr((char_u *)"+\r\nt.z^-b", nchar) != NULL) | |
4831 && cap->count0 | |
4832 && cap->count0 != curwin->w_cursor.lnum) | |
4833 { | |
4834 setpcmark(); | |
4835 if (cap->count0 > curbuf->b_ml.ml_line_count) | |
4836 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4837 else | |
4838 curwin->w_cursor.lnum = cap->count0; | |
22 | 4839 check_cursor_col(); |
7 | 4840 } |
4841 | |
4842 switch (nchar) | |
4843 { | |
4844 /* "z+", "z<CR>" and "zt": put cursor at top of screen */ | |
4845 case '+': | |
4846 if (cap->count0 == 0) | |
4847 { | |
4848 /* No count given: put cursor at the line below screen */ | |
4849 validate_botline(); /* make sure w_botline is valid */ | |
4850 if (curwin->w_botline > curbuf->b_ml.ml_line_count) | |
4851 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4852 else | |
4853 curwin->w_cursor.lnum = curwin->w_botline; | |
4854 } | |
4855 /* FALLTHROUGH */ | |
4856 case NL: | |
4857 case CAR: | |
4858 case K_KENTER: | |
4859 beginline(BL_WHITE | BL_FIX); | |
4860 /* FALLTHROUGH */ | |
4861 | |
4862 case 't': scroll_cursor_top(0, TRUE); | |
4863 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4864 set_fraction(curwin); |
7 | 4865 break; |
4866 | |
4867 /* "z." and "zz": put cursor in middle of screen */ | |
4868 case '.': beginline(BL_WHITE | BL_FIX); | |
4869 /* FALLTHROUGH */ | |
4870 | |
4871 case 'z': scroll_cursor_halfway(TRUE); | |
4872 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4873 set_fraction(curwin); |
7 | 4874 break; |
4875 | |
4876 /* "z^", "z-" and "zb": put cursor at bottom of screen */ | |
4877 case '^': /* Strange Vi behavior: <count>z^ finds line at top of window | |
4878 * when <count> is at bottom of window, and puts that one at | |
4879 * bottom of window. */ | |
4880 if (cap->count0 != 0) | |
4881 { | |
4882 scroll_cursor_bot(0, TRUE); | |
4883 curwin->w_cursor.lnum = curwin->w_topline; | |
4884 } | |
4885 else if (curwin->w_topline == 1) | |
4886 curwin->w_cursor.lnum = 1; | |
4887 else | |
4888 curwin->w_cursor.lnum = curwin->w_topline - 1; | |
4889 /* FALLTHROUGH */ | |
4890 case '-': | |
4891 beginline(BL_WHITE | BL_FIX); | |
4892 /* FALLTHROUGH */ | |
4893 | |
4894 case 'b': scroll_cursor_bot(0, TRUE); | |
4895 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4896 set_fraction(curwin); |
7 | 4897 break; |
4898 | |
4899 /* "zH" - scroll screen right half-page */ | |
4900 case 'H': | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
4901 cap->count1 *= curwin->w_width / 2; |
7 | 4902 /* FALLTHROUGH */ |
4903 | |
4904 /* "zh" - scroll screen to the right */ | |
4905 case 'h': | |
4906 case K_LEFT: | |
4907 if (!curwin->w_p_wrap) | |
4908 { | |
4909 if ((colnr_T)cap->count1 > curwin->w_leftcol) | |
4910 curwin->w_leftcol = 0; | |
4911 else | |
4912 curwin->w_leftcol -= (colnr_T)cap->count1; | |
4913 leftcol_changed(); | |
4914 } | |
4915 break; | |
4916 | |
4917 /* "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
|
4918 case 'L': cap->count1 *= curwin->w_width / 2; |
7 | 4919 /* FALLTHROUGH */ |
4920 | |
4921 /* "zl" - scroll screen to the left */ | |
4922 case 'l': | |
4923 case K_RIGHT: | |
4924 if (!curwin->w_p_wrap) | |
4925 { | |
4926 /* scroll the window left */ | |
4927 curwin->w_leftcol += (colnr_T)cap->count1; | |
4928 leftcol_changed(); | |
4929 } | |
4930 break; | |
4931 | |
4932 /* "zs" - scroll screen, cursor at the start */ | |
4933 case 's': if (!curwin->w_p_wrap) | |
4934 { | |
4935 #ifdef FEAT_FOLDING | |
4936 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4937 col = 0; /* like the cursor is in col 0 */ | |
4938 else | |
4939 #endif | |
4940 getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL); | |
4941 if ((long)col > p_siso) | |
4942 col -= p_siso; | |
4943 else | |
4944 col = 0; | |
4945 if (curwin->w_leftcol != col) | |
4946 { | |
4947 curwin->w_leftcol = col; | |
4948 redraw_later(NOT_VALID); | |
4949 } | |
4950 } | |
4951 break; | |
4952 | |
4953 /* "ze" - scroll screen, cursor at the end */ | |
4954 case 'e': if (!curwin->w_p_wrap) | |
4955 { | |
4956 #ifdef FEAT_FOLDING | |
4957 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4958 col = 0; /* like the cursor is in col 0 */ | |
4959 else | |
4960 #endif | |
4961 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
|
4962 n = curwin->w_width - curwin_col_off(); |
7 | 4963 if ((long)col + p_siso < n) |
4964 col = 0; | |
4965 else | |
4966 col = col + p_siso - n + 1; | |
4967 if (curwin->w_leftcol != col) | |
4968 { | |
4969 curwin->w_leftcol = col; | |
4970 redraw_later(NOT_VALID); | |
4971 } | |
4972 } | |
4973 break; | |
4974 | |
4975 #ifdef FEAT_FOLDING | |
4976 /* "zF": create fold command */ | |
4977 /* "zf": create fold operator */ | |
4978 case 'F': | |
4979 case 'f': if (foldManualAllowed(TRUE)) | |
4980 { | |
4981 cap->nchar = 'f'; | |
4982 nv_operator(cap); | |
4983 curwin->w_p_fen = TRUE; | |
4984 | |
4985 /* "zF" is like "zfzf" */ | |
4986 if (nchar == 'F' && cap->oap->op_type == OP_FOLD) | |
4987 { | |
4988 nv_operator(cap); | |
4989 finish_op = TRUE; | |
4990 } | |
4991 } | |
4992 else | |
4993 clearopbeep(cap->oap); | |
4994 break; | |
4995 | |
4996 /* "zd": delete fold at cursor */ | |
4997 /* "zD": delete fold at cursor recursively */ | |
4998 case 'd': | |
4999 case 'D': if (foldManualAllowed(FALSE)) | |
5000 { | |
5001 if (VIsual_active) | |
5002 nv_operator(cap); | |
5003 else | |
5004 deleteFold(curwin->w_cursor.lnum, | |
5005 curwin->w_cursor.lnum, nchar == 'D', FALSE); | |
5006 } | |
5007 break; | |
5008 | |
4352 | 5009 /* "zE": erase all folds */ |
7 | 5010 case 'E': if (foldmethodIsManual(curwin)) |
5011 { | |
5012 clearFolding(curwin); | |
5013 changed_window_setting(); | |
5014 } | |
5015 else if (foldmethodIsMarker(curwin)) | |
5016 deleteFold((linenr_T)1, curbuf->b_ml.ml_line_count, | |
5017 TRUE, FALSE); | |
5018 else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
5019 emsg(_("E352: Cannot erase folds with current 'foldmethod'")); |
7 | 5020 break; |
5021 | |
5022 /* "zn": fold none: reset 'foldenable' */ | |
5023 case 'n': curwin->w_p_fen = FALSE; | |
5024 break; | |
5025 | |
5026 /* "zN": fold Normal: set 'foldenable' */ | |
5027 case 'N': curwin->w_p_fen = TRUE; | |
5028 break; | |
5029 | |
5030 /* "zi": invert folding: toggle 'foldenable' */ | |
5031 case 'i': curwin->w_p_fen = !curwin->w_p_fen; | |
5032 break; | |
5033 | |
5034 /* "za": open closed fold or close open fold at cursor */ | |
5035 case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
5036 openFold(curwin->w_cursor.lnum, cap->count1); | |
5037 else | |
5038 { | |
5039 closeFold(curwin->w_cursor.lnum, cap->count1); | |
5040 curwin->w_p_fen = TRUE; | |
5041 } | |
5042 break; | |
5043 | |
5044 /* "zA": open fold at cursor recursively */ | |
5045 case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
5046 openFoldRecurse(curwin->w_cursor.lnum); | |
5047 else | |
5048 { | |
5049 closeFoldRecurse(curwin->w_cursor.lnum); | |
5050 curwin->w_p_fen = TRUE; | |
5051 } | |
5052 break; | |
5053 | |
5054 /* "zo": open fold at cursor or Visual area */ | |
5055 case 'o': if (VIsual_active) | |
5056 nv_operator(cap); | |
5057 else | |
5058 openFold(curwin->w_cursor.lnum, cap->count1); | |
5059 break; | |
5060 | |
5061 /* "zO": open fold recursively */ | |
5062 case 'O': if (VIsual_active) | |
5063 nv_operator(cap); | |
5064 else | |
5065 openFoldRecurse(curwin->w_cursor.lnum); | |
5066 break; | |
5067 | |
5068 /* "zc": close fold at cursor or Visual area */ | |
5069 case 'c': if (VIsual_active) | |
5070 nv_operator(cap); | |
5071 else | |
5072 closeFold(curwin->w_cursor.lnum, cap->count1); | |
5073 curwin->w_p_fen = TRUE; | |
5074 break; | |
5075 | |
5076 /* "zC": close fold recursively */ | |
5077 case 'C': if (VIsual_active) | |
5078 nv_operator(cap); | |
5079 else | |
5080 closeFoldRecurse(curwin->w_cursor.lnum); | |
5081 curwin->w_p_fen = TRUE; | |
5082 break; | |
5083 | |
5084 /* "zv": open folds at the cursor */ | |
5085 case 'v': foldOpenCursor(); | |
5086 break; | |
5087 | |
5088 /* "zx": re-apply 'foldlevel' and open folds at the cursor */ | |
5089 case 'x': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5090 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5091 newFoldLevel(); /* update right now */ |
7 | 5092 foldOpenCursor(); |
5093 break; | |
5094 | |
5095 /* "zX": undo manual opens/closes, re-apply 'foldlevel' */ | |
5096 case 'X': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5097 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5098 old_fdl = -1; /* force an update */ |
7 | 5099 break; |
5100 | |
5101 /* "zm": fold more */ | |
5102 case 'm': if (curwin->w_p_fdl > 0) | |
6725 | 5103 { |
5104 curwin->w_p_fdl -= cap->count1; | |
5105 if (curwin->w_p_fdl < 0) | |
5106 curwin->w_p_fdl = 0; | |
5107 } | |
7 | 5108 old_fdl = -1; /* force an update */ |
5109 curwin->w_p_fen = TRUE; | |
5110 break; | |
5111 | |
5112 /* "zM": close all folds */ | |
5113 case 'M': curwin->w_p_fdl = 0; | |
5114 old_fdl = -1; /* force an update */ | |
5115 curwin->w_p_fen = TRUE; | |
5116 break; | |
5117 | |
5118 /* "zr": reduce folding */ | |
6725 | 5119 case 'r': curwin->w_p_fdl += cap->count1; |
5120 { | |
5121 int d = getDeepestNesting(); | |
5122 | |
5123 if (curwin->w_p_fdl >= d) | |
5124 curwin->w_p_fdl = d; | |
5125 } | |
7 | 5126 break; |
5127 | |
5128 /* "zR": open all folds */ | |
5129 case 'R': curwin->w_p_fdl = getDeepestNesting(); | |
5130 old_fdl = -1; /* force an update */ | |
5131 break; | |
5132 | |
5133 case 'j': /* "zj" move to next fold downwards */ | |
5134 case 'k': /* "zk" move to next fold upwards */ | |
5135 if (foldMoveTo(TRUE, nchar == 'j' ? FORWARD : BACKWARD, | |
5136 cap->count1) == FAIL) | |
5137 clearopbeep(cap->oap); | |
5138 break; | |
5139 | |
5140 #endif /* FEAT_FOLDING */ | |
5141 | |
737 | 5142 #ifdef FEAT_SPELL |
710 | 5143 case 'u': /* "zug" and "zuw": undo "zg" and "zw" */ |
5144 ++no_mapping; | |
5145 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 5146 nchar = plain_vgetc(); |
710 | 5147 LANGMAP_ADJUST(nchar, TRUE); |
5148 --no_mapping; | |
5149 --allow_keys; | |
5150 #ifdef FEAT_CMDL_INFO | |
5151 (void)add_to_showcmd(nchar); | |
5152 #endif | |
5153 if (vim_strchr((char_u *)"gGwW", nchar) == NULL) | |
5154 { | |
5155 clearopbeep(cap->oap); | |
5156 break; | |
5157 } | |
5158 undo = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
5159 /* FALLTHROUGH */ |
710 | 5160 |
310 | 5161 case 'g': /* "zg": add good word to word list */ |
5162 case 'w': /* "zw": add wrong word to word list */ | |
381 | 5163 case 'G': /* "zG": add good word to temp word list */ |
5164 case 'W': /* "zW": add wrong word to temp word list */ | |
310 | 5165 { |
5166 char_u *ptr = NULL; | |
5167 int len; | |
5168 | |
5169 if (checkclearop(cap->oap)) | |
5170 break; | |
5171 if (VIsual_active && get_visual_text(cap, &ptr, &len) | |
5172 == FAIL) | |
5173 return; | |
501 | 5174 if (ptr == NULL) |
5175 { | |
5176 pos_T pos = curwin->w_cursor; | |
5177 | |
5374 | 5178 /* Find bad word under the cursor. When 'spell' is |
5179 * off this fails and find_ident_under_cursor() is | |
5180 * used below. */ | |
5181 emsg_off++; | |
534 | 5182 len = spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL); |
5374 | 5183 emsg_off--; |
501 | 5184 if (len != 0 && curwin->w_cursor.col <= pos.col) |
5185 ptr = ml_get_pos(&curwin->w_cursor); | |
5186 curwin->w_cursor = pos; | |
5187 } | |
5188 | |
310 | 5189 if (ptr == NULL && (len = find_ident_under_cursor(&ptr, |
5190 FIND_IDENT)) == 0) | |
5191 return; | |
381 | 5192 spell_add_word(ptr, len, nchar == 'w' || nchar == 'W', |
710 | 5193 (nchar == 'G' || nchar == 'W') |
5194 ? 0 : (int)cap->count1, | |
5195 undo); | |
310 | 5196 } |
316 | 5197 break; |
323 | 5198 |
584 | 5199 case '=': /* "z=": suggestions for a badly spelled word */ |
638 | 5200 if (!checkclearop(cap->oap)) |
485 | 5201 spell_suggest((int)cap->count0); |
323 | 5202 break; |
310 | 5203 #endif |
5204 | |
7 | 5205 default: clearopbeep(cap->oap); |
5206 } | |
5207 | |
5208 #ifdef FEAT_FOLDING | |
5209 /* Redraw when 'foldenable' changed */ | |
5210 if (old_fen != curwin->w_p_fen) | |
5211 { | |
5212 # ifdef FEAT_DIFF | |
5213 win_T *wp; | |
5214 | |
5215 if (foldmethodIsDiff(curwin) && curwin->w_p_scb) | |
5216 { | |
5217 /* Adjust 'foldenable' in diff-synced windows. */ | |
5218 FOR_ALL_WINDOWS(wp) | |
5219 { | |
5220 if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) | |
5221 { | |
5222 wp->w_p_fen = curwin->w_p_fen; | |
5223 changed_window_setting_win(wp); | |
5224 } | |
5225 } | |
5226 } | |
5227 # endif | |
5228 changed_window_setting(); | |
5229 } | |
5230 | |
5231 /* Redraw when 'foldlevel' changed. */ | |
5232 if (old_fdl != curwin->w_p_fdl) | |
5233 newFoldLevel(); | |
5234 #endif | |
5235 } | |
5236 | |
5237 #ifdef FEAT_GUI | |
5238 /* | |
5239 * Vertical scrollbar movement. | |
5240 */ | |
5241 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5242 nv_ver_scrollbar(cmdarg_T *cap) |
7 | 5243 { |
5244 if (cap->oap->op_type != OP_NOP) | |
5245 clearopbeep(cap->oap); | |
5246 | |
5247 /* Even if an operator was pending, we still want to scroll */ | |
5248 gui_do_scroll(); | |
5249 } | |
5250 | |
5251 /* | |
5252 * Horizontal scrollbar movement. | |
5253 */ | |
5254 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5255 nv_hor_scrollbar(cmdarg_T *cap) |
7 | 5256 { |
5257 if (cap->oap->op_type != OP_NOP) | |
5258 clearopbeep(cap->oap); | |
5259 | |
5260 /* 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
|
5261 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 5262 } |
5263 #endif | |
5264 | |
690 | 5265 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
685 | 5266 /* |
5267 * Click in GUI tab. | |
5268 */ | |
5269 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5270 nv_tabline(cmdarg_T *cap) |
685 | 5271 { |
5272 if (cap->oap->op_type != OP_NOP) | |
5273 clearopbeep(cap->oap); | |
5274 | |
5275 /* Even if an operator was pending, we still want to jump tabs. */ | |
5276 goto_tabpage(current_tab); | |
5277 } | |
686 | 5278 |
5279 /* | |
5280 * Selected item in tab line menu. | |
5281 */ | |
5282 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5283 nv_tabmenu(cmdarg_T *cap) |
686 | 5284 { |
5285 if (cap->oap->op_type != OP_NOP) | |
5286 clearopbeep(cap->oap); | |
5287 | |
5288 /* Even if an operator was pending, we still want to jump tabs. */ | |
690 | 5289 handle_tabmenu(); |
5290 } | |
5291 | |
5292 /* | |
5293 * Handle selecting an item of the GUI tab line menu. | |
5294 * Used in Normal and Insert mode. | |
5295 */ | |
5296 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5297 handle_tabmenu(void) |
690 | 5298 { |
686 | 5299 switch (current_tabmenu) |
5300 { | |
5301 case TABLINE_MENU_CLOSE: | |
5302 if (current_tab == 0) | |
5303 do_cmdline_cmd((char_u *)"tabclose"); | |
5304 else | |
5305 { | |
5306 vim_snprintf((char *)IObuff, IOSIZE, "tabclose %d", | |
5307 current_tab); | |
5308 do_cmdline_cmd(IObuff); | |
5309 } | |
5310 break; | |
5311 | |
5312 case TABLINE_MENU_NEW: | |
6631 | 5313 if (current_tab == 0) |
5314 do_cmdline_cmd((char_u *)"$tabnew"); | |
5315 else | |
5316 { | |
5317 vim_snprintf((char *)IObuff, IOSIZE, "%dtabnew", | |
5318 current_tab - 1); | |
5319 do_cmdline_cmd(IObuff); | |
5320 } | |
686 | 5321 break; |
5322 | |
5323 case TABLINE_MENU_OPEN: | |
6631 | 5324 if (current_tab == 0) |
5325 do_cmdline_cmd((char_u *)"browse $tabnew"); | |
5326 else | |
5327 { | |
5328 vim_snprintf((char *)IObuff, IOSIZE, "browse %dtabnew", | |
5329 current_tab - 1); | |
5330 do_cmdline_cmd(IObuff); | |
5331 } | |
686 | 5332 break; |
5333 } | |
5334 } | |
685 | 5335 #endif |
5336 | |
7 | 5337 /* |
5338 * "Q" command. | |
5339 */ | |
5340 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5341 nv_exmode(cmdarg_T *cap) |
7 | 5342 { |
5343 /* | |
5344 * Ignore 'Q' in Visual mode, just give a beep. | |
5345 */ | |
5346 if (VIsual_active) | |
6949 | 5347 vim_beep(BO_EX); |
5735 | 5348 else if (!checkclearop(cap->oap)) |
7 | 5349 do_exmode(FALSE); |
5350 } | |
5351 | |
5352 /* | |
5353 * Handle a ":" command. | |
5354 */ | |
5355 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5356 nv_colon(cmdarg_T *cap) |
7 | 5357 { |
5358 int old_p_im; | |
4256 | 5359 int cmd_result; |
7 | 5360 |
5361 if (VIsual_active) | |
5362 nv_operator(cap); | |
5363 else | |
5364 { | |
5365 if (cap->oap->op_type != OP_NOP) | |
5366 { | |
5367 /* Using ":" as a movement is characterwise exclusive. */ | |
5368 cap->oap->motion_type = MCHAR; | |
5369 cap->oap->inclusive = FALSE; | |
5370 } | |
5371 else if (cap->count0) | |
5372 { | |
5373 /* translate "count:" into ":.,.+(count - 1)" */ | |
5374 stuffcharReadbuff('.'); | |
5375 if (cap->count0 > 1) | |
5376 { | |
5377 stuffReadbuff((char_u *)",.+"); | |
5378 stuffnumReadbuff((long)cap->count0 - 1L); | |
5379 } | |
5380 } | |
5381 | |
5382 /* When typing, don't type below an old message */ | |
5383 if (KeyTyped) | |
5384 compute_cmdrow(); | |
5385 | |
5386 old_p_im = p_im; | |
5387 | |
5388 /* get a command line and execute it */ | |
4256 | 5389 cmd_result = do_cmdline(NULL, getexline, NULL, |
7 | 5390 cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0); |
5391 | |
5392 /* If 'insertmode' changed, enter or exit Insert mode */ | |
5393 if (p_im != old_p_im) | |
5394 { | |
5395 if (p_im) | |
5396 restart_edit = 'i'; | |
5397 else | |
5398 restart_edit = 0; | |
5399 } | |
5400 | |
4256 | 5401 if (cmd_result == FAIL) |
5402 /* The Ex command failed, do not execute the operator. */ | |
5403 clearop(cap->oap); | |
5404 else if (cap->oap->op_type != OP_NOP | |
7 | 5405 && (cap->oap->start.lnum > curbuf->b_ml.ml_line_count |
5406 || cap->oap->start.col > | |
4256 | 5407 (colnr_T)STRLEN(ml_get(cap->oap->start.lnum)) |
5408 || did_emsg | |
5409 )) | |
5410 /* The start of the operator has become invalid by the Ex command. | |
5411 */ | |
7 | 5412 clearopbeep(cap->oap); |
5413 } | |
5414 } | |
5415 | |
5416 /* | |
5417 * Handle CTRL-G command. | |
5418 */ | |
5419 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5420 nv_ctrlg(cmdarg_T *cap) |
7 | 5421 { |
5422 if (VIsual_active) /* toggle Selection/Visual mode */ | |
5423 { | |
5424 VIsual_select = !VIsual_select; | |
5425 showmode(); | |
5426 } | |
5735 | 5427 else if (!checkclearop(cap->oap)) |
7 | 5428 /* print full name if count given or :cd used */ |
5429 fileinfo((int)cap->count0, FALSE, TRUE); | |
5430 } | |
5431 | |
5432 /* | |
5433 * Handle CTRL-H <Backspace> command. | |
5434 */ | |
5435 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5436 nv_ctrlh(cmdarg_T *cap) |
7 | 5437 { |
5438 if (VIsual_active && VIsual_select) | |
5439 { | |
5440 cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */ | |
5441 v_visop(cap); | |
5442 } | |
5443 else | |
5444 nv_left(cap); | |
5445 } | |
5446 | |
5447 /* | |
5448 * CTRL-L: clear screen and redraw. | |
5449 */ | |
5450 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5451 nv_clear(cmdarg_T *cap) |
7 | 5452 { |
5453 if (!checkclearop(cap->oap)) | |
5454 { | |
5455 #if defined(__BEOS__) && !USE_THREAD_FOR_INPUT_WITH_TIMEOUT | |
5456 /* | |
5457 * Right now, the BeBox doesn't seem to have an easy way to detect | |
5458 * window resizing, so we cheat and make the user detect it | |
5459 * manually with CTRL-L instead | |
5460 */ | |
5461 ui_get_shellsize(); | |
5462 #endif | |
5463 #ifdef FEAT_SYN_HL | |
5464 /* 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
|
5465 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
|
5466 # ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5467 { |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5468 win_T *wp; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5469 |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5470 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
|
5471 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
|
5472 } |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5473 # endif |
7 | 5474 #endif |
5475 redraw_later(CLEAR); | |
5476 } | |
5477 } | |
5478 | |
5479 /* | |
5480 * CTRL-O: In Select mode: switch to Visual mode for one command. | |
5481 * Otherwise: Go to older pcmark. | |
5482 */ | |
5483 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5484 nv_ctrlo(cmdarg_T *cap) |
7 | 5485 { |
5486 if (VIsual_active && VIsual_select) | |
5487 { | |
5488 VIsual_select = FALSE; | |
5489 showmode(); | |
5490 restart_VIsual_select = 2; /* restart Select mode later */ | |
5491 } | |
5492 else | |
5493 { | |
5494 cap->count1 = -cap->count1; | |
5495 nv_pcmark(cap); | |
5496 } | |
5497 } | |
5498 | |
5499 /* | |
15006
1fd8e32532f7
patch 8.1.0514: CTRL-W ^ does not work when alternate buffer has no name
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5500 * CTRL-^ command, short for ":e #". Works even when the alternate buffer is |
1fd8e32532f7
patch 8.1.0514: CTRL-W ^ does not work when alternate buffer has no name
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5501 * not named. |
7 | 5502 */ |
5503 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5504 nv_hat(cmdarg_T *cap) |
7 | 5505 { |
5506 if (!checkclearopq(cap->oap)) | |
5507 (void)buflist_getfile((int)cap->count0, (linenr_T)0, | |
5508 GETF_SETMARK|GETF_ALT, FALSE); | |
5509 } | |
5510 | |
5511 /* | |
5512 * "Z" commands. | |
5513 */ | |
5514 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5515 nv_Zet(cmdarg_T *cap) |
7 | 5516 { |
5517 if (!checkclearopq(cap->oap)) | |
5518 { | |
5519 switch (cap->nchar) | |
5520 { | |
5521 /* "ZZ": equivalent to ":x". */ | |
5522 case 'Z': do_cmdline_cmd((char_u *)"x"); | |
5523 break; | |
5524 | |
5525 /* "ZQ": equivalent to ":q!" (Elvis compatible). */ | |
5526 case 'Q': do_cmdline_cmd((char_u *)"q!"); | |
5527 break; | |
5528 | |
5529 default: clearopbeep(cap->oap); | |
5530 } | |
5531 } | |
5532 } | |
5533 | |
5534 /* | |
5535 * Call nv_ident() as if "c1" was used, with "c2" as next character. | |
5536 */ | |
5537 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5538 do_nv_ident(int c1, int c2) |
7 | 5539 { |
5540 oparg_T oa; | |
5541 cmdarg_T ca; | |
5542 | |
5543 clear_oparg(&oa); | |
5544 vim_memset(&ca, 0, sizeof(ca)); | |
5545 ca.oap = &oa; | |
5546 ca.cmdchar = c1; | |
5547 ca.nchar = c2; | |
5548 nv_ident(&ca); | |
5549 } | |
5550 | |
5551 /* | |
5552 * Handle the commands that use the word under the cursor. | |
5553 * [g] CTRL-] :ta to current identifier | |
5554 * [g] 'K' run program for current identifier | |
5555 * [g] '*' / to current identifier or string | |
5556 * [g] '#' ? to current identifier or string | |
5557 * g ']' :tselect for current identifier | |
5558 */ | |
5559 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5560 nv_ident(cmdarg_T *cap) |
7 | 5561 { |
5562 char_u *ptr = NULL; | |
5563 char_u *buf; | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5564 unsigned buflen; |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5565 char_u *newbuf; |
7 | 5566 char_u *p; |
5567 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
|
5568 int kp_help; /* 'keywordprg' is ":he" */ |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5569 int kp_ex; /* 'keywordprg' starts with ":" */ |
7 | 5570 int n = 0; /* init for GCC */ |
5571 int cmdchar; | |
5572 int g_cmd; /* "g" command */ | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5573 int tag_cmd = FALSE; |
7 | 5574 char_u *aux_ptr; |
5575 int isman; | |
5576 int isman_s; | |
5577 | |
5578 if (cap->cmdchar == 'g') /* "g*", "g#", "g]" and "gCTRL-]" */ | |
5579 { | |
5580 cmdchar = cap->nchar; | |
5581 g_cmd = TRUE; | |
5582 } | |
5583 else | |
5584 { | |
5585 cmdchar = cap->cmdchar; | |
5586 g_cmd = FALSE; | |
5587 } | |
5588 | |
5589 if (cmdchar == POUND) /* the pound sign, '#' for English keyboards */ | |
5590 cmdchar = '#'; | |
5591 | |
5592 /* | |
5593 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode. | |
5594 */ | |
5595 if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') | |
5596 { | |
5597 if (VIsual_active && get_visual_text(cap, &ptr, &n) == FAIL) | |
5598 return; | |
5599 if (checkclearopq(cap->oap)) | |
5600 return; | |
5601 } | |
5602 | |
5603 if (ptr == NULL && (n = find_ident_under_cursor(&ptr, | |
5604 (cmdchar == '*' || cmdchar == '#') | |
5605 ? FIND_IDENT|FIND_STRING : FIND_IDENT)) == 0) | |
5606 { | |
5607 clearop(cap->oap); | |
5608 return; | |
5609 } | |
5610 | |
5611 /* Allocate buffer to put the command in. Inserting backslashes can | |
5612 * double the length of the word. p_kp / curbuf->b_p_kp could be added | |
5613 * and some numbers. */ | |
5614 kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); | |
5615 kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 | |
5616 || 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
|
5617 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
|
5618 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
5619 emsg(_(e_noident)); /* found white space only */ |
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
|
5620 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
|
5621 } |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5622 kp_ex = (*kp == ':'); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5623 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
|
5624 buf = alloc(buflen); |
7 | 5625 if (buf == NULL) |
5626 return; | |
5627 buf[0] = NUL; | |
5628 | |
5629 switch (cmdchar) | |
5630 { | |
5631 case '*': | |
5632 case '#': | |
5633 /* | |
5634 * Put cursor at start of word, makes search skip the word | |
5635 * under the cursor. | |
5636 * Call setpcmark() first, so "*``" puts the cursor back where | |
5637 * it was. | |
5638 */ | |
5639 setpcmark(); | |
5640 curwin->w_cursor.col = (colnr_T) (ptr - ml_get_curline()); | |
5641 | |
5642 if (!g_cmd && vim_iswordp(ptr)) | |
5643 STRCPY(buf, "\\<"); | |
5644 no_smartcase = TRUE; /* don't use 'smartcase' now */ | |
5645 break; | |
5646 | |
5647 case 'K': | |
5648 if (kp_help) | |
5649 STRCPY(buf, "he! "); | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5650 else if (kp_ex) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5651 { |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5652 if (cap->count0 != 0) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5653 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
|
5654 kp, cap->count0); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5655 else |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5656 STRCPY(buf, kp); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5657 STRCAT(buf, " "); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5658 } |
7 | 5659 else |
5660 { | |
1712 | 5661 /* An external command will probably use an argument starting |
5662 * with "-" as an option. To avoid trouble we skip the "-". */ | |
1728 | 5663 while (*ptr == '-' && n > 0) |
5664 { | |
1712 | 5665 ++ptr; |
1728 | 5666 --n; |
5667 } | |
5668 if (n == 0) | |
5669 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
5670 emsg(_(e_noident)); /* found dashes only */ |
1728 | 5671 vim_free(buf); |
5672 return; | |
5673 } | |
1712 | 5674 |
7 | 5675 /* When a count is given, turn it into a range. Is this |
5676 * really what we want? */ | |
5677 isman = (STRCMP(kp, "man") == 0); | |
5678 isman_s = (STRCMP(kp, "man -s") == 0); | |
5679 if (cap->count0 != 0 && !(isman || isman_s)) | |
5680 sprintf((char *)buf, ".,.+%ld", cap->count0 - 1); | |
5681 | |
5682 STRCAT(buf, "! "); | |
5683 if (cap->count0 == 0 && isman_s) | |
5684 STRCAT(buf, "man"); | |
5685 else | |
5686 STRCAT(buf, kp); | |
5687 STRCAT(buf, " "); | |
5688 if (cap->count0 != 0 && (isman || isman_s)) | |
5689 { | |
5690 sprintf((char *)buf + STRLEN(buf), "%ld", cap->count0); | |
5691 STRCAT(buf, " "); | |
5692 } | |
5693 } | |
5694 break; | |
5695 | |
5696 case ']': | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5697 tag_cmd = TRUE; |
7 | 5698 #ifdef FEAT_CSCOPE |
5699 if (p_cst) | |
5700 STRCPY(buf, "cstag "); | |
5701 else | |
5702 #endif | |
5703 STRCPY(buf, "ts "); | |
5704 break; | |
5705 | |
5706 default: | |
2112
6b5d641bcdd4
updated for version 7.2.395
Bram Moolenaar <bram@zimbu.org>
parents:
2049
diff
changeset
|
5707 tag_cmd = TRUE; |
7 | 5708 if (curbuf->b_help) |
5709 STRCPY(buf, "he! "); | |
5710 else | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5711 { |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5712 if (g_cmd) |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5713 STRCPY(buf, "tj "); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5714 else |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5715 sprintf((char *)buf, "%ldta ", cap->count0); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5716 } |
7 | 5717 } |
5718 | |
5719 /* | |
5720 * Now grab the chars in the identifier | |
5721 */ | |
1712 | 5722 if (cmdchar == 'K' && !kp_help) |
5723 { | |
1728 | 5724 ptr = vim_strnsave(ptr, n); |
10330
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5725 if (kp_ex) |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5726 /* 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
|
5727 p = vim_strsave_fnameescape(ptr, FALSE); |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5728 else |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5729 /* 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
|
5730 p = vim_strsave_shellescape(ptr, TRUE, TRUE); |
1728 | 5731 vim_free(ptr); |
1712 | 5732 if (p == NULL) |
5733 { | |
5734 vim_free(buf); | |
5735 return; | |
5736 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5737 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
|
5738 if (newbuf == NULL) |
1712 | 5739 { |
5740 vim_free(buf); | |
5741 vim_free(p); | |
5742 return; | |
5743 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5744 buf = newbuf; |
1712 | 5745 STRCAT(buf, p); |
5746 vim_free(p); | |
5747 } | |
7 | 5748 else |
1712 | 5749 { |
5750 if (cmdchar == '*') | |
5751 aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\"); | |
5752 else if (cmdchar == '#') | |
5753 aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\"); | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5754 else if (tag_cmd) |
2603 | 5755 { |
5756 if (curbuf->b_help) | |
5757 /* ":help" handles unescaped argument */ | |
5758 aux_ptr = (char_u *)""; | |
5759 else | |
5760 aux_ptr = (char_u *)"\\|\"\n["; | |
5761 } | |
1712 | 5762 else |
5763 aux_ptr = (char_u *)"\\|\"\n*?["; | |
5764 | |
5765 p = buf + STRLEN(buf); | |
5766 while (n-- > 0) | |
5767 { | |
5768 /* put a backslash before \ and some others */ | |
5769 if (vim_strchr(aux_ptr, *ptr) != NULL) | |
5770 *p++ = '\\'; | |
7 | 5771 #ifdef FEAT_MBYTE |
1712 | 5772 /* When current byte is a part of multibyte character, copy all |
5773 * bytes of that character. */ | |
5774 if (has_mbyte) | |
5775 { | |
5776 int i; | |
5777 int len = (*mb_ptr2len)(ptr) - 1; | |
5778 | |
5779 for (i = 0; i < len && n >= 1; ++i, --n) | |
5780 *p++ = *ptr++; | |
5781 } | |
5782 #endif | |
5783 *p++ = *ptr++; | |
5784 } | |
5785 *p = NUL; | |
5786 } | |
7 | 5787 |
5788 /* | |
5789 * Execute the command. | |
5790 */ | |
5791 if (cmdchar == '*' || cmdchar == '#') | |
5792 { | |
5793 if (!g_cmd && ( | |
5794 #ifdef FEAT_MBYTE | |
5795 has_mbyte ? vim_iswordp(mb_prevptr(ml_get_curline(), ptr)) : | |
5796 #endif | |
5797 vim_iswordc(ptr[-1]))) | |
5798 STRCAT(buf, "\\>"); | |
5799 #ifdef FEAT_CMDHIST | |
5800 /* put pattern in search history */ | |
2024 | 5801 init_history(); |
7 | 5802 add_to_history(HIST_SEARCH, buf, TRUE, NUL); |
5803 #endif | |
6620 | 5804 (void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0); |
7 | 5805 } |
5806 else | |
5807 do_cmdline_cmd(buf); | |
5808 | |
5809 vim_free(buf); | |
5810 } | |
5811 | |
5812 /* | |
5813 * Get visually selected text, within one line only. | |
5814 * Returns FAIL if more than one line selected. | |
5815 */ | |
344 | 5816 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5817 get_visual_text( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5818 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5819 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
|
5820 int *lenp) /* return: length of selected text */ |
7 | 5821 { |
5822 if (VIsual_mode != 'V') | |
5823 unadjust_for_sel(); | |
5824 if (VIsual.lnum != curwin->w_cursor.lnum) | |
5825 { | |
344 | 5826 if (cap != NULL) |
5827 clearopbeep(cap->oap); | |
7 | 5828 return FAIL; |
5829 } | |
5830 if (VIsual_mode == 'V') | |
5831 { | |
5832 *pp = ml_get_curline(); | |
5833 *lenp = (int)STRLEN(*pp); | |
5834 } | |
5835 else | |
5836 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5837 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 5838 { |
5839 *pp = ml_get_pos(&curwin->w_cursor); | |
5840 *lenp = VIsual.col - curwin->w_cursor.col + 1; | |
5841 } | |
5842 else | |
5843 { | |
5844 *pp = ml_get_pos(&VIsual); | |
5845 *lenp = curwin->w_cursor.col - VIsual.col + 1; | |
5846 } | |
5847 #ifdef FEAT_MBYTE | |
5848 if (has_mbyte) | |
5849 /* Correct the length to include the whole last character. */ | |
474 | 5850 *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; |
7 | 5851 #endif |
5852 } | |
5853 reset_VIsual_and_resel(); | |
5854 return OK; | |
5855 } | |
5856 | |
5857 /* | |
5858 * CTRL-T: backwards in tag stack | |
5859 */ | |
5860 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5861 nv_tagpop(cmdarg_T *cap) |
7 | 5862 { |
5863 if (!checkclearopq(cap->oap)) | |
5864 do_tag((char_u *)"", DT_POP, (int)cap->count1, FALSE, TRUE); | |
5865 } | |
5866 | |
5867 /* | |
5868 * Handle scrolling command 'H', 'L' and 'M'. | |
5869 */ | |
5870 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5871 nv_scroll(cmdarg_T *cap) |
7 | 5872 { |
5873 int used = 0; | |
5874 long n; | |
5875 #ifdef FEAT_FOLDING | |
5876 linenr_T lnum; | |
5877 #endif | |
5878 int half; | |
5879 | |
5880 cap->oap->motion_type = MLINE; | |
5881 setpcmark(); | |
5882 | |
5883 if (cap->cmdchar == 'L') | |
5884 { | |
5885 validate_botline(); /* make sure curwin->w_botline is valid */ | |
5886 curwin->w_cursor.lnum = curwin->w_botline - 1; | |
5887 if (cap->count1 - 1 >= curwin->w_cursor.lnum) | |
5888 curwin->w_cursor.lnum = 1; | |
5889 else | |
9 | 5890 { |
5891 #ifdef FEAT_FOLDING | |
5892 if (hasAnyFolding(curwin)) | |
5893 { | |
5894 /* Count a fold for one screen line. */ | |
5895 for (n = cap->count1 - 1; n > 0 | |
5896 && curwin->w_cursor.lnum > curwin->w_topline; --n) | |
5897 { | |
5898 (void)hasFolding(curwin->w_cursor.lnum, | |
5899 &curwin->w_cursor.lnum, NULL); | |
5900 --curwin->w_cursor.lnum; | |
5901 } | |
5902 } | |
5903 else | |
5904 #endif | |
5905 curwin->w_cursor.lnum -= cap->count1 - 1; | |
5906 } | |
7 | 5907 } |
5908 else | |
5909 { | |
5910 if (cap->cmdchar == 'M') | |
5911 { | |
5912 #ifdef FEAT_DIFF | |
5913 /* Don't count filler lines above the window. */ | |
5914 used -= diff_check_fill(curwin, curwin->w_topline) | |
5915 - curwin->w_topfill; | |
5916 #endif | |
5917 validate_botline(); /* make sure w_empty_rows is valid */ | |
5918 half = (curwin->w_height - curwin->w_empty_rows + 1) / 2; | |
5919 for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) | |
5920 { | |
5921 #ifdef FEAT_DIFF | |
5922 /* Count half he number of filler lines to be "below this | |
5923 * line" and half to be "above the next line". */ | |
5924 if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline | |
5925 + n) / 2 >= half) | |
5926 { | |
5927 --n; | |
5928 break; | |
5929 } | |
5930 #endif | |
5931 used += plines(curwin->w_topline + n); | |
5932 if (used >= half) | |
5933 break; | |
5934 #ifdef FEAT_FOLDING | |
5935 if (hasFolding(curwin->w_topline + n, NULL, &lnum)) | |
5936 n = lnum - curwin->w_topline; | |
5937 #endif | |
5938 } | |
5939 if (n > 0 && used > curwin->w_height) | |
5940 --n; | |
5941 } | |
9 | 5942 else /* (cap->cmdchar == 'H') */ |
5943 { | |
7 | 5944 n = cap->count1 - 1; |
9 | 5945 #ifdef FEAT_FOLDING |
5946 if (hasAnyFolding(curwin)) | |
5947 { | |
5948 /* Count a fold for one screen line. */ | |
5949 lnum = curwin->w_topline; | |
5950 while (n-- > 0 && lnum < curwin->w_botline - 1) | |
5951 { | |
7009 | 5952 (void)hasFolding(lnum, NULL, &lnum); |
9 | 5953 ++lnum; |
5954 } | |
5955 n = lnum - curwin->w_topline; | |
5956 } | |
5957 #endif | |
5958 } | |
7 | 5959 curwin->w_cursor.lnum = curwin->w_topline + n; |
5960 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
5961 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
5962 } | |
5963 | |
12646
b908a3682f6e
patch 8.0.1201: "yL" is affected by 'scrolloff'
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
5964 /* 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
|
5965 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
|
5966 cursor_correct(); |
7 | 5967 beginline(BL_SOL | BL_FIX); |
5968 } | |
5969 | |
5970 /* | |
5971 * Cursor right commands. | |
5972 */ | |
5973 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5974 nv_right(cmdarg_T *cap) |
7 | 5975 { |
5976 long n; | |
5735 | 5977 int past_line; |
7 | 5978 |
180 | 5979 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
5980 { | |
5981 /* <C-Right> and <S-Right> move a word or WORD right */ | |
5982 if (mod_mask & MOD_MASK_CTRL) | |
5983 cap->arg = TRUE; | |
5984 nv_wordcmd(cap); | |
5985 return; | |
5986 } | |
5987 | |
7 | 5988 cap->oap->motion_type = MCHAR; |
5989 cap->oap->inclusive = FALSE; | |
5735 | 5990 past_line = (VIsual_active && *p_sel != 'o'); |
5991 | |
5992 #ifdef FEAT_VIRTUALEDIT | |
7 | 5993 /* |
5735 | 5994 * In virtual edit mode, there's no such thing as "past_line", as lines |
5995 * are (theoretically) infinitely long. | |
7 | 5996 */ |
5997 if (virtual_active()) | |
5735 | 5998 past_line = 0; |
7 | 5999 #endif |
6000 | |
6001 for (n = cap->count1; n > 0; --n) | |
6002 { | |
5735 | 6003 if ((!past_line && oneright() == FAIL) |
6004 || (past_line && *ml_get_cursor() == NUL) | |
1877 | 6005 ) |
7 | 6006 { |
6007 /* | |
714 | 6008 * <Space> wraps to next line if 'whichwrap' has 's'. |
6009 * 'l' wraps to next line if 'whichwrap' has 'l'. | |
6010 * CURS_RIGHT wraps to next line if 'whichwrap' has '>'. | |
7 | 6011 */ |
6012 if ( ((cap->cmdchar == ' ' | |
6013 && vim_strchr(p_ww, 's') != NULL) | |
6014 || (cap->cmdchar == 'l' | |
6015 && vim_strchr(p_ww, 'l') != NULL) | |
229 | 6016 || (cap->cmdchar == K_RIGHT |
7 | 6017 && vim_strchr(p_ww, '>') != NULL)) |
6018 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
6019 { | |
6020 /* When deleting we also count the NL as a character. | |
6021 * Set cap->oap->inclusive when last char in the line is | |
6022 * included, move to next line after that */ | |
714 | 6023 if ( cap->oap->op_type != OP_NOP |
7 | 6024 && !cap->oap->inclusive |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6025 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6026 cap->oap->inclusive = TRUE; |
6027 else | |
6028 { | |
6029 ++curwin->w_cursor.lnum; | |
6030 curwin->w_cursor.col = 0; | |
6031 #ifdef FEAT_VIRTUALEDIT | |
6032 curwin->w_cursor.coladd = 0; | |
6033 #endif | |
6034 curwin->w_set_curswant = TRUE; | |
6035 cap->oap->inclusive = FALSE; | |
6036 } | |
6037 continue; | |
6038 } | |
6039 if (cap->oap->op_type == OP_NOP) | |
6040 { | |
6041 /* Only beep and flush if not moved at all */ | |
6042 if (n == cap->count1) | |
6043 beep_flush(); | |
6044 } | |
6045 else | |
6046 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6047 if (!LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6048 cap->oap->inclusive = TRUE; |
6049 } | |
6050 break; | |
6051 } | |
5735 | 6052 else if (past_line) |
7 | 6053 { |
6054 curwin->w_set_curswant = TRUE; | |
5735 | 6055 #ifdef FEAT_VIRTUALEDIT |
7 | 6056 if (virtual_active()) |
6057 oneright(); | |
6058 else | |
5735 | 6059 #endif |
6060 { | |
6061 #ifdef FEAT_MBYTE | |
7 | 6062 if (has_mbyte) |
6063 curwin->w_cursor.col += | |
474 | 6064 (*mb_ptr2len)(ml_get_cursor()); |
7 | 6065 else |
5735 | 6066 #endif |
7 | 6067 ++curwin->w_cursor.col; |
6068 } | |
6069 } | |
6070 } | |
6071 #ifdef FEAT_FOLDING | |
6072 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
6073 && cap->oap->op_type == OP_NOP) | |
6074 foldOpenCursor(); | |
6075 #endif | |
6076 } | |
6077 | |
6078 /* | |
6079 * Cursor left commands. | |
6080 * | |
6081 * Returns TRUE when operator end should not be adjusted. | |
6082 */ | |
6083 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6084 nv_left(cmdarg_T *cap) |
7 | 6085 { |
6086 long n; | |
6087 | |
180 | 6088 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
6089 { | |
6090 /* <C-Left> and <S-Left> move a word or WORD left */ | |
6091 if (mod_mask & MOD_MASK_CTRL) | |
6092 cap->arg = 1; | |
6093 nv_bck_word(cap); | |
6094 return; | |
6095 } | |
6096 | |
7 | 6097 cap->oap->motion_type = MCHAR; |
6098 cap->oap->inclusive = FALSE; | |
6099 for (n = cap->count1; n > 0; --n) | |
6100 { | |
6101 if (oneleft() == FAIL) | |
6102 { | |
6103 /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'. | |
6104 * 'h' wraps to previous line if 'whichwrap' has 'h'. | |
6105 * CURS_LEFT wraps to previous line if 'whichwrap' has '<'. | |
6106 */ | |
6107 if ( (((cap->cmdchar == K_BS | |
6108 || cap->cmdchar == Ctrl_H) | |
6109 && vim_strchr(p_ww, 'b') != NULL) | |
6110 || (cap->cmdchar == 'h' | |
6111 && vim_strchr(p_ww, 'h') != NULL) | |
229 | 6112 || (cap->cmdchar == K_LEFT |
7 | 6113 && vim_strchr(p_ww, '<') != NULL)) |
6114 && curwin->w_cursor.lnum > 1) | |
6115 { | |
6116 --(curwin->w_cursor.lnum); | |
6117 coladvance((colnr_T)MAXCOL); | |
6118 curwin->w_set_curswant = TRUE; | |
6119 | |
6120 /* When the NL before the first char has to be deleted we | |
6121 * put the cursor on the NUL after the previous line. | |
6122 * This is a very special case, be careful! | |
1469 | 6123 * Don't adjust op_end now, otherwise it won't work. */ |
7 | 6124 if ( (cap->oap->op_type == OP_DELETE |
6125 || 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
|
6126 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6127 { |
5682 | 6128 char_u *cp = ml_get_cursor(); |
6129 | |
6130 if (*cp != NUL) | |
6131 { | |
6132 #ifdef FEAT_MBYTE | |
6133 if (has_mbyte) | |
6134 curwin->w_cursor.col += (*mb_ptr2len)(cp); | |
6135 else | |
6136 #endif | |
6137 ++curwin->w_cursor.col; | |
6138 } | |
7 | 6139 cap->retval |= CA_NO_ADJ_OP_END; |
6140 } | |
6141 continue; | |
6142 } | |
6143 /* Only beep and flush if not moved at all */ | |
6144 else if (cap->oap->op_type == OP_NOP && n == cap->count1) | |
6145 beep_flush(); | |
6146 break; | |
6147 } | |
6148 } | |
6149 #ifdef FEAT_FOLDING | |
6150 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
6151 && cap->oap->op_type == OP_NOP) | |
6152 foldOpenCursor(); | |
6153 #endif | |
6154 } | |
6155 | |
6156 /* | |
6157 * Cursor up commands. | |
6158 * cap->arg is TRUE for "-": Move cursor to first non-blank. | |
6159 */ | |
6160 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6161 nv_up(cmdarg_T *cap) |
7 | 6162 { |
180 | 6163 if (mod_mask & MOD_MASK_SHIFT) |
6164 { | |
6165 /* <S-Up> is page up */ | |
6166 cap->arg = BACKWARD; | |
6167 nv_page(cap); | |
6168 } | |
6169 else | |
6170 { | |
6171 cap->oap->motion_type = MLINE; | |
6172 if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
6173 clearopbeep(cap->oap); | |
6174 else if (cap->arg) | |
6175 beginline(BL_WHITE | BL_FIX); | |
6176 } | |
7 | 6177 } |
6178 | |
6179 /* | |
6180 * Cursor down commands. | |
6181 * cap->arg is TRUE for CR and "+": Move cursor to first non-blank. | |
6182 */ | |
6183 static void | |
10192
758f3d5a463d
commit https://github.com/vim/vim/commit/1b010058235fb803c1d4f42a02d2883921be8ef4
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
6184 nv_down(cmdarg_T *cap) |
7 | 6185 { |
180 | 6186 if (mod_mask & MOD_MASK_SHIFT) |
6187 { | |
6188 /* <S-Down> is page down */ | |
6189 cap->arg = FORWARD; | |
6190 nv_page(cap); | |
6191 } | |
14397
19d99d9e670c
patch 8.1.0213: CTRL-W CR does not work properly in a quickfix window
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
6192 #if defined(FEAT_QUICKFIX) |
19d99d9e670c
patch 8.1.0213: CTRL-W CR does not work properly in a quickfix window
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
6193 /* Quickfix window only: view the result under the cursor. */ |
19d99d9e670c
patch 8.1.0213: CTRL-W CR does not work properly in a quickfix window
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
6194 else if (bt_quickfix(curbuf) && cap->cmdchar == CAR) |
19d99d9e670c
patch 8.1.0213: CTRL-W CR does not work properly in a quickfix window
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
6195 qf_view_result(FALSE); |
19d99d9e670c
patch 8.1.0213: CTRL-W CR does not work properly in a quickfix window
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
6196 #endif |
180 | 6197 else |
7 | 6198 { |
6199 #ifdef FEAT_CMDWIN | |
6200 /* In the cmdline window a <CR> executes the command. */ | |
170 | 6201 if (cmdwin_type != 0 && cap->cmdchar == CAR) |
7 | 6202 cmdwin_result = CAR; |
6203 else | |
6204 #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
|
6205 #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
|
6206 /* 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
|
6207 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
|
6208 && 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
|
6209 { |
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
|
6210 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
|
6211 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
|
6212 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
|
6213 } |
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
|
6214 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
|
6215 #endif |
7 | 6216 { |
6217 cap->oap->motion_type = MLINE; | |
6218 if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
6219 clearopbeep(cap->oap); | |
6220 else if (cap->arg) | |
6221 beginline(BL_WHITE | BL_FIX); | |
6222 } | |
6223 } | |
6224 } | |
6225 | |
6226 #ifdef FEAT_SEARCHPATH | |
6227 /* | |
6228 * Grab the file name under the cursor and edit it. | |
6229 */ | |
6230 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6231 nv_gotofile(cmdarg_T *cap) |
7 | 6232 { |
6233 char_u *ptr; | |
681 | 6234 linenr_T lnum = -1; |
7 | 6235 |
633 | 6236 if (text_locked()) |
7 | 6237 { |
6238 clearopbeep(cap->oap); | |
633 | 6239 text_locked_msg(); |
7 | 6240 return; |
6241 } | |
819 | 6242 if (curbuf_locked()) |
6243 { | |
6244 clearop(cap->oap); | |
6245 return; | |
6246 } | |
7 | 6247 |
681 | 6248 ptr = grab_file_name(cap->count1, &lnum); |
7 | 6249 |
6250 if (ptr != NULL) | |
6251 { | |
6252 /* 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
|
6253 if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !buf_hide(curbuf)) |
7009 | 6254 (void)autowrite(curbuf, FALSE); |
7 | 6255 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
|
6256 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
|
6257 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
|
6258 && cap->nchar == 'F' && lnum >= 0) |
681 | 6259 { |
6260 curwin->w_cursor.lnum = lnum; | |
6261 check_cursor_lnum(); | |
6262 beginline(BL_SOL | BL_FIX); | |
6263 } | |
7 | 6264 vim_free(ptr); |
6265 } | |
6266 else | |
6267 clearop(cap->oap); | |
6268 } | |
6269 #endif | |
6270 | |
6271 /* | |
6272 * <End> command: to end of current line or last line. | |
6273 */ | |
6274 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6275 nv_end(cmdarg_T *cap) |
7 | 6276 { |
180 | 6277 if (cap->arg || (mod_mask & MOD_MASK_CTRL)) /* CTRL-END = goto last line */ |
6278 { | |
6279 cap->arg = TRUE; | |
7 | 6280 nv_goto(cap); |
6281 cap->count1 = 1; /* to end of current line */ | |
6282 } | |
6283 nv_dollar(cap); | |
6284 } | |
6285 | |
6286 /* | |
6287 * Handle the "$" command. | |
6288 */ | |
6289 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6290 nv_dollar(cmdarg_T *cap) |
7 | 6291 { |
6292 cap->oap->motion_type = MCHAR; | |
6293 cap->oap->inclusive = TRUE; | |
6294 #ifdef FEAT_VIRTUALEDIT | |
6295 /* In virtual mode when off the edge of a line and an operator | |
6296 * is pending (whew!) keep the cursor where it is. | |
6297 * Otherwise, send it to the end of the line. */ | |
6298 if (!virtual_active() || gchar_cursor() != NUL | |
6299 || cap->oap->op_type == OP_NOP) | |
6300 #endif | |
6301 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
6302 if (cursor_down((long)(cap->count1 - 1), | |
6303 cap->oap->op_type == OP_NOP) == FAIL) | |
6304 clearopbeep(cap->oap); | |
6305 #ifdef FEAT_FOLDING | |
6306 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6307 foldOpenCursor(); | |
6308 #endif | |
6309 } | |
6310 | |
6311 /* | |
6312 * Implementation of '?' and '/' commands. | |
6313 * If cap->arg is TRUE don't set PC mark. | |
6314 */ | |
6315 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6316 nv_search(cmdarg_T *cap) |
7 | 6317 { |
6318 oparg_T *oap = cap->oap; | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6319 pos_T save_cursor = curwin->w_cursor; |
7 | 6320 |
6321 if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13) | |
6322 { | |
6323 /* Translate "g??" to "g?g?" */ | |
6324 cap->cmdchar = 'g'; | |
6325 cap->nchar = '?'; | |
6326 nv_operator(cap); | |
6327 return; | |
6328 } | |
6329 | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6330 /* 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
|
6331 * start position. */ |
7 | 6332 cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0); |
6333 | |
6334 if (cap->searchbuf == NULL) | |
6335 { | |
6336 clearop(oap); | |
6337 return; | |
6338 } | |
6339 | |
6620 | 6340 (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
|
6341 (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
|
6342 ? 0 : SEARCH_MARK); |
7 | 6343 } |
6344 | |
6345 /* | |
6346 * Handle "N" and "n" commands. | |
6347 * cap->arg is SEARCH_REV for "N", 0 for "n". | |
6348 */ | |
6349 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6350 nv_next(cmdarg_T *cap) |
7 | 6351 { |
6620 | 6352 pos_T old = curwin->w_cursor; |
6353 int i = normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
6354 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6355 if (i == 1 && EQUAL_POS(old, curwin->w_cursor)) |
6620 | 6356 { |
6357 /* Avoid getting stuck on the current cursor position, which can | |
6358 * happen when an offset is given and the cursor is on the last char | |
6359 * in the buffer: Repeat with count + 1. */ | |
6360 cap->count1 += 1; | |
6361 (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
6362 cap->count1 -= 1; | |
6363 } | |
7 | 6364 } |
6365 | |
6366 /* | |
6367 * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat). | |
6368 * Uses only cap->count1 and cap->oap from "cap". | |
6620 | 6369 * Return 0 for failure, 1 for found, 2 for found and line offset added. |
6370 */ | |
6371 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6372 normal_search( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6373 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6374 int dir, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6375 char_u *pat, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6376 int opt) /* extra flags for do_search() */ |
7 | 6377 { |
6378 int i; | |
6379 | |
6380 cap->oap->motion_type = MCHAR; | |
6381 cap->oap->inclusive = FALSE; | |
6382 cap->oap->use_reg_one = TRUE; | |
6383 curwin->w_set_curswant = TRUE; | |
6384 | |
6385 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
|
6386 opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL, NULL); |
7 | 6387 if (i == 0) |
6388 clearop(cap->oap); | |
6389 else | |
6390 { | |
6391 if (i == 2) | |
6392 cap->oap->motion_type = MLINE; | |
6393 #ifdef FEAT_VIRTUALEDIT | |
6394 curwin->w_cursor.coladd = 0; | |
6395 #endif | |
6396 #ifdef FEAT_FOLDING | |
6397 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
6398 foldOpenCursor(); | |
6399 #endif | |
6400 } | |
6401 | |
6402 /* "/$" will put the cursor after the end of the line, may need to | |
6403 * correct that here */ | |
6404 check_cursor(); | |
6620 | 6405 return i; |
7 | 6406 } |
6407 | |
6408 /* | |
6409 * Character search commands. | |
6410 * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for | |
6411 * ',' and FALSE for ';'. | |
6412 * cap->nchar is NUL for ',' and ';' (repeat the search) | |
6413 */ | |
6414 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6415 nv_csearch(cmdarg_T *cap) |
7 | 6416 { |
6417 int t_cmd; | |
6418 | |
6419 if (cap->cmdchar == 't' || cap->cmdchar == 'T') | |
6420 t_cmd = TRUE; | |
6421 else | |
6422 t_cmd = FALSE; | |
6423 | |
6424 cap->oap->motion_type = MCHAR; | |
6425 if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL) | |
6426 clearopbeep(cap->oap); | |
6427 else | |
6428 { | |
6429 curwin->w_set_curswant = TRUE; | |
6430 #ifdef FEAT_VIRTUALEDIT | |
6431 /* Include a Tab for "tx" and for "dfx". */ | |
6432 if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD | |
6433 && (t_cmd || cap->oap->op_type != OP_NOP)) | |
6434 { | |
6435 colnr_T scol, ecol; | |
6436 | |
6437 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
6438 curwin->w_cursor.coladd = ecol - scol; | |
6439 } | |
6440 else | |
6441 curwin->w_cursor.coladd = 0; | |
6442 #endif | |
6443 adjust_for_sel(cap); | |
6444 #ifdef FEAT_FOLDING | |
6445 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6446 foldOpenCursor(); | |
6447 #endif | |
6448 } | |
6449 } | |
6450 | |
6451 /* | |
6452 * "[" and "]" commands. | |
6453 * cap->arg is BACKWARD for "[" and FORWARD for "]". | |
6454 */ | |
6455 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6456 nv_brackets(cmdarg_T *cap) |
7 | 6457 { |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
6458 pos_T new_pos = INIT_POS_T(0, 0, 0); |
7 | 6459 pos_T prev_pos; |
6460 pos_T *pos = NULL; /* init for GCC */ | |
6461 pos_T old_pos; /* cursor position before command */ | |
6462 int flag; | |
6463 long n; | |
6464 int findc; | |
6465 int c; | |
6466 | |
6467 cap->oap->motion_type = MCHAR; | |
6468 cap->oap->inclusive = FALSE; | |
6469 old_pos = curwin->w_cursor; | |
6470 #ifdef FEAT_VIRTUALEDIT | |
6471 curwin->w_cursor.coladd = 0; /* TODO: don't do this for an error. */ | |
6472 #endif | |
6473 | |
6474 #ifdef FEAT_SEARCHPATH | |
6475 /* | |
6476 * "[f" or "]f" : Edit file under the cursor (same as "gf") | |
6477 */ | |
6478 if (cap->nchar == 'f') | |
6479 nv_gotofile(cap); | |
6480 else | |
6481 #endif | |
6482 | |
6483 #ifdef FEAT_FIND_ID | |
6484 /* | |
1188 | 6485 * Find the occurrence(s) of the identifier or define under cursor |
6486 * in current and included files or jump to the first occurrence. | |
7 | 6487 * |
6488 * search list jump | |
6489 * fwd bwd fwd bwd fwd bwd | |
6490 * identifier "]i" "[i" "]I" "[I" "]^I" "[^I" | |
6491 * define "]d" "[d" "]D" "[D" "]^D" "[^D" | |
6492 */ | |
6493 if (vim_strchr((char_u *) | |
6494 #ifdef EBCDIC | |
6495 "iI\005dD\067", | |
6496 #else | |
6497 "iI\011dD\004", | |
6498 #endif | |
6499 cap->nchar) != NULL) | |
6500 { | |
6501 char_u *ptr; | |
6502 int len; | |
6503 | |
6504 if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) | |
6505 clearop(cap->oap); | |
6506 else | |
6507 { | |
6508 find_pattern_in_path(ptr, 0, len, TRUE, | |
6509 cap->count0 == 0 ? !isupper(cap->nchar) : FALSE, | |
6510 ((cap->nchar & 0xf) == ('d' & 0xf)) ? FIND_DEFINE : FIND_ANY, | |
6511 cap->count1, | |
6512 isupper(cap->nchar) ? ACTION_SHOW_ALL : | |
6513 islower(cap->nchar) ? ACTION_SHOW : ACTION_GOTO, | |
6514 cap->cmdchar == ']' ? curwin->w_cursor.lnum + 1 : (linenr_T)1, | |
6515 (linenr_T)MAXLNUM); | |
6516 curwin->w_set_curswant = TRUE; | |
6517 } | |
6518 } | |
6519 else | |
6520 #endif | |
6521 | |
6522 /* | |
6523 * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')' | |
6524 * "[#", "]#": go to start/end of Nth innermost #if..#endif construct. | |
6525 * "[/", "[*", "]/", "]*": go to Nth comment start/end. | |
6526 * "[m" or "]m" search for prev/next start of (Java) method. | |
6527 * "[M" or "]M" search for prev/next end of (Java) method. | |
6528 */ | |
6529 if ( (cap->cmdchar == '[' | |
6530 && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL) | |
6531 || (cap->cmdchar == ']' | |
6532 && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) | |
6533 { | |
6534 if (cap->nchar == '*') | |
6535 cap->nchar = '/'; | |
6536 prev_pos.lnum = 0; | |
6537 if (cap->nchar == 'm' || cap->nchar == 'M') | |
6538 { | |
6539 if (cap->cmdchar == '[') | |
6540 findc = '{'; | |
6541 else | |
6542 findc = '}'; | |
6543 n = 9999; | |
6544 } | |
6545 else | |
6546 { | |
6547 findc = cap->nchar; | |
6548 n = cap->count1; | |
6549 } | |
6550 for ( ; n > 0; --n) | |
6551 { | |
6552 if ((pos = findmatchlimit(cap->oap, findc, | |
6553 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) | |
6554 { | |
6555 if (new_pos.lnum == 0) /* nothing found */ | |
6556 { | |
6557 if (cap->nchar != 'm' && cap->nchar != 'M') | |
6558 clearopbeep(cap->oap); | |
6559 } | |
6560 else | |
6561 pos = &new_pos; /* use last one found */ | |
6562 break; | |
6563 } | |
6564 prev_pos = new_pos; | |
6565 curwin->w_cursor = *pos; | |
6566 new_pos = *pos; | |
6567 } | |
6568 curwin->w_cursor = old_pos; | |
6569 | |
6570 /* | |
6571 * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only | |
6572 * brought us to the match for "[m" and "]M" when inside a method. | |
6573 * Try finding the '{' or '}' we want to be at. | |
6574 * Also repeat for the given count. | |
6575 */ | |
6576 if (cap->nchar == 'm' || cap->nchar == 'M') | |
6577 { | |
6578 /* norm is TRUE for "]M" and "[m" */ | |
6579 int norm = ((findc == '{') == (cap->nchar == 'm')); | |
6580 | |
6581 n = cap->count1; | |
6582 /* found a match: we were inside a method */ | |
6583 if (prev_pos.lnum != 0) | |
6584 { | |
6585 pos = &prev_pos; | |
6586 curwin->w_cursor = prev_pos; | |
6587 if (norm) | |
6588 --n; | |
6589 } | |
6590 else | |
6591 pos = NULL; | |
6592 while (n > 0) | |
6593 { | |
6594 for (;;) | |
6595 { | |
6596 if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0) | |
6597 { | |
6598 /* if not found anything, that's an error */ | |
6599 if (pos == NULL) | |
6600 clearopbeep(cap->oap); | |
6601 n = 0; | |
6602 break; | |
6603 } | |
6604 c = gchar_cursor(); | |
6605 if (c == '{' || c == '}') | |
6606 { | |
6607 /* Must have found end/start of class: use it. | |
6608 * Or found the place to be at. */ | |
6609 if ((c == findc && norm) || (n == 1 && !norm)) | |
6610 { | |
6611 new_pos = curwin->w_cursor; | |
6612 pos = &new_pos; | |
6613 n = 0; | |
6614 } | |
6615 /* if no match found at all, we started outside of the | |
6616 * class and we're inside now. Just go on. */ | |
6617 else if (new_pos.lnum == 0) | |
6618 { | |
6619 new_pos = curwin->w_cursor; | |
6620 pos = &new_pos; | |
6621 } | |
6622 /* found start/end of other method: go to match */ | |
6623 else if ((pos = findmatchlimit(cap->oap, findc, | |
6624 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, | |
6625 0)) == NULL) | |
6626 n = 0; | |
6627 else | |
6628 curwin->w_cursor = *pos; | |
6629 break; | |
6630 } | |
6631 } | |
6632 --n; | |
6633 } | |
6634 curwin->w_cursor = old_pos; | |
6635 if (pos == NULL && new_pos.lnum != 0) | |
6636 clearopbeep(cap->oap); | |
6637 } | |
6638 if (pos != NULL) | |
6639 { | |
6640 setpcmark(); | |
6641 curwin->w_cursor = *pos; | |
6642 curwin->w_set_curswant = TRUE; | |
6643 #ifdef FEAT_FOLDING | |
6644 if ((fdo_flags & FDO_BLOCK) && KeyTyped | |
6645 && cap->oap->op_type == OP_NOP) | |
6646 foldOpenCursor(); | |
6647 #endif | |
6648 } | |
6649 } | |
6650 | |
6651 /* | |
6652 * "[[", "[]", "]]" and "][": move to start or end of function | |
6653 */ | |
6654 else if (cap->nchar == '[' || cap->nchar == ']') | |
6655 { | |
6656 if (cap->nchar == cap->cmdchar) /* "]]" or "[[" */ | |
6657 flag = '{'; | |
6658 else | |
6659 flag = '}'; /* "][" or "[]" */ | |
6660 | |
6661 curwin->w_set_curswant = TRUE; | |
6662 /* | |
6663 * Imitate strange Vi behaviour: When using "]]" with an operator | |
6664 * we also stop at '}'. | |
6665 */ | |
503 | 6666 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, flag, |
7 | 6667 (cap->oap->op_type != OP_NOP |
6668 && cap->arg == FORWARD && flag == '{'))) | |
6669 clearopbeep(cap->oap); | |
6670 else | |
6671 { | |
6672 if (cap->oap->op_type == OP_NOP) | |
6673 beginline(BL_WHITE | BL_FIX); | |
6674 #ifdef FEAT_FOLDING | |
6675 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6676 foldOpenCursor(); | |
6677 #endif | |
6678 } | |
6679 } | |
6680 | |
6681 /* | |
6682 * "[p", "[P", "]P" and "]p": put with indent adjustment | |
6683 */ | |
6684 else if (cap->nchar == 'p' || cap->nchar == 'P') | |
6685 { | |
1312 | 6686 if (!checkclearop(cap->oap)) |
7 | 6687 { |
5708 | 6688 int dir = (cap->cmdchar == ']' && cap->nchar == 'p') |
6689 ? FORWARD : BACKWARD; | |
6690 int regname = cap->oap->regname; | |
6691 int was_visual = VIsual_active; | |
6692 int line_count = curbuf->b_ml.ml_line_count; | |
6693 pos_T start, end; | |
6694 | |
6695 if (VIsual_active) | |
6696 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6697 start = LTOREQ_POS(VIsual, curwin->w_cursor) |
5708 | 6698 ? 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
|
6699 end = EQUAL_POS(start,VIsual) ? curwin->w_cursor : VIsual; |
5708 | 6700 curwin->w_cursor = (dir == BACKWARD ? start : end); |
6701 } | |
6702 # ifdef FEAT_CLIPBOARD | |
6703 adjust_clip_reg(®name); | |
6704 # endif | |
7 | 6705 prep_redo_cmd(cap); |
5708 | 6706 |
6707 do_put(regname, dir, cap->count1, PUT_FIXINDENT); | |
6708 if (was_visual) | |
6709 { | |
6710 VIsual = start; | |
6711 curwin->w_cursor = end; | |
6712 if (dir == BACKWARD) | |
6713 { | |
6714 /* adjust lines */ | |
6715 VIsual.lnum += curbuf->b_ml.ml_line_count - line_count; | |
6716 curwin->w_cursor.lnum += | |
6717 curbuf->b_ml.ml_line_count - line_count; | |
6718 } | |
6719 | |
6720 VIsual_active = TRUE; | |
6721 if (VIsual_mode == 'V') | |
6722 { | |
6723 /* delete visually selected lines */ | |
6724 cap->cmdchar = 'd'; | |
6725 cap->nchar = NUL; | |
6726 cap->oap->regname = regname; | |
6727 nv_operator(cap); | |
6728 do_pending_operator(cap, 0, FALSE); | |
6729 } | |
6730 if (VIsual_active) | |
6731 { | |
6732 end_visual_mode(); | |
6733 redraw_later(SOME_VALID); | |
6734 } | |
6735 } | |
7 | 6736 } |
6737 } | |
6738 | |
6739 /* | |
6740 * "['", "[`", "]'" and "]`": jump to next mark | |
6741 */ | |
6742 else if (cap->nchar == '\'' || cap->nchar == '`') | |
6743 { | |
6744 pos = &curwin->w_cursor; | |
6745 for (n = cap->count1; n > 0; --n) | |
6746 { | |
6747 prev_pos = *pos; | |
6748 pos = getnextmark(pos, cap->cmdchar == '[' ? BACKWARD : FORWARD, | |
6749 cap->nchar == '\''); | |
6750 if (pos == NULL) | |
6751 break; | |
6752 } | |
6753 if (pos == NULL) | |
6754 pos = &prev_pos; | |
6755 nv_cursormark(cap, cap->nchar == '\'', pos); | |
6756 } | |
6757 | |
6758 #ifdef FEAT_MOUSE | |
6759 /* | |
6760 * [ or ] followed by a middle mouse click: put selected text with | |
6761 * indent adjustment. Any other button just does as usual. | |
6762 */ | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
6763 else if (cap->nchar >= K_RIGHTRELEASE && cap->nchar <= K_LEFTMOUSE) |
7 | 6764 { |
6765 (void)do_mouse(cap->oap, cap->nchar, | |
6766 (cap->cmdchar == ']') ? FORWARD : BACKWARD, | |
6767 cap->count1, PUT_FIXINDENT); | |
6768 } | |
6769 #endif /* FEAT_MOUSE */ | |
6770 | |
6771 #ifdef FEAT_FOLDING | |
6772 /* | |
6773 * "[z" and "]z": move to start or end of open fold. | |
6774 */ | |
6775 else if (cap->nchar == 'z') | |
6776 { | |
6777 if (foldMoveTo(FALSE, cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
6778 cap->count1) == FAIL) | |
6779 clearopbeep(cap->oap); | |
6780 } | |
6781 #endif | |
6782 | |
6783 #ifdef FEAT_DIFF | |
6784 /* | |
6785 * "[c" and "]c": move to next or previous diff-change. | |
6786 */ | |
6787 else if (cap->nchar == 'c') | |
6788 { | |
6789 if (diff_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
6790 cap->count1) == FAIL) | |
6791 clearopbeep(cap->oap); | |
6792 } | |
6793 #endif | |
6794 | |
737 | 6795 #ifdef FEAT_SPELL |
236 | 6796 /* |
6797 * "[s", "[S", "]s" and "]S": move to next spell error. | |
6798 */ | |
6799 else if (cap->nchar == 's' || cap->nchar == 'S') | |
6800 { | |
249 | 6801 setpcmark(); |
6802 for (n = 0; n < cap->count1; ++n) | |
498 | 6803 if (spell_move_to(curwin, cap->cmdchar == ']' ? FORWARD : BACKWARD, |
6804 cap->nchar == 's' ? TRUE : FALSE, FALSE, NULL) == 0) | |
249 | 6805 { |
6806 clearopbeep(cap->oap); | |
6807 break; | |
6808 } | |
13088
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
6809 else |
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
6810 curwin->w_set_curswant = TRUE; |
819 | 6811 # ifdef FEAT_FOLDING |
6812 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
6813 foldOpenCursor(); | |
6814 # endif | |
236 | 6815 } |
6816 #endif | |
6817 | |
7 | 6818 /* Not a valid cap->nchar. */ |
6819 else | |
6820 clearopbeep(cap->oap); | |
6821 } | |
6822 | |
6823 /* | |
6824 * Handle Normal mode "%" command. | |
6825 */ | |
6826 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6827 nv_percent(cmdarg_T *cap) |
7 | 6828 { |
6829 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
|
6830 #if defined(FEAT_FOLDING) |
7 | 6831 linenr_T lnum = curwin->w_cursor.lnum; |
6832 #endif | |
6833 | |
6834 cap->oap->inclusive = TRUE; | |
6835 if (cap->count0) /* {cnt}% : goto {cnt} percentage in file */ | |
6836 { | |
6837 if (cap->count0 > 100) | |
6838 clearopbeep(cap->oap); | |
6839 else | |
6840 { | |
6841 cap->oap->motion_type = MLINE; | |
6842 setpcmark(); | |
6843 /* Round up, so CTRL-G will give same value. Watch out for a | |
6844 * large line count, the line number must not go negative! */ | |
6845 if (curbuf->b_ml.ml_line_count > 1000000) | |
6846 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) | |
6847 / 100L * cap->count0; | |
6848 else | |
6849 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count * | |
6850 cap->count0 + 99L) / 100L; | |
6851 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
6852 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
6853 beginline(BL_SOL | BL_FIX); | |
6854 } | |
6855 } | |
6856 else /* "%" : go to matching paren */ | |
6857 { | |
6858 cap->oap->motion_type = MCHAR; | |
6859 cap->oap->use_reg_one = TRUE; | |
6860 if ((pos = findmatch(cap->oap, NUL)) == NULL) | |
6861 clearopbeep(cap->oap); | |
6862 else | |
6863 { | |
6864 setpcmark(); | |
6865 curwin->w_cursor = *pos; | |
6866 curwin->w_set_curswant = TRUE; | |
6867 #ifdef FEAT_VIRTUALEDIT | |
6868 curwin->w_cursor.coladd = 0; | |
6869 #endif | |
6870 adjust_for_sel(cap); | |
6871 } | |
6872 } | |
6873 #ifdef FEAT_FOLDING | |
6874 if (cap->oap->op_type == OP_NOP | |
6875 && lnum != curwin->w_cursor.lnum | |
6876 && (fdo_flags & FDO_PERCENT) | |
6877 && KeyTyped) | |
6878 foldOpenCursor(); | |
6879 #endif | |
6880 } | |
6881 | |
6882 /* | |
6883 * Handle "(" and ")" commands. | |
6884 * cap->arg is BACKWARD for "(" and FORWARD for ")". | |
6885 */ | |
6886 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6887 nv_brace(cmdarg_T *cap) |
7 | 6888 { |
6889 cap->oap->motion_type = MCHAR; | |
6890 cap->oap->use_reg_one = TRUE; | |
620 | 6891 /* The motion used to be inclusive for "(", but that is not what Vi does. */ |
6892 cap->oap->inclusive = FALSE; | |
7 | 6893 curwin->w_set_curswant = TRUE; |
6894 | |
6895 if (findsent(cap->arg, cap->count1) == FAIL) | |
6896 clearopbeep(cap->oap); | |
6897 else | |
6898 { | |
1505 | 6899 /* Don't leave the cursor on the NUL past end of line. */ |
6900 adjust_cursor(cap->oap); | |
7 | 6901 #ifdef FEAT_VIRTUALEDIT |
6902 curwin->w_cursor.coladd = 0; | |
6903 #endif | |
6904 #ifdef FEAT_FOLDING | |
6905 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6906 foldOpenCursor(); | |
6907 #endif | |
6908 } | |
6909 } | |
6910 | |
6911 /* | |
6912 * "m" command: Mark a position. | |
6913 */ | |
6914 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6915 nv_mark(cmdarg_T *cap) |
7 | 6916 { |
6917 if (!checkclearop(cap->oap)) | |
6918 { | |
6919 if (setmark(cap->nchar) == FAIL) | |
6920 clearopbeep(cap->oap); | |
6921 } | |
6922 } | |
6923 | |
6924 /* | |
6925 * "{" and "}" commands. | |
6926 * cmd->arg is BACKWARD for "{" and FORWARD for "}". | |
6927 */ | |
6928 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6929 nv_findpar(cmdarg_T *cap) |
7 | 6930 { |
6931 cap->oap->motion_type = MCHAR; | |
6932 cap->oap->inclusive = FALSE; | |
6933 cap->oap->use_reg_one = TRUE; | |
6934 curwin->w_set_curswant = TRUE; | |
503 | 6935 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, FALSE)) |
7 | 6936 clearopbeep(cap->oap); |
6937 else | |
6938 { | |
6939 #ifdef FEAT_VIRTUALEDIT | |
6940 curwin->w_cursor.coladd = 0; | |
6941 #endif | |
6942 #ifdef FEAT_FOLDING | |
6943 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6944 foldOpenCursor(); | |
6945 #endif | |
6946 } | |
6947 } | |
6948 | |
6949 /* | |
6950 * "u" command: Undo or make lower case. | |
6951 */ | |
6952 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6953 nv_undo(cmdarg_T *cap) |
7 | 6954 { |
5735 | 6955 if (cap->oap->op_type == OP_LOWER || VIsual_active) |
7 | 6956 { |
6957 /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */ | |
6958 cap->cmdchar = 'g'; | |
6959 cap->nchar = 'u'; | |
6960 nv_operator(cap); | |
6961 } | |
6962 else | |
6963 nv_kundo(cap); | |
6964 } | |
6965 | |
6966 /* | |
6967 * <Undo> command. | |
6968 */ | |
6969 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6970 nv_kundo(cmdarg_T *cap) |
7 | 6971 { |
6972 if (!checkclearopq(cap->oap)) | |
6973 { | |
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
|
6974 #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
|
6975 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
|
6976 { |
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
|
6977 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
|
6978 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
|
6979 } |
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
|
6980 #endif |
7 | 6981 u_undo((int)cap->count1); |
6982 curwin->w_set_curswant = TRUE; | |
6983 } | |
6984 } | |
6985 | |
6986 /* | |
6987 * Handle the "r" command. | |
6988 */ | |
6989 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6990 nv_replace(cmdarg_T *cap) |
7 | 6991 { |
6992 char_u *ptr; | |
6993 int had_ctrl_v; | |
6994 long n; | |
6995 | |
6996 if (checkclearop(cap->oap)) | |
6997 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
|
6998 #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
|
6999 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
|
7000 { |
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
|
7001 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
|
7002 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
|
7003 } |
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
|
7004 #endif |
7 | 7005 |
7006 /* get another character */ | |
7007 if (cap->nchar == Ctrl_V) | |
7008 { | |
7009 had_ctrl_v = Ctrl_V; | |
7010 cap->nchar = get_literal(); | |
7011 /* Don't redo a multibyte character with CTRL-V. */ | |
7012 if (cap->nchar > DEL) | |
7013 had_ctrl_v = NUL; | |
7014 } | |
7015 else | |
7016 had_ctrl_v = NUL; | |
7017 | |
1343 | 7018 /* Abort if the character is a special key. */ |
7019 if (IS_SPECIAL(cap->nchar)) | |
7020 { | |
7021 clearopbeep(cap->oap); | |
7022 return; | |
7023 } | |
7024 | |
7 | 7025 /* Visual mode "r" */ |
7026 if (VIsual_active) | |
7027 { | |
1797 | 7028 if (got_int) |
7029 reset_VIsual(); | |
5428 | 7030 if (had_ctrl_v) |
7031 { | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
7032 /* 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
|
7033 * 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
|
7034 if (cap->nchar == CAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
7035 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
|
7036 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
|
7037 cap->nchar = REPLACE_NL_NCHAR; |
5428 | 7038 } |
7 | 7039 nv_operator(cap); |
7040 return; | |
7041 } | |
7042 | |
7043 #ifdef FEAT_VIRTUALEDIT | |
7044 /* Break tabs, etc. */ | |
7045 if (virtual_active()) | |
7046 { | |
7047 if (u_save_cursor() == FAIL) | |
7048 return; | |
7049 if (gchar_cursor() == NUL) | |
7050 { | |
7051 /* Add extra space and put the cursor on the first one. */ | |
7052 coladvance_force((colnr_T)(getviscol() + cap->count1)); | |
7053 curwin->w_cursor.col -= cap->count1; | |
7054 } | |
7055 else if (gchar_cursor() == TAB) | |
7056 coladvance_force(getviscol()); | |
7057 } | |
7058 #endif | |
7059 | |
1343 | 7060 /* Abort if not enough characters to replace. */ |
7 | 7061 ptr = ml_get_cursor(); |
1343 | 7062 if (STRLEN(ptr) < (unsigned)cap->count1 |
7 | 7063 #ifdef FEAT_MBYTE |
7064 || (has_mbyte && mb_charlen(ptr) < cap->count1) | |
7065 #endif | |
7066 ) | |
7067 { | |
7068 clearopbeep(cap->oap); | |
7069 return; | |
7070 } | |
7071 | |
7072 /* | |
7073 * Replacing with a TAB is done by edit() when it is complicated because | |
7074 * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB. | |
7075 * Other characters are done below to avoid problems with things like | |
7076 * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC). | |
7077 */ | |
7078 if (had_ctrl_v != Ctrl_V && cap->nchar == '\t' && (curbuf->b_p_et || p_sta)) | |
7079 { | |
7080 stuffnumReadbuff(cap->count1); | |
7081 stuffcharReadbuff('R'); | |
7082 stuffcharReadbuff('\t'); | |
7083 stuffcharReadbuff(ESC); | |
7084 return; | |
7085 } | |
7086 | |
7087 /* save line for undo */ | |
7088 if (u_save_cursor() == FAIL) | |
7089 return; | |
7090 | |
7091 if (had_ctrl_v != Ctrl_V && (cap->nchar == '\r' || cap->nchar == '\n')) | |
7092 { | |
7093 /* | |
7094 * Replace character(s) by a single newline. | |
7095 * Strange vi behaviour: Only one newline is inserted. | |
7096 * Delete the characters here. | |
7097 * Insert the newline with an insert command, takes care of | |
7098 * autoindent. The insert command depends on being on the last | |
7099 * character of a line or not. | |
7100 */ | |
7101 #ifdef FEAT_MBYTE | |
7102 (void)del_chars(cap->count1, FALSE); /* delete the characters */ | |
7103 #else | |
608 | 7104 (void)del_bytes(cap->count1, FALSE, FALSE); /* delete the characters */ |
7 | 7105 #endif |
7106 stuffcharReadbuff('\r'); | |
7107 stuffcharReadbuff(ESC); | |
7108 | |
7109 /* Give 'r' to edit(), to get the redo command right. */ | |
7110 invoke_edit(cap, TRUE, 'r', FALSE); | |
7111 } | |
7112 else | |
7113 { | |
7114 prep_redo(cap->oap->regname, cap->count1, | |
7115 NUL, 'r', NUL, had_ctrl_v, cap->nchar); | |
7116 | |
7117 curbuf->b_op_start = curwin->w_cursor; | |
7118 #ifdef FEAT_MBYTE | |
7119 if (has_mbyte) | |
7120 { | |
7121 int old_State = State; | |
7122 | |
7123 if (cap->ncharC1 != 0) | |
7124 AppendCharToRedobuff(cap->ncharC1); | |
7125 if (cap->ncharC2 != 0) | |
7126 AppendCharToRedobuff(cap->ncharC2); | |
7127 | |
7128 /* This is slow, but it handles replacing a single-byte with a | |
7129 * multi-byte and the other way around. Also handles adding | |
7130 * composing characters for utf-8. */ | |
7131 for (n = cap->count1; n > 0; --n) | |
7132 { | |
7133 State = REPLACE; | |
3501 | 7134 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7135 { | |
7136 int c = ins_copychar(curwin->w_cursor.lnum | |
7137 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7138 if (c != NUL) | |
7139 ins_char(c); | |
7140 else | |
7141 /* will be decremented further down */ | |
7142 ++curwin->w_cursor.col; | |
7143 } | |
7144 else | |
7145 ins_char(cap->nchar); | |
7 | 7146 State = old_State; |
7147 if (cap->ncharC1 != 0) | |
7148 ins_char(cap->ncharC1); | |
7149 if (cap->ncharC2 != 0) | |
7150 ins_char(cap->ncharC2); | |
7151 } | |
7152 } | |
7153 else | |
7154 #endif | |
7155 { | |
7156 /* | |
7157 * Replace the characters within one line. | |
7158 */ | |
7159 for (n = cap->count1; n > 0; --n) | |
7160 { | |
7161 /* | |
7162 * Get ptr again, because u_save and/or showmatch() will have | |
7163 * released the line. At the same time we let know that the | |
7164 * line will be changed. | |
7165 */ | |
7166 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); | |
3501 | 7167 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7168 { | |
7169 int c = ins_copychar(curwin->w_cursor.lnum | |
7170 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7171 if (c != NUL) | |
7172 ptr[curwin->w_cursor.col] = c; | |
7173 } | |
7174 else | |
7175 ptr[curwin->w_cursor.col] = cap->nchar; | |
7 | 7176 if (p_sm && msg_silent == 0) |
7177 showmatch(cap->nchar); | |
7178 ++curwin->w_cursor.col; | |
7179 } | |
7180 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7181 if (netbeans_active()) |
7 | 7182 { |
2210 | 7183 colnr_T start = (colnr_T)(curwin->w_cursor.col - cap->count1); |
7 | 7184 |
33 | 7185 netbeans_removed(curbuf, curwin->w_cursor.lnum, start, |
2210 | 7186 (long)cap->count1); |
7 | 7187 netbeans_inserted(curbuf, curwin->w_cursor.lnum, start, |
33 | 7188 &ptr[start], (int)cap->count1); |
7 | 7189 } |
7190 #endif | |
7191 | |
7192 /* mark the buffer as changed and prepare for displaying */ | |
7193 changed_bytes(curwin->w_cursor.lnum, | |
7194 (colnr_T)(curwin->w_cursor.col - cap->count1)); | |
7195 } | |
7196 --curwin->w_cursor.col; /* cursor on the last replaced char */ | |
7197 #ifdef FEAT_MBYTE | |
7198 /* if the character on the left of the current cursor is a multi-byte | |
7199 * character, move two characters left */ | |
7200 if (has_mbyte) | |
7201 mb_adjust_cursor(); | |
7202 #endif | |
7203 curbuf->b_op_end = curwin->w_cursor; | |
7204 curwin->w_set_curswant = TRUE; | |
7205 set_last_insert(cap->nchar); | |
7206 } | |
7207 } | |
7208 | |
7209 /* | |
7210 * 'o': Exchange start and end of Visual area. | |
7211 * 'O': same, but in block mode exchange left and right corners. | |
7212 */ | |
7213 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7214 v_swap_corners(int cmdchar) |
7 | 7215 { |
7216 pos_T old_cursor; | |
7217 colnr_T left, right; | |
7218 | |
7219 if (cmdchar == 'O' && VIsual_mode == Ctrl_V) | |
7220 { | |
7221 old_cursor = curwin->w_cursor; | |
7222 getvcols(curwin, &old_cursor, &VIsual, &left, &right); | |
7223 curwin->w_cursor.lnum = VIsual.lnum; | |
7224 coladvance(left); | |
7225 VIsual = curwin->w_cursor; | |
7226 | |
7227 curwin->w_cursor.lnum = old_cursor.lnum; | |
7228 curwin->w_curswant = right; | |
7229 /* 'selection "exclusive" and cursor at right-bottom corner: move it | |
7230 * right one column */ | |
7231 if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') | |
7232 ++curwin->w_curswant; | |
7233 coladvance(curwin->w_curswant); | |
7234 if (curwin->w_cursor.col == old_cursor.col | |
7235 #ifdef FEAT_VIRTUALEDIT | |
7236 && (!virtual_active() | |
7237 || curwin->w_cursor.coladd == old_cursor.coladd) | |
7238 #endif | |
7239 ) | |
7240 { | |
7241 curwin->w_cursor.lnum = VIsual.lnum; | |
7242 if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') | |
7243 ++right; | |
7244 coladvance(right); | |
7245 VIsual = curwin->w_cursor; | |
7246 | |
7247 curwin->w_cursor.lnum = old_cursor.lnum; | |
7248 coladvance(left); | |
7249 curwin->w_curswant = left; | |
7250 } | |
7251 } | |
7252 else | |
7253 { | |
7254 old_cursor = curwin->w_cursor; | |
7255 curwin->w_cursor = VIsual; | |
7256 VIsual = old_cursor; | |
7257 curwin->w_set_curswant = TRUE; | |
7258 } | |
7259 } | |
7260 | |
7261 /* | |
7262 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE). | |
7263 */ | |
7264 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7265 nv_Replace(cmdarg_T *cap) |
7 | 7266 { |
7267 if (VIsual_active) /* "R" is replace lines */ | |
7268 { | |
7269 cap->cmdchar = 'c'; | |
7270 cap->nchar = NUL; | |
4213 | 7271 VIsual_mode_orig = VIsual_mode; /* remember original area for gv */ |
7 | 7272 VIsual_mode = 'V'; |
7273 nv_operator(cap); | |
7274 } | |
5735 | 7275 else if (!checkclearopq(cap->oap)) |
7 | 7276 { |
7277 if (!curbuf->b_p_ma) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
7278 emsg(_(e_modifiable)); |
7 | 7279 else |
7280 { | |
7281 #ifdef FEAT_VIRTUALEDIT | |
7282 if (virtual_active()) | |
7283 coladvance(getviscol()); | |
7284 #endif | |
7285 invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE); | |
7286 } | |
7287 } | |
7288 } | |
7289 | |
7290 /* | |
7291 * "gr". | |
7292 */ | |
7293 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7294 nv_vreplace(cmdarg_T *cap) |
7 | 7295 { |
7296 if (VIsual_active) | |
7297 { | |
7298 cap->cmdchar = 'r'; | |
7299 cap->nchar = cap->extra_char; | |
7300 nv_replace(cap); /* Do same as "r" in Visual mode for now */ | |
7301 } | |
5735 | 7302 else if (!checkclearopq(cap->oap)) |
7 | 7303 { |
7304 if (!curbuf->b_p_ma) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
7305 emsg(_(e_modifiable)); |
7 | 7306 else |
7307 { | |
7308 if (cap->extra_char == Ctrl_V) /* get another character */ | |
7309 cap->extra_char = get_literal(); | |
7310 stuffcharReadbuff(cap->extra_char); | |
7311 stuffcharReadbuff(ESC); | |
14424
0a69e6e708f9
patch 8.1.0226: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
14397
diff
changeset
|
7312 #ifdef FEAT_VIRTUALEDIT |
7 | 7313 if (virtual_active()) |
7314 coladvance(getviscol()); | |
14424
0a69e6e708f9
patch 8.1.0226: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
14397
diff
changeset
|
7315 #endif |
7 | 7316 invoke_edit(cap, TRUE, 'v', FALSE); |
7317 } | |
7318 } | |
7319 } | |
7320 | |
7321 /* | |
7322 * Swap case for "~" command, when it does not work like an operator. | |
7323 */ | |
7324 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7325 n_swapchar(cmdarg_T *cap) |
7 | 7326 { |
7327 long n; | |
7328 pos_T startpos; | |
7329 int did_change = 0; | |
7330 #ifdef FEAT_NETBEANS_INTG | |
7331 pos_T pos; | |
7332 char_u *ptr; | |
7333 int count; | |
7334 #endif | |
7335 | |
7336 if (checkclearopq(cap->oap)) | |
7337 return; | |
7338 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7339 if (LINEEMPTY(curwin->w_cursor.lnum) && vim_strchr(p_ww, '~') == NULL) |
7 | 7340 { |
7341 clearopbeep(cap->oap); | |
7342 return; | |
7343 } | |
7344 | |
7345 prep_redo_cmd(cap); | |
7346 | |
7347 if (u_save_cursor() == FAIL) | |
7348 return; | |
7349 | |
7350 startpos = curwin->w_cursor; | |
7351 #ifdef FEAT_NETBEANS_INTG | |
7352 pos = startpos; | |
7353 #endif | |
7354 for (n = cap->count1; n > 0; --n) | |
7355 { | |
7356 did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor); | |
7357 inc_cursor(); | |
7358 if (gchar_cursor() == NUL) | |
7359 { | |
7360 if (vim_strchr(p_ww, '~') != NULL | |
7361 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
7362 { | |
7363 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7364 if (netbeans_active()) |
7 | 7365 { |
7366 if (did_change) | |
7367 { | |
7368 ptr = ml_get(pos.lnum); | |
835 | 7369 count = (int)STRLEN(ptr) - pos.col; |
33 | 7370 netbeans_removed(curbuf, pos.lnum, pos.col, |
7371 (long)count); | |
7 | 7372 netbeans_inserted(curbuf, pos.lnum, pos.col, |
33 | 7373 &ptr[pos.col], count); |
7 | 7374 } |
7375 pos.col = 0; | |
7376 pos.lnum++; | |
7377 } | |
7378 #endif | |
7379 ++curwin->w_cursor.lnum; | |
7380 curwin->w_cursor.col = 0; | |
7381 if (n > 1) | |
7382 { | |
7383 if (u_savesub(curwin->w_cursor.lnum) == FAIL) | |
7384 break; | |
7385 u_clearline(); | |
7386 } | |
7387 } | |
7388 else | |
7389 break; | |
7390 } | |
7391 } | |
7392 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7393 if (did_change && netbeans_active()) |
7 | 7394 { |
7395 ptr = ml_get(pos.lnum); | |
7396 count = curwin->w_cursor.col - pos.col; | |
33 | 7397 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7398 netbeans_inserted(curbuf, pos.lnum, pos.col, &ptr[pos.col], count); | |
7 | 7399 } |
7400 #endif | |
7401 | |
7402 | |
7403 check_cursor(); | |
7404 curwin->w_set_curswant = TRUE; | |
7405 if (did_change) | |
7406 { | |
7407 changed_lines(startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1, | |
7408 0L); | |
7409 curbuf->b_op_start = startpos; | |
7410 curbuf->b_op_end = curwin->w_cursor; | |
7411 if (curbuf->b_op_end.col > 0) | |
7412 --curbuf->b_op_end.col; | |
7413 } | |
7414 } | |
7415 | |
7416 /* | |
7417 * Move cursor to mark. | |
7418 */ | |
7419 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7420 nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos) |
7 | 7421 { |
7422 if (check_mark(pos) == FAIL) | |
7423 clearop(cap->oap); | |
7424 else | |
7425 { | |
7426 if (cap->cmdchar == '\'' | |
7427 || cap->cmdchar == '`' | |
7428 || cap->cmdchar == '[' | |
7429 || cap->cmdchar == ']') | |
7430 setpcmark(); | |
7431 curwin->w_cursor = *pos; | |
7432 if (flag) | |
7433 beginline(BL_WHITE | BL_FIX); | |
7434 else | |
7435 check_cursor(); | |
7436 } | |
7437 cap->oap->motion_type = flag ? MLINE : MCHAR; | |
7438 if (cap->cmdchar == '`') | |
7439 cap->oap->use_reg_one = TRUE; | |
7440 cap->oap->inclusive = FALSE; /* ignored if not MCHAR */ | |
7441 curwin->w_set_curswant = TRUE; | |
7442 } | |
7443 | |
7444 /* | |
7445 * Handle commands that are operators in Visual mode. | |
7446 */ | |
7447 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7448 v_visop(cmdarg_T *cap) |
7 | 7449 { |
7450 static char_u trans[] = "YyDdCcxdXdAAIIrr"; | |
7451 | |
7452 /* Uppercase means linewise, except in block mode, then "D" deletes till | |
4352 | 7453 * the end of the line, and "C" replaces till EOL */ |
7 | 7454 if (isupper(cap->cmdchar)) |
7455 { | |
7456 if (VIsual_mode != Ctrl_V) | |
4213 | 7457 { |
7458 VIsual_mode_orig = VIsual_mode; | |
7 | 7459 VIsual_mode = 'V'; |
4213 | 7460 } |
7 | 7461 else if (cap->cmdchar == 'C' || cap->cmdchar == 'D') |
7462 curwin->w_curswant = MAXCOL; | |
7463 } | |
7464 cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1); | |
7465 nv_operator(cap); | |
7466 } | |
7467 | |
7468 /* | |
7469 * "s" and "S" commands. | |
7470 */ | |
7471 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7472 nv_subst(cmdarg_T *cap) |
7 | 7473 { |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7474 #ifdef FEAT_TERMINAL |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7475 /* 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
|
7476 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
|
7477 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7478 #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
|
7479 #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
|
7480 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
|
7481 { |
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
|
7482 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
|
7483 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
|
7484 } |
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
|
7485 #endif |
7 | 7486 if (VIsual_active) /* "vs" and "vS" are the same as "vc" */ |
7487 { | |
7488 if (cap->cmdchar == 'S') | |
4213 | 7489 { |
7490 VIsual_mode_orig = VIsual_mode; | |
7 | 7491 VIsual_mode = 'V'; |
4213 | 7492 } |
7 | 7493 cap->cmdchar = 'c'; |
7494 nv_operator(cap); | |
7495 } | |
7496 else | |
7497 nv_optrans(cap); | |
7498 } | |
7499 | |
7500 /* | |
7501 * Abbreviated commands. | |
7502 */ | |
7503 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7504 nv_abbrev(cmdarg_T *cap) |
7 | 7505 { |
7506 if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) | |
7507 cap->cmdchar = 'x'; /* DEL key behaves like 'x' */ | |
7508 | |
7509 /* in Visual mode these commands are operators */ | |
7510 if (VIsual_active) | |
7511 v_visop(cap); | |
7512 else | |
7513 nv_optrans(cap); | |
7514 } | |
7515 | |
7516 /* | |
7517 * Translate a command into another command. | |
7518 */ | |
7519 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7520 nv_optrans(cmdarg_T *cap) |
7 | 7521 { |
7522 static char_u *(ar[8]) = {(char_u *)"dl", (char_u *)"dh", | |
7523 (char_u *)"d$", (char_u *)"c$", | |
7524 (char_u *)"cl", (char_u *)"cc", | |
7525 (char_u *)"yy", (char_u *)":s\r"}; | |
7526 static char_u *str = (char_u *)"xXDCsSY&"; | |
7527 | |
7528 if (!checkclearopq(cap->oap)) | |
7529 { | |
164 | 7530 /* In Vi "2D" doesn't delete the next line. Can't translate it |
7531 * either, because "2." should also not use the count. */ | |
7532 if (cap->cmdchar == 'D' && vim_strchr(p_cpo, CPO_HASH) != NULL) | |
7533 { | |
7534 cap->oap->start = curwin->w_cursor; | |
7535 cap->oap->op_type = OP_DELETE; | |
1490 | 7536 #ifdef FEAT_EVAL |
7537 set_op_var(OP_DELETE); | |
7538 #endif | |
164 | 7539 cap->count1 = 1; |
7540 nv_dollar(cap); | |
7541 finish_op = TRUE; | |
7542 ResetRedobuff(); | |
7543 AppendCharToRedobuff('D'); | |
7544 } | |
7545 else | |
7546 { | |
7547 if (cap->count0) | |
7548 stuffnumReadbuff(cap->count0); | |
7549 stuffReadbuff(ar[(int)(vim_strchr(str, cap->cmdchar) - str)]); | |
7550 } | |
7 | 7551 } |
7552 cap->opcount = 0; | |
7553 } | |
7554 | |
7555 /* | |
7556 * "'" and "`" commands. Also for "g'" and "g`". | |
7557 * cap->arg is TRUE for "'" and "g'". | |
7558 */ | |
7559 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7560 nv_gomark(cmdarg_T *cap) |
7 | 7561 { |
7562 pos_T *pos; | |
7563 int c; | |
7564 #ifdef FEAT_FOLDING | |
4017 | 7565 pos_T old_cursor = curwin->w_cursor; |
7 | 7566 int old_KeyTyped = KeyTyped; /* getting file may reset it */ |
7567 #endif | |
7568 | |
7569 if (cap->cmdchar == 'g') | |
7570 c = cap->extra_char; | |
7571 else | |
7572 c = cap->nchar; | |
7573 pos = getmark(c, (cap->oap->op_type == OP_NOP)); | |
7574 if (pos == (pos_T *)-1) /* jumped to other file */ | |
7575 { | |
7576 if (cap->arg) | |
7577 { | |
7578 check_cursor_lnum(); | |
7579 beginline(BL_WHITE | BL_FIX); | |
7580 } | |
7581 else | |
7582 check_cursor(); | |
7583 } | |
7584 else | |
7585 nv_cursormark(cap, cap->arg, pos); | |
7586 | |
7587 #ifdef FEAT_VIRTUALEDIT | |
7588 /* May need to clear the coladd that a mark includes. */ | |
7589 if (!virtual_active()) | |
7590 curwin->w_cursor.coladd = 0; | |
7591 #endif | |
12164
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
7592 check_cursor_col(); |
7 | 7593 #ifdef FEAT_FOLDING |
7594 if (cap->oap->op_type == OP_NOP | |
4057 | 7595 && pos != NULL |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7596 && (pos == (pos_T *)-1 || !EQUAL_POS(old_cursor, *pos)) |
7 | 7597 && (fdo_flags & FDO_MARK) |
7598 && old_KeyTyped) | |
7599 foldOpenCursor(); | |
7600 #endif | |
7601 } | |
7602 | |
7603 /* | |
7604 * Handle CTRL-O, CTRL-I, "g;" and "g," commands. | |
7605 */ | |
7606 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7607 nv_pcmark(cmdarg_T *cap) |
7 | 7608 { |
7609 #ifdef FEAT_JUMPLIST | |
7610 pos_T *pos; | |
7611 # ifdef FEAT_FOLDING | |
7612 linenr_T lnum = curwin->w_cursor.lnum; | |
7613 int old_KeyTyped = KeyTyped; /* getting file may reset it */ | |
7614 # endif | |
7615 | |
7616 if (!checkclearopq(cap->oap)) | |
7617 { | |
7618 if (cap->cmdchar == 'g') | |
7619 pos = movechangelist((int)cap->count1); | |
7620 else | |
7621 pos = movemark((int)cap->count1); | |
7622 if (pos == (pos_T *)-1) /* jump to other file */ | |
7623 { | |
7624 curwin->w_set_curswant = TRUE; | |
7625 check_cursor(); | |
7626 } | |
7627 else if (pos != NULL) /* can jump */ | |
7628 nv_cursormark(cap, FALSE, pos); | |
7629 else if (cap->cmdchar == 'g') | |
7630 { | |
7631 if (curbuf->b_changelistlen == 0) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
7632 emsg(_("E664: changelist is empty")); |
7 | 7633 else if (cap->count1 < 0) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
7634 emsg(_("E662: At start of changelist")); |
7 | 7635 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
7636 emsg(_("E663: At end of changelist")); |
7 | 7637 } |
7638 else | |
7639 clearopbeep(cap->oap); | |
7640 # ifdef FEAT_FOLDING | |
7641 if (cap->oap->op_type == OP_NOP | |
7642 && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum) | |
7643 && (fdo_flags & FDO_MARK) | |
7644 && old_KeyTyped) | |
7645 foldOpenCursor(); | |
7646 # endif | |
7647 } | |
7648 #else | |
7649 clearopbeep(cap->oap); | |
7650 #endif | |
7651 } | |
7652 | |
7653 /* | |
7654 * Handle '"' command. | |
7655 */ | |
7656 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7657 nv_regname(cmdarg_T *cap) |
7 | 7658 { |
7659 if (checkclearop(cap->oap)) | |
7660 return; | |
7661 #ifdef FEAT_EVAL | |
7662 if (cap->nchar == '=') | |
7663 cap->nchar = get_expr_register(); | |
7664 #endif | |
7665 if (cap->nchar != NUL && valid_yank_reg(cap->nchar, FALSE)) | |
7666 { | |
7667 cap->oap->regname = cap->nchar; | |
7668 cap->opcount = cap->count0; /* remember count before '"' */ | |
7669 #ifdef FEAT_EVAL | |
7670 set_reg_var(cap->oap->regname); | |
7671 #endif | |
7672 } | |
7673 else | |
7674 clearopbeep(cap->oap); | |
7675 } | |
7676 | |
7677 /* | |
7678 * Handle "v", "V" and "CTRL-V" commands. | |
7679 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg | |
7680 * is TRUE. | |
167 | 7681 * Handle CTRL-Q just like CTRL-V. |
7 | 7682 */ |
7683 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7684 nv_visual(cmdarg_T *cap) |
7 | 7685 { |
167 | 7686 if (cap->cmdchar == Ctrl_Q) |
7687 cap->cmdchar = Ctrl_V; | |
7688 | |
7 | 7689 /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it |
7690 * characterwise, linewise, or blockwise. */ | |
7691 if (cap->oap->op_type != OP_NOP) | |
7692 { | |
15279
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
7693 motion_force = cap->oap->motion_force = cap->cmdchar; |
7 | 7694 finish_op = FALSE; /* operator doesn't finish now but later */ |
7695 return; | |
7696 } | |
7697 | |
7698 VIsual_select = cap->arg; | |
7699 if (VIsual_active) /* change Visual mode */ | |
7700 { | |
7701 if (VIsual_mode == cap->cmdchar) /* stop visual mode */ | |
7702 end_visual_mode(); | |
7703 else /* toggle char/block mode */ | |
7704 { /* or char/line mode */ | |
7705 VIsual_mode = cap->cmdchar; | |
7706 showmode(); | |
7707 } | |
7708 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
7709 } | |
7710 else /* start Visual mode */ | |
7711 { | |
7712 check_visual_highlight(); | |
3537 | 7713 if (cap->count0 > 0 && resel_VIsual_mode != NUL) |
7714 { | |
7715 /* use previously selected part */ | |
7 | 7716 VIsual = curwin->w_cursor; |
7717 | |
7718 VIsual_active = TRUE; | |
7719 VIsual_reselect = TRUE; | |
7720 if (!cap->arg) | |
7721 /* start Select mode when 'selectmode' contains "cmd" */ | |
7722 may_start_select('c'); | |
7723 #ifdef FEAT_MOUSE | |
7724 setmouse(); | |
7725 #endif | |
641 | 7726 if (p_smd && msg_silent == 0) |
7 | 7727 redraw_cmdline = TRUE; /* show visual mode later */ |
7728 /* | |
7729 * For V and ^V, we multiply the number of lines even if there | |
7730 * was only one -- webb | |
7731 */ | |
7732 if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) | |
7733 { | |
7734 curwin->w_cursor.lnum += | |
7735 resel_VIsual_line_count * cap->count0 - 1; | |
7736 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
7737 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7738 } | |
7739 VIsual_mode = resel_VIsual_mode; | |
7740 if (VIsual_mode == 'v') | |
7741 { | |
7742 if (resel_VIsual_line_count <= 1) | |
3125 | 7743 { |
7744 validate_virtcol(); | |
7745 curwin->w_curswant = curwin->w_virtcol | |
7746 + resel_VIsual_vcol * cap->count0 - 1; | |
7747 } | |
7 | 7748 else |
3125 | 7749 curwin->w_curswant = resel_VIsual_vcol; |
7750 coladvance(curwin->w_curswant); | |
7 | 7751 } |
3125 | 7752 if (resel_VIsual_vcol == MAXCOL) |
7 | 7753 { |
7754 curwin->w_curswant = MAXCOL; | |
7755 coladvance((colnr_T)MAXCOL); | |
7756 } | |
7757 else if (VIsual_mode == Ctrl_V) | |
7758 { | |
7759 validate_virtcol(); | |
7760 curwin->w_curswant = curwin->w_virtcol | |
3125 | 7761 + resel_VIsual_vcol * cap->count0 - 1; |
7 | 7762 coladvance(curwin->w_curswant); |
7763 } | |
7764 else | |
7765 curwin->w_set_curswant = TRUE; | |
7766 redraw_curbuf_later(INVERTED); /* show the inversion */ | |
7767 } | |
7768 else | |
7769 { | |
7770 if (!cap->arg) | |
7771 /* start Select mode when 'selectmode' contains "cmd" */ | |
7772 may_start_select('c'); | |
7773 n_start_visual_mode(cap->cmdchar); | |
3537 | 7774 if (VIsual_mode != 'V' && *p_sel == 'e') |
7775 ++cap->count1; /* include one more char */ | |
7776 if (cap->count0 > 0 && --cap->count1 > 0) | |
7777 { | |
7778 /* With a count select that many characters or lines. */ | |
7779 if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) | |
7780 nv_right(cap); | |
7781 else if (VIsual_mode == 'V') | |
7782 nv_down(cap); | |
7783 } | |
7 | 7784 } |
7785 } | |
7786 } | |
7787 | |
7788 /* | |
7789 * Start selection for Shift-movement keys. | |
7790 */ | |
7791 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7792 start_selection(void) |
7 | 7793 { |
7794 /* if 'selectmode' contains "key", start Select mode */ | |
7795 may_start_select('k'); | |
7796 n_start_visual_mode('v'); | |
7797 } | |
7798 | |
7799 /* | |
7800 * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu. | |
7801 */ | |
7802 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7803 may_start_select(int c) |
7 | 7804 { |
7805 VIsual_select = (stuff_empty() && typebuf_typed() | |
7806 && (vim_strchr(p_slm, c) != NULL)); | |
7807 } | |
7808 | |
7809 /* | |
7810 * Start Visual mode "c". | |
7811 * Should set VIsual_select before calling this. | |
7812 */ | |
7813 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7814 n_start_visual_mode(int c) |
7 | 7815 { |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7816 #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
|
7817 /* Check for redraw before changing the state. */ |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13772
diff
changeset
|
7818 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
|
7819 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7820 |
7 | 7821 VIsual_mode = c; |
7822 VIsual_active = TRUE; | |
7823 VIsual_reselect = TRUE; | |
7824 #ifdef FEAT_VIRTUALEDIT | |
7825 /* Corner case: the 0 position in a tab may change when going into | |
7826 * virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting. | |
7827 */ | |
7828 if (c == Ctrl_V && (ve_flags & VE_BLOCK) && gchar_cursor() == TAB) | |
3742 | 7829 { |
7830 validate_virtcol(); | |
7 | 7831 coladvance(curwin->w_virtcol); |
3742 | 7832 } |
7 | 7833 #endif |
7834 VIsual = curwin->w_cursor; | |
7835 | |
7836 #ifdef FEAT_FOLDING | |
7837 foldAdjustVisual(); | |
7838 #endif | |
7839 | |
7840 #ifdef FEAT_MOUSE | |
7841 setmouse(); | |
7842 #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
|
7843 #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
|
7844 /* Check for redraw after changing the state. */ |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13772
diff
changeset
|
7845 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
|
7846 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7847 |
641 | 7848 if (p_smd && msg_silent == 0) |
7 | 7849 redraw_cmdline = TRUE; /* show visual mode later */ |
7850 #ifdef FEAT_CLIPBOARD | |
7851 /* Make sure the clipboard gets updated. Needed because start and | |
7852 * end may still be the same, and the selection needs to be owned */ | |
7853 clip_star.vmode = NUL; | |
7854 #endif | |
7855 | |
7856 /* Only need to redraw this line, unless still need to redraw an old | |
7857 * Visual area (when 'lazyredraw' is set). */ | |
7858 if (curwin->w_redr_type < INVERTED) | |
7859 { | |
7860 curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
7861 curwin->w_old_visual_lnum = curwin->w_cursor.lnum; | |
7862 } | |
7863 } | |
7864 | |
7865 | |
7866 /* | |
7867 * CTRL-W: Window commands | |
7868 */ | |
7869 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7870 nv_window(cmdarg_T *cap) |
7 | 7871 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7872 if (cap->nchar == ':') |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7873 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7874 /* "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
|
7875 cap->cmdchar = ':'; |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7876 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
|
7877 nv_colon(cap); |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7878 } |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7879 else if (!checkclearop(cap->oap)) |
7 | 7880 do_window(cap->nchar, cap->count0, NUL); /* everything is in window.c */ |
7881 } | |
7882 | |
7883 /* | |
7884 * CTRL-Z: Suspend | |
7885 */ | |
7886 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7887 nv_suspend(cmdarg_T *cap) |
7 | 7888 { |
7889 clearop(cap->oap); | |
7890 if (VIsual_active) | |
7891 end_visual_mode(); /* stop Visual mode */ | |
7892 do_cmdline_cmd((char_u *)"st"); | |
7893 } | |
7894 | |
7895 /* | |
7896 * Commands starting with "g". | |
7897 */ | |
7898 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7899 nv_g_cmd(cmdarg_T *cap) |
7 | 7900 { |
7901 oparg_T *oap = cap->oap; | |
7902 pos_T tpos; | |
7903 int i; | |
7904 int flag = FALSE; | |
7905 | |
7906 switch (cap->nchar) | |
7907 { | |
6868 | 7908 case Ctrl_A: |
7909 case Ctrl_X: | |
7 | 7910 #ifdef MEM_PROFILE |
7911 /* | |
7912 * "g^A": dump log of used memory. | |
7913 */ | |
6868 | 7914 if (!VIsual_active && cap->nchar == Ctrl_A) |
7915 vim_mem_profile_dump(); | |
7916 else | |
7917 #endif | |
7918 /* | |
7919 * "g^A/g^X": sequentially increment visually selected region | |
7920 */ | |
7921 if (VIsual_active) | |
7922 { | |
7923 cap->arg = TRUE; | |
7924 cap->cmdchar = cap->nchar; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
7925 cap->nchar = NUL; |
6868 | 7926 nv_addsub(cap); |
7927 } | |
7928 else | |
7929 clearopbeep(oap); | |
7 | 7930 break; |
7931 | |
7932 /* | |
7933 * "gR": Enter virtual replace mode. | |
7934 */ | |
7935 case 'R': | |
7936 cap->arg = TRUE; | |
7937 nv_Replace(cap); | |
7938 break; | |
7939 | |
7940 case 'r': | |
7941 nv_vreplace(cap); | |
7942 break; | |
7943 | |
7944 case '&': | |
7945 do_cmdline_cmd((char_u *)"%s//~/&"); | |
7946 break; | |
7947 | |
7948 /* | |
7949 * "gv": Reselect the previous Visual area. If Visual already active, | |
7950 * exchange previous and current Visual area. | |
7951 */ | |
7952 case 'v': | |
7953 if (checkclearop(oap)) | |
7954 break; | |
7955 | |
690 | 7956 if ( curbuf->b_visual.vi_start.lnum == 0 |
7957 || curbuf->b_visual.vi_start.lnum > curbuf->b_ml.ml_line_count | |
7958 || curbuf->b_visual.vi_end.lnum == 0) | |
7 | 7959 beep_flush(); |
7960 else | |
7961 { | |
7962 /* set w_cursor to the start of the Visual area, tpos to the end */ | |
7963 if (VIsual_active) | |
7964 { | |
7965 i = VIsual_mode; | |
690 | 7966 VIsual_mode = curbuf->b_visual.vi_mode; |
7967 curbuf->b_visual.vi_mode = i; | |
7 | 7968 # ifdef FEAT_EVAL |
7969 curbuf->b_visual_mode_eval = i; | |
7970 # endif | |
7971 i = curwin->w_curswant; | |
690 | 7972 curwin->w_curswant = curbuf->b_visual.vi_curswant; |
7973 curbuf->b_visual.vi_curswant = i; | |
7974 | |
7975 tpos = curbuf->b_visual.vi_end; | |
7976 curbuf->b_visual.vi_end = curwin->w_cursor; | |
7977 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7978 curbuf->b_visual.vi_start = VIsual; | |
7 | 7979 } |
7980 else | |
7981 { | |
690 | 7982 VIsual_mode = curbuf->b_visual.vi_mode; |
7983 curwin->w_curswant = curbuf->b_visual.vi_curswant; | |
7984 tpos = curbuf->b_visual.vi_end; | |
7985 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7 | 7986 } |
7987 | |
7988 VIsual_active = TRUE; | |
7989 VIsual_reselect = TRUE; | |
7990 | |
7991 /* Set Visual to the start and w_cursor to the end of the Visual | |
7992 * area. Make sure they are on an existing character. */ | |
7993 check_cursor(); | |
7994 VIsual = curwin->w_cursor; | |
7995 curwin->w_cursor = tpos; | |
7996 check_cursor(); | |
7997 update_topline(); | |
7998 /* | |
7999 * When called from normal "g" command: start Select mode when | |
8000 * 'selectmode' contains "cmd". When called for K_SELECT, always | |
8001 * start Select mode. | |
8002 */ | |
8003 if (cap->arg) | |
8004 VIsual_select = TRUE; | |
8005 else | |
8006 may_start_select('c'); | |
8007 #ifdef FEAT_MOUSE | |
8008 setmouse(); | |
8009 #endif | |
8010 #ifdef FEAT_CLIPBOARD | |
8011 /* Make sure the clipboard gets updated. Needed because start and | |
8012 * end are still the same, and the selection needs to be owned */ | |
8013 clip_star.vmode = NUL; | |
8014 #endif | |
8015 redraw_curbuf_later(INVERTED); | |
8016 showmode(); | |
8017 } | |
8018 break; | |
8019 /* | |
8020 * "gV": Don't reselect the previous Visual area after a Select mode | |
8021 * mapping of menu. | |
8022 */ | |
8023 case 'V': | |
8024 VIsual_reselect = FALSE; | |
8025 break; | |
8026 | |
8027 /* | |
8028 * "gh": start Select mode. | |
8029 * "gH": start Select line mode. | |
8030 * "g^H": start Select block mode. | |
8031 */ | |
8032 case K_BS: | |
8033 cap->nchar = Ctrl_H; | |
8034 /* FALLTHROUGH */ | |
8035 case 'h': | |
8036 case 'H': | |
8037 case Ctrl_H: | |
8038 # ifdef EBCDIC | |
8039 /* EBCDIC: 'v'-'h' != '^v'-'^h' */ | |
8040 if (cap->nchar == Ctrl_H) | |
8041 cap->cmdchar = Ctrl_V; | |
8042 else | |
8043 # endif | |
8044 cap->cmdchar = cap->nchar + ('v' - 'h'); | |
8045 cap->arg = TRUE; | |
8046 nv_visual(cap); | |
8047 break; | |
3701 | 8048 |
8049 /* "gn", "gN" visually select next/previous search match | |
8050 * "gn" selects next match | |
8051 * "gN" selects previous match | |
8052 */ | |
8053 case 'N': | |
8054 case 'n': | |
8055 if (!current_search(cap->count1, cap->nchar == 'n')) | |
3896 | 8056 clearopbeep(oap); |
3701 | 8057 break; |
7 | 8058 |
8059 /* | |
8060 * "gj" and "gk" two new funny movement keys -- up and down | |
8061 * movement based on *screen* line rather than *file* line. | |
8062 */ | |
8063 case 'j': | |
8064 case K_DOWN: | |
8065 /* with 'nowrap' it works just like the normal "j" command; also when | |
8066 * in a closed fold */ | |
8067 if (!curwin->w_p_wrap | |
8068 #ifdef FEAT_FOLDING | |
8069 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
8070 #endif | |
8071 ) | |
8072 { | |
8073 oap->motion_type = MLINE; | |
8074 i = cursor_down(cap->count1, oap->op_type == OP_NOP); | |
8075 } | |
8076 else | |
8077 i = nv_screengo(oap, FORWARD, cap->count1); | |
8078 if (i == FAIL) | |
8079 clearopbeep(oap); | |
8080 break; | |
8081 | |
8082 case 'k': | |
8083 case K_UP: | |
8084 /* with 'nowrap' it works just like the normal "k" command; also when | |
8085 * in a closed fold */ | |
8086 if (!curwin->w_p_wrap | |
8087 #ifdef FEAT_FOLDING | |
8088 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
8089 #endif | |
8090 ) | |
8091 { | |
8092 oap->motion_type = MLINE; | |
8093 i = cursor_up(cap->count1, oap->op_type == OP_NOP); | |
8094 } | |
8095 else | |
8096 i = nv_screengo(oap, BACKWARD, cap->count1); | |
8097 if (i == FAIL) | |
8098 clearopbeep(oap); | |
8099 break; | |
8100 | |
8101 /* | |
8102 * "gJ": join two lines without inserting a space. | |
8103 */ | |
8104 case 'J': | |
8105 nv_join(cap); | |
8106 break; | |
8107 | |
8108 /* | |
8109 * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines. | |
8110 * "gm": middle of "g0" and "g$". | |
8111 */ | |
8112 case '^': | |
8113 flag = TRUE; | |
8114 /* FALLTHROUGH */ | |
8115 | |
8116 case '0': | |
8117 case 'm': | |
8118 case K_HOME: | |
8119 case K_KHOME: | |
8120 oap->motion_type = MCHAR; | |
8121 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
|
8122 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 8123 { |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8124 int width1 = curwin->w_width - curwin_col_off(); |
7 | 8125 int width2 = width1 + curwin_col_off2(); |
8126 | |
8127 validate_virtcol(); | |
8128 i = 0; | |
8129 if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0) | |
8130 i = (curwin->w_virtcol - width1) / width2 * width2 + width1; | |
8131 } | |
8132 else | |
8133 i = curwin->w_leftcol; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2139
diff
changeset
|
8134 /* 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
|
8135 * '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
|
8136 * to the left. */ |
7 | 8137 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
|
8138 i += (curwin->w_width - curwin_col_off() |
7 | 8139 + ((curwin->w_p_wrap && i > 0) |
8140 ? curwin_col_off2() : 0)) / 2; | |
8141 coladvance((colnr_T)i); | |
8142 if (flag) | |
8143 { | |
8144 do | |
8145 i = gchar_cursor(); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
8146 while (VIM_ISWHITE(i) && oneright() == OK); |
15062
3a94f7918980
patch 8.1.0542: shiftwidth() does not take 'vartabstop' into account
Bram Moolenaar <Bram@vim.org>
parents:
15006
diff
changeset
|
8147 curwin->w_valid &= ~VALID_WCOL; |
7 | 8148 } |
8149 curwin->w_set_curswant = TRUE; | |
8150 break; | |
8151 | |
8152 case '_': | |
8153 /* "g_": to the last non-blank character in the line or <count> lines | |
8154 * downward. */ | |
8155 cap->oap->motion_type = MCHAR; | |
8156 cap->oap->inclusive = TRUE; | |
8157 curwin->w_curswant = MAXCOL; | |
8158 if (cursor_down((long)(cap->count1 - 1), | |
8159 cap->oap->op_type == OP_NOP) == FAIL) | |
8160 clearopbeep(cap->oap); | |
8161 else | |
8162 { | |
8163 char_u *ptr = ml_get_curline(); | |
8164 | |
8165 /* In Visual mode we may end up after the line. */ | |
8166 if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) | |
8167 --curwin->w_cursor.col; | |
8168 | |
8169 /* Decrease the cursor column until it's on a non-blank. */ | |
8170 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
|
8171 && VIM_ISWHITE(ptr[curwin->w_cursor.col])) |
7 | 8172 --curwin->w_cursor.col; |
8173 curwin->w_set_curswant = TRUE; | |
2040
70c67b1bb1f1
updated for version 7.2.329
Bram Moolenaar <bram@zimbu.org>
parents:
2024
diff
changeset
|
8174 adjust_for_sel(cap); |
7 | 8175 } |
8176 break; | |
8177 | |
8178 case '$': | |
8179 case K_END: | |
8180 case K_KEND: | |
8181 { | |
8182 int col_off = curwin_col_off(); | |
8183 | |
8184 oap->motion_type = MCHAR; | |
8185 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
|
8186 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 8187 { |
8188 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
8189 if (cap->count1 == 1) | |
8190 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8191 int width1 = curwin->w_width - col_off; |
7 | 8192 int width2 = width1 + curwin_col_off2(); |
8193 | |
8194 validate_virtcol(); | |
8195 i = width1 - 1; | |
8196 if (curwin->w_virtcol >= (colnr_T)width1) | |
8197 i += ((curwin->w_virtcol - width1) / width2 + 1) | |
8198 * width2; | |
8199 coladvance((colnr_T)i); | |
5162
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8200 |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8201 /* Make sure we stick in this column. */ |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8202 validate_virtcol(); |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8203 curwin->w_curswant = curwin->w_virtcol; |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8204 curwin->w_set_curswant = FALSE; |
7 | 8205 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE) |
8206 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
8207 { | |
8208 /* | |
8209 * Check for landing on a character that got split at | |
8210 * the end of the line. We do not want to advance to | |
8211 * the next screen line. | |
8212 */ | |
8213 if (curwin->w_virtcol > (colnr_T)i) | |
8214 --curwin->w_cursor.col; | |
8215 } | |
8216 #endif | |
8217 } | |
8218 else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == FAIL) | |
8219 clearopbeep(oap); | |
8220 } | |
8221 else | |
8222 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8223 i = curwin->w_leftcol + curwin->w_width - col_off - 1; |
7 | 8224 coladvance((colnr_T)i); |
40 | 8225 |
8226 /* Make sure we stick in this column. */ | |
8227 validate_virtcol(); | |
8228 curwin->w_curswant = curwin->w_virtcol; | |
8229 curwin->w_set_curswant = FALSE; | |
7 | 8230 } |
8231 } | |
8232 break; | |
8233 | |
8234 /* | |
8235 * "g*" and "g#", like "*" and "#" but without using "\<" and "\>" | |
8236 */ | |
8237 case '*': | |
8238 case '#': | |
8239 #if POUND != '#' | |
8240 case POUND: /* pound sign (sometimes equal to '#') */ | |
8241 #endif | |
8242 case Ctrl_RSB: /* :tag or :tselect for current identifier */ | |
8243 case ']': /* :tselect for current identifier */ | |
8244 nv_ident(cap); | |
8245 break; | |
8246 | |
8247 /* | |
8248 * ge and gE: go back to end of word | |
8249 */ | |
8250 case 'e': | |
8251 case 'E': | |
8252 oap->motion_type = MCHAR; | |
8253 curwin->w_set_curswant = TRUE; | |
8254 oap->inclusive = TRUE; | |
8255 if (bckend_word(cap->count1, cap->nchar == 'E', FALSE) == FAIL) | |
8256 clearopbeep(oap); | |
8257 break; | |
8258 | |
8259 /* | |
8260 * "g CTRL-G": display info about cursor position | |
8261 */ | |
8262 case Ctrl_G: | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7311
diff
changeset
|
8263 cursor_pos_info(NULL); |
7 | 8264 break; |
8265 | |
8266 /* | |
8267 * "gi": start Insert at the last position. | |
8268 */ | |
8269 case 'i': | |
8270 if (curbuf->b_last_insert.lnum != 0) | |
8271 { | |
8272 curwin->w_cursor = curbuf->b_last_insert; | |
8273 check_cursor_lnum(); | |
8274 i = (int)STRLEN(ml_get_curline()); | |
8275 if (curwin->w_cursor.col > (colnr_T)i) | |
8276 { | |
8277 #ifdef FEAT_VIRTUALEDIT | |
8278 if (virtual_active()) | |
8279 curwin->w_cursor.coladd += curwin->w_cursor.col - i; | |
8280 #endif | |
8281 curwin->w_cursor.col = i; | |
8282 } | |
8283 } | |
8284 cap->cmdchar = 'i'; | |
8285 nv_edit(cap); | |
8286 break; | |
8287 | |
8288 /* | |
8289 * "gI": Start insert in column 1. | |
8290 */ | |
8291 case 'I': | |
8292 beginline(0); | |
8293 if (!checkclearopq(oap)) | |
8294 invoke_edit(cap, FALSE, 'g', FALSE); | |
8295 break; | |
8296 | |
8297 #ifdef FEAT_SEARCHPATH | |
8298 /* | |
8299 * "gf": goto file, edit file under cursor | |
8300 * "]f" and "[f": can also be used. | |
8301 */ | |
8302 case 'f': | |
681 | 8303 case 'F': |
7 | 8304 nv_gotofile(cap); |
8305 break; | |
8306 #endif | |
8307 | |
8308 /* "g'm" and "g`m": jump to mark without setting pcmark */ | |
8309 case '\'': | |
8310 cap->arg = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
8311 /* FALLTHROUGH */ |
7 | 8312 case '`': |
8313 nv_gomark(cap); | |
8314 break; | |
8315 | |
8316 /* | |
8317 * "gs": Goto sleep. | |
8318 */ | |
8319 case 's': | |
8320 do_sleep(cap->count1 * 1000L); | |
8321 break; | |
8322 | |
8323 /* | |
8324 * "ga": Display the ascii value of the character under the | |
8325 * cursor. It is displayed in decimal, hex, and octal. -- webb | |
8326 */ | |
8327 case 'a': | |
8328 do_ascii(NULL); | |
8329 break; | |
8330 | |
8331 #ifdef FEAT_MBYTE | |
8332 /* | |
8333 * "g8": Display the bytes used for the UTF-8 character under the | |
8334 * cursor. It is displayed in hex. | |
775 | 8335 * "8g8" finds illegal byte sequence. |
7 | 8336 */ |
8337 case '8': | |
775 | 8338 if (cap->count0 == 8) |
8339 utf_find_illegal(); | |
8340 else | |
8341 show_utf8(); | |
7 | 8342 break; |
8343 #endif | |
8344 | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
8345 /* "g<": show scrollback text */ |
447 | 8346 case '<': |
8347 show_sb_text(); | |
8348 break; | |
8349 | |
7 | 8350 /* |
8351 * "gg": Goto the first line in file. With a count it goes to | |
8352 * that line number like for "G". -- webb | |
8353 */ | |
8354 case 'g': | |
8355 cap->arg = FALSE; | |
8356 nv_goto(cap); | |
8357 break; | |
8358 | |
8359 /* | |
8360 * Two-character operators: | |
8361 * "gq" Format text | |
8362 * "gw" Format text and keep cursor position | |
8363 * "g~" Toggle the case of the text. | |
8364 * "gu" Change text to lower case. | |
8365 * "gU" Change text to upper case. | |
8366 * "g?" rot13 encoding | |
602 | 8367 * "g@" call 'operatorfunc' |
7 | 8368 */ |
8369 case 'q': | |
8370 case 'w': | |
8371 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
|
8372 /* FALLTHROUGH */ |
7 | 8373 case '~': |
8374 case 'u': | |
8375 case 'U': | |
8376 case '?': | |
602 | 8377 case '@': |
7 | 8378 nv_operator(cap); |
8379 break; | |
8380 | |
8381 /* | |
1188 | 8382 * "gd": Find first occurrence of pattern under the cursor in the |
7 | 8383 * current function |
8384 * "gD": idem, but in the current file. | |
8385 */ | |
8386 case 'd': | |
8387 case 'D': | |
523 | 8388 nv_gd(oap, cap->nchar, (int)cap->count0); |
7 | 8389 break; |
8390 | |
8391 #ifdef FEAT_MOUSE | |
8392 /* | |
8393 * g<*Mouse> : <C-*mouse> | |
8394 */ | |
8395 case K_MIDDLEMOUSE: | |
8396 case K_MIDDLEDRAG: | |
8397 case K_MIDDLERELEASE: | |
8398 case K_LEFTMOUSE: | |
8399 case K_LEFTDRAG: | |
8400 case K_LEFTRELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
8401 case K_MOUSEMOVE: |
7 | 8402 case K_RIGHTMOUSE: |
8403 case K_RIGHTDRAG: | |
8404 case K_RIGHTRELEASE: | |
8405 case K_X1MOUSE: | |
8406 case K_X1DRAG: | |
8407 case K_X1RELEASE: | |
8408 case K_X2MOUSE: | |
8409 case K_X2DRAG: | |
8410 case K_X2RELEASE: | |
8411 mod_mask = MOD_MASK_CTRL; | |
8412 (void)do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0); | |
8413 break; | |
8414 #endif | |
8415 | |
8416 case K_IGNORE: | |
8417 break; | |
8418 | |
8419 /* | |
8420 * "gP" and "gp": same as "P" and "p" but leave cursor just after new text | |
8421 */ | |
8422 case 'p': | |
8423 case 'P': | |
8424 nv_put(cap); | |
8425 break; | |
8426 | |
8427 #ifdef FEAT_BYTEOFF | |
8428 /* "go": goto byte count from start of buffer */ | |
8429 case 'o': | |
8430 goto_byte(cap->count0); | |
8431 break; | |
8432 #endif | |
8433 | |
8434 /* "gQ": improved Ex mode */ | |
8435 case 'Q': | |
633 | 8436 if (text_locked()) |
7 | 8437 { |
8438 clearopbeep(cap->oap); | |
633 | 8439 text_locked_msg(); |
7 | 8440 break; |
8441 } | |
631 | 8442 |
7 | 8443 if (!checkclearopq(oap)) |
8444 do_exmode(TRUE); | |
8445 break; | |
8446 | |
8447 #ifdef FEAT_JUMPLIST | |
8448 case ',': | |
8449 nv_pcmark(cap); | |
8450 break; | |
8451 | |
8452 case ';': | |
8453 cap->count1 = -cap->count1; | |
8454 nv_pcmark(cap); | |
8455 break; | |
8456 #endif | |
8457 | |
667 | 8458 case 't': |
3630 | 8459 if (!checkclearop(oap)) |
8460 goto_tabpage((int)cap->count0); | |
667 | 8461 break; |
682 | 8462 case 'T': |
3630 | 8463 if (!checkclearop(oap)) |
8464 goto_tabpage(-(int)cap->count1); | |
682 | 8465 break; |
667 | 8466 |
750 | 8467 case '+': |
8468 case '-': /* "g+" and "g-": undo or redo along the timeline */ | |
8469 if (!checkclearopq(oap)) | |
771 | 8470 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
|
8471 FALSE, FALSE, FALSE); |
750 | 8472 break; |
8473 | |
7 | 8474 default: |
8475 clearopbeep(oap); | |
8476 break; | |
8477 } | |
8478 } | |
8479 | |
8480 /* | |
8481 * Handle "o" and "O" commands. | |
8482 */ | |
8483 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8484 n_opencmd(cmdarg_T *cap) |
7 | 8485 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8486 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8487 linenr_T oldline = curwin->w_cursor.lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8488 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8489 |
7 | 8490 if (!checkclearopq(cap->oap)) |
8491 { | |
8492 #ifdef FEAT_FOLDING | |
8493 if (cap->cmdchar == 'O') | |
8494 /* Open above the first line of a folded sequence of lines */ | |
8495 (void)hasFolding(curwin->w_cursor.lnum, | |
8496 &curwin->w_cursor.lnum, NULL); | |
8497 else | |
8498 /* Open below the last line of a folded sequence of lines */ | |
8499 (void)hasFolding(curwin->w_cursor.lnum, | |
8500 NULL, &curwin->w_cursor.lnum); | |
8501 #endif | |
8502 if (u_save((linenr_T)(curwin->w_cursor.lnum - | |
8503 (cap->cmdchar == 'O' ? 1 : 0)), | |
8504 (linenr_T)(curwin->w_cursor.lnum + | |
8505 (cap->cmdchar == 'o' ? 1 : 0)) | |
8506 ) == OK | |
8507 && open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD, | |
8508 #ifdef FEAT_COMMENTS | |
8509 has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM : | |
8510 #endif | |
13772
cc21507ee4b1
patch 8.0.1758: open_line() returns TRUE/FALSE for success/failure
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
8511 0, 0) == OK) |
7 | 8512 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8513 #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
|
8514 if (curwin->w_p_cole > 0 && oldline != curwin->w_cursor.lnum) |
15436
29f3d59bb6f0
patch 8.1.0726: redrawing specifically for conceal feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
8515 redrawWinline(curwin, oldline); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8516 #endif |
6834 | 8517 #ifdef FEAT_SYN_HL |
6821 | 8518 if (curwin->w_p_cul) |
8519 /* force redraw of cursorline */ | |
8520 curwin->w_valid &= ~VALID_CROW; | |
6834 | 8521 #endif |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
8522 /* When '#' is in 'cpoptions' ignore the count. */ |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
8523 if (vim_strchr(p_cpo, CPO_HASH) != NULL) |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
8524 cap->count1 = 1; |
7 | 8525 invoke_edit(cap, FALSE, cap->cmdchar, TRUE); |
8526 } | |
8527 } | |
8528 } | |
8529 | |
8530 /* | |
8531 * "." command: redo last change. | |
8532 */ | |
8533 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8534 nv_dot(cmdarg_T *cap) |
7 | 8535 { |
8536 if (!checkclearopq(cap->oap)) | |
8537 { | |
8538 /* | |
8539 * If "restart_edit" is TRUE, the last but one command is repeated | |
8540 * instead of the last command (inserting text). This is used for | |
8541 * CTRL-O <.> in insert mode. | |
8542 */ | |
8543 if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == FAIL) | |
8544 clearopbeep(cap->oap); | |
8545 } | |
8546 } | |
8547 | |
8548 /* | |
8549 * CTRL-R: undo undo | |
8550 */ | |
8551 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8552 nv_redo(cmdarg_T *cap) |
7 | 8553 { |
8554 if (!checkclearopq(cap->oap)) | |
8555 { | |
8556 u_redo((int)cap->count1); | |
8557 curwin->w_set_curswant = TRUE; | |
8558 } | |
8559 } | |
8560 | |
8561 /* | |
8562 * Handle "U" command. | |
8563 */ | |
8564 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8565 nv_Undo(cmdarg_T *cap) |
7 | 8566 { |
8567 /* In Visual mode and typing "gUU" triggers an operator */ | |
5735 | 8568 if (cap->oap->op_type == OP_UPPER || VIsual_active) |
7 | 8569 { |
8570 /* translate "gUU" to "gUgU" */ | |
8571 cap->cmdchar = 'g'; | |
8572 cap->nchar = 'U'; | |
8573 nv_operator(cap); | |
8574 } | |
8575 else if (!checkclearopq(cap->oap)) | |
8576 { | |
8577 u_undoline(); | |
8578 curwin->w_set_curswant = TRUE; | |
8579 } | |
8580 } | |
8581 | |
8582 /* | |
8583 * '~' command: If tilde is not an operator and Visual is off: swap case of a | |
8584 * single character. | |
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_tilde(cmdarg_T *cap) |
7 | 8588 { |
5735 | 8589 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
|
8590 { |
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
|
8591 #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
|
8592 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
|
8593 { |
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
|
8594 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
|
8595 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
|
8596 } |
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
|
8597 #endif |
7 | 8598 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
|
8599 } |
7 | 8600 else |
8601 nv_operator(cap); | |
8602 } | |
8603 | |
8604 /* | |
8605 * Handle an operator command. | |
8606 * The actual work is done by do_pending_operator(). | |
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_operator(cmdarg_T *cap) |
7 | 8610 { |
8611 int op_type; | |
8612 | |
8613 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
|
8614 #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
|
8615 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
|
8616 { |
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 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
|
8618 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
|
8619 } |
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
|
8620 #endif |
7 | 8621 |
8622 if (op_type == cap->oap->op_type) /* double operator works on lines */ | |
8623 nv_lineop(cap); | |
8624 else if (!checkclearop(cap->oap)) | |
8625 { | |
8626 cap->oap->start = curwin->w_cursor; | |
8627 cap->oap->op_type = op_type; | |
1490 | 8628 #ifdef FEAT_EVAL |
8629 set_op_var(op_type); | |
8630 #endif | |
8631 } | |
8632 } | |
8633 | |
8634 #ifdef FEAT_EVAL | |
8635 /* | |
8636 * Set v:operator to the characters for "optype". | |
8637 */ | |
8638 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8639 set_op_var(int optype) |
1490 | 8640 { |
8641 char_u opchars[3]; | |
8642 | |
8643 if (optype == OP_NOP) | |
8644 set_vim_var_string(VV_OP, NULL, 0); | |
8645 else | |
8646 { | |
8647 opchars[0] = get_op_char(optype); | |
8648 opchars[1] = get_extra_op_char(optype); | |
8649 opchars[2] = NUL; | |
8650 set_vim_var_string(VV_OP, opchars, -1); | |
8651 } | |
8652 } | |
8653 #endif | |
7 | 8654 |
8655 /* | |
8656 * Handle linewise operator "dd", "yy", etc. | |
8657 * | |
8658 * "_" is is a strange motion command that helps make operators more logical. | |
8659 * It is actually implemented, but not documented in the real Vi. This motion | |
8660 * command actually refers to "the current line". Commands like "dd" and "yy" | |
8661 * are really an alternate form of "d_" and "y_". It does accept a count, so | |
8662 * "d3_" works to delete 3 lines. | |
8663 */ | |
8664 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8665 nv_lineop(cmdarg_T *cap) |
7 | 8666 { |
8667 cap->oap->motion_type = MLINE; | |
8668 if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL) | |
8669 clearopbeep(cap->oap); | |
4011 | 8670 else if ( (cap->oap->op_type == OP_DELETE /* only with linewise motions */ |
8671 && cap->oap->motion_force != 'v' | |
8672 && cap->oap->motion_force != Ctrl_V) | |
7 | 8673 || cap->oap->op_type == OP_LSHIFT |
8674 || cap->oap->op_type == OP_RSHIFT) | |
8675 beginline(BL_SOL | BL_FIX); | |
8676 else if (cap->oap->op_type != OP_YANK) /* 'Y' does not move cursor */ | |
8677 beginline(BL_WHITE | BL_FIX); | |
8678 } | |
8679 | |
8680 /* | |
8681 * <Home> command. | |
8682 */ | |
8683 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8684 nv_home(cmdarg_T *cap) |
7 | 8685 { |
180 | 8686 /* CTRL-HOME is like "gg" */ |
8687 if (mod_mask & MOD_MASK_CTRL) | |
8688 nv_goto(cap); | |
8689 else | |
8690 { | |
8691 cap->count0 = 1; | |
8692 nv_pipe(cap); | |
8693 } | |
229 | 8694 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8695 one-character line). */ | |
7 | 8696 } |
8697 | |
8698 /* | |
8699 * "|" command. | |
8700 */ | |
8701 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8702 nv_pipe(cmdarg_T *cap) |
7 | 8703 { |
8704 cap->oap->motion_type = MCHAR; | |
8705 cap->oap->inclusive = FALSE; | |
8706 beginline(0); | |
8707 if (cap->count0 > 0) | |
8708 { | |
8709 coladvance((colnr_T)(cap->count0 - 1)); | |
8710 curwin->w_curswant = (colnr_T)(cap->count0 - 1); | |
8711 } | |
8712 else | |
8713 curwin->w_curswant = 0; | |
8714 /* keep curswant at the column where we wanted to go, not where | |
2667 | 8715 * we ended; differs if line is too short */ |
7 | 8716 curwin->w_set_curswant = FALSE; |
8717 } | |
8718 | |
8719 /* | |
8720 * Handle back-word command "b" and "B". | |
8721 * cap->arg is 1 for "B" | |
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_bck_word(cmdarg_T *cap) |
7 | 8725 { |
8726 cap->oap->motion_type = MCHAR; | |
8727 cap->oap->inclusive = FALSE; | |
8728 curwin->w_set_curswant = TRUE; | |
8729 if (bck_word(cap->count1, cap->arg, FALSE) == FAIL) | |
8730 clearopbeep(cap->oap); | |
8731 #ifdef FEAT_FOLDING | |
8732 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8733 foldOpenCursor(); | |
8734 #endif | |
8735 } | |
8736 | |
8737 /* | |
8738 * Handle word motion commands "e", "E", "w" and "W". | |
8739 * cap->arg is TRUE for "E" and "W". | |
8740 */ | |
8741 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8742 nv_wordcmd(cmdarg_T *cap) |
7 | 8743 { |
8744 int n; | |
8745 int word_end; | |
8746 int flag = FALSE; | |
1573 | 8747 pos_T startpos = curwin->w_cursor; |
7 | 8748 |
8749 /* | |
8750 * Set inclusive for the "E" and "e" command. | |
8751 */ | |
8752 if (cap->cmdchar == 'e' || cap->cmdchar == 'E') | |
8753 word_end = TRUE; | |
8754 else | |
8755 word_end = FALSE; | |
8756 cap->oap->inclusive = word_end; | |
8757 | |
8758 /* | |
8759 * "cw" and "cW" are a special case. | |
8760 */ | |
8761 if (!word_end && cap->oap->op_type == OP_CHANGE) | |
8762 { | |
8763 n = gchar_cursor(); | |
8764 if (n != NUL) /* not an empty line */ | |
8765 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
8766 if (VIM_ISWHITE(n)) |
7 | 8767 { |
8768 /* | |
8769 * Reproduce a funny Vi behaviour: "cw" on a blank only | |
8770 * changes one character, not all blanks until the start of | |
8771 * the next word. Only do this when the 'w' flag is included | |
8772 * in 'cpoptions'. | |
8773 */ | |
8774 if (cap->count1 == 1 && vim_strchr(p_cpo, CPO_CW) != NULL) | |
8775 { | |
8776 cap->oap->inclusive = TRUE; | |
8777 cap->oap->motion_type = MCHAR; | |
8778 return; | |
8779 } | |
8780 } | |
8781 else | |
8782 { | |
8783 /* | |
8784 * This is a little strange. To match what the real Vi does, | |
8785 * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided | |
8786 * that we are not on a space or a TAB. This seems impolite | |
8787 * at first, but it's really more what we mean when we say | |
8788 * 'cw'. | |
8789 * Another strangeness: When standing on the end of a word | |
4352 | 8790 * "ce" will change until the end of the next word, but "cw" |
7 | 8791 * will change only one character! This is done by setting |
8792 * flag. | |
8793 */ | |
8794 cap->oap->inclusive = TRUE; | |
8795 word_end = TRUE; | |
8796 flag = TRUE; | |
8797 } | |
8798 } | |
8799 } | |
8800 | |
8801 cap->oap->motion_type = MCHAR; | |
8802 curwin->w_set_curswant = TRUE; | |
8803 if (word_end) | |
8804 n = end_word(cap->count1, cap->arg, flag, FALSE); | |
8805 else | |
8806 n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP); | |
8807 | |
1573 | 8808 /* Don't leave the cursor on the NUL past the end of line. Unless we |
8809 * 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
|
8810 if (LT_POS(startpos, curwin->w_cursor)) |
1505 | 8811 adjust_cursor(cap->oap); |
7 | 8812 |
8813 if (n == FAIL && cap->oap->op_type == OP_NOP) | |
8814 clearopbeep(cap->oap); | |
8815 else | |
8816 { | |
8817 adjust_for_sel(cap); | |
8818 #ifdef FEAT_FOLDING | |
8819 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8820 foldOpenCursor(); | |
8821 #endif | |
8822 } | |
8823 } | |
8824 | |
8825 /* | |
1505 | 8826 * Used after a movement command: If the cursor ends up on the NUL after the |
8827 * end of the line, may move it back to the last character and make the motion | |
8828 * inclusive. | |
8829 */ | |
8830 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8831 adjust_cursor(oparg_T *oap) |
1505 | 8832 { |
8833 /* The cursor cannot remain on the NUL when: | |
8834 * - the column is > 0 | |
8835 * - not in Visual mode or 'selection' is "o" | |
8836 * - 'virtualedit' is not "all" and not "onemore". | |
8837 */ | |
8838 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL | |
8839 && (!VIsual_active || *p_sel == 'o') | |
8840 #ifdef FEAT_VIRTUALEDIT | |
8841 && !virtual_active() && (ve_flags & VE_ONEMORE) == 0 | |
8842 #endif | |
8843 ) | |
8844 { | |
8845 --curwin->w_cursor.col; | |
8846 #ifdef FEAT_MBYTE | |
8847 /* prevent cursor from moving on the trail byte */ | |
8848 if (has_mbyte) | |
8849 mb_adjust_cursor(); | |
8850 #endif | |
8851 oap->inclusive = TRUE; | |
8852 } | |
8853 } | |
8854 | |
8855 /* | |
7 | 8856 * "0" and "^" commands. |
8857 * cap->arg is the argument for beginline(). | |
8858 */ | |
8859 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8860 nv_beginline(cmdarg_T *cap) |
7 | 8861 { |
8862 cap->oap->motion_type = MCHAR; | |
8863 cap->oap->inclusive = FALSE; | |
8864 beginline(cap->arg); | |
8865 #ifdef FEAT_FOLDING | |
8866 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8867 foldOpenCursor(); | |
8868 #endif | |
557 | 8869 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8870 one-character line). */ | |
7 | 8871 } |
8872 | |
8873 /* | |
8874 * In exclusive Visual mode, may include the last character. | |
8875 */ | |
8876 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8877 adjust_for_sel(cmdarg_T *cap) |
7 | 8878 { |
8879 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
|
8880 && gchar_cursor() != NUL && LT_POS(VIsual, curwin->w_cursor)) |
7 | 8881 { |
5735 | 8882 #ifdef FEAT_MBYTE |
7 | 8883 if (has_mbyte) |
8884 inc_cursor(); | |
8885 else | |
5735 | 8886 #endif |
7 | 8887 ++curwin->w_cursor.col; |
8888 cap->oap->inclusive = FALSE; | |
8889 } | |
8890 } | |
8891 | |
8892 /* | |
8893 * Exclude last character at end of Visual area for 'selection' == "exclusive". | |
8894 * Should check VIsual_mode before calling this. | |
8895 * Returns TRUE when backed up to the previous line. | |
8896 */ | |
8897 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8898 unadjust_for_sel(void) |
7 | 8899 { |
8900 pos_T *pp; | |
8901 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8902 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
|
8903 { |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8904 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 8905 pp = &curwin->w_cursor; |
8906 else | |
8907 pp = &VIsual; | |
8908 #ifdef FEAT_VIRTUALEDIT | |
8909 if (pp->coladd > 0) | |
8910 --pp->coladd; | |
8911 else | |
8912 #endif | |
8913 if (pp->col > 0) | |
8914 { | |
8915 --pp->col; | |
8916 #ifdef FEAT_MBYTE | |
2933 | 8917 mb_adjustpos(curbuf, pp); |
7 | 8918 #endif |
8919 } | |
8920 else if (pp->lnum > 1) | |
8921 { | |
8922 --pp->lnum; | |
8923 pp->col = (colnr_T)STRLEN(ml_get(pp->lnum)); | |
8924 return TRUE; | |
8925 } | |
8926 } | |
8927 return FALSE; | |
8928 } | |
8929 | |
8930 /* | |
8931 * SELECT key in Normal or Visual mode: end of Select mode mapping. | |
8932 */ | |
8933 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8934 nv_select(cmdarg_T *cap) |
7 | 8935 { |
8936 if (VIsual_active) | |
8937 VIsual_select = TRUE; | |
8938 else if (VIsual_reselect) | |
8939 { | |
8940 cap->nchar = 'v'; /* fake "gv" command */ | |
8941 cap->arg = TRUE; | |
8942 nv_g_cmd(cap); | |
8943 } | |
8944 } | |
8945 | |
8946 | |
8947 /* | |
8948 * "G", "gg", CTRL-END, CTRL-HOME. | |
8949 * cap->arg is TRUE for "G". | |
8950 */ | |
8951 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8952 nv_goto(cmdarg_T *cap) |
7 | 8953 { |
8954 linenr_T lnum; | |
8955 | |
8956 if (cap->arg) | |
8957 lnum = curbuf->b_ml.ml_line_count; | |
8958 else | |
8959 lnum = 1L; | |
8960 cap->oap->motion_type = MLINE; | |
8961 setpcmark(); | |
8962 | |
8963 /* When a count is given, use it instead of the default lnum */ | |
8964 if (cap->count0 != 0) | |
8965 lnum = cap->count0; | |
8966 if (lnum < 1L) | |
8967 lnum = 1L; | |
8968 else if (lnum > curbuf->b_ml.ml_line_count) | |
8969 lnum = curbuf->b_ml.ml_line_count; | |
8970 curwin->w_cursor.lnum = lnum; | |
8971 beginline(BL_SOL | BL_FIX); | |
8972 #ifdef FEAT_FOLDING | |
8973 if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8974 foldOpenCursor(); | |
8975 #endif | |
8976 } | |
8977 | |
8978 /* | |
8979 * CTRL-\ in Normal mode. | |
8980 */ | |
8981 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8982 nv_normal(cmdarg_T *cap) |
7 | 8983 { |
8984 if (cap->nchar == Ctrl_N || cap->nchar == Ctrl_G) | |
8985 { | |
8986 clearop(cap->oap); | |
643 | 8987 if (restart_edit != 0 && mode_displayed) |
7 | 8988 clear_cmdline = TRUE; /* unshow mode later */ |
8989 restart_edit = 0; | |
8990 #ifdef FEAT_CMDWIN | |
8991 if (cmdwin_type != 0) | |
8992 cmdwin_result = Ctrl_C; | |
8993 #endif | |
8994 if (VIsual_active) | |
8995 { | |
8996 end_visual_mode(); /* stop Visual */ | |
8997 redraw_curbuf_later(INVERTED); | |
8998 } | |
8999 /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */ | |
9000 if (cap->nchar == Ctrl_G && p_im) | |
9001 restart_edit = 'a'; | |
9002 } | |
9003 else | |
9004 clearopbeep(cap->oap); | |
9005 } | |
9006 | |
9007 /* | |
9008 * ESC in Normal mode: beep, but don't flush buffers. | |
9009 * Don't even beep if we are canceling a command. | |
9010 */ | |
9011 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9012 nv_esc(cmdarg_T *cap) |
7 | 9013 { |
9014 int no_reason; | |
9015 | |
9016 no_reason = (cap->oap->op_type == OP_NOP | |
9017 && cap->opcount == 0 | |
9018 && cap->count0 == 0 | |
9019 && cap->oap->regname == 0 | |
9020 && !p_im); | |
9021 | |
9022 if (cap->arg) /* TRUE for CTRL-C */ | |
9023 { | |
9024 if (restart_edit == 0 | |
9025 #ifdef FEAT_CMDWIN | |
9026 && cmdwin_type == 0 | |
9027 #endif | |
9028 && !VIsual_active | |
9029 && 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
|
9030 MSG(_("Type :qa! and press <Enter> to abandon all changes and exit Vim")); |
7 | 9031 |
9032 /* Don't reset "restart_edit" when 'insertmode' is set, it won't be | |
9033 * set again below when halfway a mapping. */ | |
9034 if (!p_im) | |
9035 restart_edit = 0; | |
9036 #ifdef FEAT_CMDWIN | |
9037 if (cmdwin_type != 0) | |
9038 { | |
9039 cmdwin_result = K_IGNORE; | |
9040 got_int = FALSE; /* don't stop executing autocommands et al. */ | |
9041 return; | |
9042 } | |
9043 #endif | |
9044 } | |
9045 | |
9046 if (VIsual_active) | |
9047 { | |
9048 end_visual_mode(); /* stop Visual */ | |
9049 check_cursor_col(); /* make sure cursor is not beyond EOL */ | |
9050 curwin->w_set_curswant = TRUE; | |
9051 redraw_curbuf_later(INVERTED); | |
9052 } | |
5735 | 9053 else if (no_reason) |
6949 | 9054 vim_beep(BO_ESC); |
7 | 9055 clearop(cap->oap); |
9056 | |
9057 /* A CTRL-C is often used at the start of a menu. When 'insertmode' is | |
9058 * 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
|
9059 if (restart_edit == 0 && goto_im() && ex_normal_busy == 0) |
7 | 9060 restart_edit = 'a'; |
9061 } | |
9062 | |
9063 /* | |
9064 * 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
|
9065 * Also handle K_PS, start bracketed paste. |
7 | 9066 */ |
9067 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9068 nv_edit(cmdarg_T *cap) |
7 | 9069 { |
9070 /* <Insert> is equal to "i" */ | |
9071 if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) | |
9072 cap->cmdchar = 'i'; | |
9073 | |
9074 /* in Visual mode "A" and "I" are an operator */ | |
9075 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
|
9076 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9077 #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
|
9078 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
|
9079 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9080 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
|
9081 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
|
9082 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
|
9083 return; |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9084 } |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9085 #endif |
7 | 9086 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
|
9087 } |
7 | 9088 |
9089 /* in Visual mode and after an operator "a" and "i" are for text objects */ | |
5735 | 9090 else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') |
9091 && (cap->oap->op_type != OP_NOP || VIsual_active)) | |
7 | 9092 { |
9093 #ifdef FEAT_TEXTOBJ | |
9094 nv_object(cap); | |
9095 #else | |
9096 clearopbeep(cap->oap); | |
9097 #endif | |
9098 } | |
11892
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9099 #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
|
9100 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
|
9101 { |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9102 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
|
9103 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
|
9104 return; |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9105 } |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9106 #endif |
7 | 9107 else if (!curbuf->b_p_ma && !p_im) |
9108 { | |
9109 /* Only give this error when 'insertmode' is off. */ | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
9110 emsg(_(e_modifiable)); |
7 | 9111 clearop(cap->oap); |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9112 if (cap->cmdchar == K_PS) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9113 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9114 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 9115 } |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9116 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
|
9117 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9118 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
|
9119 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
|
9120 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9121 /* 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
|
9122 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
|
9123 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9124 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
|
9125 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
|
9126 } |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9127 else |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9128 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
|
9129 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
|
9130 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
|
9131 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
|
9132 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
|
9133 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
|
9134 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9135 /* 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
|
9136 * 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
|
9137 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
|
9138 && 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
|
9139 inc_cursor(); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9140 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9141 /* 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
|
9142 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
|
9143 } |
7 | 9144 else if (!checkclearopq(cap->oap)) |
9145 { | |
9146 switch (cap->cmdchar) | |
9147 { | |
9148 case 'A': /* "A"ppend after the line */ | |
9149 curwin->w_set_curswant = TRUE; | |
9150 #ifdef FEAT_VIRTUALEDIT | |
9151 if (ve_flags == VE_ALL) | |
9152 { | |
9153 int save_State = State; | |
9154 | |
4352 | 9155 /* Pretend Insert mode here to allow the cursor on the |
7 | 9156 * character past the end of the line */ |
9157 State = INSERT; | |
9158 coladvance((colnr_T)MAXCOL); | |
9159 State = save_State; | |
9160 } | |
9161 else | |
9162 #endif | |
9163 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor()); | |
9164 break; | |
9165 | |
9166 case 'I': /* "I"nsert before the first non-blank */ | |
164 | 9167 if (vim_strchr(p_cpo, CPO_INSEND) == NULL) |
9168 beginline(BL_WHITE); | |
9169 else | |
9170 beginline(BL_WHITE|BL_FIX); | |
7 | 9171 break; |
9172 | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9173 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
|
9174 /* 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
|
9175 * 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
|
9176 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
|
9177 break; |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
9178 /* FALLTHROUGH */ |
10813
09eb5fd275e0
patch 8.0.0296: bracketed paste can only append, not insert
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
9179 |
7 | 9180 case 'a': /* "a"ppend is like "i"nsert on the next character. */ |
9181 #ifdef FEAT_VIRTUALEDIT | |
9182 /* increment coladd when in virtual space, increment the | |
9183 * column otherwise, also to append after an unprintable char */ | |
9184 if (virtual_active() | |
9185 && (curwin->w_cursor.coladd > 0 | |
9186 || *ml_get_cursor() == NUL | |
9187 || *ml_get_cursor() == TAB)) | |
9188 curwin->w_cursor.coladd++; | |
9189 else | |
9190 #endif | |
9191 if (*ml_get_cursor() != NUL) | |
9192 inc_cursor(); | |
9193 break; | |
9194 } | |
9195 | |
9196 #ifdef FEAT_VIRTUALEDIT | |
9197 if (curwin->w_cursor.coladd && cap->cmdchar != 'A') | |
9198 { | |
9199 int save_State = State; | |
9200 | |
4352 | 9201 /* Pretend Insert mode here to allow the cursor on the |
7 | 9202 * character past the end of the line */ |
9203 State = INSERT; | |
9204 coladvance(getviscol()); | |
9205 State = save_State; | |
9206 } | |
9207 #endif | |
9208 | |
9209 invoke_edit(cap, FALSE, cap->cmdchar, FALSE); | |
9210 } | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9211 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
|
9212 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9213 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 9214 } |
9215 | |
9216 /* | |
9217 * Invoke edit() and take care of "restart_edit" and the return value. | |
9218 */ | |
9219 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9220 invoke_edit( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9221 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9222 int repl, /* "r" or "gr" command */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9223 int cmd, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9224 int startln) |
7 | 9225 { |
9226 int restart_edit_save = 0; | |
9227 | |
9228 /* Complicated: When the user types "a<C-O>a" we don't want to do Insert | |
9229 * mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow | |
9230 * it. */ | |
9231 if (repl || !stuff_empty()) | |
9232 restart_edit_save = restart_edit; | |
9233 else | |
9234 restart_edit_save = 0; | |
9235 | |
9236 /* Always reset "restart_edit", this is not a restarted edit. */ | |
9237 restart_edit = 0; | |
9238 | |
9239 if (edit(cmd, startln, cap->count1)) | |
9240 cap->retval |= CA_COMMAND_BUSY; | |
9241 | |
9242 if (restart_edit == 0) | |
9243 restart_edit = restart_edit_save; | |
9244 } | |
9245 | |
9246 #ifdef FEAT_TEXTOBJ | |
9247 /* | |
9248 * "a" or "i" while an operator is pending or in Visual mode: object motion. | |
9249 */ | |
9250 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9251 nv_object( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9252 cmdarg_T *cap) |
7 | 9253 { |
9254 int flag; | |
9255 int include; | |
9256 char_u *mps_save; | |
9257 | |
9258 if (cap->cmdchar == 'i') | |
9259 include = FALSE; /* "ix" = inner object: exclude white space */ | |
9260 else | |
9261 include = TRUE; /* "ax" = an object: include white space */ | |
9262 | |
9263 /* Make sure (), [], {} and <> are in 'matchpairs' */ | |
9264 mps_save = curbuf->b_p_mps; | |
9265 curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>"; | |
9266 | |
9267 switch (cap->nchar) | |
9268 { | |
9269 case 'w': /* "aw" = a word */ | |
9270 flag = current_word(cap->oap, cap->count1, include, FALSE); | |
9271 break; | |
9272 case 'W': /* "aW" = a WORD */ | |
9273 flag = current_word(cap->oap, cap->count1, include, TRUE); | |
9274 break; | |
9275 case 'b': /* "ab" = a braces block */ | |
9276 case '(': | |
9277 case ')': | |
9278 flag = current_block(cap->oap, cap->count1, include, '(', ')'); | |
9279 break; | |
9280 case 'B': /* "aB" = a Brackets block */ | |
9281 case '{': | |
9282 case '}': | |
9283 flag = current_block(cap->oap, cap->count1, include, '{', '}'); | |
9284 break; | |
9285 case '[': /* "a[" = a [] block */ | |
9286 case ']': | |
9287 flag = current_block(cap->oap, cap->count1, include, '[', ']'); | |
9288 break; | |
9289 case '<': /* "a<" = a <> block */ | |
9290 case '>': | |
9291 flag = current_block(cap->oap, cap->count1, include, '<', '>'); | |
9292 break; | |
420 | 9293 case 't': /* "at" = a tag block (xml and html) */ |
6661 | 9294 /* Do not adjust oap->end in do_pending_operator() |
9295 * otherwise there are different results for 'dit' | |
9296 * (note leading whitespace in last line): | |
9297 * 1) <b> 2) <b> | |
9298 * foobar foobar | |
9299 * </b> </b> | |
9300 */ | |
9301 cap->retval |= CA_NO_ADJ_OP_END; | |
420 | 9302 flag = current_tagblock(cap->oap, cap->count1, include); |
9303 break; | |
7 | 9304 case 'p': /* "ap" = a paragraph */ |
9305 flag = current_par(cap->oap, cap->count1, include, 'p'); | |
9306 break; | |
9307 case 's': /* "as" = a sentence */ | |
9308 flag = current_sent(cap->oap, cap->count1, include); | |
9309 break; | |
12 | 9310 case '"': /* "a"" = a double quoted string */ |
9311 case '\'': /* "a'" = a single quoted string */ | |
9312 case '`': /* "a`" = a backtick quoted string */ | |
9313 flag = current_quote(cap->oap, cap->count1, include, | |
9314 cap->nchar); | |
9315 break; | |
7 | 9316 #if 0 /* TODO */ |
9317 case 'S': /* "aS" = a section */ | |
9318 case 'f': /* "af" = a filename */ | |
9319 case 'u': /* "au" = a URL */ | |
9320 #endif | |
9321 default: | |
9322 flag = FAIL; | |
9323 break; | |
9324 } | |
9325 | |
9326 curbuf->b_p_mps = mps_save; | |
9327 if (flag == FAIL) | |
9328 clearopbeep(cap->oap); | |
9329 adjust_cursor_col(); | |
9330 curwin->w_set_curswant = TRUE; | |
9331 } | |
9332 #endif | |
9333 | |
9334 /* | |
9335 * "q" command: Start/stop recording. | |
9336 * "q:", "q/", "q?": edit command-line in command-line window. | |
9337 */ | |
9338 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9339 nv_record(cmdarg_T *cap) |
7 | 9340 { |
9341 if (cap->oap->op_type == OP_FORMAT) | |
9342 { | |
9343 /* "gqq" is the same as "gqgq": format line */ | |
9344 cap->cmdchar = 'g'; | |
9345 cap->nchar = 'q'; | |
9346 nv_operator(cap); | |
9347 } | |
9348 else if (!checkclearop(cap->oap)) | |
9349 { | |
9350 #ifdef FEAT_CMDWIN | |
9351 if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?') | |
9352 { | |
9353 stuffcharReadbuff(cap->nchar); | |
9354 stuffcharReadbuff(K_CMDWIN); | |
9355 } | |
9356 else | |
9357 #endif | |
9358 /* (stop) recording into a named register, unless executing a | |
9359 * 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
|
9360 if (reg_executing == 0 && do_record(cap->nchar) == FAIL) |
7 | 9361 clearopbeep(cap->oap); |
9362 } | |
9363 } | |
9364 | |
9365 /* | |
9366 * Handle the "@r" command. | |
9367 */ | |
9368 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9369 nv_at(cmdarg_T *cap) |
7 | 9370 { |
9371 if (checkclearop(cap->oap)) | |
9372 return; | |
9373 #ifdef FEAT_EVAL | |
9374 if (cap->nchar == '=') | |
9375 { | |
9376 if (get_expr_register() == NUL) | |
9377 return; | |
9378 } | |
9379 #endif | |
9380 while (cap->count1-- && !got_int) | |
9381 { | |
1034 | 9382 if (do_execreg(cap->nchar, FALSE, FALSE, FALSE) == FAIL) |
7 | 9383 { |
9384 clearopbeep(cap->oap); | |
9385 break; | |
9386 } | |
9387 line_breakcheck(); | |
9388 } | |
9389 } | |
9390 | |
9391 /* | |
9392 * Handle the CTRL-U and CTRL-D commands. | |
9393 */ | |
9394 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9395 nv_halfpage(cmdarg_T *cap) |
7 | 9396 { |
9397 if ((cap->cmdchar == Ctrl_U && curwin->w_cursor.lnum == 1) | |
9398 || (cap->cmdchar == Ctrl_D | |
9399 && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)) | |
9400 clearopbeep(cap->oap); | |
9401 else if (!checkclearop(cap->oap)) | |
9402 halfpage(cap->cmdchar == Ctrl_D, cap->count0); | |
9403 } | |
9404 | |
9405 /* | |
9406 * Handle "J" or "gJ" command. | |
9407 */ | |
9408 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9409 nv_join(cmdarg_T *cap) |
7 | 9410 { |
9411 if (VIsual_active) /* join the visual lines */ | |
9412 nv_operator(cap); | |
5735 | 9413 else if (!checkclearop(cap->oap)) |
7 | 9414 { |
9415 if (cap->count0 <= 1) | |
9416 cap->count0 = 2; /* default for join is two lines! */ | |
9417 if (curwin->w_cursor.lnum + cap->count0 - 1 > | |
9418 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
|
9419 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9420 /* 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
|
9421 if (cap->count0 <= 2) |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9422 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9423 clearopbeep(cap->oap); |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9424 return; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9425 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9426 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
|
9427 - curwin->w_cursor.lnum + 1; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9428 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9429 |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9430 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
|
9431 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
|
9432 (void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE, TRUE); |
7 | 9433 } |
9434 } | |
9435 | |
9436 /* | |
9437 * "P", "gP", "p" and "gp" commands. | |
9438 */ | |
9439 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9440 nv_put(cmdarg_T *cap) |
7 | 9441 { |
9442 int regname = 0; | |
9443 void *reg1 = NULL, *reg2 = NULL; | |
84 | 9444 int empty = FALSE; |
236 | 9445 int was_visual = FALSE; |
7 | 9446 int dir; |
9447 int flags = 0; | |
9448 | |
9449 if (cap->oap->op_type != OP_NOP) | |
9450 { | |
9451 #ifdef FEAT_DIFF | |
9452 /* "dp" is ":diffput" */ | |
9453 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') | |
9454 { | |
9455 clearop(cap->oap); | |
6314 | 9456 nv_diffgetput(TRUE, cap->opcount); |
7 | 9457 } |
9458 else | |
9459 #endif | |
9460 clearopbeep(cap->oap); | |
9461 } | |
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
|
9462 #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
|
9463 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
|
9464 { |
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
|
9465 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
|
9466 } |
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
|
9467 #endif |
7 | 9468 else |
9469 { | |
9470 dir = (cap->cmdchar == 'P' | |
9471 || (cap->cmdchar == 'g' && cap->nchar == 'P')) | |
9472 ? BACKWARD : FORWARD; | |
9473 prep_redo_cmd(cap); | |
9474 if (cap->cmdchar == 'g') | |
9475 flags |= PUT_CURSEND; | |
9476 | |
9477 if (VIsual_active) | |
9478 { | |
9479 /* Putting in Visual mode: The put text replaces the selected | |
9480 * text. First delete the selected text, then put the new text. | |
9481 * Need to save and restore the registers that the delete | |
9482 * overwrites if the old contents is being put. | |
9483 */ | |
236 | 9484 was_visual = TRUE; |
7 | 9485 regname = cap->oap->regname; |
5735 | 9486 #ifdef FEAT_CLIPBOARD |
7 | 9487 adjust_clip_reg(®name); |
5735 | 9488 #endif |
5682 | 9489 if (regname == 0 || regname == '"' |
4013 | 9490 || VIM_ISDIGIT(regname) || regname == '-' |
5735 | 9491 #ifdef FEAT_CLIPBOARD |
7 | 9492 || (clip_unnamed && (regname == '*' || regname == '+')) |
5735 | 9493 #endif |
7 | 9494 |
9495 ) | |
9496 { | |
4013 | 9497 /* The delete is going to overwrite the register we want to |
7 | 9498 * put, save it first. */ |
9499 reg1 = get_register(regname, TRUE); | |
9500 } | |
9501 | |
9502 /* Now delete the selected text. */ | |
9503 cap->cmdchar = 'd'; | |
9504 cap->nchar = NUL; | |
9505 cap->oap->regname = NUL; | |
9506 nv_operator(cap); | |
9507 do_pending_operator(cap, 0, FALSE); | |
84 | 9508 empty = (curbuf->b_ml.ml_flags & ML_EMPTY); |
7 | 9509 |
9510 /* delete PUT_LINE_BACKWARD; */ | |
9511 cap->oap->regname = regname; | |
9512 | |
9513 if (reg1 != NULL) | |
9514 { | |
9515 /* Delete probably changed the register we want to put, save | |
9516 * it first. Then put back what was there before the delete. */ | |
9517 reg2 = get_register(regname, FALSE); | |
9518 put_register(regname, reg1); | |
9519 } | |
9520 | |
9521 /* When deleted a linewise Visual area, put the register as | |
9522 * lines to avoid it joined with the next line. When deletion was | |
9523 * characterwise, split a line when putting lines. */ | |
9524 if (VIsual_mode == 'V') | |
9525 flags |= PUT_LINE; | |
9526 else if (VIsual_mode == 'v') | |
9527 flags |= PUT_LINE_SPLIT; | |
9528 if (VIsual_mode == Ctrl_V && dir == FORWARD) | |
9529 flags |= PUT_LINE_FORWARD; | |
9530 dir = BACKWARD; | |
9531 if ((VIsual_mode != 'V' | |
9532 && curwin->w_cursor.col < curbuf->b_op_start.col) | |
9533 || (VIsual_mode == 'V' | |
9534 && curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) | |
9535 /* cursor is at the end of the line or end of file, put | |
9536 * forward. */ | |
9537 dir = FORWARD; | |
5365 | 9538 /* May have been reset in do_put(). */ |
9539 VIsual_active = TRUE; | |
7 | 9540 } |
9541 do_put(cap->oap->regname, dir, cap->count1, flags); | |
9542 | |
9543 /* If a register was saved, put it back now. */ | |
9544 if (reg2 != NULL) | |
9545 put_register(regname, reg2); | |
236 | 9546 |
9547 /* What to reselect with "gv"? Selecting the just put text seems to | |
9548 * be the most useful, since the original text was removed. */ | |
9549 if (was_visual) | |
9550 { | |
690 | 9551 curbuf->b_visual.vi_start = curbuf->b_op_start; |
9552 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
|
9553 /* need to adjust cursor position */ |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
9554 if (*p_sel == 'e') |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
9555 inc(&curbuf->b_visual.vi_end); |
236 | 9556 } |
9557 | |
84 | 9558 /* When all lines were selected and deleted do_put() leaves an empty |
236 | 9559 * line that needs to be deleted now. */ |
84 | 9560 if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) |
817 | 9561 { |
84 | 9562 ml_delete(curbuf->b_ml.ml_line_count, TRUE); |
817 | 9563 |
9564 /* If the cursor was in that line, move it to the end of the last | |
9565 * line. */ | |
9566 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
9567 { | |
9568 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
9569 coladvance((colnr_T)MAXCOL); | |
9570 } | |
9571 } | |
7 | 9572 auto_format(FALSE, TRUE); |
9573 } | |
9574 } | |
9575 | |
9576 /* | |
9577 * "o" and "O" commands. | |
9578 */ | |
9579 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9580 nv_open(cmdarg_T *cap) |
7 | 9581 { |
9582 #ifdef FEAT_DIFF | |
9583 /* "do" is ":diffget" */ | |
9584 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') | |
9585 { | |
9586 clearop(cap->oap); | |
6314 | 9587 nv_diffgetput(FALSE, cap->opcount); |
7 | 9588 } |
9589 else | |
9590 #endif | |
9591 if (VIsual_active) /* switch start and end of visual */ | |
9592 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
|
9593 #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
|
9594 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
|
9595 { |
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
|
9596 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
|
9597 } |
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
|
9598 #endif |
7 | 9599 else |
9600 n_opencmd(cap); | |
9601 } | |
9602 | |
9603 #ifdef FEAT_NETBEANS_INTG | |
9604 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9605 nv_nbcmd(cmdarg_T *cap) |
7 | 9606 { |
9607 netbeans_keycommand(cap->nchar); | |
9608 } | |
9609 #endif | |
9610 | |
9611 #ifdef FEAT_DND | |
9612 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9613 nv_drop(cmdarg_T *cap UNUSED) |
7 | 9614 { |
9615 do_put('~', BACKWARD, 1L, PUT_CURSEND); | |
9616 } | |
9617 #endif | |
203 | 9618 |
9619 /* | |
9620 * Trigger CursorHold event. | |
9621 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the | |
9622 * input buffer. "did_cursorhold" is set to avoid retriggering. | |
9623 */ | |
9624 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9625 nv_cursorhold(cmdarg_T *cap) |
203 | 9626 { |
9627 apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); | |
9628 did_cursorhold = TRUE; | |
226 | 9629 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
9630 } | |
6866 | 9631 |
9632 /* | |
7001 | 9633 * Calculate start/end virtual columns for operating in block mode. |
6866 | 9634 */ |
9635 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9636 get_op_vcol( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9637 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9638 colnr_T redo_VIsual_vcol, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9639 int initial) /* when TRUE adjust position for 'selectmode' */ |
6866 | 9640 { |
9641 colnr_T start, end; | |
9642 | |
7001 | 9643 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
|
9644 || (!initial && oap->end.col < curwin->w_width)) |
6866 | 9645 return; |
9646 | |
7143
fe6d525d12f4
commit https://github.com/vim/vim/commit/10ad1d90da8c464e1bf08bf23d92d4888378a8a1
Christian Brabandt <cb@256bit.org>
parents:
7090
diff
changeset
|
9647 oap->block_mode = TRUE; |
6866 | 9648 |
9649 #ifdef FEAT_MBYTE | |
9650 /* prevent from moving onto a trail byte */ | |
9651 if (has_mbyte) | |
9652 mb_adjustpos(curwin->w_buffer, &oap->end); | |
9653 #endif | |
9654 | |
9655 getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol); | |
6961 | 9656 |
9657 if (!redo_VIsual_busy) | |
9658 { | |
9659 getvvcol(curwin, &(oap->end), &start, NULL, &end); | |
9660 | |
9661 if (start < oap->start_vcol) | |
9662 oap->start_vcol = start; | |
9663 if (end > oap->end_vcol) | |
9664 { | |
9665 if (initial && *p_sel == 'e' && start >= 1 | |
9666 && start - 1 >= oap->end_vcol) | |
9667 oap->end_vcol = start - 1; | |
9668 else | |
9669 oap->end_vcol = end; | |
9670 } | |
9671 } | |
9672 | |
6866 | 9673 /* if '$' was used, get oap->end_vcol from longest line */ |
9674 if (curwin->w_curswant == MAXCOL) | |
9675 { | |
9676 curwin->w_cursor.col = MAXCOL; | |
9677 oap->end_vcol = 0; | |
9678 for (curwin->w_cursor.lnum = oap->start.lnum; | |
9679 curwin->w_cursor.lnum <= oap->end.lnum; | |
9680 ++curwin->w_cursor.lnum) | |
9681 { | |
9682 getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end); | |
9683 if (end > oap->end_vcol) | |
9684 oap->end_vcol = end; | |
9685 } | |
9686 } | |
9687 else if (redo_VIsual_busy) | |
9688 oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1; | |
9689 /* | |
9690 * Correct oap->end.col and oap->start.col to be the | |
9691 * upper-left and lower-right corner of the block area. | |
9692 * | |
9693 * (Actually, this does convert column positions into character | |
9694 * positions) | |
9695 */ | |
9696 curwin->w_cursor.lnum = oap->end.lnum; | |
9697 coladvance(oap->end_vcol); | |
9698 oap->end = curwin->w_cursor; | |
9699 | |
9700 curwin->w_cursor = oap->start; | |
9701 coladvance(oap->start_vcol); | |
9702 oap->start = curwin->w_cursor; | |
9703 } |