Mercurial > vim
annotate src/normal.c @ 16089:4411c38f3d16 v8.1.1049
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
commit https://github.com/vim/vim/commit/a84a3dd6635fcd2e07f510cba6a999585dcc381a
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Mar 25 22:21:24 2019 +0100
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Problem: When user tries to exit with CTRL-C message is confusing.
Solution: Only mention ":qa!" when there is a changed buffer. (closes https://github.com/vim/vim/issues/4163)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 25 Mar 2019 22:30:05 +0100 |
parents | 78faa25f9698 |
children | cd5c83115ec6 |
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}, | |
16054
78faa25f9698
patch 8.1.1032: warnings from clang static analyzer
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
217 {CAR, 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_NETBEANS_INTG |
401 {K_F21, nv_nbcmd, NV_NCH_ALW, 0}, | |
402 #endif | |
403 #ifdef FEAT_DND | |
404 {K_DROP, nv_drop, NV_STS, 0}, | |
405 #endif | |
819 | 406 {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
|
407 {K_PS, nv_edit, 0, 0}, |
7 | 408 }; |
409 | |
410 /* Number of commands in nv_cmds[]. */ | |
411 #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd)) | |
412 | |
413 /* Sorted index of commands in nv_cmds[]. */ | |
414 static short nv_cmd_idx[NV_CMDS_SIZE]; | |
415 | |
416 /* The highest index for which | |
417 * nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] */ | |
418 static int nv_max_linear; | |
419 | |
420 /* | |
421 * Compare functions for qsort() below, that checks the command character | |
422 * through the index in nv_cmd_idx[]. | |
423 */ | |
424 static int | |
425 #ifdef __BORLANDC__ | |
426 _RTLENTRYF | |
427 #endif | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
428 nv_compare(const void *s1, const void *s2) |
7 | 429 { |
430 int c1, c2; | |
431 | |
432 /* The commands are sorted on absolute value. */ | |
433 c1 = nv_cmds[*(const short *)s1].cmd_char; | |
434 c2 = nv_cmds[*(const short *)s2].cmd_char; | |
435 if (c1 < 0) | |
436 c1 = -c1; | |
437 if (c2 < 0) | |
438 c2 = -c2; | |
439 return c1 - c2; | |
440 } | |
441 | |
442 /* | |
443 * Initialize the nv_cmd_idx[] table. | |
444 */ | |
445 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
446 init_normal_cmds(void) |
7 | 447 { |
448 int i; | |
449 | |
450 /* Fill the index table with a one to one relation. */ | |
1877 | 451 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 452 nv_cmd_idx[i] = i; |
453 | |
454 /* Sort the commands by the command character. */ | |
455 qsort((void *)&nv_cmd_idx, (size_t)NV_CMDS_SIZE, sizeof(short), nv_compare); | |
456 | |
457 /* Find the first entry that can't be indexed by the command character. */ | |
1877 | 458 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 459 if (i != nv_cmds[nv_cmd_idx[i]].cmd_char) |
460 break; | |
461 nv_max_linear = i - 1; | |
462 } | |
463 | |
464 /* | |
465 * Search for a command in the commands table. | |
466 * Returns -1 for invalid command. | |
467 */ | |
468 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
469 find_command(int cmdchar) |
7 | 470 { |
471 int i; | |
472 int idx; | |
473 int top, bot; | |
474 int c; | |
475 | |
476 /* A multi-byte character is never a command. */ | |
477 if (cmdchar >= 0x100) | |
478 return -1; | |
479 | |
480 /* We use the absolute value of the character. Special keys have a | |
481 * negative value, but are sorted on their absolute value. */ | |
482 if (cmdchar < 0) | |
483 cmdchar = -cmdchar; | |
484 | |
485 /* If the character is in the first part: The character is the index into | |
486 * nv_cmd_idx[]. */ | |
487 if (cmdchar <= nv_max_linear) | |
488 return nv_cmd_idx[cmdchar]; | |
489 | |
490 /* Perform a binary search. */ | |
491 bot = nv_max_linear + 1; | |
492 top = NV_CMDS_SIZE - 1; | |
493 idx = -1; | |
494 while (bot <= top) | |
495 { | |
496 i = (top + bot) / 2; | |
497 c = nv_cmds[nv_cmd_idx[i]].cmd_char; | |
498 if (c < 0) | |
499 c = -c; | |
500 if (cmdchar == c) | |
501 { | |
502 idx = nv_cmd_idx[i]; | |
503 break; | |
504 } | |
505 if (cmdchar > c) | |
506 bot = i + 1; | |
507 else | |
508 top = i - 1; | |
509 } | |
510 return idx; | |
511 } | |
512 | |
513 /* | |
514 * Execute a command in Normal mode. | |
515 */ | |
516 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
517 normal_cmd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
518 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
519 int toplevel UNUSED) /* TRUE when called from main() */ |
7 | 520 { |
521 cmdarg_T ca; /* command arguments */ | |
522 int c; | |
523 int ctrl_w = FALSE; /* got CTRL-W command */ | |
524 int old_col = curwin->w_curswant; | |
525 #ifdef FEAT_CMDL_INFO | |
526 int need_flushbuf; /* need to call out_flush() */ | |
527 #endif | |
528 pos_T old_pos; /* cursor position before command */ | |
529 int mapped_len; | |
530 static int old_mapped_len = 0; | |
531 int idx; | |
1751 | 532 #ifdef FEAT_EVAL |
533 int set_prevcount = FALSE; | |
534 #endif | |
7 | 535 |
536 vim_memset(&ca, 0, sizeof(ca)); /* also resets ca.retval */ | |
537 ca.oap = oap; | |
1692 | 538 |
539 /* Use a count remembered from before entering an operator. After typing | |
540 * "3d" we return from normal_cmd() and come back here, the "3" is | |
541 * remembered in "opcount". */ | |
7 | 542 ca.opcount = opcount; |
543 | |
544 /* | |
545 * If there is an operator pending, then the command we take this time | |
546 * will terminate it. Finish_op tells us to finish the operation before | |
547 * returning this time (unless the operation was cancelled). | |
548 */ | |
549 #ifdef CURSOR_SHAPE | |
550 c = finish_op; | |
551 #endif | |
552 finish_op = (oap->op_type != OP_NOP); | |
553 #ifdef CURSOR_SHAPE | |
554 if (finish_op != c) | |
555 { | |
556 ui_cursor_shape(); /* may show different cursor shape */ | |
557 # ifdef FEAT_MOUSESHAPE | |
558 update_mouseshape(-1); | |
559 # endif | |
560 } | |
561 #endif | |
562 | |
1692 | 563 /* When not finishing an operator and no register name typed, reset the |
564 * count. */ | |
7 | 565 if (!finish_op && !oap->regname) |
1751 | 566 { |
7 | 567 ca.opcount = 0; |
1751 | 568 #ifdef FEAT_EVAL |
569 set_prevcount = TRUE; | |
570 #endif | |
571 } | |
7 | 572 |
1692 | 573 /* Restore counts from before receiving K_CURSORHOLD. This means after |
574 * typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not | |
575 * "3 * 2". */ | |
576 if (oap->prev_opcount > 0 || oap->prev_count0 > 0) | |
577 { | |
578 ca.opcount = oap->prev_opcount; | |
579 ca.count0 = oap->prev_count0; | |
580 oap->prev_opcount = 0; | |
581 oap->prev_count0 = 0; | |
582 } | |
583 | |
7 | 584 mapped_len = typebuf_maplen(); |
585 | |
586 State = NORMAL_BUSY; | |
587 #ifdef USE_ON_FLY_SCROLL | |
588 dont_scroll = FALSE; /* allow scrolling here */ | |
589 #endif | |
590 | |
2667 | 591 #ifdef FEAT_EVAL |
592 /* Set v:count here, when called from main() and not a stuffed | |
593 * command, so that v:count can be used in an expression mapping | |
5649 | 594 * when there is no count. Do set it for redo. */ |
595 if (toplevel && readbuf1_empty()) | |
2667 | 596 set_vcount_ca(&ca, &set_prevcount); |
597 #endif | |
598 | |
7 | 599 /* |
600 * Get the command character from the user. | |
601 */ | |
602 c = safe_vgetc(); | |
7703
39251e981d1f
commit https://github.com/vim/vim/commit/25281634cda03ce302aaf9f906a9520b5f81f91e
Christian Brabandt <cb@256bit.org>
parents:
7578
diff
changeset
|
603 LANGMAP_ADJUST(c, get_real_state() != SELECTMODE); |
7 | 604 |
605 /* | |
606 * If a mapping was started in Visual or Select mode, remember the length | |
607 * of the mapping. This is used below to not return to Insert mode for as | |
608 * long as the mapping is being executed. | |
609 */ | |
610 if (restart_edit == 0) | |
611 old_mapped_len = 0; | |
612 else if (old_mapped_len | |
819 | 613 || (VIsual_active && mapped_len == 0 && typebuf_maplen() > 0)) |
7 | 614 old_mapped_len = typebuf_maplen(); |
615 | |
616 if (c == NUL) | |
617 c = K_ZERO; | |
618 | |
619 /* | |
620 * In Select mode, typed text replaces the selection. | |
621 */ | |
622 if (VIsual_active | |
623 && VIsual_select | |
624 && (vim_isprintc(c) || c == NL || c == CAR || c == K_KENTER)) | |
625 { | |
275 | 626 /* Fake a "c"hange command. When "restart_edit" is set (e.g., because |
627 * 'insertmode' is set) fake a "d"elete command, Insert mode will | |
628 * restart automatically. | |
1051 | 629 * Insert the typed character in the typeahead buffer, so that it can |
630 * be mapped in Insert mode. Required for ":lmap" to work. */ | |
852 | 631 ins_char_typebuf(c); |
275 | 632 if (restart_edit != 0) |
633 c = 'd'; | |
634 else | |
635 c = 'c'; | |
695 | 636 msg_nowait = TRUE; /* don't delay going to insert mode */ |
4472 | 637 old_mapped_len = 0; /* do go to Insert mode */ |
7 | 638 } |
639 | |
640 #ifdef FEAT_CMDL_INFO | |
641 need_flushbuf = add_to_showcmd(c); | |
642 #endif | |
643 | |
644 getcount: | |
645 if (!(VIsual_active && VIsual_select)) | |
646 { | |
647 /* | |
648 * Handle a count before a command and compute ca.count0. | |
649 * Note that '0' is a command and not the start of a count, but it's | |
650 * part of a count after other digits. | |
651 */ | |
652 while ( (c >= '1' && c <= '9') | |
653 || (ca.count0 != 0 && (c == K_DEL || c == K_KDEL || c == '0'))) | |
654 { | |
655 if (c == K_DEL || c == K_KDEL) | |
656 { | |
657 ca.count0 /= 10; | |
658 #ifdef FEAT_CMDL_INFO | |
659 del_from_showcmd(4); /* delete the digit and ~@% */ | |
660 #endif | |
661 } | |
662 else | |
663 ca.count0 = ca.count0 * 10 + (c - '0'); | |
664 if (ca.count0 < 0) /* got too large! */ | |
665 ca.count0 = 999999999L; | |
1425 | 666 #ifdef FEAT_EVAL |
667 /* Set v:count here, when called from main() and not a stuffed | |
668 * command, so that v:count can be used in an expression mapping | |
5649 | 669 * right after the count. Do set it for redo. */ |
670 if (toplevel && readbuf1_empty()) | |
2667 | 671 set_vcount_ca(&ca, &set_prevcount); |
1425 | 672 #endif |
7 | 673 if (ctrl_w) |
674 { | |
675 ++no_mapping; | |
676 ++allow_keys; /* no mapping for nchar, but keys */ | |
677 } | |
678 ++no_zero_mapping; /* don't map zero here */ | |
1389 | 679 c = plain_vgetc(); |
7 | 680 LANGMAP_ADJUST(c, TRUE); |
681 --no_zero_mapping; | |
682 if (ctrl_w) | |
683 { | |
684 --no_mapping; | |
685 --allow_keys; | |
686 } | |
687 #ifdef FEAT_CMDL_INFO | |
688 need_flushbuf |= add_to_showcmd(c); | |
689 #endif | |
690 } | |
691 | |
692 /* | |
693 * If we got CTRL-W there may be a/another count | |
694 */ | |
695 if (c == Ctrl_W && !ctrl_w && oap->op_type == OP_NOP) | |
696 { | |
697 ctrl_w = TRUE; | |
698 ca.opcount = ca.count0; /* remember first count */ | |
699 ca.count0 = 0; | |
700 ++no_mapping; | |
701 ++allow_keys; /* no mapping for nchar, but keys */ | |
1389 | 702 c = plain_vgetc(); /* get next character */ |
7 | 703 LANGMAP_ADJUST(c, TRUE); |
704 --no_mapping; | |
705 --allow_keys; | |
706 #ifdef FEAT_CMDL_INFO | |
707 need_flushbuf |= add_to_showcmd(c); | |
708 #endif | |
709 goto getcount; /* jump back */ | |
710 } | |
711 } | |
712 | |
1692 | 713 if (c == K_CURSORHOLD) |
714 { | |
715 /* Save the count values so that ca.opcount and ca.count0 are exactly | |
716 * the same when coming back here after handling K_CURSORHOLD. */ | |
717 oap->prev_opcount = ca.opcount; | |
718 oap->prev_count0 = ca.count0; | |
719 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
720 else if (ca.opcount != 0) |
1692 | 721 { |
722 /* | |
723 * If we're in the middle of an operator (including after entering a | |
724 * yank buffer with '"') AND we had a count before the operator, then | |
725 * that count overrides the current value of ca.count0. | |
726 * What this means effectively, is that commands like "3dw" get turned | |
727 * into "d3w" which makes things fall into place pretty neatly. | |
728 * If you give a count before AND after the operator, they are | |
729 * multiplied. | |
730 */ | |
7 | 731 if (ca.count0) |
732 ca.count0 *= ca.opcount; | |
733 else | |
734 ca.count0 = ca.opcount; | |
735 } | |
736 | |
737 /* | |
738 * Always remember the count. It will be set to zero (on the next call, | |
739 * above) when there is no pending operator. | |
740 * When called from main(), save the count for use by the "count" built-in | |
741 * variable. | |
742 */ | |
743 ca.opcount = ca.count0; | |
744 ca.count1 = (ca.count0 == 0 ? 1 : ca.count0); | |
745 | |
746 #ifdef FEAT_EVAL | |
747 /* | |
748 * Only set v:count when called from main() and not a stuffed command. | |
5649 | 749 * Do set it for redo. |
7 | 750 */ |
5649 | 751 if (toplevel && readbuf1_empty()) |
1751 | 752 set_vcount(ca.count0, ca.count1, set_prevcount); |
7 | 753 #endif |
754 | |
755 /* | |
756 * Find the command character in the table of commands. | |
757 * For CTRL-W we already got nchar when looking for a count. | |
758 */ | |
759 if (ctrl_w) | |
760 { | |
761 ca.nchar = c; | |
762 ca.cmdchar = Ctrl_W; | |
763 } | |
764 else | |
765 ca.cmdchar = c; | |
766 idx = find_command(ca.cmdchar); | |
767 if (idx < 0) | |
768 { | |
769 /* Not a known command: beep. */ | |
770 clearopbeep(oap); | |
771 goto normal_end; | |
772 } | |
631 | 773 |
633 | 774 if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW)) |
631 | 775 { |
5848 | 776 /* This command is not allowed while editing a cmdline: beep. */ |
7 | 777 clearopbeep(oap); |
633 | 778 text_locked_msg(); |
7 | 779 goto normal_end; |
780 } | |
819 | 781 if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked()) |
782 goto normal_end; | |
7 | 783 |
784 /* | |
785 * In Visual/Select mode, a few keys are handled in a special way. | |
786 */ | |
787 if (VIsual_active) | |
788 { | |
789 /* when 'keymodel' contains "stopsel" may stop Select/Visual mode */ | |
790 if (km_stopsel | |
791 && (nv_cmds[idx].cmd_flags & NV_STS) | |
792 && !(mod_mask & MOD_MASK_SHIFT)) | |
793 { | |
794 end_visual_mode(); | |
795 redraw_curbuf_later(INVERTED); | |
796 } | |
797 | |
798 /* Keys that work different when 'keymodel' contains "startsel" */ | |
799 if (km_startsel) | |
800 { | |
801 if (nv_cmds[idx].cmd_flags & NV_SS) | |
802 { | |
803 unshift_special(&ca); | |
804 idx = find_command(ca.cmdchar); | |
840 | 805 if (idx < 0) |
806 { | |
807 /* Just in case */ | |
808 clearopbeep(oap); | |
809 goto normal_end; | |
810 } | |
7 | 811 } |
812 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
813 && (mod_mask & MOD_MASK_SHIFT)) | |
814 { | |
815 mod_mask &= ~MOD_MASK_SHIFT; | |
816 } | |
817 } | |
818 } | |
819 | |
820 #ifdef FEAT_RIGHTLEFT | |
821 if (curwin->w_p_rl && KeyTyped && !KeyStuffed | |
822 && (nv_cmds[idx].cmd_flags & NV_RL)) | |
823 { | |
824 /* Invert horizontal movements and operations. Only when typed by the | |
825 * user directly, not when the result of a mapping or "x" translated | |
826 * to "dl". */ | |
827 switch (ca.cmdchar) | |
828 { | |
829 case 'l': ca.cmdchar = 'h'; break; | |
830 case K_RIGHT: ca.cmdchar = K_LEFT; break; | |
831 case K_S_RIGHT: ca.cmdchar = K_S_LEFT; break; | |
832 case K_C_RIGHT: ca.cmdchar = K_C_LEFT; break; | |
833 case 'h': ca.cmdchar = 'l'; break; | |
834 case K_LEFT: ca.cmdchar = K_RIGHT; break; | |
835 case K_S_LEFT: ca.cmdchar = K_S_RIGHT; break; | |
836 case K_C_LEFT: ca.cmdchar = K_C_RIGHT; break; | |
837 case '>': ca.cmdchar = '<'; break; | |
838 case '<': ca.cmdchar = '>'; break; | |
839 } | |
840 idx = find_command(ca.cmdchar); | |
841 } | |
842 #endif | |
843 | |
844 /* | |
845 * Get an additional character if we need one. | |
846 */ | |
847 if ((nv_cmds[idx].cmd_flags & NV_NCH) | |
848 && (((nv_cmds[idx].cmd_flags & NV_NCH_NOP) == NV_NCH_NOP | |
849 && oap->op_type == OP_NOP) | |
850 || (nv_cmds[idx].cmd_flags & NV_NCH_ALW) == NV_NCH_ALW | |
851 || (ca.cmdchar == 'q' | |
852 && 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
|
853 && 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
|
854 && reg_executing == 0) |
7 | 855 || ((ca.cmdchar == 'a' || ca.cmdchar == 'i') |
5735 | 856 && (oap->op_type != OP_NOP || VIsual_active)))) |
7 | 857 { |
858 int *cp; | |
859 int repl = FALSE; /* get character for replace mode */ | |
860 int lit = FALSE; /* get extra character literally */ | |
861 int langmap_active = FALSE; /* using :lmap mappings */ | |
862 int lang; /* getting a text character */ | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
863 #ifdef HAVE_INPUT_METHOD |
7 | 864 int save_smd; /* saved value of p_smd */ |
865 #endif | |
866 | |
867 ++no_mapping; | |
868 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1343 | 869 /* Don't generate a CursorHold event here, most commands can't handle |
870 * it, e.g., nv_replace(), nv_csearch(). */ | |
871 did_cursorhold = TRUE; | |
7 | 872 if (ca.cmdchar == 'g') |
873 { | |
874 /* | |
875 * For 'g' get the next character now, so that we can check for | |
876 * "gr", "g'" and "g`". | |
877 */ | |
1389 | 878 ca.nchar = plain_vgetc(); |
7 | 879 LANGMAP_ADJUST(ca.nchar, TRUE); |
880 #ifdef FEAT_CMDL_INFO | |
881 need_flushbuf |= add_to_showcmd(ca.nchar); | |
882 #endif | |
883 if (ca.nchar == 'r' || ca.nchar == '\'' || ca.nchar == '`' | |
5523 | 884 || ca.nchar == Ctrl_BSL) |
7 | 885 { |
886 cp = &ca.extra_char; /* need to get a third character */ | |
887 if (ca.nchar != 'r') | |
888 lit = TRUE; /* get it literally */ | |
889 else | |
890 repl = TRUE; /* get it in replace mode */ | |
891 } | |
892 else | |
893 cp = NULL; /* no third character needed */ | |
894 } | |
895 else | |
896 { | |
897 if (ca.cmdchar == 'r') /* get it in replace mode */ | |
898 repl = TRUE; | |
899 cp = &ca.nchar; | |
900 } | |
901 lang = (repl || (nv_cmds[idx].cmd_flags & NV_LANG)); | |
902 | |
903 /* | |
904 * Get a second or third character. | |
905 */ | |
906 if (cp != NULL) | |
907 { | |
908 #ifdef CURSOR_SHAPE | |
909 if (repl) | |
910 { | |
911 State = REPLACE; /* pretend Replace mode */ | |
912 ui_cursor_shape(); /* show different cursor shape */ | |
913 } | |
914 #endif | |
915 if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) | |
916 { | |
917 /* Allow mappings defined with ":lmap". */ | |
918 --no_mapping; | |
919 --allow_keys; | |
920 if (repl) | |
921 State = LREPLACE; | |
922 else | |
923 State = LANGMAP; | |
924 langmap_active = TRUE; | |
925 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
926 #ifdef HAVE_INPUT_METHOD |
7 | 927 save_smd = p_smd; |
928 p_smd = FALSE; /* Don't let the IM code show the mode here */ | |
929 if (lang && curbuf->b_p_iminsert == B_IMODE_IM) | |
930 im_set_active(TRUE); | |
931 #endif | |
932 | |
1389 | 933 *cp = plain_vgetc(); |
7 | 934 |
935 if (langmap_active) | |
936 { | |
937 /* Undo the decrement done above */ | |
938 ++no_mapping; | |
939 ++allow_keys; | |
940 State = NORMAL_BUSY; | |
941 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
942 #ifdef HAVE_INPUT_METHOD |
7 | 943 if (lang) |
944 { | |
945 if (curbuf->b_p_iminsert != B_IMODE_LMAP) | |
946 im_save_status(&curbuf->b_p_iminsert); | |
947 im_set_active(FALSE); | |
948 } | |
949 p_smd = save_smd; | |
950 #endif | |
951 #ifdef CURSOR_SHAPE | |
952 State = NORMAL_BUSY; | |
953 #endif | |
954 #ifdef FEAT_CMDL_INFO | |
955 need_flushbuf |= add_to_showcmd(*cp); | |
956 #endif | |
957 | |
958 if (!lit) | |
959 { | |
960 #ifdef FEAT_DIGRAPHS | |
961 /* Typing CTRL-K gets a digraph. */ | |
962 if (*cp == Ctrl_K | |
963 && ((nv_cmds[idx].cmd_flags & NV_LANG) | |
964 || cp == &ca.extra_char) | |
965 && vim_strchr(p_cpo, CPO_DIGRAPH) == NULL) | |
966 { | |
967 c = get_digraph(FALSE); | |
968 if (c > 0) | |
969 { | |
970 *cp = c; | |
971 # ifdef FEAT_CMDL_INFO | |
972 /* Guessing how to update showcmd here... */ | |
973 del_from_showcmd(3); | |
974 need_flushbuf |= add_to_showcmd(*cp); | |
975 # endif | |
976 } | |
977 } | |
978 #endif | |
979 | |
980 /* adjust chars > 127, except after "tTfFr" commands */ | |
981 LANGMAP_ADJUST(*cp, !lang); | |
982 #ifdef FEAT_RIGHTLEFT | |
983 /* adjust Hebrew mapped char */ | |
984 if (p_hkmap && lang && KeyTyped) | |
985 *cp = hkmap(*cp); | |
986 #endif | |
987 } | |
988 | |
989 /* | |
990 * When the next character is CTRL-\ a following CTRL-N means the | |
991 * command is aborted and we go to Normal mode. | |
992 */ | |
993 if (cp == &ca.extra_char | |
994 && ca.nchar == Ctrl_BSL | |
995 && (ca.extra_char == Ctrl_N || ca.extra_char == Ctrl_G)) | |
996 { | |
997 ca.cmdchar = Ctrl_BSL; | |
998 ca.nchar = ca.extra_char; | |
999 idx = find_command(ca.cmdchar); | |
1000 } | |
3908 | 1001 else if ((ca.nchar == 'n' || ca.nchar == 'N') && ca.cmdchar == 'g') |
3896 | 1002 ca.oap->op_type = get_op_type(*cp, NUL); |
7 | 1003 else if (*cp == Ctrl_BSL) |
1004 { | |
1005 long towait = (p_ttm >= 0 ? p_ttm : p_tm); | |
1006 | |
1007 /* There is a busy wait here when typing "f<C-\>" and then | |
1008 * something different from CTRL-N. Can't be avoided. */ | |
1009 while ((c = vpeekc()) <= 0 && towait > 0L) | |
1010 { | |
1011 do_sleep(towait > 50L ? 50L : towait); | |
1012 towait -= 50L; | |
1013 } | |
1014 if (c > 0) | |
1015 { | |
1389 | 1016 c = plain_vgetc(); |
7 | 1017 if (c != Ctrl_N && c != Ctrl_G) |
1018 vungetc(c); | |
1019 else | |
1020 { | |
1021 ca.cmdchar = Ctrl_BSL; | |
1022 ca.nchar = c; | |
1023 idx = find_command(ca.cmdchar); | |
1024 } | |
1025 } | |
1026 } | |
1027 | |
1028 /* When getting a text character and the next character is a | |
1029 * multi-byte character, it could be a composing character. | |
6071 | 1030 * However, don't wait for it to arrive. Also, do enable mapping, |
1031 * because if it's put back with vungetc() it's too late to apply | |
1032 * mapping. */ | |
1033 --no_mapping; | |
7 | 1034 while (enc_utf8 && lang && (c = vpeekc()) > 0 |
1035 && (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) | |
1036 { | |
1389 | 1037 c = plain_vgetc(); |
7 | 1038 if (!utf_iscomposing(c)) |
1039 { | |
1040 vungetc(c); /* it wasn't, put it back */ | |
1041 break; | |
1042 } | |
1043 else if (ca.ncharC1 == 0) | |
1044 ca.ncharC1 = c; | |
1045 else | |
1046 ca.ncharC2 = c; | |
1047 } | |
6071 | 1048 ++no_mapping; |
7 | 1049 } |
1050 --no_mapping; | |
1051 --allow_keys; | |
1052 } | |
1053 | |
1054 #ifdef FEAT_CMDL_INFO | |
1055 /* | |
1056 * Flush the showcmd characters onto the screen so we can see them while | |
1057 * the command is being executed. Only do this when the shown command was | |
1058 * actually displayed, otherwise this will slow down a lot when executing | |
1059 * mappings. | |
1060 */ | |
1061 if (need_flushbuf) | |
1062 out_flush(); | |
1063 #endif | |
1727 | 1064 if (ca.cmdchar != K_IGNORE) |
1065 did_cursorhold = FALSE; | |
7 | 1066 |
1067 State = NORMAL; | |
1068 | |
1069 if (ca.nchar == ESC) | |
1070 { | |
1071 clearop(oap); | |
1072 if (restart_edit == 0 && goto_im()) | |
1073 restart_edit = 'a'; | |
1074 goto normal_end; | |
1075 } | |
1076 | |
24 | 1077 if (ca.cmdchar != K_IGNORE) |
1078 { | |
1079 msg_didout = FALSE; /* don't scroll screen up for normal command */ | |
1080 msg_col = 0; | |
1081 } | |
7 | 1082 |
1083 old_pos = curwin->w_cursor; /* remember where cursor was */ | |
1084 | |
1085 /* When 'keymodel' contains "startsel" some keys start Select/Visual | |
1086 * mode. */ | |
1087 if (!VIsual_active && km_startsel) | |
1088 { | |
1089 if (nv_cmds[idx].cmd_flags & NV_SS) | |
1090 { | |
1091 start_selection(); | |
1092 unshift_special(&ca); | |
1093 idx = find_command(ca.cmdchar); | |
1094 } | |
1095 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
1096 && (mod_mask & MOD_MASK_SHIFT)) | |
1097 { | |
1098 start_selection(); | |
1099 mod_mask &= ~MOD_MASK_SHIFT; | |
1100 } | |
1101 } | |
1102 | |
1103 /* | |
1104 * Execute the command! | |
1105 * Call the command function found in the commands table. | |
1106 */ | |
1107 ca.arg = nv_cmds[idx].cmd_arg; | |
1108 (nv_cmds[idx].cmd_func)(&ca); | |
1109 | |
1110 /* | |
1111 * If we didn't start or finish an operator, reset oap->regname, unless we | |
1112 * need it later. | |
1113 */ | |
1114 if (!finish_op | |
1115 && !oap->op_type | |
1116 && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) | |
1117 { | |
1118 clearop(oap); | |
1119 #ifdef FEAT_EVAL | |
2821 | 1120 { |
1121 int regname = 0; | |
2829 | 1122 |
2821 | 1123 /* Adjust the register according to 'clipboard', so that when |
1124 * "unnamed" is present it becomes '*' or '+' instead of '"'. */ | |
2829 | 1125 # ifdef FEAT_CLIPBOARD |
2821 | 1126 adjust_clip_reg(®name); |
2829 | 1127 # endif |
2821 | 1128 set_reg_var(regname); |
1129 } | |
7 | 1130 #endif |
1131 } | |
1132 | |
570 | 1133 /* Get the length of mapped chars again after typing a count, second |
36 | 1134 * character or "z333<cr>". */ |
1135 if (old_mapped_len > 0) | |
1136 old_mapped_len = typebuf_maplen(); | |
1137 | |
7 | 1138 /* |
1139 * If an operation is pending, handle it... | |
1140 */ | |
1141 do_pending_operator(&ca, old_col, FALSE); | |
1142 | |
1143 /* | |
1144 * Wait for a moment when a message is displayed that will be overwritten | |
1145 * by the mode message. | |
1146 * In Visual mode and with "^O" in Insert mode, a short message will be | |
1147 * overwritten by the mode message. Wait a bit, until a key is hit. | |
1148 * In Visual mode, it's more important to keep the Visual area updated | |
1149 * than keeping a message (e.g. from a /pat search). | |
1150 * Only do this if the command was typed, not from a mapping. | |
1151 * Don't wait when emsg_silent is non-zero. | |
1152 * Also wait a bit after an error message, e.g. for "^O:". | |
1153 * Don't redraw the screen, it would remove the message. | |
1154 */ | |
1155 if ( ((p_smd | |
641 | 1156 && msg_silent == 0 |
7 | 1157 && (restart_edit != 0 |
1158 || (VIsual_active | |
1159 && old_pos.lnum == curwin->w_cursor.lnum | |
1160 && old_pos.col == curwin->w_cursor.col) | |
1161 ) | |
1162 && (clear_cmdline | |
1163 || redraw_cmdline) | |
1164 && (msg_didout || (msg_didany && msg_scroll)) | |
1165 && !msg_nowait | |
1166 && KeyTyped) | |
1167 || (restart_edit != 0 | |
1168 && !VIsual_active | |
1169 && (msg_scroll | |
1170 || emsg_on_display))) | |
1171 && oap->regname == 0 | |
1172 && !(ca.retval & CA_COMMAND_BUSY) | |
1173 && stuff_empty() | |
1174 && typebuf_typed() | |
1175 && emsg_silent == 0 | |
1176 && !did_wait_return | |
1177 && oap->op_type == OP_NOP) | |
1178 { | |
1179 int save_State = State; | |
1180 | |
1181 /* Draw the cursor with the right shape here */ | |
1182 if (restart_edit != 0) | |
1183 State = INSERT; | |
1184 | |
1185 /* If need to redraw, and there is a "keep_msg", redraw before the | |
1186 * delay */ | |
1187 if (must_redraw && keep_msg != NULL && !emsg_on_display) | |
1188 { | |
1189 char_u *kmsg; | |
1190 | |
1191 kmsg = keep_msg; | |
1192 keep_msg = NULL; | |
1193 /* showmode() will clear keep_msg, but we want to use it anyway */ | |
1194 update_screen(0); | |
1195 /* now reset it, otherwise it's put in the history again */ | |
1196 keep_msg = kmsg; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1197 msg_attr((char *)kmsg, keep_msg_attr); |
7 | 1198 vim_free(kmsg); |
1199 } | |
1200 setcursor(); | |
1201 cursor_on(); | |
1202 out_flush(); | |
1203 if (msg_scroll || emsg_on_display) | |
1204 ui_delay(1000L, TRUE); /* wait at least one second */ | |
1205 ui_delay(3000L, FALSE); /* wait up to three seconds */ | |
1206 State = save_State; | |
1207 | |
1208 msg_scroll = FALSE; | |
1209 emsg_on_display = FALSE; | |
1210 } | |
1211 | |
1212 /* | |
1213 * Finish up after executing a Normal mode command. | |
1214 */ | |
1215 normal_end: | |
1216 | |
1217 msg_nowait = FALSE; | |
1218 | |
1219 /* Reset finish_op, in case it was set */ | |
1220 #ifdef CURSOR_SHAPE | |
1221 c = finish_op; | |
1222 #endif | |
1223 finish_op = FALSE; | |
1224 #ifdef CURSOR_SHAPE | |
1225 /* Redraw the cursor with another shape, if we were in Operator-pending | |
1226 * mode or did a replace command. */ | |
1227 if (c || ca.cmdchar == 'r') | |
1228 { | |
1229 ui_cursor_shape(); /* may show different cursor shape */ | |
1230 # ifdef FEAT_MOUSESHAPE | |
1231 update_mouseshape(-1); | |
1232 # endif | |
1233 } | |
1234 #endif | |
1235 | |
1236 #ifdef FEAT_CMDL_INFO | |
1692 | 1237 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
|
1238 && ca.cmdchar != K_CURSORHOLD) |
7 | 1239 clear_showcmd(); |
1240 #endif | |
1241 | |
1242 checkpcmark(); /* check if we moved since setting pcmark */ | |
1243 vim_free(ca.searchbuf); | |
1244 | |
1245 if (has_mbyte) | |
1246 mb_adjust_cursor(); | |
1247 | |
1248 if (curwin->w_p_scb && toplevel) | |
1249 { | |
1250 validate_cursor(); /* may need to update w_leftcol */ | |
1251 do_check_scrollbind(TRUE); | |
1252 } | |
13384
6740c499de13
patch 8.0.1566: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1253 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1254 if (curwin->w_p_crb && toplevel) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1255 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1256 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
|
1257 do_check_cursorbind(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1258 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1259 |
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
|
1260 #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
|
1261 /* 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
|
1262 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
|
1263 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
|
1264 #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
|
1265 |
7 | 1266 /* |
1267 * May restart edit(), if we got here with CTRL-O in Insert mode (but not | |
1268 * if still inside a mapping that started in Visual mode). | |
1269 * May switch from Visual to Select mode after CTRL-O command. | |
1270 */ | |
1271 if ( oap->op_type == OP_NOP | |
1272 && ((restart_edit != 0 && !VIsual_active && old_mapped_len == 0) | |
1273 || restart_VIsual_select == 1) | |
1274 && !(ca.retval & CA_COMMAND_BUSY) | |
1275 && stuff_empty() | |
1276 && oap->regname == 0) | |
1277 { | |
1278 if (restart_VIsual_select == 1) | |
1279 { | |
1280 VIsual_select = TRUE; | |
1281 showmode(); | |
1282 restart_VIsual_select = 0; | |
1283 } | |
5735 | 1284 if (restart_edit != 0 && !VIsual_active && old_mapped_len == 0) |
7 | 1285 (void)edit(restart_edit, FALSE, 1L); |
1286 } | |
1287 | |
1288 if (restart_VIsual_select == 2) | |
1289 restart_VIsual_select = 1; | |
1290 | |
1291 /* Save count before an operator for next time. */ | |
1292 opcount = ca.opcount; | |
1293 } | |
1294 | |
2667 | 1295 #ifdef FEAT_EVAL |
1296 /* | |
1297 * Set v:count and v:count1 according to "cap". | |
1298 * Set v:prevcount only when "set_prevcount" is TRUE. | |
1299 */ | |
1300 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1301 set_vcount_ca(cmdarg_T *cap, int *set_prevcount) |
2667 | 1302 { |
1303 long count = cap->count0; | |
1304 | |
1305 /* multiply with cap->opcount the same way as above */ | |
1306 if (cap->opcount != 0) | |
1307 count = cap->opcount * (count == 0 ? 1 : count); | |
1308 set_vcount(count, count == 0 ? 1 : count, *set_prevcount); | |
1309 *set_prevcount = FALSE; /* only set v:prevcount once */ | |
1310 } | |
1311 #endif | |
1312 | |
7 | 1313 /* |
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
|
1314 * 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
|
1315 * "gui_yank" is true when yanking text for the clipboard. |
7 | 1316 */ |
1317 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1318 do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank) |
7 | 1319 { |
1320 oparg_T *oap = cap->oap; | |
1321 pos_T old_cursor; | |
1322 int empty_region_error; | |
1323 int restart_edit_save; | |
6266 | 1324 #ifdef FEAT_LINEBREAK |
1325 int lbr_saved = curwin->w_p_lbr; | |
1326 #endif | |
7 | 1327 |
1328 /* The visual area is remembered for redo */ | |
1329 static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ | |
1330 static linenr_T redo_VIsual_line_count; /* number of lines */ | |
3125 | 1331 static colnr_T redo_VIsual_vcol; /* number of cols or end column */ |
7 | 1332 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
|
1333 static int redo_VIsual_arg; /* extra argument */ |
7 | 1334 int include_line_break = FALSE; |
1335 | |
1336 #if defined(FEAT_CLIPBOARD) | |
1337 /* | |
1338 * Yank the visual area into the GUI selection register before we operate | |
1339 * on it and lose it forever. | |
1340 * Don't do it if a specific register was specified, so that ""x"*P works. | |
1341 * This could call do_pending_operator() recursively, but that's OK | |
1342 * because gui_yank will be TRUE for the nested call. | |
1343 */ | |
3674 | 1344 if ((clip_star.available || clip_plus.available) |
7 | 1345 && oap->op_type != OP_NOP |
1346 && !gui_yank | |
1347 && VIsual_active | |
1348 && !redo_VIsual_busy | |
1349 && oap->regname == 0) | |
1350 clip_auto_select(); | |
1351 #endif | |
1352 old_cursor = curwin->w_cursor; | |
1353 | |
1354 /* | |
1355 * If an operation is pending, handle it... | |
1356 */ | |
5735 | 1357 if ((finish_op || VIsual_active) && oap->op_type != OP_NOP) |
1358 { | |
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
|
1359 // 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
|
1360 // 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
|
1361 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
|
1362 |
6497 | 1363 #ifdef FEAT_LINEBREAK |
1364 /* Avoid a problem with unwanted linebreaks in block mode. */ | |
6866 | 1365 if (curwin->w_p_lbr) |
1366 curwin->w_valid &= ~VALID_VIRTCOL; | |
6497 | 1367 curwin->w_p_lbr = FALSE; |
1368 #endif | |
7 | 1369 oap->is_VIsual = VIsual_active; |
1370 if (oap->motion_force == 'V') | |
1371 oap->motion_type = MLINE; | |
1372 else if (oap->motion_force == 'v') | |
1373 { | |
1374 /* If the motion was linewise, "inclusive" will not have been set. | |
1375 * Use "exclusive" to be consistent. Makes "dvj" work nice. */ | |
1376 if (oap->motion_type == MLINE) | |
1377 oap->inclusive = FALSE; | |
1378 /* If the motion already was characterwise, toggle "inclusive" */ | |
1379 else if (oap->motion_type == MCHAR) | |
1380 oap->inclusive = !oap->inclusive; | |
1381 oap->motion_type = MCHAR; | |
1382 } | |
1383 else if (oap->motion_force == Ctrl_V) | |
1384 { | |
1385 /* 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
|
1386 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
|
1387 { |
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1388 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
|
1389 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
|
1390 } |
7 | 1391 VIsual_mode = Ctrl_V; |
1392 VIsual_select = FALSE; | |
1393 VIsual_reselect = FALSE; | |
1394 } | |
1395 | |
4337 | 1396 /* Only redo yank when 'y' flag is in 'cpoptions'. */ |
1397 /* 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
|
1398 if ((redo_yank || oap->op_type != OP_YANK) |
4337 | 1399 && ((!VIsual_active || oap->motion_force) |
1400 /* Also redo Operator-pending Visual mode mappings */ | |
1401 || (VIsual_active && cap->cmdchar == ':' | |
1402 && oap->op_type != OP_COLON)) | |
164 | 1403 && cap->cmdchar != 'D' |
7 | 1404 #ifdef FEAT_FOLDING |
1405 && oap->op_type != OP_FOLD | |
1406 && oap->op_type != OP_FOLDOPEN | |
1407 && oap->op_type != OP_FOLDOPENREC | |
1408 && oap->op_type != OP_FOLDCLOSE | |
1409 && oap->op_type != OP_FOLDCLOSEREC | |
1410 && oap->op_type != OP_FOLDDEL | |
1411 && oap->op_type != OP_FOLDDELREC | |
1412 #endif | |
1413 ) | |
1414 { | |
1415 prep_redo(oap->regname, cap->count0, | |
1416 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1417 oap->motion_force, cap->cmdchar, cap->nchar); | |
1418 if (cap->cmdchar == '/' || cap->cmdchar == '?') /* was a search */ | |
1419 { | |
1420 /* | |
1421 * If 'cpoptions' does not contain 'r', insert the search | |
1422 * pattern to really repeat the same command. | |
1423 */ | |
1424 if (vim_strchr(p_cpo, CPO_REDO) == NULL) | |
620 | 1425 AppendToRedobuffLit(cap->searchbuf, -1); |
7 | 1426 AppendToRedobuff(NL_STR); |
1427 } | |
1428 else if (cap->cmdchar == ':') | |
1429 { | |
1430 /* do_cmdline() has stored the first typed line in | |
1431 * "repeat_cmdline". When several lines are typed repeating | |
1432 * won't be possible. */ | |
1433 if (repeat_cmdline == NULL) | |
1434 ResetRedobuff(); | |
1435 else | |
1436 { | |
620 | 1437 AppendToRedobuffLit(repeat_cmdline, -1); |
7 | 1438 AppendToRedobuff(NL_STR); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
1439 VIM_CLEAR(repeat_cmdline); |
7 | 1440 } |
1441 } | |
1442 } | |
1443 | |
1444 if (redo_VIsual_busy) | |
1445 { | |
3125 | 1446 /* Redo of an operation on a Visual area. Use the same size from |
1447 * redo_VIsual_line_count and redo_VIsual_vcol. */ | |
7 | 1448 oap->start = curwin->w_cursor; |
1449 curwin->w_cursor.lnum += redo_VIsual_line_count - 1; | |
1450 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
1451 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
1452 VIsual_mode = redo_VIsual_mode; | |
3125 | 1453 if (redo_VIsual_vcol == MAXCOL || VIsual_mode == 'v') |
7 | 1454 { |
3125 | 1455 if (VIsual_mode == 'v') |
1456 { | |
1457 if (redo_VIsual_line_count <= 1) | |
1458 { | |
1459 validate_virtcol(); | |
1460 curwin->w_curswant = | |
1461 curwin->w_virtcol + redo_VIsual_vcol - 1; | |
1462 } | |
1463 else | |
1464 curwin->w_curswant = redo_VIsual_vcol; | |
1465 } | |
7 | 1466 else |
3125 | 1467 { |
1468 curwin->w_curswant = MAXCOL; | |
1469 } | |
1470 coladvance(curwin->w_curswant); | |
7 | 1471 } |
1472 cap->count0 = redo_VIsual_count; | |
1473 if (redo_VIsual_count != 0) | |
1474 cap->count1 = redo_VIsual_count; | |
1475 else | |
1476 cap->count1 = 1; | |
1477 } | |
1478 else if (VIsual_active) | |
1479 { | |
999 | 1480 if (!gui_yank) |
1481 { | |
1482 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
1483 curbuf->b_visual.vi_start = VIsual; | |
1484 curbuf->b_visual.vi_end = curwin->w_cursor; | |
1485 curbuf->b_visual.vi_mode = VIsual_mode; | |
4213 | 1486 if (VIsual_mode_orig != NUL) |
1487 { | |
1488 curbuf->b_visual.vi_mode = VIsual_mode_orig; | |
1489 VIsual_mode_orig = NUL; | |
1490 } | |
999 | 1491 curbuf->b_visual.vi_curswant = curwin->w_curswant; |
7 | 1492 # ifdef FEAT_EVAL |
999 | 1493 curbuf->b_visual_mode_eval = VIsual_mode; |
7 | 1494 # endif |
999 | 1495 } |
7 | 1496 |
1497 /* In Select mode, a linewise selection is operated upon like a | |
6826 | 1498 * characterwise selection. |
1499 * Special case: gH<Del> deletes the last line. */ | |
1500 if (VIsual_select && VIsual_mode == 'V' | |
1501 && cap->oap->op_type != OP_DELETE) | |
7 | 1502 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1503 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 1504 { |
1505 VIsual.col = 0; | |
1506 curwin->w_cursor.col = | |
1507 (colnr_T)STRLEN(ml_get(curwin->w_cursor.lnum)); | |
1508 } | |
1509 else | |
1510 { | |
1511 curwin->w_cursor.col = 0; | |
1512 VIsual.col = (colnr_T)STRLEN(ml_get(VIsual.lnum)); | |
1513 } | |
1514 VIsual_mode = 'v'; | |
1515 } | |
1516 /* If 'selection' is "exclusive", backup one character for | |
1517 * charwise selections. */ | |
1518 else if (VIsual_mode == 'v') | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
1519 include_line_break = unadjust_for_sel(); |
7 | 1520 |
1521 oap->start = VIsual; | |
1522 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
|
1523 { |
7 | 1524 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
|
1525 oap->start.coladd = 0; |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1526 } |
7 | 1527 } |
1528 | |
1529 /* | |
1530 * Set oap->start to the first position of the operated text, oap->end | |
1531 * to the end of the operated text. w_cursor is equal to oap->start. | |
1532 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1533 if (LT_POS(oap->start, curwin->w_cursor)) |
7 | 1534 { |
1535 #ifdef FEAT_FOLDING | |
1536 /* Include folded lines completely. */ | |
1537 if (!VIsual_active) | |
1538 { | |
1539 if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL)) | |
1540 oap->start.col = 0; | |
1541 if (hasFolding(curwin->w_cursor.lnum, NULL, | |
1542 &curwin->w_cursor.lnum)) | |
1543 curwin->w_cursor.col = (colnr_T)STRLEN(ml_get_curline()); | |
1544 } | |
1545 #endif | |
1546 oap->end = curwin->w_cursor; | |
1547 curwin->w_cursor = oap->start; | |
1548 | |
1549 /* w_virtcol may have been updated; if the cursor goes back to its | |
1550 * previous position w_virtcol becomes invalid and isn't updated | |
1551 * automatically. */ | |
1552 curwin->w_valid &= ~VALID_VIRTCOL; | |
1553 } | |
1554 else | |
1555 { | |
1556 #ifdef FEAT_FOLDING | |
1557 /* Include folded lines completely. */ | |
1558 if (!VIsual_active && oap->motion_type == MLINE) | |
1559 { | |
1560 if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, | |
1561 NULL)) | |
1562 curwin->w_cursor.col = 0; | |
1563 if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) | |
1564 oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum)); | |
1565 } | |
1566 #endif | |
1567 oap->end = oap->start; | |
1568 oap->start = curwin->w_cursor; | |
1569 } | |
1570 | |
10154
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10110
diff
changeset
|
1571 /* 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
|
1572 check_pos(curwin->w_buffer, &oap->end); |
7 | 1573 oap->line_count = oap->end.lnum - oap->start.lnum + 1; |
1574 | |
1575 /* Set "virtual_op" before resetting VIsual_active. */ | |
1576 virtual_op = virtual_active(); | |
1577 | |
1578 if (VIsual_active || redo_VIsual_busy) | |
1579 { | |
6866 | 1580 get_op_vcol(oap, redo_VIsual_vcol, TRUE); |
7 | 1581 |
1582 if (!redo_VIsual_busy && !gui_yank) | |
1583 { | |
1584 /* | |
1585 * Prepare to reselect and redo Visual: this is based on the | |
1586 * size of the Visual text | |
1587 */ | |
1588 resel_VIsual_mode = VIsual_mode; | |
1589 if (curwin->w_curswant == MAXCOL) | |
3125 | 1590 resel_VIsual_vcol = MAXCOL; |
7 | 1591 else |
3125 | 1592 { |
1593 if (VIsual_mode != Ctrl_V) | |
1594 getvvcol(curwin, &(oap->end), | |
1595 NULL, NULL, &oap->end_vcol); | |
1596 if (VIsual_mode == Ctrl_V || oap->line_count <= 1) | |
1597 { | |
1598 if (VIsual_mode != Ctrl_V) | |
1599 getvvcol(curwin, &(oap->start), | |
1600 &oap->start_vcol, NULL, NULL); | |
1601 resel_VIsual_vcol = oap->end_vcol - oap->start_vcol + 1; | |
1602 } | |
1603 else | |
1604 resel_VIsual_vcol = oap->end_vcol; | |
1605 } | |
7 | 1606 resel_VIsual_line_count = oap->line_count; |
1607 } | |
1608 | |
1609 /* 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
|
1610 if ((redo_yank || oap->op_type != OP_YANK) |
7 | 1611 && oap->op_type != OP_COLON |
1612 #ifdef FEAT_FOLDING | |
1613 && oap->op_type != OP_FOLD | |
1614 && oap->op_type != OP_FOLDOPEN | |
1615 && oap->op_type != OP_FOLDOPENREC | |
1616 && oap->op_type != OP_FOLDCLOSE | |
1617 && oap->op_type != OP_FOLDCLOSEREC | |
1618 && oap->op_type != OP_FOLDDEL | |
1619 && oap->op_type != OP_FOLDDELREC | |
1620 #endif | |
1621 && oap->motion_force == NUL | |
1622 ) | |
1623 { | |
1624 /* Prepare for redoing. Only use the nchar field for "r", | |
1625 * otherwise it might be the second char of the operator. */ | |
3701 | 1626 if (cap->cmdchar == 'g' && (cap->nchar == 'n' |
1627 || cap->nchar == 'N')) | |
5523 | 1628 prep_redo(oap->regname, cap->count0, |
1629 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1630 oap->motion_force, cap->cmdchar, cap->nchar); | |
4337 | 1631 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
|
1632 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1633 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
|
1634 |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1635 /* 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
|
1636 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
|
1637 nchar = CAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1638 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
|
1639 nchar = NL; |
3701 | 1640 prep_redo(oap->regname, 0L, NUL, 'v', |
1641 get_op_char(oap->op_type), | |
1642 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
|
1643 nchar); |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1644 } |
7 | 1645 if (!redo_VIsual_busy) |
1646 { | |
1647 redo_VIsual_mode = resel_VIsual_mode; | |
3125 | 1648 redo_VIsual_vcol = resel_VIsual_vcol; |
7 | 1649 redo_VIsual_line_count = resel_VIsual_line_count; |
1650 redo_VIsual_count = cap->count0; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
1651 redo_VIsual_arg = cap->arg; |
7 | 1652 } |
1653 } | |
1654 | |
1655 /* | |
1656 * oap->inclusive defaults to TRUE. | |
1657 * If oap->end is on a NUL (empty line) oap->inclusive becomes | |
1658 * FALSE. This makes "d}P" and "v}dP" work the same. | |
1659 */ | |
1660 if (oap->motion_force == NUL || oap->motion_type == MLINE) | |
1661 oap->inclusive = TRUE; | |
1662 if (VIsual_mode == 'V') | |
1663 oap->motion_type = MLINE; | |
1664 else | |
1665 { | |
1666 oap->motion_type = MCHAR; | |
1667 if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
1668 && (include_line_break || !virtual_op)) |
7 | 1669 { |
1670 oap->inclusive = FALSE; | |
1671 /* Try to include the newline, unless it's an operator | |
2957 | 1672 * that works on lines only. */ |
6826 | 1673 if (*p_sel != 'o' |
1674 && !op_on_lines(oap->op_type) | |
1675 && oap->end.lnum < curbuf->b_ml.ml_line_count) | |
7 | 1676 { |
6826 | 1677 ++oap->end.lnum; |
1678 oap->end.col = 0; | |
1679 oap->end.coladd = 0; | |
1680 ++oap->line_count; | |
7 | 1681 } |
1682 } | |
1683 } | |
1684 | |
1685 redo_VIsual_busy = FALSE; | |
592 | 1686 |
7 | 1687 /* |
1688 * Switch Visual off now, so screen updating does | |
1689 * not show inverted text when the screen is redrawn. | |
1690 * With OP_YANK and sometimes with OP_COLON and OP_FILTER there is | |
1691 * no screen redraw, so it is done here to remove the inverted | |
1692 * part. | |
1693 */ | |
1694 if (!gui_yank) | |
1695 { | |
1696 VIsual_active = FALSE; | |
5735 | 1697 #ifdef FEAT_MOUSE |
7 | 1698 setmouse(); |
1699 mouse_dragging = 0; | |
5735 | 1700 #endif |
6979 | 1701 may_clear_cmdline(); |
7 | 1702 if ((oap->op_type == OP_YANK |
1703 || oap->op_type == OP_COLON | |
592 | 1704 || oap->op_type == OP_FUNCTION |
7 | 1705 || oap->op_type == OP_FILTER) |
1706 && oap->motion_force == NUL) | |
6497 | 1707 { |
1708 #ifdef FEAT_LINEBREAK | |
1709 /* make sure redrawing is correct */ | |
1710 curwin->w_p_lbr = lbr_saved; | |
1711 #endif | |
7 | 1712 redraw_curbuf_later(INVERTED); |
6497 | 1713 } |
7 | 1714 } |
1715 } | |
1716 | |
1717 /* Include the trailing byte of a multi-byte char. */ | |
1718 if (has_mbyte && oap->inclusive) | |
1719 { | |
1720 int l; | |
1721 | |
474 | 1722 l = (*mb_ptr2len)(ml_get_pos(&oap->end)); |
7 | 1723 if (l > 1) |
1724 oap->end.col += l - 1; | |
1725 } | |
1726 curwin->w_set_curswant = TRUE; | |
1727 | |
1728 /* | |
1729 * oap->empty is set when start and end are the same. The inclusive | |
1730 * flag affects this too, unless yanking and the end is on a NUL. | |
1731 */ | |
1732 oap->empty = (oap->motion_type == MCHAR | |
1733 && (!oap->inclusive | |
1734 || (oap->op_type == OP_YANK | |
1735 && 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
|
1736 && EQUAL_POS(oap->start, oap->end) |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
1737 && !(virtual_op && oap->start.coladd != oap->end.coladd)); |
7 | 1738 /* |
1739 * For delete, change and yank, it's an error to operate on an | |
1740 * empty region, when 'E' included in 'cpoptions' (Vi compatible). | |
1741 */ | |
1742 empty_region_error = (oap->empty | |
1743 && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL); | |
1744 | |
1745 /* Force a redraw when operating on an empty Visual region, when | |
1746 * 'modifiable is off or creating a fold. */ | |
1747 if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma | |
5735 | 1748 #ifdef FEAT_FOLDING |
7 | 1749 || oap->op_type == OP_FOLD |
5735 | 1750 #endif |
7 | 1751 )) |
6497 | 1752 { |
1753 #ifdef FEAT_LINEBREAK | |
1754 curwin->w_p_lbr = lbr_saved; | |
1755 #endif | |
7 | 1756 redraw_curbuf_later(INVERTED); |
6497 | 1757 } |
7 | 1758 |
1759 /* | |
1760 * If the end of an operator is in column one while oap->motion_type | |
1761 * is MCHAR and oap->inclusive is FALSE, we put op_end after the last | |
1762 * character in the previous line. If op_start is on or before the | |
1763 * first non-blank in the line, the operator becomes linewise | |
1764 * (strange, but that's the way vi does it). | |
1765 */ | |
1766 if ( oap->motion_type == MCHAR | |
1767 && oap->inclusive == FALSE | |
1768 && !(cap->retval & CA_NO_ADJ_OP_END) | |
1769 && oap->end.col == 0 | |
1770 && (!oap->is_VIsual || *p_sel == 'o') | |
47 | 1771 && !oap->block_mode |
7 | 1772 && oap->line_count > 1) |
1773 { | |
1774 oap->end_adjusted = TRUE; /* remember that we did this */ | |
1775 --oap->line_count; | |
1776 --oap->end.lnum; | |
1777 if (inindent(0)) | |
1778 oap->motion_type = MLINE; | |
1779 else | |
1780 { | |
1781 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
1782 if (oap->end.col) | |
1783 { | |
1784 --oap->end.col; | |
1785 oap->inclusive = TRUE; | |
1786 } | |
1787 } | |
1788 } | |
1789 else | |
1790 oap->end_adjusted = FALSE; | |
1791 | |
1792 switch (oap->op_type) | |
1793 { | |
1794 case OP_LSHIFT: | |
1795 case OP_RSHIFT: | |
5735 | 1796 op_shift(oap, TRUE, oap->is_VIsual ? (int)cap->count1 : 1); |
7 | 1797 auto_format(FALSE, TRUE); |
1798 break; | |
1799 | |
1800 case OP_JOIN_NS: | |
1801 case OP_JOIN: | |
1802 if (oap->line_count < 2) | |
1803 oap->line_count = 2; | |
1804 if (curwin->w_cursor.lnum + oap->line_count - 1 > | |
1805 curbuf->b_ml.ml_line_count) | |
1806 beep_flush(); | |
1807 else | |
1808 { | |
5735 | 1809 (void)do_join(oap->line_count, oap->op_type == OP_JOIN, |
5848 | 1810 TRUE, TRUE, TRUE); |
7 | 1811 auto_format(FALSE, TRUE); |
1812 } | |
1813 break; | |
1814 | |
1815 case OP_DELETE: | |
1816 VIsual_reselect = FALSE; /* don't reselect now */ | |
1817 if (empty_region_error) | |
3324 | 1818 { |
6949 | 1819 vim_beep(BO_OPER); |
3324 | 1820 CancelRedo(); |
1821 } | |
7 | 1822 else |
1823 { | |
1824 (void)op_delete(oap); | |
1825 if (oap->motion_type == MLINE && has_format_option(FO_AUTO)) | |
1826 u_save_cursor(); /* cursor line wasn't saved yet */ | |
1827 auto_format(FALSE, TRUE); | |
1828 } | |
1829 break; | |
1830 | |
1831 case OP_YANK: | |
1832 if (empty_region_error) | |
1833 { | |
1834 if (!gui_yank) | |
3324 | 1835 { |
6949 | 1836 vim_beep(BO_OPER); |
3324 | 1837 CancelRedo(); |
1838 } | |
7 | 1839 } |
1840 else | |
6497 | 1841 { |
1842 #ifdef FEAT_LINEBREAK | |
1843 curwin->w_p_lbr = lbr_saved; | |
1844 #endif | |
7 | 1845 (void)op_yank(oap, FALSE, !gui_yank); |
6497 | 1846 } |
7 | 1847 check_cursor_col(); |
1848 break; | |
1849 | |
1850 case OP_CHANGE: | |
1851 VIsual_reselect = FALSE; /* don't reselect now */ | |
1852 if (empty_region_error) | |
3324 | 1853 { |
6949 | 1854 vim_beep(BO_OPER); |
3324 | 1855 CancelRedo(); |
1856 } | |
7 | 1857 else |
1858 { | |
1859 /* This is a new edit command, not a restart. Need to | |
1860 * remember it to make 'insertmode' work with mappings for | |
1861 * Visual mode. But do this only once and not when typed and | |
1862 * 'insertmode' isn't set. */ | |
1863 if (p_im || !KeyTyped) | |
1864 restart_edit_save = restart_edit; | |
1865 else | |
1866 restart_edit_save = 0; | |
1867 restart_edit = 0; | |
6497 | 1868 #ifdef FEAT_LINEBREAK |
1869 /* Restore linebreak, so that when the user edits it looks as | |
1870 * before. */ | |
6866 | 1871 if (curwin->w_p_lbr != lbr_saved) |
1872 { | |
1873 curwin->w_p_lbr = lbr_saved; | |
1874 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
1875 } | |
6497 | 1876 #endif |
7 | 1877 /* Reset finish_op now, don't want it set inside edit(). */ |
1878 finish_op = FALSE; | |
1879 if (op_change(oap)) /* will call edit() */ | |
1880 cap->retval |= CA_COMMAND_BUSY; | |
1881 if (restart_edit == 0) | |
1882 restart_edit = restart_edit_save; | |
1883 } | |
1884 break; | |
1885 | |
1886 case OP_FILTER: | |
1887 if (vim_strchr(p_cpo, CPO_FILTER) != NULL) | |
1888 AppendToRedobuff((char_u *)"!\r"); /* use any last used !cmd */ | |
1889 else | |
1890 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
|
1891 /* FALLTHROUGH */ |
7 | 1892 |
1893 case OP_INDENT: | |
1894 case OP_COLON: | |
1895 | |
1896 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
1897 /* | |
1898 * If 'equalprg' is empty, do the indenting internally. | |
1899 */ | |
1900 if (oap->op_type == OP_INDENT && *get_equalprg() == NUL) | |
1901 { | |
1902 # ifdef FEAT_LISP | |
1903 if (curbuf->b_p_lisp) | |
1904 { | |
1905 op_reindent(oap, get_lisp_indent); | |
1906 break; | |
1907 } | |
1908 # endif | |
1909 # ifdef FEAT_CINDENT | |
1910 op_reindent(oap, | |
1911 # ifdef FEAT_EVAL | |
1912 *curbuf->b_p_inde != NUL ? get_expr_indent : | |
1913 # endif | |
1914 get_c_indent); | |
1915 break; | |
1916 # endif | |
1917 } | |
1918 #endif | |
1919 | |
1920 op_colon(oap); | |
1921 break; | |
1922 | |
1923 case OP_TILDE: | |
1924 case OP_UPPER: | |
1925 case OP_LOWER: | |
1926 case OP_ROT13: | |
1927 if (empty_region_error) | |
3324 | 1928 { |
6949 | 1929 vim_beep(BO_OPER); |
3324 | 1930 CancelRedo(); |
1931 } | |
7 | 1932 else |
1933 op_tilde(oap); | |
1934 check_cursor_col(); | |
1935 break; | |
1936 | |
1937 case OP_FORMAT: | |
667 | 1938 #if defined(FEAT_EVAL) |
1939 if (*curbuf->b_p_fex != NUL) | |
1940 op_formatexpr(oap); /* use expression */ | |
1941 else | |
1942 #endif | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
1943 if (*p_fp != NUL || *curbuf->b_p_fp != NUL) |
7 | 1944 op_colon(oap); /* use external command */ |
1945 else | |
1946 op_format(oap, FALSE); /* use internal function */ | |
1947 break; | |
1948 | |
1949 case OP_FORMAT2: | |
1950 op_format(oap, TRUE); /* use internal function */ | |
1951 break; | |
1952 | |
592 | 1953 case OP_FUNCTION: |
10342
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1954 #ifdef FEAT_LINEBREAK |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1955 /* 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
|
1956 * before. */ |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1957 curwin->w_p_lbr = lbr_saved; |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1958 #endif |
592 | 1959 op_function(oap); /* call 'operatorfunc' */ |
1960 break; | |
1961 | |
7 | 1962 case OP_INSERT: |
1963 case OP_APPEND: | |
1964 VIsual_reselect = FALSE; /* don't reselect now */ | |
1965 if (empty_region_error) | |
3324 | 1966 { |
6949 | 1967 vim_beep(BO_OPER); |
3324 | 1968 CancelRedo(); |
1969 } | |
7 | 1970 else |
1971 { | |
1972 /* This is a new edit command, not a restart. Need to | |
1973 * remember it to make 'insertmode' work with mappings for | |
1974 * Visual mode. But do this only once. */ | |
1975 restart_edit_save = restart_edit; | |
1976 restart_edit = 0; | |
6497 | 1977 #ifdef FEAT_LINEBREAK |
1978 /* Restore linebreak, so that when the user edits it looks as | |
1979 * before. */ | |
6866 | 1980 if (curwin->w_p_lbr != lbr_saved) |
1981 { | |
1982 curwin->w_p_lbr = lbr_saved; | |
1983 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
1984 } | |
6497 | 1985 #endif |
7 | 1986 op_insert(oap, cap->count1); |
6497 | 1987 #ifdef FEAT_LINEBREAK |
1988 /* Reset linebreak, so that formatting works correctly. */ | |
1989 curwin->w_p_lbr = FALSE; | |
1990 #endif | |
7 | 1991 |
1992 /* TODO: when inserting in several lines, should format all | |
1993 * the lines. */ | |
1994 auto_format(FALSE, TRUE); | |
1995 | |
1996 if (restart_edit == 0) | |
1997 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
|
1998 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
|
1999 cap->retval |= CA_COMMAND_BUSY; |
7 | 2000 } |
2001 break; | |
2002 | |
2003 case OP_REPLACE: | |
2004 VIsual_reselect = FALSE; /* don't reselect now */ | |
2005 if (empty_region_error) | |
3324 | 2006 { |
6949 | 2007 vim_beep(BO_OPER); |
3324 | 2008 CancelRedo(); |
2009 } | |
7 | 2010 else |
6497 | 2011 { |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15357
diff
changeset
|
2012 #ifdef FEAT_LINEBREAK |
6497 | 2013 /* Restore linebreak, so that when the user edits it looks as |
2014 * before. */ | |
6866 | 2015 if (curwin->w_p_lbr != lbr_saved) |
2016 { | |
2017 curwin->w_p_lbr = lbr_saved; | |
2018 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
2019 } | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15357
diff
changeset
|
2020 #endif |
7 | 2021 op_replace(oap, cap->nchar); |
6497 | 2022 } |
7 | 2023 break; |
2024 | |
2025 #ifdef FEAT_FOLDING | |
2026 case OP_FOLD: | |
2027 VIsual_reselect = FALSE; /* don't reselect now */ | |
2028 foldCreate(oap->start.lnum, oap->end.lnum); | |
2029 break; | |
2030 | |
2031 case OP_FOLDOPEN: | |
2032 case OP_FOLDOPENREC: | |
2033 case OP_FOLDCLOSE: | |
2034 case OP_FOLDCLOSEREC: | |
2035 VIsual_reselect = FALSE; /* don't reselect now */ | |
2036 opFoldRange(oap->start.lnum, oap->end.lnum, | |
2037 oap->op_type == OP_FOLDOPEN | |
2038 || oap->op_type == OP_FOLDOPENREC, | |
2039 oap->op_type == OP_FOLDOPENREC | |
2040 || oap->op_type == OP_FOLDCLOSEREC, | |
2041 oap->is_VIsual); | |
2042 break; | |
2043 | |
2044 case OP_FOLDDEL: | |
2045 case OP_FOLDDELREC: | |
2046 VIsual_reselect = FALSE; /* don't reselect now */ | |
2047 deleteFold(oap->start.lnum, oap->end.lnum, | |
2048 oap->op_type == OP_FOLDDELREC, oap->is_VIsual); | |
2049 break; | |
2050 #endif | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2051 case OP_NR_ADD: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2052 case OP_NR_SUB: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2053 if (empty_region_error) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2054 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2055 vim_beep(BO_OPER); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2056 CancelRedo(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2057 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2058 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2059 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2060 VIsual_active = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2061 #ifdef FEAT_LINEBREAK |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2062 curwin->w_p_lbr = lbr_saved; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2063 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2064 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
|
2065 VIsual_active = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2066 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2067 check_cursor_col(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2068 break; |
7 | 2069 default: |
2070 clearopbeep(oap); | |
2071 } | |
2072 virtual_op = MAYBE; | |
2073 if (!gui_yank) | |
2074 { | |
2075 /* | |
2076 * if 'sol' not set, go back to old column for some commands | |
2077 */ | |
2078 if (!p_sol && oap->motion_type == MLINE && !oap->end_adjusted | |
2079 && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT | |
2080 || oap->op_type == OP_DELETE)) | |
6497 | 2081 { |
2082 #ifdef FEAT_LINEBREAK | |
2083 curwin->w_p_lbr = FALSE; | |
2084 #endif | |
7 | 2085 coladvance(curwin->w_curswant = old_col); |
6497 | 2086 } |
7 | 2087 } |
2088 else | |
2089 { | |
2090 curwin->w_cursor = old_cursor; | |
2091 } | |
2092 oap->block_mode = FALSE; | |
2093 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
|
2094 motion_force = NUL; |
7 | 2095 } |
6266 | 2096 #ifdef FEAT_LINEBREAK |
2097 curwin->w_p_lbr = lbr_saved; | |
2098 #endif | |
7 | 2099 } |
2100 | |
2101 /* | |
2102 * Handle indent and format operators and visual mode ":". | |
2103 */ | |
2104 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2105 op_colon(oparg_T *oap) |
7 | 2106 { |
2107 stuffcharReadbuff(':'); | |
2108 if (oap->is_VIsual) | |
2109 stuffReadbuff((char_u *)"'<,'>"); | |
2110 else | |
2111 { | |
2112 /* | |
2113 * Make the range look nice, so it can be repeated. | |
2114 */ | |
2115 if (oap->start.lnum == curwin->w_cursor.lnum) | |
2116 stuffcharReadbuff('.'); | |
2117 else | |
2118 stuffnumReadbuff((long)oap->start.lnum); | |
2119 if (oap->end.lnum != oap->start.lnum) | |
2120 { | |
2121 stuffcharReadbuff(','); | |
2122 if (oap->end.lnum == curwin->w_cursor.lnum) | |
2123 stuffcharReadbuff('.'); | |
2124 else if (oap->end.lnum == curbuf->b_ml.ml_line_count) | |
2125 stuffcharReadbuff('$'); | |
2126 else if (oap->start.lnum == curwin->w_cursor.lnum) | |
2127 { | |
2128 stuffReadbuff((char_u *)".+"); | |
2129 stuffnumReadbuff((long)oap->line_count - 1); | |
2130 } | |
2131 else | |
2132 stuffnumReadbuff((long)oap->end.lnum); | |
2133 } | |
2134 } | |
2135 if (oap->op_type != OP_COLON) | |
2136 stuffReadbuff((char_u *)"!"); | |
2137 if (oap->op_type == OP_INDENT) | |
2138 { | |
2139 #ifndef FEAT_CINDENT | |
2140 if (*get_equalprg() == NUL) | |
2141 stuffReadbuff((char_u *)"indent"); | |
2142 else | |
2143 #endif | |
2144 stuffReadbuff(get_equalprg()); | |
2145 stuffReadbuff((char_u *)"\n"); | |
2146 } | |
2147 else if (oap->op_type == OP_FORMAT) | |
2148 { | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2149 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
|
2150 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
|
2151 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
|
2152 stuffReadbuff(p_fp); |
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2153 else |
7 | 2154 stuffReadbuff((char_u *)"fmt"); |
216 | 2155 stuffReadbuff((char_u *)"\n']"); |
7 | 2156 } |
2157 | |
2158 /* | |
2159 * do_cmdline() does the rest | |
2160 */ | |
2161 } | |
2162 | |
592 | 2163 /* |
602 | 2164 * Handle the "g@" operator: call 'operatorfunc'. |
592 | 2165 */ |
690 | 2166 static void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2167 op_function(oparg_T *oap UNUSED) |
592 | 2168 { |
2169 #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
|
2170 typval_T argv[2]; |
3431 | 2171 int save_virtual_op = virtual_op; |
592 | 2172 |
2173 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
|
2174 emsg(_("E774: 'operatorfunc' is empty")); |
592 | 2175 else |
2176 { | |
2177 /* Set '[ and '] marks to text to be operated on. */ | |
2178 curbuf->b_op_start = oap->start; | |
2179 curbuf->b_op_end = oap->end; | |
2180 if (oap->motion_type != MLINE && !oap->inclusive) | |
2181 /* Exclude the end position. */ | |
2182 decl(&curbuf->b_op_end); | |
2183 | |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2184 argv[0].v_type = VAR_STRING; |
592 | 2185 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
|
2186 argv[0].vval.v_string = (char_u *)"block"; |
592 | 2187 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
|
2188 argv[0].vval.v_string = (char_u *)"line"; |
592 | 2189 else |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2190 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
|
2191 argv[1].v_type = VAR_UNKNOWN; |
3431 | 2192 |
2193 /* Reset virtual_op so that 'virtualedit' can be changed in the | |
2194 * function. */ | |
2195 virtual_op = MAYBE; | |
2196 | |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
2197 (void)call_func_retnr(p_opfunc, 1, argv); |
3431 | 2198 |
2199 virtual_op = save_virtual_op; | |
592 | 2200 } |
2201 #else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2202 emsg(_("E775: Eval feature not available")); |
592 | 2203 #endif |
2204 } | |
2205 | |
7 | 2206 #if defined(FEAT_MOUSE) || defined(PROTO) |
2207 /* | |
2208 * Do the appropriate action for the current mouse click in the current mode. | |
2209 * Not used for Command-line mode. | |
2210 * | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2211 * Normal and Visual Mode: |
7 | 2212 * event modi- position visual change action |
2213 * fier cursor window | |
2214 * left press - yes end yes | |
2215 * 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
|
2216 * left press S yes end (popup: extend) yes "*" (2) |
7 | 2217 * left drag - yes start if moved no |
2218 * left relse - yes start if moved no | |
2219 * middle press - yes if not active no put register | |
2220 * middle press - yes if active no yank and put | |
2221 * right press - yes start or extend yes | |
2222 * right press S yes no change yes "#" (2) | |
2223 * right drag - yes extend no | |
2224 * right relse - yes extend no | |
2225 * | |
2226 * Insert or Replace Mode: | |
2227 * event modi- position visual change action | |
2228 * fier cursor window | |
2229 * left press - yes (cannot be active) yes | |
2230 * left press C yes (cannot be active) yes "CTRL-O^]" (2) | |
2231 * left press S yes (cannot be active) yes "CTRL-O*" (2) | |
2232 * left drag - yes start or extend (1) no CTRL-O (1) | |
2233 * left relse - yes start or extend (1) no CTRL-O (1) | |
2234 * middle press - no (cannot be active) no put register | |
2235 * right press - yes start or extend yes CTRL-O | |
2236 * right press S yes (cannot be active) yes "CTRL-O#" (2) | |
2237 * | |
2238 * (1) only if mouse pointer moved since press | |
2239 * (2) only if click is in same buffer | |
2240 * | |
2241 * Return TRUE if start_arrow() should be called for edit mode. | |
2242 */ | |
2243 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2244 do_mouse( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2245 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
|
2246 int c, /* K_LEFTMOUSE, etc */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2247 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
|
2248 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2249 int fixindent) /* PUT_FIXINDENT if fixing indent necessary */ |
7 | 2250 { |
2251 static int do_always = FALSE; /* ignore 'mouse' setting next time */ | |
2252 static int got_click = FALSE; /* got a click some time back */ | |
2253 | |
2254 int which_button; /* MOUSE_LEFT, _MIDDLE or _RIGHT */ | |
2255 int is_click; /* If FALSE it's a drag or release event */ | |
2256 int is_drag; /* If TRUE it's a drag event */ | |
2257 int jump_flags = 0; /* flags for jump_to_mouse() */ | |
2258 pos_T start_visual; | |
2259 int moved; /* Has cursor moved? */ | |
2260 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
|
2261 static int in_tab_line = FALSE; /* mouse clicked in tab line */ |
7 | 2262 int in_sep_line; /* mouse in vertical separator line */ |
2263 int c1, c2; | |
2264 #if defined(FEAT_FOLDING) | |
2265 pos_T save_cursor; | |
2266 #endif | |
2267 win_T *old_curwin = curwin; | |
2268 static pos_T orig_cursor; | |
2269 colnr_T leftcol, rightcol; | |
2270 pos_T end_visual; | |
2271 int diff; | |
2272 int old_active = VIsual_active; | |
2273 int old_mode = VIsual_mode; | |
2274 int regname; | |
2275 | |
2276 #if defined(FEAT_FOLDING) | |
2277 save_cursor = curwin->w_cursor; | |
2278 #endif | |
2279 | |
2280 /* | |
2281 * When GUI is active, always recognize mouse events, otherwise: | |
2282 * - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'. | |
2283 * - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'. | |
2284 * - For command line and insert mode 'mouse' is checked before calling | |
2285 * do_mouse(). | |
2286 */ | |
2287 if (do_always) | |
2288 do_always = FALSE; | |
2289 else | |
2290 #ifdef FEAT_GUI | |
2291 if (!gui.in_use) | |
2292 #endif | |
2293 { | |
2294 if (VIsual_active) | |
2295 { | |
2296 if (!mouse_has(MOUSE_VISUAL)) | |
2297 return FALSE; | |
2298 } | |
5735 | 2299 else if (State == NORMAL && !mouse_has(MOUSE_NORMAL)) |
7 | 2300 return FALSE; |
2301 } | |
2302 | |
4221 | 2303 for (;;) |
2304 { | |
2305 which_button = get_mouse_button(KEY2TERMCAP1(c), &is_click, &is_drag); | |
2306 if (is_drag) | |
2307 { | |
2308 /* If the next character is the same mouse event then use that | |
2309 * one. Speeds up dragging the status line. */ | |
2310 if (vpeekc() != NUL) | |
2311 { | |
2312 int nc; | |
2313 int save_mouse_row = mouse_row; | |
2314 int save_mouse_col = mouse_col; | |
2315 | |
2316 /* Need to get the character, peeking doesn't get the actual | |
2317 * one. */ | |
2318 nc = safe_vgetc(); | |
2319 if (c == nc) | |
2320 continue; | |
2321 vungetc(nc); | |
2322 mouse_row = save_mouse_row; | |
2323 mouse_col = save_mouse_col; | |
2324 } | |
2325 } | |
2326 break; | |
2327 } | |
7 | 2328 |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2329 if (c == K_MOUSEMOVE) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2330 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2331 /* 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
|
2332 #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
|
2333 ui_may_remove_balloon(); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2334 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
|
2335 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2336 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
|
2337 bevalexpr_due_set = TRUE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2338 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2339 #endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2340 return FALSE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2341 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2342 |
7 | 2343 #ifdef FEAT_MOUSESHAPE |
2344 /* May have stopped dragging the status or separator line. The pointer is | |
2345 * most likely still on the status or separator line. */ | |
2346 if (!is_drag && drag_status_line) | |
2347 { | |
2348 drag_status_line = FALSE; | |
2349 update_mouseshape(SHAPE_IDX_STATUS); | |
2350 } | |
2351 if (!is_drag && drag_sep_line) | |
2352 { | |
2353 drag_sep_line = FALSE; | |
2354 update_mouseshape(SHAPE_IDX_VSEP); | |
2355 } | |
2356 #endif | |
2357 | |
2358 /* | |
2359 * Ignore drag and release events if we didn't get a click. | |
2360 */ | |
2361 if (is_click) | |
2362 got_click = TRUE; | |
2363 else | |
2364 { | |
2365 if (!got_click) /* didn't get click, ignore */ | |
2366 return FALSE; | |
2367 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
|
2368 { |
7 | 2369 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
|
2370 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
|
2371 { |
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
|
2372 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
|
2373 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
|
2374 } |
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
|
2375 } |
7 | 2376 } |
2377 | |
2378 /* | |
2379 * CTRL right mouse button does CTRL-T | |
2380 */ | |
2381 if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) | |
2382 { | |
2383 if (State & INSERT) | |
2384 stuffcharReadbuff(Ctrl_O); | |
2385 if (count > 1) | |
2386 stuffnumReadbuff(count); | |
2387 stuffcharReadbuff(Ctrl_T); | |
2388 got_click = FALSE; /* ignore drag&release now */ | |
2389 return FALSE; | |
2390 } | |
2391 | |
2392 /* | |
2393 * CTRL only works with left mouse button | |
2394 */ | |
2395 if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT) | |
2396 return FALSE; | |
2397 | |
2398 /* | |
2399 * When a modifier is down, ignore drag and release events, as well as | |
2400 * multiple clicks and the middle mouse button. | |
2401 * Accept shift-leftmouse drags when 'mousemodel' is "popup.*". | |
2402 */ | |
179 | 2403 if ((mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT |
2404 | MOD_MASK_META)) | |
7 | 2405 && (!is_click |
2406 || (mod_mask & MOD_MASK_MULTI_CLICK) | |
2407 || which_button == MOUSE_MIDDLE) | |
598 | 2408 && !((mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT)) |
7 | 2409 && mouse_model_popup() |
2410 && which_button == MOUSE_LEFT) | |
598 | 2411 && !((mod_mask & MOD_MASK_ALT) |
2412 && !mouse_model_popup() | |
2413 && which_button == MOUSE_RIGHT) | |
7 | 2414 ) |
2415 return FALSE; | |
2416 | |
2417 /* | |
2418 * If the button press was used as the movement command for an operator | |
2419 * (eg "d<MOUSE>"), or it is the middle button that is held down, ignore | |
2420 * drag/release events. | |
2421 */ | |
2422 if (!is_click && which_button == MOUSE_MIDDLE) | |
2423 return FALSE; | |
2424 | |
2425 if (oap != NULL) | |
2426 regname = oap->regname; | |
2427 else | |
2428 regname = 0; | |
2429 | |
2430 /* | |
2431 * Middle mouse button does a 'put' of the selected text | |
2432 */ | |
2433 if (which_button == MOUSE_MIDDLE) | |
2434 { | |
2435 if (State == NORMAL) | |
2436 { | |
2437 /* | |
2438 * If an operator was pending, we don't know what the user wanted | |
2439 * to do. Go back to normal mode: Clear the operator and beep(). | |
2440 */ | |
2441 if (oap != NULL && oap->op_type != OP_NOP) | |
2442 { | |
2443 clearopbeep(oap); | |
2444 return FALSE; | |
2445 } | |
2446 | |
2447 /* | |
2448 * If visual was active, yank the highlighted text and put it | |
2449 * before the mouse pointer position. | |
1016 | 2450 * In Select mode replace the highlighted text with the clipboard. |
7 | 2451 */ |
2452 if (VIsual_active) | |
2453 { | |
1016 | 2454 if (VIsual_select) |
2455 { | |
2456 stuffcharReadbuff(Ctrl_G); | |
1019 | 2457 stuffReadbuff((char_u *)"\"+p"); |
1016 | 2458 } |
2459 else | |
2460 { | |
2461 stuffcharReadbuff('y'); | |
2462 stuffcharReadbuff(K_MIDDLEMOUSE); | |
2463 } | |
7 | 2464 do_always = TRUE; /* ignore 'mouse' setting next time */ |
2465 return FALSE; | |
2466 } | |
2467 /* | |
2468 * The rest is below jump_to_mouse() | |
2469 */ | |
2470 } | |
2471 | |
2472 else if ((State & INSERT) == 0) | |
2473 return FALSE; | |
2474 | |
2475 /* | |
2476 * Middle click in insert mode doesn't move the mouse, just insert the | |
2477 * contents of a register. '.' register is special, can't insert that | |
2478 * with do_put(). | |
2479 * Also paste at the cursor if the current mode isn't in 'mouse' (only | |
2480 * happens for the GUI). | |
2481 */ | |
2482 if ((State & INSERT) || !mouse_has(MOUSE_NORMAL)) | |
2483 { | |
2484 if (regname == '.') | |
2485 insert_reg(regname, TRUE); | |
2486 else | |
2487 { | |
2488 #ifdef FEAT_CLIPBOARD | |
2489 if (clip_star.available && regname == 0) | |
2490 regname = '*'; | |
2491 #endif | |
2492 if ((State & REPLACE_FLAG) && !yank_register_mline(regname)) | |
2493 insert_reg(regname, TRUE); | |
2494 else | |
2495 { | |
2496 do_put(regname, BACKWARD, 1L, fixindent | PUT_CURSEND); | |
2497 | |
2498 /* Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r */ | |
2499 AppendCharToRedobuff(Ctrl_R); | |
2500 AppendCharToRedobuff(fixindent ? Ctrl_P : Ctrl_O); | |
2501 AppendCharToRedobuff(regname == 0 ? '"' : regname); | |
2502 } | |
2503 } | |
2504 return FALSE; | |
2505 } | |
2506 } | |
2507 | |
2508 /* When dragging or button-up stay in the same window. */ | |
2509 if (!is_click) | |
2510 jump_flags |= MOUSE_FOCUS | MOUSE_DID_MOVE; | |
2511 | |
2512 start_visual.lnum = 0; | |
2513 | |
671 | 2514 /* Check for clicking in the tab page line. */ |
2515 if (mouse_row == 0 && firstwin->w_winrow > 0) | |
2516 { | |
1619 | 2517 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
|
2518 { |
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
|
2519 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
|
2520 { |
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
|
2521 c1 = TabPageIdxs[mouse_col]; |
7090
052043fc57ab
commit https://github.com/vim/vim/commit/4a4b821085847651b71d8ad9fab9f180635cb453
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2522 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
|
2523 ? 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
|
2524 } |
1619 | 2525 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
|
2526 } |
671 | 2527 |
2528 /* click in a tab selects that tab page */ | |
2529 if (is_click | |
2530 # ifdef FEAT_CMDWIN | |
2531 && cmdwin_type == 0 | |
2532 # endif | |
681 | 2533 && mouse_col < Columns) |
2534 { | |
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
|
2535 in_tab_line = TRUE; |
681 | 2536 c1 = TabPageIdxs[mouse_col]; |
2537 if (c1 >= 0) | |
2538 { | |
682 | 2539 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) |
2540 { | |
2541 /* double click opens new page */ | |
681 | 2542 end_visual_mode(); |
682 | 2543 tabpage_new(); |
2544 tabpage_move(c1 == 0 ? 9999 : c1 - 1); | |
2545 } | |
2546 else | |
2547 { | |
2548 /* Go to specified tab page, or next one if not clicking | |
2549 * on a label. */ | |
2550 goto_tabpage(c1); | |
2551 | |
2552 /* It's like clicking on the status line of a window. */ | |
2553 if (curwin != old_curwin) | |
2554 end_visual_mode(); | |
2555 } | |
681 | 2556 } |
13762
9de2b25932eb
patch 8.0.1753: various warnings from a static analyser
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2557 else |
681 | 2558 { |
2559 tabpage_T *tp; | |
2560 | |
2561 /* Close the current or specified tab page. */ | |
2562 if (c1 == -999) | |
2563 tp = curtab; | |
2564 else | |
2565 tp = find_tabpage(-c1); | |
2566 if (tp == curtab) | |
2567 { | |
2568 if (first_tabpage->tp_next != NULL) | |
2569 tabpage_close(FALSE); | |
2570 } | |
2571 else if (tp != NULL) | |
2572 tabpage_close_other(tp, FALSE); | |
2573 } | |
2574 } | |
2575 return TRUE; | |
671 | 2576 } |
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
|
2577 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
|
2578 { |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2579 c1 = TabPageIdxs[mouse_col]; |
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
|
2580 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
|
2581 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
|
2582 } |
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
|
2583 |
7 | 2584 /* |
2585 * When 'mousemodel' is "popup" or "popup_setpos", translate mouse events: | |
2586 * right button up -> pop-up menu | |
2587 * shift-left button -> right button | |
598 | 2588 * alt-left button -> alt-right button |
7 | 2589 */ |
2590 if (mouse_model_popup()) | |
2591 { | |
2592 if (which_button == MOUSE_RIGHT | |
2593 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | |
2594 { | |
573 | 2595 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \ |
7 | 2596 || 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
|
2597 || 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
|
2598 || 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
|
2599 # ifdef FEAT_GUI |
7 | 2600 if (gui.in_use) |
2601 { | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2602 # 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
|
2603 || 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
|
2604 if (!is_click) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2605 /* 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
|
2606 * 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
|
2607 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2608 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2609 # 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
|
2610 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
|
2611 /* 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
|
2612 * 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
|
2613 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2614 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2615 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2616 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2617 # 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
|
2618 else |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2619 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2620 # 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
|
2621 if (!is_click) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2622 /* 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
|
2623 * 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
|
2624 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2625 #endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2626 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2627 jump_flags = 0; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2628 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
|
2629 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2630 /* 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
|
2631 * menu. */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2632 if (VIsual_active) |
7 | 2633 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2634 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
|
2635 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2636 /* |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2637 * 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
|
2638 * 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
|
2639 * negative here) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2640 */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2641 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
|
2642 || mouse_row |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2643 > (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
|
2644 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
|
2645 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
|
2646 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
|
2647 else |
7 | 2648 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2649 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
|
2650 && (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
|
2651 || 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
|
2652 || (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
|
2653 && (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
|
2654 || 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
|
2655 { |
7 | 2656 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
|
2657 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2658 else if (VIsual_mode == Ctrl_V) |
7 | 2659 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2660 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
|
2661 &leftcol, &rightcol); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2662 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
|
2663 if (m_pos.col < leftcol || m_pos.col > rightcol) |
7 | 2664 jump_flags = MOUSE_MAY_STOP_VIS; |
2665 } | |
2666 } | |
2667 } | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2668 else |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2669 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
|
2670 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2671 if (jump_flags) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2672 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2673 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
|
2674 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
|
2675 setcursor(); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2676 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
|
2677 } |
7 | 2678 # 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
|
2679 show_popupmenu(); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2680 got_click = FALSE; /* ignore release events */ |
7 | 2681 # endif |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2682 return (jump_flags & CURSOR_MOVED) != 0; |
7 | 2683 #else |
2684 return FALSE; | |
2685 #endif | |
2686 } | |
598 | 2687 if (which_button == MOUSE_LEFT |
2688 && (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT))) | |
7 | 2689 { |
2690 which_button = MOUSE_RIGHT; | |
2691 mod_mask &= ~MOD_MASK_SHIFT; | |
2692 } | |
2693 } | |
2694 | |
2695 if ((State & (NORMAL | INSERT)) | |
2696 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | |
2697 { | |
2698 if (which_button == MOUSE_LEFT) | |
2699 { | |
2700 if (is_click) | |
2701 { | |
2702 /* stop Visual mode for a left click in a window, but not when | |
2703 * on a status line */ | |
2704 if (VIsual_active) | |
2705 jump_flags |= MOUSE_MAY_STOP_VIS; | |
2706 } | |
2707 else if (mouse_has(MOUSE_VISUAL)) | |
2708 jump_flags |= MOUSE_MAY_VIS; | |
2709 } | |
2710 else if (which_button == MOUSE_RIGHT) | |
2711 { | |
2712 if (is_click && VIsual_active) | |
2713 { | |
2714 /* | |
2715 * Remember the start and end of visual before moving the | |
2716 * cursor. | |
2717 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2718 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 2719 { |
2720 start_visual = curwin->w_cursor; | |
2721 end_visual = VIsual; | |
2722 } | |
2723 else | |
2724 { | |
2725 start_visual = VIsual; | |
2726 end_visual = curwin->w_cursor; | |
2727 } | |
2728 } | |
2729 jump_flags |= MOUSE_FOCUS; | |
2730 if (mouse_has(MOUSE_VISUAL)) | |
2731 jump_flags |= MOUSE_MAY_VIS; | |
2732 } | |
2733 } | |
2734 | |
2735 /* | |
2736 * If an operator is pending, ignore all drags and releases until the | |
2737 * next mouse click. | |
2738 */ | |
2739 if (!is_drag && oap != NULL && oap->op_type != OP_NOP) | |
2740 { | |
2741 got_click = FALSE; | |
2742 oap->motion_type = MCHAR; | |
2743 } | |
2744 | |
2745 /* When releasing the button let jump_to_mouse() know. */ | |
2746 if (!is_click && !is_drag) | |
2747 jump_flags |= MOUSE_RELEASED; | |
2748 | |
2749 /* | |
2750 * JUMP! | |
2751 */ | |
2752 jump_flags = jump_to_mouse(jump_flags, | |
2753 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
|
2754 |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2755 #ifdef FEAT_MENU |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2756 /* 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
|
2757 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
|
2758 return FALSE; |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2759 #endif |
7 | 2760 moved = (jump_flags & CURSOR_MOVED); |
2761 in_status_line = (jump_flags & IN_STATUS_LINE); | |
2762 in_sep_line = (jump_flags & IN_SEP_LINE); | |
2763 | |
2764 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2765 if (isNetbeansBuffer(curbuf) |
7 | 2766 && !(jump_flags & (IN_STATUS_LINE | IN_SEP_LINE))) |
2767 { | |
2768 int key = KEY2TERMCAP1(c); | |
2769 | |
2770 if (key == (int)KE_LEFTRELEASE || key == (int)KE_MIDDLERELEASE | |
2771 || key == (int)KE_RIGHTRELEASE) | |
2772 netbeans_button_release(which_button); | |
2773 } | |
2774 #endif | |
2775 | |
2776 /* When jumping to another window, clear a pending operator. That's a bit | |
2777 * friendlier than beeping and not jumping to that window. */ | |
2778 if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP) | |
2779 clearop(oap); | |
2780 | |
2781 #ifdef FEAT_FOLDING | |
2782 if (mod_mask == 0 | |
2783 && !is_drag | |
2784 && (jump_flags & (MOUSE_FOLD_CLOSE | MOUSE_FOLD_OPEN)) | |
2785 && which_button == MOUSE_LEFT) | |
2786 { | |
2787 /* open or close a fold at this line */ | |
2788 if (jump_flags & MOUSE_FOLD_OPEN) | |
2789 openFold(curwin->w_cursor.lnum, 1L); | |
2790 else | |
2791 closeFold(curwin->w_cursor.lnum, 1L); | |
2792 /* don't move the cursor if still in the same window */ | |
2793 if (curwin == old_curwin) | |
2794 curwin->w_cursor = save_cursor; | |
2795 } | |
2796 #endif | |
2797 | |
2798 #if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN) | |
2799 if ((jump_flags & IN_OTHER_WIN) && !VIsual_active && clip_star.available) | |
2800 { | |
2801 clip_modeless(which_button, is_click, is_drag); | |
2802 return FALSE; | |
2803 } | |
2804 #endif | |
2805 | |
2806 /* Set global flag that we are extending the Visual area with mouse | |
1188 | 2807 * dragging; temporarily minimize 'scrolloff'. */ |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
2808 if (VIsual_active && is_drag && get_scrolloff_value()) |
7 | 2809 { |
2810 /* In the very first line, allow scrolling one line */ | |
2811 if (mouse_row == 0) | |
2812 mouse_dragging = 2; | |
2813 else | |
2814 mouse_dragging = 1; | |
2815 } | |
2816 | |
2817 /* When dragging the mouse above the window, scroll down. */ | |
2818 if (is_drag && mouse_row < 0 && !in_status_line) | |
2819 { | |
2820 scroll_redraw(FALSE, 1L); | |
2821 mouse_row = 0; | |
2822 } | |
2823 | |
2824 if (start_visual.lnum) /* right click in visual mode */ | |
2825 { | |
598 | 2826 /* When ALT is pressed make Visual mode blockwise. */ |
2827 if (mod_mask & MOD_MASK_ALT) | |
2828 VIsual_mode = Ctrl_V; | |
2829 | |
7 | 2830 /* |
2831 * In Visual-block mode, divide the area in four, pick up the corner | |
2832 * that is in the quarter that the cursor is in. | |
2833 */ | |
2834 if (VIsual_mode == Ctrl_V) | |
2835 { | |
2836 getvcols(curwin, &start_visual, &end_visual, &leftcol, &rightcol); | |
2837 if (curwin->w_curswant > (leftcol + rightcol) / 2) | |
2838 end_visual.col = leftcol; | |
2839 else | |
2840 end_visual.col = rightcol; | |
7009 | 2841 if (curwin->w_cursor.lnum >= |
7 | 2842 (start_visual.lnum + end_visual.lnum) / 2) |
2843 end_visual.lnum = start_visual.lnum; | |
2844 | |
2845 /* move VIsual to the right column */ | |
2846 start_visual = curwin->w_cursor; /* save the cursor pos */ | |
2847 curwin->w_cursor = end_visual; | |
2848 coladvance(end_visual.col); | |
2849 VIsual = curwin->w_cursor; | |
2850 curwin->w_cursor = start_visual; /* restore the cursor */ | |
2851 } | |
2852 else | |
2853 { | |
2854 /* | |
2855 * If the click is before the start of visual, change the start. | |
2856 * If the click is after the end of visual, change the end. If | |
2857 * the click is inside the visual, change the closest side. | |
2858 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2859 if (LT_POS(curwin->w_cursor, start_visual)) |
7 | 2860 VIsual = end_visual; |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2861 else if (LT_POS(end_visual, curwin->w_cursor)) |
7 | 2862 VIsual = start_visual; |
2863 else | |
2864 { | |
2865 /* In the same line, compare column number */ | |
2866 if (end_visual.lnum == start_visual.lnum) | |
2867 { | |
2868 if (curwin->w_cursor.col - start_visual.col > | |
2869 end_visual.col - curwin->w_cursor.col) | |
2870 VIsual = start_visual; | |
2871 else | |
2872 VIsual = end_visual; | |
2873 } | |
2874 | |
2875 /* In different lines, compare line number */ | |
2876 else | |
2877 { | |
2878 diff = (curwin->w_cursor.lnum - start_visual.lnum) - | |
2879 (end_visual.lnum - curwin->w_cursor.lnum); | |
2880 | |
2881 if (diff > 0) /* closest to end */ | |
2882 VIsual = start_visual; | |
2883 else if (diff < 0) /* closest to start */ | |
2884 VIsual = end_visual; | |
2885 else /* in the middle line */ | |
2886 { | |
2887 if (curwin->w_cursor.col < | |
2888 (start_visual.col + end_visual.col) / 2) | |
2889 VIsual = end_visual; | |
2890 else | |
2891 VIsual = start_visual; | |
2892 } | |
2893 } | |
2894 } | |
2895 } | |
2896 } | |
2897 /* | |
2898 * If Visual mode started in insert mode, execute "CTRL-O" | |
2899 */ | |
2900 else if ((State & INSERT) && VIsual_active) | |
2901 stuffcharReadbuff(Ctrl_O); | |
2902 | |
2903 /* | |
2904 * Middle mouse click: Put text before cursor. | |
2905 */ | |
2906 if (which_button == MOUSE_MIDDLE) | |
2907 { | |
2908 #ifdef FEAT_CLIPBOARD | |
2909 if (clip_star.available && regname == 0) | |
2910 regname = '*'; | |
2911 #endif | |
2912 if (yank_register_mline(regname)) | |
2913 { | |
2914 if (mouse_past_bottom) | |
2915 dir = FORWARD; | |
2916 } | |
2917 else if (mouse_past_eol) | |
2918 dir = FORWARD; | |
2919 | |
2920 if (fixindent) | |
2921 { | |
2922 c1 = (dir == BACKWARD) ? '[' : ']'; | |
2923 c2 = 'p'; | |
2924 } | |
2925 else | |
2926 { | |
2927 c1 = (dir == FORWARD) ? 'p' : 'P'; | |
2928 c2 = NUL; | |
2929 } | |
2930 prep_redo(regname, count, NUL, c1, NUL, c2, NUL); | |
2931 | |
2932 /* | |
2933 * Remember where the paste started, so in edit() Insstart can be set | |
2934 * to this position | |
2935 */ | |
2936 if (restart_edit != 0) | |
2937 where_paste_started = curwin->w_cursor; | |
2938 do_put(regname, dir, count, fixindent | PUT_CURSEND); | |
2939 } | |
2940 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
2941 #if defined(FEAT_QUICKFIX) |
7 | 2942 /* |
2943 * Ctrl-Mouse click or double click in a quickfix window jumps to the | |
2944 * error under the mouse pointer. | |
2945 */ | |
2946 else if (((mod_mask & MOD_MASK_CTRL) | |
2947 || (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
2948 && bt_quickfix(curbuf)) | |
2949 { | |
643 | 2950 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
|
2951 do_cmdline_cmd((char_u *)".cc"); |
643 | 2952 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
|
2953 do_cmdline_cmd((char_u *)".ll"); |
7 | 2954 got_click = FALSE; /* ignore drag&release now */ |
2955 } | |
2956 #endif | |
2957 | |
2958 /* | |
2959 * Ctrl-Mouse click (or double click in a help window) jumps to the tag | |
2960 * under the mouse pointer. | |
2961 */ | |
2962 else if ((mod_mask & MOD_MASK_CTRL) || (curbuf->b_help | |
2963 && (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)) | |
2964 { | |
2965 if (State & INSERT) | |
2966 stuffcharReadbuff(Ctrl_O); | |
2967 stuffcharReadbuff(Ctrl_RSB); | |
2968 got_click = FALSE; /* ignore drag&release now */ | |
2969 } | |
2970 | |
2971 /* | |
2972 * Shift-Mouse click searches for the next occurrence of the word under | |
2973 * the mouse pointer | |
2974 */ | |
2975 else if ((mod_mask & MOD_MASK_SHIFT)) | |
2976 { | |
5735 | 2977 if ((State & INSERT) || (VIsual_active && VIsual_select)) |
7 | 2978 stuffcharReadbuff(Ctrl_O); |
2979 if (which_button == MOUSE_LEFT) | |
2980 stuffcharReadbuff('*'); | |
2981 else /* MOUSE_RIGHT */ | |
2982 stuffcharReadbuff('#'); | |
2983 } | |
2984 | |
2985 /* Handle double clicks, unless on status line */ | |
2986 else if (in_status_line) | |
2987 { | |
2988 #ifdef FEAT_MOUSESHAPE | |
2989 if ((is_drag || is_click) && !drag_status_line) | |
2990 { | |
2991 drag_status_line = TRUE; | |
2992 update_mouseshape(-1); | |
2993 } | |
2994 #endif | |
2995 } | |
2996 else if (in_sep_line) | |
2997 { | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
2998 #ifdef FEAT_MOUSESHAPE |
7 | 2999 if ((is_drag || is_click) && !drag_sep_line) |
3000 { | |
3001 drag_sep_line = TRUE; | |
3002 update_mouseshape(-1); | |
3003 } | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3004 #endif |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3005 } |
7 | 3006 else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT)) |
3007 && mouse_has(MOUSE_VISUAL)) | |
3008 { | |
3009 if (is_click || !VIsual_active) | |
3010 { | |
3011 if (VIsual_active) | |
3012 orig_cursor = VIsual; | |
3013 else | |
3014 { | |
3015 check_visual_highlight(); | |
3016 VIsual = curwin->w_cursor; | |
3017 orig_cursor = VIsual; | |
3018 VIsual_active = TRUE; | |
3019 VIsual_reselect = TRUE; | |
3020 /* start Select mode if 'selectmode' contains "mouse" */ | |
3021 may_start_select('o'); | |
3022 setmouse(); | |
3023 } | |
3024 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
598 | 3025 { |
3026 /* Double click with ALT pressed makes it blockwise. */ | |
3027 if (mod_mask & MOD_MASK_ALT) | |
3028 VIsual_mode = Ctrl_V; | |
3029 else | |
3030 VIsual_mode = 'v'; | |
3031 } | |
7 | 3032 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK) |
3033 VIsual_mode = 'V'; | |
3034 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK) | |
3035 VIsual_mode = Ctrl_V; | |
3036 #ifdef FEAT_CLIPBOARD | |
3037 /* Make sure the clipboard gets updated. Needed because start and | |
3038 * end may still be the same, and the selection needs to be owned */ | |
3039 clip_star.vmode = NUL; | |
3040 #endif | |
3041 } | |
3042 /* | |
3043 * A double click selects a word or a block. | |
3044 */ | |
3045 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
3046 { | |
3047 pos_T *pos = NULL; | |
300 | 3048 int gc; |
7 | 3049 |
3050 if (is_click) | |
3051 { | |
3052 /* If the character under the cursor (skipping white space) is | |
3053 * not a word character, try finding a match and select a (), | |
3054 * {}, [], #if/#endif, etc. block. */ | |
3055 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
|
3056 while (gc = gchar_pos(&end_visual), VIM_ISWHITE(gc)) |
7 | 3057 inc(&end_visual); |
3058 if (oap != NULL) | |
3059 oap->motion_type = MCHAR; | |
3060 if (oap != NULL | |
3061 && VIsual_mode == 'v' | |
3062 && !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
|
3063 && EQUAL_POS(curwin->w_cursor, VIsual) |
7 | 3064 && (pos = findmatch(oap, NUL)) != NULL) |
3065 { | |
3066 curwin->w_cursor = *pos; | |
3067 if (oap->motion_type == MLINE) | |
3068 VIsual_mode = 'V'; | |
3069 else if (*p_sel == 'e') | |
3070 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3071 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 3072 ++VIsual.col; |
3073 else | |
3074 ++curwin->w_cursor.col; | |
3075 } | |
3076 } | |
3077 } | |
3078 | |
3079 if (pos == NULL && (is_click || is_drag)) | |
3080 { | |
3081 /* When not found a match or when dragging: extend to include | |
3082 * a word. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3083 if (LT_POS(curwin->w_cursor, orig_cursor)) |
7 | 3084 { |
3085 find_start_of_word(&curwin->w_cursor); | |
3086 find_end_of_word(&VIsual); | |
3087 } | |
3088 else | |
3089 { | |
3090 find_start_of_word(&VIsual); | |
3091 if (*p_sel == 'e' && *ml_get_cursor() != NUL) | |
3092 curwin->w_cursor.col += | |
474 | 3093 (*mb_ptr2len)(ml_get_cursor()); |
7 | 3094 find_end_of_word(&curwin->w_cursor); |
3095 } | |
3096 } | |
3097 curwin->w_set_curswant = TRUE; | |
3098 } | |
3099 if (is_click) | |
3100 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
3101 } | |
3102 else if (VIsual_active && !old_active) | |
598 | 3103 { |
3104 if (mod_mask & MOD_MASK_ALT) | |
3105 VIsual_mode = Ctrl_V; | |
3106 else | |
3107 VIsual_mode = 'v'; | |
3108 } | |
7 | 3109 |
3110 /* If Visual mode changed show it later. */ | |
643 | 3111 if ((!VIsual_active && old_active && mode_displayed) |
3112 || (VIsual_active && p_smd && msg_silent == 0 | |
3113 && (!old_active || VIsual_mode != old_mode))) | |
7 | 3114 redraw_cmdline = TRUE; |
3115 | |
3116 return moved; | |
3117 } | |
3118 | |
3119 /* | |
3120 * Move "pos" back to the start of the word it's in. | |
3121 */ | |
3122 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3123 find_start_of_word(pos_T *pos) |
7 | 3124 { |
3125 char_u *line; | |
3126 int cclass; | |
3127 int col; | |
3128 | |
3129 line = ml_get(pos->lnum); | |
3130 cclass = get_mouse_class(line + pos->col); | |
3131 | |
3132 while (pos->col > 0) | |
3133 { | |
3134 col = pos->col - 1; | |
3135 col -= (*mb_head_off)(line, line + col); | |
3136 if (get_mouse_class(line + col) != cclass) | |
3137 break; | |
3138 pos->col = col; | |
3139 } | |
3140 } | |
3141 | |
3142 /* | |
3143 * Move "pos" forward to the end of the word it's in. | |
3144 * When 'selection' is "exclusive", the position is just after the word. | |
3145 */ | |
3146 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3147 find_end_of_word(pos_T *pos) |
7 | 3148 { |
3149 char_u *line; | |
3150 int cclass; | |
3151 int col; | |
3152 | |
3153 line = ml_get(pos->lnum); | |
3154 if (*p_sel == 'e' && pos->col > 0) | |
3155 { | |
3156 --pos->col; | |
3157 pos->col -= (*mb_head_off)(line, line + pos->col); | |
3158 } | |
3159 cclass = get_mouse_class(line + pos->col); | |
3160 while (line[pos->col] != NUL) | |
3161 { | |
474 | 3162 col = pos->col + (*mb_ptr2len)(line + pos->col); |
7 | 3163 if (get_mouse_class(line + col) != cclass) |
3164 { | |
3165 if (*p_sel == 'e') | |
3166 pos->col = col; | |
3167 break; | |
3168 } | |
3169 pos->col = col; | |
3170 } | |
3171 } | |
3172 | |
3173 /* | |
3174 * Get class of a character for selection: same class means same word. | |
3175 * 0: blank | |
3176 * 1: punctuation groups | |
3177 * 2: normal word character | |
3178 * >2: multi-byte word character. | |
3179 */ | |
3180 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3181 get_mouse_class(char_u *p) |
7 | 3182 { |
3183 int c; | |
3184 | |
3185 if (has_mbyte && MB_BYTE2LEN(p[0]) > 1) | |
3186 return mb_get_class(p); | |
3187 | |
3188 c = *p; | |
3189 if (c == ' ' || c == '\t') | |
3190 return 0; | |
3191 | |
3192 if (vim_iswordc(c)) | |
3193 return 2; | |
3194 | |
3195 /* | |
3196 * There are a few special cases where we want certain combinations of | |
3197 * characters to be considered as a single word. These are things like | |
3198 * "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
3199 * character is in its own class. |
7 | 3200 */ |
3201 if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL) | |
3202 return 1; | |
3203 return c; | |
3204 } | |
3205 #endif /* FEAT_MOUSE */ | |
3206 | |
3207 /* | |
3208 * Check if highlighting for visual mode is possible, give a warning message | |
3209 * if not. | |
3210 */ | |
3211 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3212 check_visual_highlight(void) |
7 | 3213 { |
3214 static int did_check = FALSE; | |
3215 | |
3216 if (full_screen) | |
3217 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3218 if (!did_check && HL_ATTR(HLF_V) == 0) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3219 msg(_("Warning: terminal cannot highlight")); |
7 | 3220 did_check = TRUE; |
3221 } | |
3222 } | |
3223 | |
3224 /* | |
638 | 3225 * End Visual mode. |
7 | 3226 * This function should ALWAYS be called to end Visual mode, except from |
3227 * do_pending_operator(). | |
3228 */ | |
3229 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3230 end_visual_mode(void) |
7 | 3231 { |
3232 #ifdef FEAT_CLIPBOARD | |
3233 /* | |
3234 * If we are using the clipboard, then remember what was selected in case | |
3235 * we need to paste it somewhere while we still own the selection. | |
3236 * Only do this when the clipboard is already owned. Don't want to grab | |
3237 * the selection when hitting ESC. | |
3238 */ | |
3239 if (clip_star.available && clip_star.owned) | |
3240 clip_auto_select(); | |
3241 #endif | |
3242 | |
3243 VIsual_active = FALSE; | |
3244 #ifdef FEAT_MOUSE | |
3245 setmouse(); | |
3246 mouse_dragging = 0; | |
3247 #endif | |
3248 | |
3249 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
690 | 3250 curbuf->b_visual.vi_mode = VIsual_mode; |
3251 curbuf->b_visual.vi_start = VIsual; | |
3252 curbuf->b_visual.vi_end = curwin->w_cursor; | |
3253 curbuf->b_visual.vi_curswant = curwin->w_curswant; | |
7 | 3254 #ifdef FEAT_EVAL |
3255 curbuf->b_visual_mode_eval = VIsual_mode; | |
3256 #endif | |
3257 if (!virtual_active()) | |
3258 curwin->w_cursor.coladd = 0; | |
6979 | 3259 may_clear_cmdline(); |
7 | 3260 |
844 | 3261 adjust_cursor_eol(); |
7 | 3262 } |
3263 | |
3264 /* | |
3265 * Reset VIsual_active and VIsual_reselect. | |
3266 */ | |
3267 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3268 reset_VIsual_and_resel(void) |
7 | 3269 { |
3270 if (VIsual_active) | |
3271 { | |
3272 end_visual_mode(); | |
3273 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
3274 } | |
3275 VIsual_reselect = FALSE; | |
3276 } | |
3277 | |
3278 /* | |
3279 * Reset VIsual_active and VIsual_reselect if it's set. | |
3280 */ | |
3281 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3282 reset_VIsual(void) |
7 | 3283 { |
3284 if (VIsual_active) | |
3285 { | |
3286 end_visual_mode(); | |
3287 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
3288 VIsual_reselect = FALSE; | |
3289 } | |
3290 } | |
3291 | |
3292 /* | |
3293 * Check for a balloon-eval special item to include when searching for an | |
3294 * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid! | |
3295 * Returns TRUE if the character at "*ptr" should be included. | |
3296 * "dir" is FORWARD or BACKWARD, the direction of searching. | |
3297 * "*colp" is in/decremented if "ptr[-dir]" should also be included. | |
3298 * "bnp" points to a counter for square brackets. | |
3299 */ | |
3300 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3301 find_is_eval_item( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3302 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3303 int *colp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3304 int *bnp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3305 int dir) |
7 | 3306 { |
3307 /* Accept everything inside []. */ | |
3308 if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) | |
3309 ++*bnp; | |
3310 if (*bnp > 0) | |
3311 { | |
3312 if ((*ptr == '[' && dir == BACKWARD) || (*ptr == ']' && dir == FORWARD)) | |
3313 --*bnp; | |
3314 return TRUE; | |
3315 } | |
3316 | |
3317 /* skip over "s.var" */ | |
3318 if (*ptr == '.') | |
3319 return TRUE; | |
3320 | |
3321 /* two-character item: s->var */ | |
3322 if (ptr[dir == BACKWARD ? 0 : 1] == '>' | |
3323 && ptr[dir == BACKWARD ? -1 : 0] == '-') | |
3324 { | |
3325 *colp += dir; | |
3326 return TRUE; | |
3327 } | |
3328 return FALSE; | |
3329 } | |
3330 | |
3331 /* | |
3332 * Find the identifier under or to the right of the cursor. | |
3333 * "find_type" can have one of three values: | |
3334 * FIND_IDENT: find an identifier (keyword) | |
3335 * FIND_STRING: find any non-white string | |
3336 * FIND_IDENT + FIND_STRING: find any non-white string, identifier preferred. | |
184 | 3337 * FIND_EVAL: find text useful for C program debugging |
7 | 3338 * |
3339 * There are three steps: | |
3340 * 1. Search forward for the start of an identifier/string. Doesn't move if | |
3341 * already on one. | |
3342 * 2. Search backward for the start of this identifier/string. | |
3343 * This doesn't match the real Vi but I like it a little better and it | |
3344 * shouldn't bother anyone. | |
3345 * 3. Search forward to the end of this identifier/string. | |
3346 * When FIND_IDENT isn't defined, we backup until a blank. | |
3347 * | |
3348 * Returns the length of the string, or zero if no string is found. | |
3349 * If a string is found, a pointer to the string is put in "*string". This | |
3350 * string is not always NUL terminated. | |
3351 */ | |
3352 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3353 find_ident_under_cursor(char_u **string, int find_type) |
7 | 3354 { |
3355 return find_ident_at_pos(curwin, curwin->w_cursor.lnum, | |
3356 curwin->w_cursor.col, string, find_type); | |
3357 } | |
3358 | |
3359 /* | |
3360 * Like find_ident_under_cursor(), but for any window and any position. | |
3361 * However: Uses 'iskeyword' from the current window!. | |
3362 */ | |
3363 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3364 find_ident_at_pos( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3365 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3366 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3367 colnr_T startcol, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3368 char_u **string, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3369 int find_type) |
7 | 3370 { |
3371 char_u *ptr; | |
3372 int col = 0; /* init to shut up GCC */ | |
3373 int i; | |
3374 int this_class = 0; | |
3375 int prev_class; | |
3376 int prevcol; | |
3377 int bn = 0; /* bracket nesting */ | |
3378 | |
3379 /* | |
3380 * if i == 0: try to find an identifier | |
3381 * if i == 1: try to find any non-white string | |
3382 */ | |
3383 ptr = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3384 for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; ++i) | |
3385 { | |
3386 /* | |
3387 * 1. skip to start of identifier/string | |
3388 */ | |
3389 col = startcol; | |
3390 if (has_mbyte) | |
3391 { | |
3392 while (ptr[col] != NUL) | |
3393 { | |
3394 /* Stop at a ']' to evaluate "a[x]". */ | |
3395 if ((find_type & FIND_EVAL) && ptr[col] == ']') | |
3396 break; | |
3397 this_class = mb_get_class(ptr + col); | |
3398 if (this_class != 0 && (i == 1 || this_class != 1)) | |
3399 break; | |
474 | 3400 col += (*mb_ptr2len)(ptr + col); |
7 | 3401 } |
3402 } | |
3403 else | |
3404 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
|
3405 && (i == 0 ? !vim_iswordc(ptr[col]) : VIM_ISWHITE(ptr[col])) |
7 | 3406 && (!(find_type & FIND_EVAL) || ptr[col] != ']') |
3407 ) | |
3408 ++col; | |
3409 | |
3410 /* When starting on a ']' count it, so that we include the '['. */ | |
3411 bn = ptr[col] == ']'; | |
3412 | |
3413 /* | |
3414 * 2. Back up to start of identifier/string. | |
3415 */ | |
3416 if (has_mbyte) | |
3417 { | |
3418 /* Remember class of character under cursor. */ | |
3419 if ((find_type & FIND_EVAL) && ptr[col] == ']') | |
3420 this_class = mb_get_class((char_u *)"a"); | |
3421 else | |
3422 this_class = mb_get_class(ptr + col); | |
835 | 3423 while (col > 0 && this_class != 0) |
7 | 3424 { |
3425 prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1); | |
3426 prev_class = mb_get_class(ptr + prevcol); | |
3427 if (this_class != prev_class | |
3428 && (i == 0 | |
3429 || prev_class == 0 | |
3430 || (find_type & FIND_IDENT)) | |
3431 && (!(find_type & FIND_EVAL) | |
3432 || prevcol == 0 | |
3433 || !find_is_eval_item(ptr + prevcol, &prevcol, | |
3434 &bn, BACKWARD)) | |
3435 ) | |
3436 break; | |
3437 col = prevcol; | |
3438 } | |
3439 | |
3440 /* If we don't want just any old string, or we've found an | |
3441 * identifier, stop searching. */ | |
3442 if (this_class > 2) | |
3443 this_class = 2; | |
3444 if (!(find_type & FIND_STRING) || this_class == 2) | |
3445 break; | |
3446 } | |
3447 else | |
3448 { | |
3449 while (col > 0 | |
3450 && ((i == 0 | |
3451 ? 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
|
3452 : (!VIM_ISWHITE(ptr[col - 1]) |
7 | 3453 && (!(find_type & FIND_IDENT) |
3454 || !vim_iswordc(ptr[col - 1])))) | |
3455 || ((find_type & FIND_EVAL) | |
3456 && col > 1 | |
3457 && find_is_eval_item(ptr + col - 1, &col, | |
3458 &bn, BACKWARD)) | |
3459 )) | |
3460 --col; | |
3461 | |
3462 /* If we don't want just any old string, or we've found an | |
3463 * identifier, stop searching. */ | |
3464 if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col])) | |
3465 break; | |
3466 } | |
3467 } | |
3468 | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
3469 if (ptr[col] == NUL || (i == 0 |
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
3470 && (has_mbyte ? this_class != 2 : !vim_iswordc(ptr[col])))) |
7 | 3471 { |
3472 /* | |
3473 * didn't find an identifier or string | |
3474 */ | |
3475 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
|
3476 emsg(_("E348: No string under cursor")); |
7 | 3477 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
3478 emsg(_(e_noident)); |
7 | 3479 return 0; |
3480 } | |
3481 ptr += col; | |
3482 *string = ptr; | |
3483 | |
3484 /* | |
3485 * 3. Find the end if the identifier/string. | |
3486 */ | |
3487 bn = 0; | |
3488 startcol -= col; | |
3489 col = 0; | |
3490 if (has_mbyte) | |
3491 { | |
3492 /* Search for point of changing multibyte character class. */ | |
3493 this_class = mb_get_class(ptr); | |
3494 while (ptr[col] != NUL | |
3495 && ((i == 0 ? mb_get_class(ptr + col) == this_class | |
3496 : mb_get_class(ptr + col) != 0) | |
3497 || ((find_type & FIND_EVAL) | |
3498 && col <= (int)startcol | |
3499 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
3500 )) | |
474 | 3501 col += (*mb_ptr2len)(ptr + col); |
7 | 3502 } |
3503 else | |
3504 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
|
3505 : (ptr[col] != NUL && !VIM_ISWHITE(ptr[col]))) |
7 | 3506 || ((find_type & FIND_EVAL) |
3507 && col <= (int)startcol | |
3508 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
3509 ) | |
3510 { | |
3511 ++col; | |
3512 } | |
3513 | |
3514 return col; | |
3515 } | |
3516 | |
3517 /* | |
3518 * Prepare for redo of a normal command. | |
3519 */ | |
3520 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3521 prep_redo_cmd(cmdarg_T *cap) |
7 | 3522 { |
3523 prep_redo(cap->oap->regname, cap->count0, | |
3524 NUL, cap->cmdchar, NUL, NUL, cap->nchar); | |
3525 } | |
3526 | |
3527 /* | |
3528 * Prepare for redo of any command. | |
3529 * Note that only the last argument can be a multi-byte char. | |
3530 */ | |
3531 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3532 prep_redo( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3533 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3534 long num, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3535 int cmd1, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3536 int cmd2, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3537 int cmd3, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3538 int cmd4, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3539 int cmd5) |
7 | 3540 { |
3541 ResetRedobuff(); | |
3542 if (regname != 0) /* yank from specified buffer */ | |
3543 { | |
3544 AppendCharToRedobuff('"'); | |
3545 AppendCharToRedobuff(regname); | |
3546 } | |
3547 if (num) | |
3548 AppendNumberToRedobuff(num); | |
3549 | |
3550 if (cmd1 != NUL) | |
3551 AppendCharToRedobuff(cmd1); | |
3552 if (cmd2 != NUL) | |
3553 AppendCharToRedobuff(cmd2); | |
3554 if (cmd3 != NUL) | |
3555 AppendCharToRedobuff(cmd3); | |
3556 if (cmd4 != NUL) | |
3557 AppendCharToRedobuff(cmd4); | |
3558 if (cmd5 != NUL) | |
3559 AppendCharToRedobuff(cmd5); | |
3560 } | |
3561 | |
3562 /* | |
3563 * check for operator active and clear it | |
3564 * | |
3565 * return TRUE if operator was active | |
3566 */ | |
3567 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3568 checkclearop(oparg_T *oap) |
7 | 3569 { |
3570 if (oap->op_type == OP_NOP) | |
3571 return FALSE; | |
3572 clearopbeep(oap); | |
3573 return TRUE; | |
3574 } | |
3575 | |
3576 /* | |
1131 | 3577 * Check for operator or Visual active. Clear active operator. |
7 | 3578 * |
1131 | 3579 * Return TRUE if operator or Visual was active. |
7 | 3580 */ |
3581 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3582 checkclearopq(oparg_T *oap) |
7 | 3583 { |
5735 | 3584 if (oap->op_type == OP_NOP && !VIsual_active) |
7 | 3585 return FALSE; |
3586 clearopbeep(oap); | |
3587 return TRUE; | |
3588 } | |
3589 | |
3590 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3591 clearop(oparg_T *oap) |
7 | 3592 { |
3593 oap->op_type = OP_NOP; | |
3594 oap->regname = 0; | |
3595 oap->motion_force = NUL; | |
3596 oap->use_reg_one = FALSE; | |
3597 } | |
3598 | |
3599 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3600 clearopbeep(oparg_T *oap) |
7 | 3601 { |
3602 clearop(oap); | |
3603 beep_flush(); | |
3604 } | |
3605 | |
3606 /* | |
3607 * Remove the shift modifier from a special key. | |
3608 */ | |
3609 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3610 unshift_special(cmdarg_T *cap) |
7 | 3611 { |
3612 switch (cap->cmdchar) | |
3613 { | |
3614 case K_S_RIGHT: cap->cmdchar = K_RIGHT; break; | |
3615 case K_S_LEFT: cap->cmdchar = K_LEFT; break; | |
3616 case K_S_UP: cap->cmdchar = K_UP; break; | |
3617 case K_S_DOWN: cap->cmdchar = K_DOWN; break; | |
3618 case K_S_HOME: cap->cmdchar = K_HOME; break; | |
3619 case K_S_END: cap->cmdchar = K_END; break; | |
3620 } | |
3621 cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask); | |
3622 } | |
3623 | |
6979 | 3624 /* |
3625 * If the mode is currently displayed clear the command line or update the | |
3626 * command displayed. | |
3627 */ | |
3628 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3629 may_clear_cmdline(void) |
6979 | 3630 { |
3631 if (mode_displayed) | |
3632 clear_cmdline = TRUE; /* unshow visual mode later */ | |
3633 #ifdef FEAT_CMDL_INFO | |
3634 else | |
3635 clear_showcmd(); | |
3636 #endif | |
3637 } | |
3638 | |
7 | 3639 #if defined(FEAT_CMDL_INFO) || defined(PROTO) |
3640 /* | |
3641 * Routines for displaying a partly typed command | |
3642 */ | |
3643 | |
5735 | 3644 #define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 |
7 | 3645 static char_u showcmd_buf[SHOWCMD_BUFLEN]; |
3646 static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */ | |
3647 static int showcmd_is_clear = TRUE; | |
3648 static int showcmd_visual = FALSE; | |
3649 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
3650 static void display_showcmd(void); |
7 | 3651 |
3652 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3653 clear_showcmd(void) |
7 | 3654 { |
3655 if (!p_sc) | |
3656 return; | |
3657 | |
3658 if (VIsual_active && !char_avail()) | |
3659 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3660 int cursor_bot = LT_POS(VIsual, curwin->w_cursor); |
7 | 3661 long lines; |
3662 colnr_T leftcol, rightcol; | |
3663 linenr_T top, bot; | |
3664 | |
3665 /* Show the size of the Visual area. */ | |
1866 | 3666 if (cursor_bot) |
7 | 3667 { |
3668 top = VIsual.lnum; | |
3669 bot = curwin->w_cursor.lnum; | |
3670 } | |
3671 else | |
3672 { | |
3673 top = curwin->w_cursor.lnum; | |
3674 bot = VIsual.lnum; | |
3675 } | |
3676 # ifdef FEAT_FOLDING | |
3677 /* Include closed folds as a whole. */ | |
7009 | 3678 (void)hasFolding(top, &top, NULL); |
3679 (void)hasFolding(bot, NULL, &bot); | |
7 | 3680 # endif |
3681 lines = bot - top + 1; | |
3682 | |
3683 if (VIsual_mode == Ctrl_V) | |
3684 { | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3685 # ifdef FEAT_LINEBREAK |
1866 | 3686 char_u *saved_sbr = p_sbr; |
3687 | |
3688 /* Make 'sbr' empty for a moment to get the correct size. */ | |
3689 p_sbr = empty_option; | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3690 # endif |
7 | 3691 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
|
3692 # ifdef FEAT_LINEBREAK |
1866 | 3693 p_sbr = saved_sbr; |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3694 # endif |
7 | 3695 sprintf((char *)showcmd_buf, "%ldx%ld", lines, |
3696 (long)(rightcol - leftcol + 1)); | |
3697 } | |
3698 else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum) | |
3699 sprintf((char *)showcmd_buf, "%ld", lines); | |
3700 else | |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3701 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3702 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
|
3703 int l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3704 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
|
3705 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
|
3706 |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3707 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
|
3708 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3709 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
|
3710 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
|
3711 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3712 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3713 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3714 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
|
3715 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
|
3716 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3717 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
|
3718 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3719 l = (*mb_ptr2len)(s); |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3720 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
|
3721 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3722 ++bytes; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3723 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3724 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
|
3725 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3726 bytes += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3727 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3728 s += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3729 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3730 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
|
3731 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
|
3732 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3733 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
|
3734 } |
7 | 3735 showcmd_buf[SHOWCMD_COLS] = NUL; /* truncate */ |
3736 showcmd_visual = TRUE; | |
3737 } | |
3738 else | |
3739 { | |
3740 showcmd_buf[0] = NUL; | |
3741 showcmd_visual = FALSE; | |
3742 | |
3743 /* Don't actually display something if there is nothing to clear. */ | |
3744 if (showcmd_is_clear) | |
3745 return; | |
3746 } | |
3747 | |
3748 display_showcmd(); | |
3749 } | |
3750 | |
3751 /* | |
3752 * Add 'c' to string of shown command chars. | |
3753 * Return TRUE if output has been written (and setcursor() has been called). | |
3754 */ | |
3755 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3756 add_to_showcmd(int c) |
7 | 3757 { |
3758 char_u *p; | |
3759 int old_len; | |
3760 int extra_len; | |
3761 int overflow; | |
3762 #if defined(FEAT_MOUSE) | |
3763 int i; | |
3764 static int ignore[] = | |
3765 { | |
660 | 3766 # ifdef FEAT_GUI |
7 | 3767 K_VER_SCROLLBAR, K_HOR_SCROLLBAR, |
3768 K_LEFTMOUSE_NM, K_LEFTRELEASE_NM, | |
660 | 3769 # endif |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
3770 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
|
3771 K_LEFTMOUSE, K_LEFTDRAG, K_LEFTRELEASE, K_MOUSEMOVE, |
7 | 3772 K_MIDDLEMOUSE, K_MIDDLEDRAG, K_MIDDLERELEASE, |
3773 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
|
3774 K_MOUSEDOWN, K_MOUSEUP, K_MOUSELEFT, K_MOUSERIGHT, |
7 | 3775 K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE, |
631 | 3776 K_CURSORHOLD, |
7 | 3777 0 |
3778 }; | |
3779 #endif | |
3780 | |
641 | 3781 if (!p_sc || msg_silent != 0) |
7 | 3782 return FALSE; |
3783 | |
3784 if (showcmd_visual) | |
3785 { | |
3786 showcmd_buf[0] = NUL; | |
3787 showcmd_visual = FALSE; | |
3788 } | |
3789 | |
3790 #if defined(FEAT_MOUSE) | |
3791 /* Ignore keys that are scrollbar updates and mouse clicks */ | |
3792 if (IS_SPECIAL(c)) | |
3793 for (i = 0; ignore[i] != 0; ++i) | |
3794 if (ignore[i] == c) | |
3795 return FALSE; | |
3796 #endif | |
3797 | |
3798 p = transchar(c); | |
5535 | 3799 if (*p == ' ') |
3800 STRCPY(p, "<20>"); | |
7 | 3801 old_len = (int)STRLEN(showcmd_buf); |
3802 extra_len = (int)STRLEN(p); | |
3803 overflow = old_len + extra_len - SHOWCMD_COLS; | |
3804 if (overflow > 0) | |
1362 | 3805 mch_memmove(showcmd_buf, showcmd_buf + overflow, |
3806 old_len - overflow + 1); | |
7 | 3807 STRCAT(showcmd_buf, p); |
3808 | |
3809 if (char_avail()) | |
3810 return FALSE; | |
3811 | |
3812 display_showcmd(); | |
3813 | |
3814 return TRUE; | |
3815 } | |
3816 | |
3817 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3818 add_to_showcmd_c(int c) |
7 | 3819 { |
3820 if (!add_to_showcmd(c)) | |
3821 setcursor(); | |
3822 } | |
3823 | |
3824 /* | |
3825 * Delete 'len' characters from the end of the shown command. | |
3826 */ | |
3827 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3828 del_from_showcmd(int len) |
7 | 3829 { |
3830 int old_len; | |
3831 | |
3832 if (!p_sc) | |
3833 return; | |
3834 | |
3835 old_len = (int)STRLEN(showcmd_buf); | |
3836 if (len > old_len) | |
3837 len = old_len; | |
3838 showcmd_buf[old_len - len] = NUL; | |
3839 | |
3840 if (!char_avail()) | |
3841 display_showcmd(); | |
3842 } | |
3843 | |
3844 /* | |
3845 * push_showcmd() and pop_showcmd() are used when waiting for the user to type | |
3846 * something and there is a partial mapping. | |
3847 */ | |
3848 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3849 push_showcmd(void) |
7 | 3850 { |
3851 if (p_sc) | |
3852 STRCPY(old_showcmd_buf, showcmd_buf); | |
3853 } | |
3854 | |
3855 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3856 pop_showcmd(void) |
7 | 3857 { |
3858 if (!p_sc) | |
3859 return; | |
3860 | |
3861 STRCPY(showcmd_buf, old_showcmd_buf); | |
3862 | |
3863 display_showcmd(); | |
3864 } | |
3865 | |
3866 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3867 display_showcmd(void) |
7 | 3868 { |
3869 int len; | |
3870 | |
3871 cursor_off(); | |
3872 | |
3873 len = (int)STRLEN(showcmd_buf); | |
3874 if (len == 0) | |
3875 showcmd_is_clear = TRUE; | |
3876 else | |
3877 { | |
3878 screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0); | |
3879 showcmd_is_clear = FALSE; | |
3880 } | |
3881 | |
3882 /* | |
1188 | 3883 * clear the rest of an old message by outputting up to SHOWCMD_COLS |
3884 * spaces | |
7 | 3885 */ |
3886 screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0); | |
3887 | |
3888 setcursor(); /* put cursor back where it belongs */ | |
3889 } | |
3890 #endif | |
3891 | |
3892 /* | |
3893 * When "check" is FALSE, prepare for commands that scroll the window. | |
3894 * When "check" is TRUE, take care of scroll-binding after the window has | |
3895 * scrolled. Called from normal_cmd() and edit(). | |
3896 */ | |
3897 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3898 do_check_scrollbind(int check) |
7 | 3899 { |
3900 static win_T *old_curwin = NULL; | |
3901 static linenr_T old_topline = 0; | |
3902 #ifdef FEAT_DIFF | |
3903 static int old_topfill = 0; | |
3904 #endif | |
3905 static buf_T *old_buf = NULL; | |
3906 static colnr_T old_leftcol = 0; | |
3907 | |
3908 if (check && curwin->w_p_scb) | |
3909 { | |
3910 /* If a ":syncbind" command was just used, don't scroll, only reset | |
3911 * the values. */ | |
3912 if (did_syncbind) | |
3913 did_syncbind = FALSE; | |
3914 else if (curwin == old_curwin) | |
3915 { | |
3916 /* | |
3917 * Synchronize other windows, as necessary according to | |
3918 * 'scrollbind'. Don't do this after an ":edit" command, except | |
3919 * when 'diff' is set. | |
3920 */ | |
3921 if ((curwin->w_buffer == old_buf | |
3922 #ifdef FEAT_DIFF | |
3923 || curwin->w_p_diff | |
3924 #endif | |
3925 ) | |
3926 && (curwin->w_topline != old_topline | |
3927 #ifdef FEAT_DIFF | |
3928 || curwin->w_topfill != old_topfill | |
3929 #endif | |
3930 || curwin->w_leftcol != old_leftcol)) | |
3931 { | |
3932 check_scrollbind(curwin->w_topline - old_topline, | |
3933 (long)(curwin->w_leftcol - old_leftcol)); | |
3934 } | |
3935 } | |
3936 else if (vim_strchr(p_sbo, 'j')) /* jump flag set in 'scrollopt' */ | |
3937 { | |
3938 /* | |
3939 * When switching between windows, make sure that the relative | |
3940 * vertical offset is valid for the new window. The relative | |
3941 * offset is invalid whenever another 'scrollbind' window has | |
3942 * scrolled to a point that would force the current window to | |
3943 * scroll past the beginning or end of its buffer. When the | |
3944 * resync is performed, some of the other 'scrollbind' windows may | |
3945 * need to jump so that the current window's relative position is | |
3946 * visible on-screen. | |
3947 */ | |
3948 check_scrollbind(curwin->w_topline - curwin->w_scbind_pos, 0L); | |
3949 } | |
3950 curwin->w_scbind_pos = curwin->w_topline; | |
3951 } | |
3952 | |
3953 old_curwin = curwin; | |
3954 old_topline = curwin->w_topline; | |
3955 #ifdef FEAT_DIFF | |
3956 old_topfill = curwin->w_topfill; | |
3957 #endif | |
3958 old_buf = curwin->w_buffer; | |
3959 old_leftcol = curwin->w_leftcol; | |
3960 } | |
3961 | |
3962 /* | |
3963 * Synchronize any windows that have "scrollbind" set, based on the | |
3964 * number of rows by which the current window has changed | |
3965 * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>) | |
3966 */ | |
3967 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3968 check_scrollbind(linenr_T topline_diff, long leftcol_diff) |
7 | 3969 { |
3970 int want_ver; | |
3971 int want_hor; | |
3972 win_T *old_curwin = curwin; | |
3973 buf_T *old_curbuf = curbuf; | |
3974 int old_VIsual_select = VIsual_select; | |
3975 int old_VIsual_active = VIsual_active; | |
3976 colnr_T tgt_leftcol = curwin->w_leftcol; | |
3977 long topline; | |
3978 long y; | |
3979 | |
3980 /* | |
3981 * check 'scrollopt' string for vertical and horizontal scroll options | |
3982 */ | |
3983 want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0); | |
3984 #ifdef FEAT_DIFF | |
3985 want_ver |= old_curwin->w_p_diff; | |
3986 #endif | |
3987 want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0)); | |
3988 | |
3989 /* | |
3990 * loop through the scrollbound windows and scroll accordingly | |
3991 */ | |
3992 VIsual_select = VIsual_active = 0; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9399
diff
changeset
|
3993 FOR_ALL_WINDOWS(curwin) |
7 | 3994 { |
3995 curbuf = curwin->w_buffer; | |
3996 /* skip original window and windows with 'noscrollbind' */ | |
3997 if (curwin != old_curwin && curwin->w_p_scb) | |
3998 { | |
3999 /* | |
4000 * do the vertical scroll | |
4001 */ | |
4002 if (want_ver) | |
4003 { | |
4004 #ifdef FEAT_DIFF | |
4005 if (old_curwin->w_p_diff && curwin->w_p_diff) | |
4006 { | |
4007 diff_set_topline(old_curwin, curwin); | |
4008 } | |
4009 else | |
4010 #endif | |
4011 { | |
4012 curwin->w_scbind_pos += topline_diff; | |
4013 topline = curwin->w_scbind_pos; | |
4014 if (topline > curbuf->b_ml.ml_line_count) | |
4015 topline = curbuf->b_ml.ml_line_count; | |
4016 if (topline < 1) | |
4017 topline = 1; | |
4018 | |
4019 y = topline - curwin->w_topline; | |
4020 if (y > 0) | |
4021 scrollup(y, FALSE); | |
4022 else | |
4023 scrolldown(-y, FALSE); | |
4024 } | |
4025 | |
4026 redraw_later(VALID); | |
4027 cursor_correct(); | |
4028 curwin->w_redr_status = TRUE; | |
4029 } | |
4030 | |
4031 /* | |
4032 * do the horizontal scroll | |
4033 */ | |
4034 if (want_hor && curwin->w_leftcol != tgt_leftcol) | |
4035 { | |
4036 curwin->w_leftcol = tgt_leftcol; | |
4037 leftcol_changed(); | |
4038 } | |
4039 } | |
4040 } | |
4041 | |
4042 /* | |
4043 * reset current-window | |
4044 */ | |
4045 VIsual_select = old_VIsual_select; | |
4046 VIsual_active = old_VIsual_active; | |
4047 curwin = old_curwin; | |
4048 curbuf = old_curbuf; | |
4049 } | |
4050 | |
4051 /* | |
4052 * Command character that's ignored. | |
4053 * 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
|
4054 * xon/xoff. |
7 | 4055 */ |
4056 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4057 nv_ignore(cmdarg_T *cap) |
7 | 4058 { |
226 | 4059 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
7 | 4060 } |
4061 | |
4062 /* | |
620 | 4063 * Command character that doesn't do anything, but unlike nv_ignore() does |
4064 * start edit(). Used for "startinsert" executed while starting up. | |
4065 */ | |
4066 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4067 nv_nop(cmdarg_T *cap UNUSED) |
620 | 4068 { |
4069 } | |
4070 | |
4071 /* | |
7 | 4072 * Command character doesn't exist. |
4073 */ | |
4074 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4075 nv_error(cmdarg_T *cap) |
7 | 4076 { |
4077 clearopbeep(cap->oap); | |
4078 } | |
4079 | |
4080 /* | |
4081 * <Help> and <F1> commands. | |
4082 */ | |
4083 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4084 nv_help(cmdarg_T *cap) |
7 | 4085 { |
4086 if (!checkclearopq(cap->oap)) | |
4087 ex_help(NULL); | |
4088 } | |
4089 | |
4090 /* | |
4091 * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor. | |
4092 */ | |
4093 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4094 nv_addsub(cmdarg_T *cap) |
7 | 4095 { |
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
|
4096 #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
|
4097 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
|
4098 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
|
4099 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
|
4100 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4101 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
|
4102 { |
7578
fdae4c496775
commit https://github.com/vim/vim/commit/ef2b5036b3005f1ce15d146dce72379a9834c56d
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
4103 prep_redo_cmd(cap); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4104 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
|
4105 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
|
4106 cap->oap->op_type = OP_NOP; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4107 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4108 else if (VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4109 nv_operator(cap); |
6868 | 4110 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4111 clearop(cap->oap); |
7 | 4112 } |
4113 | |
4114 /* | |
4115 * CTRL-F, CTRL-B, etc: Scroll page up or down. | |
4116 */ | |
4117 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4118 nv_page(cmdarg_T *cap) |
7 | 4119 { |
4120 if (!checkclearop(cap->oap)) | |
819 | 4121 { |
4122 if (mod_mask & MOD_MASK_CTRL) | |
4123 { | |
4124 /* <C-PageUp>: tab page back; <C-PageDown>: tab page forward */ | |
4125 if (cap->arg == BACKWARD) | |
4126 goto_tabpage(-(int)cap->count1); | |
4127 else | |
4128 goto_tabpage((int)cap->count0); | |
4129 } | |
4130 else | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
4131 (void)onepage(cap->arg, cap->count1); |
819 | 4132 } |
7 | 4133 } |
4134 | |
4135 /* | |
4136 * Implementation of "gd" and "gD" command. | |
4137 */ | |
4138 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4139 nv_gd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4140 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4141 int nchar, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4142 int thisblock) /* 1 for "1gd" and "1gD" */ |
7 | 4143 { |
4144 int len; | |
503 | 4145 char_u *ptr; |
4146 | |
4147 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
|
4148 || 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
|
4149 == FAIL) |
503 | 4150 clearopbeep(oap); |
4151 #ifdef FEAT_FOLDING | |
4152 else if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) | |
4153 foldOpenCursor(); | |
4154 #endif | |
4155 } | |
4156 | |
4157 /* | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4158 * 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
|
4159 * otherwise. |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4160 */ |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4161 static int |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4162 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
|
4163 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4164 int i; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4165 int incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4166 int instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4167 int prev = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4168 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4169 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
|
4170 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4171 if (instring != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4172 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4173 if (prev != '\\' && line[i] == instring) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4174 instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4175 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4176 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
|
4177 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4178 instring = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4179 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4180 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4181 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4182 if (incomment) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4183 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4184 if (prev == '*' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4185 incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4186 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4187 else if (prev == '/' && line[i] == '*') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4188 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4189 incomment = TRUE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4190 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4191 else if (prev == '/' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4192 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4193 return FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4194 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4195 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4196 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4197 prev = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4198 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4199 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4200 return incomment == FALSE && instring == 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4201 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4202 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4203 /* |
523 | 4204 * Search for variable declaration of "ptr[len]". |
4205 * When "locally" is TRUE in the current function ("gd"), otherwise in the | |
4206 * current file ("gD"). | |
4207 * When "thisblock" is TRUE check the {} block scope. | |
503 | 4208 * Return FAIL when not found. |
4209 */ | |
4210 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4211 find_decl( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4212 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4213 int len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4214 int locally, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4215 int thisblock, |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4216 int flags_arg) /* flags passed to searchit() */ |
503 | 4217 { |
7 | 4218 char_u *pat; |
4219 pos_T old_pos; | |
503 | 4220 pos_T par_pos; |
4221 pos_T found_pos; | |
7 | 4222 int t; |
4223 int save_p_ws; | |
4224 int save_p_scs; | |
503 | 4225 int retval = OK; |
944 | 4226 int incll; |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4227 int searchflags = flags_arg; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4228 int valid; |
503 | 4229 |
4230 if ((pat = alloc(len + 7)) == NULL) | |
4231 return FAIL; | |
268 | 4232 |
4233 /* Put "\V" before the pattern to avoid that the special meaning of "." | |
4234 * and "~" causes trouble. */ | |
4235 sprintf((char *)pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", | |
4236 len, ptr); | |
7 | 4237 old_pos = curwin->w_cursor; |
4238 save_p_ws = p_ws; | |
4239 save_p_scs = p_scs; | |
4240 p_ws = FALSE; /* don't wrap around end of file now */ | |
4241 p_scs = FALSE; /* don't switch ignorecase off now */ | |
4242 | |
4243 /* | |
4244 * With "gD" go to line 1. | |
4245 * With "gd" Search back for the start of the current function, then go | |
4246 * back until a blank line. If this fails go to line 1. | |
4247 */ | |
944 | 4248 if (!locally || !findpar(&incll, BACKWARD, 1L, '{', FALSE)) |
7 | 4249 { |
4250 setpcmark(); /* Set in findpar() otherwise */ | |
4251 curwin->w_cursor.lnum = 1; | |
539 | 4252 par_pos = curwin->w_cursor; |
7 | 4253 } |
4254 else | |
4255 { | |
539 | 4256 par_pos = curwin->w_cursor; |
7 | 4257 while (curwin->w_cursor.lnum > 1 && *skipwhite(ml_get_curline()) != NUL) |
4258 --curwin->w_cursor.lnum; | |
4259 } | |
4260 curwin->w_cursor.col = 0; | |
4261 | |
4262 /* 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
|
4263 CLEAR_POS(&found_pos); |
503 | 4264 for (;;) |
4265 { | |
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
|
4266 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
|
4267 pat, 1L, searchflags, RE_LAST, (linenr_T)0, NULL, NULL); |
503 | 4268 if (curwin->w_cursor.lnum >= old_pos.lnum) |
4269 t = FAIL; /* match after start is failure too */ | |
523 | 4270 |
718 | 4271 if (thisblock && t != FAIL) |
523 | 4272 { |
4273 pos_T *pos; | |
4274 | |
4275 /* Check that the block the match is in doesn't end before the | |
4276 * position where we started the search from. */ | |
4277 if ((pos = findmatchlimit(NULL, '}', FM_FORWARD, | |
4278 (int)(old_pos.lnum - curwin->w_cursor.lnum + 1))) != NULL | |
4279 && pos->lnum < old_pos.lnum) | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4280 { |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4281 /* 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
|
4282 * Skip to the end. */ |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4283 curwin->w_cursor = *pos; |
523 | 4284 continue; |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4285 } |
523 | 4286 } |
4287 | |
503 | 4288 if (t == FAIL) |
4289 { | |
4290 /* If we previously found a valid position, use it. */ | |
4291 if (found_pos.lnum != 0) | |
4292 { | |
4293 curwin->w_cursor = found_pos; | |
4294 t = OK; | |
4295 } | |
4296 break; | |
4297 } | |
7 | 4298 #ifdef FEAT_COMMENTS |
3562 | 4299 if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0) |
503 | 4300 { |
4301 /* Ignore this line, continue at start of next line. */ | |
4302 ++curwin->w_cursor.lnum; | |
4303 curwin->w_cursor.col = 0; | |
4304 continue; | |
4305 } | |
4306 #endif | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4307 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
|
4308 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4309 /* 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
|
4310 * 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
|
4311 if (!valid && found_pos.lnum != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4312 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4313 curwin->w_cursor = found_pos; |
503 | 4314 break; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4315 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4316 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4317 /* 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
|
4318 if (valid && !locally) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4319 break; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4320 if (valid && curwin->w_cursor.lnum >= par_pos.lnum) |
503 | 4321 { |
4322 /* If we previously found a valid position, use it. */ | |
4323 if (found_pos.lnum != 0) | |
4324 curwin->w_cursor = found_pos; | |
4325 break; | |
4326 } | |
4327 | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4328 /* 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
|
4329 * 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
|
4330 * 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
|
4331 if (!valid) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4332 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4333 CLEAR_POS(&found_pos); |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4334 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4335 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4336 found_pos = curwin->w_cursor; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4337 /* 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
|
4338 * position. */ |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4339 searchflags &= ~SEARCH_START; |
503 | 4340 } |
4341 | |
4342 if (t == FAIL) | |
4343 { | |
4344 retval = FAIL; | |
7 | 4345 curwin->w_cursor = old_pos; |
4346 } | |
4347 else | |
4348 { | |
4349 curwin->w_set_curswant = TRUE; | |
4350 /* "n" searches forward now */ | |
4351 reset_search_dir(); | |
4352 } | |
4353 | |
4354 vim_free(pat); | |
4355 p_ws = save_p_ws; | |
4356 p_scs = save_p_scs; | |
503 | 4357 |
4358 return retval; | |
7 | 4359 } |
4360 | |
4361 /* | |
4362 * Move 'dist' lines in direction 'dir', counting lines by *screen* | |
4363 * lines rather than lines in the file. | |
4364 * 'dist' must be positive. | |
4365 * | |
4366 * Return OK if able to move cursor, FAIL otherwise. | |
4367 */ | |
4368 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4369 nv_screengo(oparg_T *oap, int dir, long dist) |
7 | 4370 { |
4371 int linelen = linetabsize(ml_get_curline()); | |
4372 int retval = OK; | |
4373 int atend = FALSE; | |
4374 int n; | |
4375 int col_off1; /* margin offset for first screen line */ | |
4376 int col_off2; /* margin offset for wrapped screen line */ | |
4377 int width1; /* text width for first screen line */ | |
4378 int width2; /* test width for wrapped screen line */ | |
4379 | |
4380 oap->motion_type = MCHAR; | |
5192
c28202427d71
updated for version 7.4a.022
Bram Moolenaar <bram@vim.org>
parents:
5162
diff
changeset
|
4381 oap->inclusive = (curwin->w_curswant == MAXCOL); |
7 | 4382 |
4383 col_off1 = curwin_col_off(); | |
4384 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
|
4385 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
|
4386 width2 = curwin->w_width - col_off2; |
6559 | 4387 if (width2 == 0) |
4388 width2 = 1; /* avoid divide by zero */ | |
7 | 4389 |
4390 if (curwin->w_width != 0) | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4391 { |
7 | 4392 /* |
4393 * Instead of sticking at the last character of the buffer line we | |
4394 * try to stick in the last column of the screen. | |
4395 */ | |
4396 if (curwin->w_curswant == MAXCOL) | |
4397 { | |
4398 atend = TRUE; | |
4399 validate_virtcol(); | |
4400 if (width1 <= 0) | |
4401 curwin->w_curswant = 0; | |
4402 else | |
4403 { | |
4404 curwin->w_curswant = width1 - 1; | |
4405 if (curwin->w_virtcol > curwin->w_curswant) | |
4406 curwin->w_curswant += ((curwin->w_virtcol | |
4407 - curwin->w_curswant - 1) / width2 + 1) * width2; | |
4408 } | |
4409 } | |
4410 else | |
4411 { | |
4412 if (linelen > width1) | |
4413 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
4414 else | |
4415 n = width1; | |
4416 if (curwin->w_curswant > (colnr_T)n + 1) | |
4417 curwin->w_curswant -= ((curwin->w_curswant - n) / width2 + 1) | |
4418 * width2; | |
4419 } | |
4420 | |
4421 while (dist--) | |
4422 { | |
4423 if (dir == BACKWARD) | |
4424 { | |
4425 if ((long)curwin->w_curswant >= width2) | |
4426 /* move back within line */ | |
4427 curwin->w_curswant -= width2; | |
4428 else | |
4429 { | |
4430 /* to previous line */ | |
4431 if (curwin->w_cursor.lnum == 1) | |
4432 { | |
4433 retval = FAIL; | |
4434 break; | |
4435 } | |
4436 --curwin->w_cursor.lnum; | |
4437 #ifdef FEAT_FOLDING | |
4438 /* Move to the start of a closed fold. Don't do that when | |
4439 * 'foldopen' contains "all": it will open in a moment. */ | |
4440 if (!(fdo_flags & FDO_ALL)) | |
4441 (void)hasFolding(curwin->w_cursor.lnum, | |
4442 &curwin->w_cursor.lnum, NULL); | |
4443 #endif | |
4444 linelen = linetabsize(ml_get_curline()); | |
4445 if (linelen > width1) | |
4446 curwin->w_curswant += (((linelen - width1 - 1) / width2) | |
4447 + 1) * width2; | |
4448 } | |
4449 } | |
4450 else /* dir == FORWARD */ | |
4451 { | |
4452 if (linelen > width1) | |
4453 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
4454 else | |
4455 n = width1; | |
4456 if (curwin->w_curswant + width2 < (colnr_T)n) | |
4457 /* move forward within line */ | |
4458 curwin->w_curswant += width2; | |
4459 else | |
4460 { | |
4461 /* to next line */ | |
4462 #ifdef FEAT_FOLDING | |
4463 /* Move to the end of a closed fold. */ | |
4464 (void)hasFolding(curwin->w_cursor.lnum, NULL, | |
4465 &curwin->w_cursor.lnum); | |
4466 #endif | |
4467 if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
4468 { | |
4469 retval = FAIL; | |
4470 break; | |
4471 } | |
4472 curwin->w_cursor.lnum++; | |
4473 curwin->w_curswant %= width2; | |
2911 | 4474 linelen = linetabsize(ml_get_curline()); |
7 | 4475 } |
4476 } | |
4477 } | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4478 } |
7 | 4479 |
5600 | 4480 if (virtual_active() && atend) |
4481 coladvance(MAXCOL); | |
4482 else | |
4483 coladvance(curwin->w_curswant); | |
7 | 4484 |
4485 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
4486 { | |
6178 | 4487 colnr_T virtcol; |
4488 | |
7 | 4489 /* |
4490 * Check for landing on a character that got split at the end of the | |
4491 * last line. We want to advance a screenline, not end up in the same | |
4492 * screenline or move two screenlines. | |
4493 */ | |
4494 validate_virtcol(); | |
6178 | 4495 virtcol = curwin->w_virtcol; |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4496 #if defined(FEAT_LINEBREAK) |
6178 | 4497 if (virtcol > (colnr_T)width1 && *p_sbr != NUL) |
4498 virtcol -= vim_strsize(p_sbr); | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4499 #endif |
6178 | 4500 |
4501 if (virtcol > curwin->w_curswant | |
7 | 4502 && (curwin->w_curswant < (colnr_T)width1 |
4503 ? (curwin->w_curswant > (colnr_T)width1 / 2) | |
4504 : ((curwin->w_curswant - width1) % width2 | |
4505 > (colnr_T)width2 / 2))) | |
4506 --curwin->w_cursor.col; | |
4507 } | |
4508 | |
4509 if (atend) | |
4510 curwin->w_curswant = MAXCOL; /* stick in the last column */ | |
4511 | |
4512 return retval; | |
4513 } | |
4514 | |
4515 #ifdef FEAT_MOUSE | |
4516 /* | |
4517 * Mouse scroll wheel: Default action is to scroll three lines, or one page | |
4518 * 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
|
4519 * 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
|
4520 * K_MOUSELEFT (cap->arg == -1) or K_MOUSERIGHT (cap->arg == -2) |
7 | 4521 */ |
4522 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4523 nv_mousescroll(cmdarg_T *cap) |
7 | 4524 { |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4525 win_T *old_curwin = curwin, *wp; |
7 | 4526 |
4162 | 4527 if (mouse_row >= 0 && mouse_col >= 0) |
7 | 4528 { |
4529 int row, col; | |
4530 | |
4531 row = mouse_row; | |
4532 col = mouse_col; | |
4533 | |
4534 /* 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
|
4535 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
|
4536 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
|
4537 return; |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4538 curwin = wp; |
7 | 4539 curbuf = curwin->w_buffer; |
4540 } | |
4541 | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4542 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
|
4543 { |
11983
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4544 # 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
|
4545 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
|
4546 /* 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
|
4547 * 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
|
4548 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
|
4549 else |
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4550 # endif |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4551 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
|
4552 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4553 (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
|
4554 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4555 else |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4556 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4557 cap->count1 = 3; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4558 cap->count0 = 3; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4559 nv_scroll_line(cap); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4560 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4561 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4562 # ifdef FEAT_GUI |
7 | 4563 else |
4564 { | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4565 /* 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
|
4566 if (!curwin->w_p_wrap) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4567 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4568 int val, step = 6; |
2416
1a9c16dd76d4
Fix compiler warnings on 64 bit systems.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4569 |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4570 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
|
4571 step = curwin->w_width; |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4572 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
|
4573 if (val < 0) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4574 val = 0; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4575 |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4576 gui_do_horiz_scroll(val, TRUE); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4577 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4578 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4579 # endif |
15697
b7a88676e81c
patch 8.1.0856: when scrolling a window the cursorline is not always updated
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
4580 # ifdef FEAT_SYN_HL |
b7a88676e81c
patch 8.1.0856: when scrolling a window the cursorline is not always updated
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
4581 if (curwin != old_curwin && curwin->w_p_cul) |
b7a88676e81c
patch 8.1.0856: when scrolling a window the cursorline is not always updated
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
4582 redraw_for_cursorline(curwin); |
b7a88676e81c
patch 8.1.0856: when scrolling a window the cursorline is not always updated
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
4583 # endif |
7 | 4584 |
4585 curwin->w_redr_status = TRUE; | |
4586 | |
4587 curwin = old_curwin; | |
4588 curbuf = curwin->w_buffer; | |
4589 } | |
4590 | |
4591 /* | |
4592 * Mouse clicks and drags. | |
4593 */ | |
4594 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4595 nv_mouse(cmdarg_T *cap) |
7 | 4596 { |
4597 (void)do_mouse(cap->oap, cap->cmdchar, BACKWARD, cap->count1, 0); | |
4598 } | |
4599 #endif | |
4600 | |
4601 /* | |
4602 * Handle CTRL-E and CTRL-Y commands: scroll a line up or down. | |
4603 * cap->arg must be TRUE for CTRL-E. | |
4604 */ | |
4605 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4606 nv_scroll_line(cmdarg_T *cap) |
7 | 4607 { |
4608 if (!checkclearop(cap->oap)) | |
4609 scroll_redraw(cap->arg, cap->count1); | |
4610 } | |
4611 | |
4612 /* | |
4613 * Scroll "count" lines up or down, and redraw. | |
4614 */ | |
4615 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4616 scroll_redraw(int up, long count) |
7 | 4617 { |
4618 linenr_T prev_topline = curwin->w_topline; | |
4619 #ifdef FEAT_DIFF | |
4620 int prev_topfill = curwin->w_topfill; | |
4621 #endif | |
4622 linenr_T prev_lnum = curwin->w_cursor.lnum; | |
4623 | |
4624 if (up) | |
4625 scrollup(count, TRUE); | |
4626 else | |
4627 scrolldown(count, TRUE); | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
4628 if (get_scrolloff_value()) |
7 | 4629 { |
4630 /* Adjust the cursor position for 'scrolloff'. Mark w_topline as | |
4631 * valid, otherwise the screen jumps back at the end of the file. */ | |
4632 cursor_correct(); | |
4633 check_cursor_moved(curwin); | |
4634 curwin->w_valid |= VALID_TOPLINE; | |
4635 | |
4636 /* If moved back to where we were, at least move the cursor, otherwise | |
4637 * we get stuck at one position. Don't move the cursor up if the | |
4638 * first line of the buffer is already on the screen */ | |
4639 while (curwin->w_topline == prev_topline | |
4640 #ifdef FEAT_DIFF | |
4641 && curwin->w_topfill == prev_topfill | |
4642 #endif | |
4643 ) | |
4644 { | |
4645 if (up) | |
4646 { | |
4647 if (curwin->w_cursor.lnum > prev_lnum | |
4648 || cursor_down(1L, FALSE) == FAIL) | |
4649 break; | |
4650 } | |
4651 else | |
4652 { | |
4653 if (curwin->w_cursor.lnum < prev_lnum | |
4654 || prev_topline == 1L | |
4655 || cursor_up(1L, FALSE) == FAIL) | |
4656 break; | |
4657 } | |
4658 /* Mark w_topline as valid, otherwise the screen jumps back at the | |
4659 * end of the file. */ | |
4660 check_cursor_moved(curwin); | |
4661 curwin->w_valid |= VALID_TOPLINE; | |
4662 } | |
4663 } | |
4664 if (curwin->w_cursor.lnum != prev_lnum) | |
4665 coladvance(curwin->w_curswant); | |
4666 redraw_later(VALID); | |
4667 } | |
4668 | |
4669 /* | |
4670 * Commands that start with "z". | |
4671 */ | |
4672 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4673 nv_zet(cmdarg_T *cap) |
7 | 4674 { |
4675 long n; | |
4676 colnr_T col; | |
4677 int nchar = cap->nchar; | |
4678 #ifdef FEAT_FOLDING | |
4679 long old_fdl = curwin->w_p_fdl; | |
4680 int old_fen = curwin->w_p_fen; | |
4681 #endif | |
737 | 4682 #ifdef FEAT_SPELL |
710 | 4683 int undo = FALSE; |
4684 #endif | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
4685 long siso = get_sidescrolloff_value(); |
7 | 4686 |
4687 if (VIM_ISDIGIT(nchar)) | |
4688 { | |
4689 /* | |
4690 * "z123{nchar}": edit the count before obtaining {nchar} | |
4691 */ | |
4692 if (checkclearop(cap->oap)) | |
4693 return; | |
4694 n = nchar - '0'; | |
4695 for (;;) | |
4696 { | |
4697 #ifdef USE_ON_FLY_SCROLL | |
4698 dont_scroll = TRUE; /* disallow scrolling here */ | |
4699 #endif | |
4700 ++no_mapping; | |
4701 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 4702 nchar = plain_vgetc(); |
7 | 4703 LANGMAP_ADJUST(nchar, TRUE); |
4704 --no_mapping; | |
4705 --allow_keys; | |
4706 #ifdef FEAT_CMDL_INFO | |
4707 (void)add_to_showcmd(nchar); | |
4708 #endif | |
4709 if (nchar == K_DEL || nchar == K_KDEL) | |
4710 n /= 10; | |
4711 else if (VIM_ISDIGIT(nchar)) | |
4712 n = n * 10 + (nchar - '0'); | |
4713 else if (nchar == CAR) | |
4714 { | |
4715 #ifdef FEAT_GUI | |
4716 need_mouse_correct = TRUE; | |
4717 #endif | |
4718 win_setheight((int)n); | |
4719 break; | |
4720 } | |
4721 else if (nchar == 'l' | |
4722 || nchar == 'h' | |
4723 || nchar == K_LEFT | |
229 | 4724 || nchar == K_RIGHT) |
7 | 4725 { |
4726 cap->count1 = n ? n * cap->count1 : cap->count1; | |
4727 goto dozet; | |
4728 } | |
4729 else | |
4730 { | |
4731 clearopbeep(cap->oap); | |
4732 break; | |
4733 } | |
4734 } | |
4735 cap->oap->op_type = OP_NOP; | |
4736 return; | |
4737 } | |
4738 | |
4739 dozet: | |
4740 if ( | |
4741 #ifdef FEAT_FOLDING | |
4742 /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" | |
4743 * and "zC" only in Visual mode. "zj" and "zk" are motion | |
4744 * commands. */ | |
4745 cap->nchar != 'f' && cap->nchar != 'F' | |
4746 && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) | |
4747 && cap->nchar != 'j' && cap->nchar != 'k' | |
4748 && | |
4749 #endif | |
4750 checkclearop(cap->oap)) | |
4751 return; | |
4752 | |
4753 /* | |
4754 * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb": | |
4755 * If line number given, set cursor. | |
4756 */ | |
4757 if ((vim_strchr((char_u *)"+\r\nt.z^-b", nchar) != NULL) | |
4758 && cap->count0 | |
4759 && cap->count0 != curwin->w_cursor.lnum) | |
4760 { | |
4761 setpcmark(); | |
4762 if (cap->count0 > curbuf->b_ml.ml_line_count) | |
4763 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4764 else | |
4765 curwin->w_cursor.lnum = cap->count0; | |
22 | 4766 check_cursor_col(); |
7 | 4767 } |
4768 | |
4769 switch (nchar) | |
4770 { | |
4771 /* "z+", "z<CR>" and "zt": put cursor at top of screen */ | |
4772 case '+': | |
4773 if (cap->count0 == 0) | |
4774 { | |
4775 /* No count given: put cursor at the line below screen */ | |
4776 validate_botline(); /* make sure w_botline is valid */ | |
4777 if (curwin->w_botline > curbuf->b_ml.ml_line_count) | |
4778 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4779 else | |
4780 curwin->w_cursor.lnum = curwin->w_botline; | |
4781 } | |
4782 /* FALLTHROUGH */ | |
4783 case NL: | |
4784 case CAR: | |
4785 case K_KENTER: | |
4786 beginline(BL_WHITE | BL_FIX); | |
4787 /* FALLTHROUGH */ | |
4788 | |
4789 case 't': scroll_cursor_top(0, TRUE); | |
4790 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4791 set_fraction(curwin); |
7 | 4792 break; |
4793 | |
4794 /* "z." and "zz": put cursor in middle of screen */ | |
4795 case '.': beginline(BL_WHITE | BL_FIX); | |
4796 /* FALLTHROUGH */ | |
4797 | |
4798 case 'z': scroll_cursor_halfway(TRUE); | |
4799 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4800 set_fraction(curwin); |
7 | 4801 break; |
4802 | |
4803 /* "z^", "z-" and "zb": put cursor at bottom of screen */ | |
4804 case '^': /* Strange Vi behavior: <count>z^ finds line at top of window | |
4805 * when <count> is at bottom of window, and puts that one at | |
4806 * bottom of window. */ | |
4807 if (cap->count0 != 0) | |
4808 { | |
4809 scroll_cursor_bot(0, TRUE); | |
4810 curwin->w_cursor.lnum = curwin->w_topline; | |
4811 } | |
4812 else if (curwin->w_topline == 1) | |
4813 curwin->w_cursor.lnum = 1; | |
4814 else | |
4815 curwin->w_cursor.lnum = curwin->w_topline - 1; | |
4816 /* FALLTHROUGH */ | |
4817 case '-': | |
4818 beginline(BL_WHITE | BL_FIX); | |
4819 /* FALLTHROUGH */ | |
4820 | |
4821 case 'b': scroll_cursor_bot(0, TRUE); | |
4822 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4823 set_fraction(curwin); |
7 | 4824 break; |
4825 | |
4826 /* "zH" - scroll screen right half-page */ | |
4827 case 'H': | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
4828 cap->count1 *= curwin->w_width / 2; |
7 | 4829 /* FALLTHROUGH */ |
4830 | |
4831 /* "zh" - scroll screen to the right */ | |
4832 case 'h': | |
4833 case K_LEFT: | |
4834 if (!curwin->w_p_wrap) | |
4835 { | |
4836 if ((colnr_T)cap->count1 > curwin->w_leftcol) | |
4837 curwin->w_leftcol = 0; | |
4838 else | |
4839 curwin->w_leftcol -= (colnr_T)cap->count1; | |
4840 leftcol_changed(); | |
4841 } | |
4842 break; | |
4843 | |
4844 /* "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
|
4845 case 'L': cap->count1 *= curwin->w_width / 2; |
7 | 4846 /* FALLTHROUGH */ |
4847 | |
4848 /* "zl" - scroll screen to the left */ | |
4849 case 'l': | |
4850 case K_RIGHT: | |
4851 if (!curwin->w_p_wrap) | |
4852 { | |
4853 /* scroll the window left */ | |
4854 curwin->w_leftcol += (colnr_T)cap->count1; | |
4855 leftcol_changed(); | |
4856 } | |
4857 break; | |
4858 | |
4859 /* "zs" - scroll screen, cursor at the start */ | |
4860 case 's': if (!curwin->w_p_wrap) | |
4861 { | |
4862 #ifdef FEAT_FOLDING | |
4863 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4864 col = 0; /* like the cursor is in col 0 */ | |
4865 else | |
4866 #endif | |
4867 getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL); | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
4868 if ((long)col > siso) |
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
4869 col -= siso; |
7 | 4870 else |
4871 col = 0; | |
4872 if (curwin->w_leftcol != col) | |
4873 { | |
4874 curwin->w_leftcol = col; | |
4875 redraw_later(NOT_VALID); | |
4876 } | |
4877 } | |
4878 break; | |
4879 | |
4880 /* "ze" - scroll screen, cursor at the end */ | |
4881 case 'e': if (!curwin->w_p_wrap) | |
4882 { | |
4883 #ifdef FEAT_FOLDING | |
4884 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4885 col = 0; /* like the cursor is in col 0 */ | |
4886 else | |
4887 #endif | |
4888 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
|
4889 n = curwin->w_width - curwin_col_off(); |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
4890 if ((long)col + siso < n) |
7 | 4891 col = 0; |
4892 else | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15697
diff
changeset
|
4893 col = col + siso - n + 1; |
7 | 4894 if (curwin->w_leftcol != col) |
4895 { | |
4896 curwin->w_leftcol = col; | |
4897 redraw_later(NOT_VALID); | |
4898 } | |
4899 } | |
4900 break; | |
4901 | |
4902 #ifdef FEAT_FOLDING | |
4903 /* "zF": create fold command */ | |
4904 /* "zf": create fold operator */ | |
4905 case 'F': | |
4906 case 'f': if (foldManualAllowed(TRUE)) | |
4907 { | |
4908 cap->nchar = 'f'; | |
4909 nv_operator(cap); | |
4910 curwin->w_p_fen = TRUE; | |
4911 | |
4912 /* "zF" is like "zfzf" */ | |
4913 if (nchar == 'F' && cap->oap->op_type == OP_FOLD) | |
4914 { | |
4915 nv_operator(cap); | |
4916 finish_op = TRUE; | |
4917 } | |
4918 } | |
4919 else | |
4920 clearopbeep(cap->oap); | |
4921 break; | |
4922 | |
4923 /* "zd": delete fold at cursor */ | |
4924 /* "zD": delete fold at cursor recursively */ | |
4925 case 'd': | |
4926 case 'D': if (foldManualAllowed(FALSE)) | |
4927 { | |
4928 if (VIsual_active) | |
4929 nv_operator(cap); | |
4930 else | |
4931 deleteFold(curwin->w_cursor.lnum, | |
4932 curwin->w_cursor.lnum, nchar == 'D', FALSE); | |
4933 } | |
4934 break; | |
4935 | |
4352 | 4936 /* "zE": erase all folds */ |
7 | 4937 case 'E': if (foldmethodIsManual(curwin)) |
4938 { | |
4939 clearFolding(curwin); | |
4940 changed_window_setting(); | |
4941 } | |
4942 else if (foldmethodIsMarker(curwin)) | |
4943 deleteFold((linenr_T)1, curbuf->b_ml.ml_line_count, | |
4944 TRUE, FALSE); | |
4945 else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
4946 emsg(_("E352: Cannot erase folds with current 'foldmethod'")); |
7 | 4947 break; |
4948 | |
4949 /* "zn": fold none: reset 'foldenable' */ | |
4950 case 'n': curwin->w_p_fen = FALSE; | |
4951 break; | |
4952 | |
4953 /* "zN": fold Normal: set 'foldenable' */ | |
4954 case 'N': curwin->w_p_fen = TRUE; | |
4955 break; | |
4956 | |
4957 /* "zi": invert folding: toggle 'foldenable' */ | |
4958 case 'i': curwin->w_p_fen = !curwin->w_p_fen; | |
4959 break; | |
4960 | |
4961 /* "za": open closed fold or close open fold at cursor */ | |
4962 case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4963 openFold(curwin->w_cursor.lnum, cap->count1); | |
4964 else | |
4965 { | |
4966 closeFold(curwin->w_cursor.lnum, cap->count1); | |
4967 curwin->w_p_fen = TRUE; | |
4968 } | |
4969 break; | |
4970 | |
4971 /* "zA": open fold at cursor recursively */ | |
4972 case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4973 openFoldRecurse(curwin->w_cursor.lnum); | |
4974 else | |
4975 { | |
4976 closeFoldRecurse(curwin->w_cursor.lnum); | |
4977 curwin->w_p_fen = TRUE; | |
4978 } | |
4979 break; | |
4980 | |
4981 /* "zo": open fold at cursor or Visual area */ | |
4982 case 'o': if (VIsual_active) | |
4983 nv_operator(cap); | |
4984 else | |
4985 openFold(curwin->w_cursor.lnum, cap->count1); | |
4986 break; | |
4987 | |
4988 /* "zO": open fold recursively */ | |
4989 case 'O': if (VIsual_active) | |
4990 nv_operator(cap); | |
4991 else | |
4992 openFoldRecurse(curwin->w_cursor.lnum); | |
4993 break; | |
4994 | |
4995 /* "zc": close fold at cursor or Visual area */ | |
4996 case 'c': if (VIsual_active) | |
4997 nv_operator(cap); | |
4998 else | |
4999 closeFold(curwin->w_cursor.lnum, cap->count1); | |
5000 curwin->w_p_fen = TRUE; | |
5001 break; | |
5002 | |
5003 /* "zC": close fold recursively */ | |
5004 case 'C': if (VIsual_active) | |
5005 nv_operator(cap); | |
5006 else | |
5007 closeFoldRecurse(curwin->w_cursor.lnum); | |
5008 curwin->w_p_fen = TRUE; | |
5009 break; | |
5010 | |
5011 /* "zv": open folds at the cursor */ | |
5012 case 'v': foldOpenCursor(); | |
5013 break; | |
5014 | |
5015 /* "zx": re-apply 'foldlevel' and open folds at the cursor */ | |
5016 case 'x': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5017 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5018 newFoldLevel(); /* update right now */ |
7 | 5019 foldOpenCursor(); |
5020 break; | |
5021 | |
5022 /* "zX": undo manual opens/closes, re-apply 'foldlevel' */ | |
5023 case 'X': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5024 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5025 old_fdl = -1; /* force an update */ |
7 | 5026 break; |
5027 | |
5028 /* "zm": fold more */ | |
5029 case 'm': if (curwin->w_p_fdl > 0) | |
6725 | 5030 { |
5031 curwin->w_p_fdl -= cap->count1; | |
5032 if (curwin->w_p_fdl < 0) | |
5033 curwin->w_p_fdl = 0; | |
5034 } | |
7 | 5035 old_fdl = -1; /* force an update */ |
5036 curwin->w_p_fen = TRUE; | |
5037 break; | |
5038 | |
5039 /* "zM": close all folds */ | |
5040 case 'M': curwin->w_p_fdl = 0; | |
5041 old_fdl = -1; /* force an update */ | |
5042 curwin->w_p_fen = TRUE; | |
5043 break; | |
5044 | |
5045 /* "zr": reduce folding */ | |
6725 | 5046 case 'r': curwin->w_p_fdl += cap->count1; |
5047 { | |
5048 int d = getDeepestNesting(); | |
5049 | |
5050 if (curwin->w_p_fdl >= d) | |
5051 curwin->w_p_fdl = d; | |
5052 } | |
7 | 5053 break; |
5054 | |
5055 /* "zR": open all folds */ | |
5056 case 'R': curwin->w_p_fdl = getDeepestNesting(); | |
5057 old_fdl = -1; /* force an update */ | |
5058 break; | |
5059 | |
5060 case 'j': /* "zj" move to next fold downwards */ | |
5061 case 'k': /* "zk" move to next fold upwards */ | |
5062 if (foldMoveTo(TRUE, nchar == 'j' ? FORWARD : BACKWARD, | |
5063 cap->count1) == FAIL) | |
5064 clearopbeep(cap->oap); | |
5065 break; | |
5066 | |
5067 #endif /* FEAT_FOLDING */ | |
5068 | |
737 | 5069 #ifdef FEAT_SPELL |
710 | 5070 case 'u': /* "zug" and "zuw": undo "zg" and "zw" */ |
5071 ++no_mapping; | |
5072 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 5073 nchar = plain_vgetc(); |
710 | 5074 LANGMAP_ADJUST(nchar, TRUE); |
5075 --no_mapping; | |
5076 --allow_keys; | |
5077 #ifdef FEAT_CMDL_INFO | |
5078 (void)add_to_showcmd(nchar); | |
5079 #endif | |
5080 if (vim_strchr((char_u *)"gGwW", nchar) == NULL) | |
5081 { | |
5082 clearopbeep(cap->oap); | |
5083 break; | |
5084 } | |
5085 undo = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
5086 /* FALLTHROUGH */ |
710 | 5087 |
310 | 5088 case 'g': /* "zg": add good word to word list */ |
5089 case 'w': /* "zw": add wrong word to word list */ | |
381 | 5090 case 'G': /* "zG": add good word to temp word list */ |
5091 case 'W': /* "zW": add wrong word to temp word list */ | |
310 | 5092 { |
5093 char_u *ptr = NULL; | |
5094 int len; | |
5095 | |
5096 if (checkclearop(cap->oap)) | |
5097 break; | |
5098 if (VIsual_active && get_visual_text(cap, &ptr, &len) | |
5099 == FAIL) | |
5100 return; | |
501 | 5101 if (ptr == NULL) |
5102 { | |
5103 pos_T pos = curwin->w_cursor; | |
5104 | |
5374 | 5105 /* Find bad word under the cursor. When 'spell' is |
5106 * off this fails and find_ident_under_cursor() is | |
5107 * used below. */ | |
5108 emsg_off++; | |
534 | 5109 len = spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL); |
5374 | 5110 emsg_off--; |
501 | 5111 if (len != 0 && curwin->w_cursor.col <= pos.col) |
5112 ptr = ml_get_pos(&curwin->w_cursor); | |
5113 curwin->w_cursor = pos; | |
5114 } | |
5115 | |
310 | 5116 if (ptr == NULL && (len = find_ident_under_cursor(&ptr, |
5117 FIND_IDENT)) == 0) | |
5118 return; | |
381 | 5119 spell_add_word(ptr, len, nchar == 'w' || nchar == 'W', |
710 | 5120 (nchar == 'G' || nchar == 'W') |
5121 ? 0 : (int)cap->count1, | |
5122 undo); | |
310 | 5123 } |
316 | 5124 break; |
323 | 5125 |
584 | 5126 case '=': /* "z=": suggestions for a badly spelled word */ |
638 | 5127 if (!checkclearop(cap->oap)) |
485 | 5128 spell_suggest((int)cap->count0); |
323 | 5129 break; |
310 | 5130 #endif |
5131 | |
7 | 5132 default: clearopbeep(cap->oap); |
5133 } | |
5134 | |
5135 #ifdef FEAT_FOLDING | |
5136 /* Redraw when 'foldenable' changed */ | |
5137 if (old_fen != curwin->w_p_fen) | |
5138 { | |
5139 # ifdef FEAT_DIFF | |
5140 win_T *wp; | |
5141 | |
5142 if (foldmethodIsDiff(curwin) && curwin->w_p_scb) | |
5143 { | |
5144 /* Adjust 'foldenable' in diff-synced windows. */ | |
5145 FOR_ALL_WINDOWS(wp) | |
5146 { | |
5147 if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) | |
5148 { | |
5149 wp->w_p_fen = curwin->w_p_fen; | |
5150 changed_window_setting_win(wp); | |
5151 } | |
5152 } | |
5153 } | |
5154 # endif | |
5155 changed_window_setting(); | |
5156 } | |
5157 | |
5158 /* Redraw when 'foldlevel' changed. */ | |
5159 if (old_fdl != curwin->w_p_fdl) | |
5160 newFoldLevel(); | |
5161 #endif | |
5162 } | |
5163 | |
5164 #ifdef FEAT_GUI | |
5165 /* | |
5166 * Vertical scrollbar movement. | |
5167 */ | |
5168 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5169 nv_ver_scrollbar(cmdarg_T *cap) |
7 | 5170 { |
5171 if (cap->oap->op_type != OP_NOP) | |
5172 clearopbeep(cap->oap); | |
5173 | |
5174 /* Even if an operator was pending, we still want to scroll */ | |
5175 gui_do_scroll(); | |
5176 } | |
5177 | |
5178 /* | |
5179 * Horizontal scrollbar movement. | |
5180 */ | |
5181 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5182 nv_hor_scrollbar(cmdarg_T *cap) |
7 | 5183 { |
5184 if (cap->oap->op_type != OP_NOP) | |
5185 clearopbeep(cap->oap); | |
5186 | |
5187 /* 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
|
5188 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 5189 } |
5190 #endif | |
5191 | |
690 | 5192 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
685 | 5193 /* |
5194 * Click in GUI tab. | |
5195 */ | |
5196 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5197 nv_tabline(cmdarg_T *cap) |
685 | 5198 { |
5199 if (cap->oap->op_type != OP_NOP) | |
5200 clearopbeep(cap->oap); | |
5201 | |
5202 /* Even if an operator was pending, we still want to jump tabs. */ | |
5203 goto_tabpage(current_tab); | |
5204 } | |
686 | 5205 |
5206 /* | |
5207 * Selected item in tab line menu. | |
5208 */ | |
5209 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5210 nv_tabmenu(cmdarg_T *cap) |
686 | 5211 { |
5212 if (cap->oap->op_type != OP_NOP) | |
5213 clearopbeep(cap->oap); | |
5214 | |
5215 /* Even if an operator was pending, we still want to jump tabs. */ | |
690 | 5216 handle_tabmenu(); |
5217 } | |
5218 | |
5219 /* | |
5220 * Handle selecting an item of the GUI tab line menu. | |
5221 * Used in Normal and Insert mode. | |
5222 */ | |
5223 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5224 handle_tabmenu(void) |
690 | 5225 { |
686 | 5226 switch (current_tabmenu) |
5227 { | |
5228 case TABLINE_MENU_CLOSE: | |
5229 if (current_tab == 0) | |
5230 do_cmdline_cmd((char_u *)"tabclose"); | |
5231 else | |
5232 { | |
5233 vim_snprintf((char *)IObuff, IOSIZE, "tabclose %d", | |
5234 current_tab); | |
5235 do_cmdline_cmd(IObuff); | |
5236 } | |
5237 break; | |
5238 | |
5239 case TABLINE_MENU_NEW: | |
6631 | 5240 if (current_tab == 0) |
5241 do_cmdline_cmd((char_u *)"$tabnew"); | |
5242 else | |
5243 { | |
5244 vim_snprintf((char *)IObuff, IOSIZE, "%dtabnew", | |
5245 current_tab - 1); | |
5246 do_cmdline_cmd(IObuff); | |
5247 } | |
686 | 5248 break; |
5249 | |
5250 case TABLINE_MENU_OPEN: | |
6631 | 5251 if (current_tab == 0) |
5252 do_cmdline_cmd((char_u *)"browse $tabnew"); | |
5253 else | |
5254 { | |
5255 vim_snprintf((char *)IObuff, IOSIZE, "browse %dtabnew", | |
5256 current_tab - 1); | |
5257 do_cmdline_cmd(IObuff); | |
5258 } | |
686 | 5259 break; |
5260 } | |
5261 } | |
685 | 5262 #endif |
5263 | |
7 | 5264 /* |
5265 * "Q" command. | |
5266 */ | |
5267 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5268 nv_exmode(cmdarg_T *cap) |
7 | 5269 { |
5270 /* | |
5271 * Ignore 'Q' in Visual mode, just give a beep. | |
5272 */ | |
5273 if (VIsual_active) | |
6949 | 5274 vim_beep(BO_EX); |
5735 | 5275 else if (!checkclearop(cap->oap)) |
7 | 5276 do_exmode(FALSE); |
5277 } | |
5278 | |
5279 /* | |
5280 * Handle a ":" command. | |
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_colon(cmdarg_T *cap) |
7 | 5284 { |
5285 int old_p_im; | |
4256 | 5286 int cmd_result; |
7 | 5287 |
5288 if (VIsual_active) | |
5289 nv_operator(cap); | |
5290 else | |
5291 { | |
5292 if (cap->oap->op_type != OP_NOP) | |
5293 { | |
5294 /* Using ":" as a movement is characterwise exclusive. */ | |
5295 cap->oap->motion_type = MCHAR; | |
5296 cap->oap->inclusive = FALSE; | |
5297 } | |
5298 else if (cap->count0) | |
5299 { | |
5300 /* translate "count:" into ":.,.+(count - 1)" */ | |
5301 stuffcharReadbuff('.'); | |
5302 if (cap->count0 > 1) | |
5303 { | |
5304 stuffReadbuff((char_u *)",.+"); | |
5305 stuffnumReadbuff((long)cap->count0 - 1L); | |
5306 } | |
5307 } | |
5308 | |
5309 /* When typing, don't type below an old message */ | |
5310 if (KeyTyped) | |
5311 compute_cmdrow(); | |
5312 | |
5313 old_p_im = p_im; | |
5314 | |
5315 /* get a command line and execute it */ | |
4256 | 5316 cmd_result = do_cmdline(NULL, getexline, NULL, |
7 | 5317 cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0); |
5318 | |
5319 /* If 'insertmode' changed, enter or exit Insert mode */ | |
5320 if (p_im != old_p_im) | |
5321 { | |
5322 if (p_im) | |
5323 restart_edit = 'i'; | |
5324 else | |
5325 restart_edit = 0; | |
5326 } | |
5327 | |
4256 | 5328 if (cmd_result == FAIL) |
5329 /* The Ex command failed, do not execute the operator. */ | |
5330 clearop(cap->oap); | |
5331 else if (cap->oap->op_type != OP_NOP | |
7 | 5332 && (cap->oap->start.lnum > curbuf->b_ml.ml_line_count |
5333 || cap->oap->start.col > | |
4256 | 5334 (colnr_T)STRLEN(ml_get(cap->oap->start.lnum)) |
5335 || did_emsg | |
5336 )) | |
5337 /* The start of the operator has become invalid by the Ex command. | |
5338 */ | |
7 | 5339 clearopbeep(cap->oap); |
5340 } | |
5341 } | |
5342 | |
5343 /* | |
5344 * Handle CTRL-G command. | |
5345 */ | |
5346 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5347 nv_ctrlg(cmdarg_T *cap) |
7 | 5348 { |
5349 if (VIsual_active) /* toggle Selection/Visual mode */ | |
5350 { | |
5351 VIsual_select = !VIsual_select; | |
5352 showmode(); | |
5353 } | |
5735 | 5354 else if (!checkclearop(cap->oap)) |
7 | 5355 /* print full name if count given or :cd used */ |
5356 fileinfo((int)cap->count0, FALSE, TRUE); | |
5357 } | |
5358 | |
5359 /* | |
5360 * Handle CTRL-H <Backspace> command. | |
5361 */ | |
5362 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5363 nv_ctrlh(cmdarg_T *cap) |
7 | 5364 { |
5365 if (VIsual_active && VIsual_select) | |
5366 { | |
5367 cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */ | |
5368 v_visop(cap); | |
5369 } | |
5370 else | |
5371 nv_left(cap); | |
5372 } | |
5373 | |
5374 /* | |
5375 * CTRL-L: clear screen and redraw. | |
5376 */ | |
5377 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5378 nv_clear(cmdarg_T *cap) |
7 | 5379 { |
5380 if (!checkclearop(cap->oap)) | |
5381 { | |
5382 #if defined(__BEOS__) && !USE_THREAD_FOR_INPUT_WITH_TIMEOUT | |
5383 /* | |
5384 * Right now, the BeBox doesn't seem to have an easy way to detect | |
5385 * window resizing, so we cheat and make the user detect it | |
5386 * manually with CTRL-L instead | |
5387 */ | |
5388 ui_get_shellsize(); | |
5389 #endif | |
5390 #ifdef FEAT_SYN_HL | |
5391 /* 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
|
5392 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
|
5393 # ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5394 { |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5395 win_T *wp; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5396 |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5397 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
|
5398 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
|
5399 } |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5400 # endif |
7 | 5401 #endif |
5402 redraw_later(CLEAR); | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15866
diff
changeset
|
5403 #if defined(MSWIN) && !defined(FEAT_GUI_MSWIN) |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
5404 resize_console_buf(); |
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
5405 #endif |
7 | 5406 } |
5407 } | |
5408 | |
5409 /* | |
5410 * CTRL-O: In Select mode: switch to Visual mode for one command. | |
5411 * Otherwise: Go to older pcmark. | |
5412 */ | |
5413 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5414 nv_ctrlo(cmdarg_T *cap) |
7 | 5415 { |
5416 if (VIsual_active && VIsual_select) | |
5417 { | |
5418 VIsual_select = FALSE; | |
5419 showmode(); | |
5420 restart_VIsual_select = 2; /* restart Select mode later */ | |
5421 } | |
5422 else | |
5423 { | |
5424 cap->count1 = -cap->count1; | |
5425 nv_pcmark(cap); | |
5426 } | |
5427 } | |
5428 | |
5429 /* | |
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
|
5430 * 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
|
5431 * not named. |
7 | 5432 */ |
5433 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5434 nv_hat(cmdarg_T *cap) |
7 | 5435 { |
5436 if (!checkclearopq(cap->oap)) | |
5437 (void)buflist_getfile((int)cap->count0, (linenr_T)0, | |
5438 GETF_SETMARK|GETF_ALT, FALSE); | |
5439 } | |
5440 | |
5441 /* | |
5442 * "Z" commands. | |
5443 */ | |
5444 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5445 nv_Zet(cmdarg_T *cap) |
7 | 5446 { |
5447 if (!checkclearopq(cap->oap)) | |
5448 { | |
5449 switch (cap->nchar) | |
5450 { | |
5451 /* "ZZ": equivalent to ":x". */ | |
5452 case 'Z': do_cmdline_cmd((char_u *)"x"); | |
5453 break; | |
5454 | |
5455 /* "ZQ": equivalent to ":q!" (Elvis compatible). */ | |
5456 case 'Q': do_cmdline_cmd((char_u *)"q!"); | |
5457 break; | |
5458 | |
5459 default: clearopbeep(cap->oap); | |
5460 } | |
5461 } | |
5462 } | |
5463 | |
5464 /* | |
5465 * Call nv_ident() as if "c1" was used, with "c2" as next character. | |
5466 */ | |
5467 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5468 do_nv_ident(int c1, int c2) |
7 | 5469 { |
5470 oparg_T oa; | |
5471 cmdarg_T ca; | |
5472 | |
5473 clear_oparg(&oa); | |
5474 vim_memset(&ca, 0, sizeof(ca)); | |
5475 ca.oap = &oa; | |
5476 ca.cmdchar = c1; | |
5477 ca.nchar = c2; | |
5478 nv_ident(&ca); | |
5479 } | |
5480 | |
5481 /* | |
5482 * Handle the commands that use the word under the cursor. | |
5483 * [g] CTRL-] :ta to current identifier | |
5484 * [g] 'K' run program for current identifier | |
5485 * [g] '*' / to current identifier or string | |
5486 * [g] '#' ? to current identifier or string | |
5487 * g ']' :tselect for current identifier | |
5488 */ | |
5489 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5490 nv_ident(cmdarg_T *cap) |
7 | 5491 { |
5492 char_u *ptr = NULL; | |
5493 char_u *buf; | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5494 unsigned buflen; |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5495 char_u *newbuf; |
7 | 5496 char_u *p; |
5497 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
|
5498 int kp_help; /* 'keywordprg' is ":he" */ |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5499 int kp_ex; /* 'keywordprg' starts with ":" */ |
7 | 5500 int n = 0; /* init for GCC */ |
5501 int cmdchar; | |
5502 int g_cmd; /* "g" command */ | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5503 int tag_cmd = FALSE; |
7 | 5504 char_u *aux_ptr; |
5505 int isman; | |
5506 int isman_s; | |
5507 | |
5508 if (cap->cmdchar == 'g') /* "g*", "g#", "g]" and "gCTRL-]" */ | |
5509 { | |
5510 cmdchar = cap->nchar; | |
5511 g_cmd = TRUE; | |
5512 } | |
5513 else | |
5514 { | |
5515 cmdchar = cap->cmdchar; | |
5516 g_cmd = FALSE; | |
5517 } | |
5518 | |
5519 if (cmdchar == POUND) /* the pound sign, '#' for English keyboards */ | |
5520 cmdchar = '#'; | |
5521 | |
5522 /* | |
5523 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode. | |
5524 */ | |
5525 if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') | |
5526 { | |
5527 if (VIsual_active && get_visual_text(cap, &ptr, &n) == FAIL) | |
5528 return; | |
5529 if (checkclearopq(cap->oap)) | |
5530 return; | |
5531 } | |
5532 | |
5533 if (ptr == NULL && (n = find_ident_under_cursor(&ptr, | |
5534 (cmdchar == '*' || cmdchar == '#') | |
5535 ? FIND_IDENT|FIND_STRING : FIND_IDENT)) == 0) | |
5536 { | |
5537 clearop(cap->oap); | |
5538 return; | |
5539 } | |
5540 | |
5541 /* Allocate buffer to put the command in. Inserting backslashes can | |
5542 * double the length of the word. p_kp / curbuf->b_p_kp could be added | |
5543 * and some numbers. */ | |
5544 kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); | |
5545 kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 | |
5546 || 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
|
5547 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
|
5548 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
5549 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
|
5550 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
|
5551 } |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5552 kp_ex = (*kp == ':'); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5553 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
|
5554 buf = alloc(buflen); |
7 | 5555 if (buf == NULL) |
5556 return; | |
5557 buf[0] = NUL; | |
5558 | |
5559 switch (cmdchar) | |
5560 { | |
5561 case '*': | |
5562 case '#': | |
5563 /* | |
5564 * Put cursor at start of word, makes search skip the word | |
5565 * under the cursor. | |
5566 * Call setpcmark() first, so "*``" puts the cursor back where | |
5567 * it was. | |
5568 */ | |
5569 setpcmark(); | |
5570 curwin->w_cursor.col = (colnr_T) (ptr - ml_get_curline()); | |
5571 | |
5572 if (!g_cmd && vim_iswordp(ptr)) | |
5573 STRCPY(buf, "\\<"); | |
5574 no_smartcase = TRUE; /* don't use 'smartcase' now */ | |
5575 break; | |
5576 | |
5577 case 'K': | |
5578 if (kp_help) | |
5579 STRCPY(buf, "he! "); | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5580 else if (kp_ex) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5581 { |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5582 if (cap->count0 != 0) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5583 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
|
5584 kp, cap->count0); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5585 else |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5586 STRCPY(buf, kp); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5587 STRCAT(buf, " "); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5588 } |
7 | 5589 else |
5590 { | |
1712 | 5591 /* An external command will probably use an argument starting |
5592 * with "-" as an option. To avoid trouble we skip the "-". */ | |
1728 | 5593 while (*ptr == '-' && n > 0) |
5594 { | |
1712 | 5595 ++ptr; |
1728 | 5596 --n; |
5597 } | |
5598 if (n == 0) | |
5599 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
5600 emsg(_(e_noident)); /* found dashes only */ |
1728 | 5601 vim_free(buf); |
5602 return; | |
5603 } | |
1712 | 5604 |
7 | 5605 /* When a count is given, turn it into a range. Is this |
5606 * really what we want? */ | |
5607 isman = (STRCMP(kp, "man") == 0); | |
5608 isman_s = (STRCMP(kp, "man -s") == 0); | |
5609 if (cap->count0 != 0 && !(isman || isman_s)) | |
5610 sprintf((char *)buf, ".,.+%ld", cap->count0 - 1); | |
5611 | |
5612 STRCAT(buf, "! "); | |
5613 if (cap->count0 == 0 && isman_s) | |
5614 STRCAT(buf, "man"); | |
5615 else | |
5616 STRCAT(buf, kp); | |
5617 STRCAT(buf, " "); | |
5618 if (cap->count0 != 0 && (isman || isman_s)) | |
5619 { | |
5620 sprintf((char *)buf + STRLEN(buf), "%ld", cap->count0); | |
5621 STRCAT(buf, " "); | |
5622 } | |
5623 } | |
5624 break; | |
5625 | |
5626 case ']': | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5627 tag_cmd = TRUE; |
7 | 5628 #ifdef FEAT_CSCOPE |
5629 if (p_cst) | |
5630 STRCPY(buf, "cstag "); | |
5631 else | |
5632 #endif | |
5633 STRCPY(buf, "ts "); | |
5634 break; | |
5635 | |
5636 default: | |
2112
6b5d641bcdd4
updated for version 7.2.395
Bram Moolenaar <bram@zimbu.org>
parents:
2049
diff
changeset
|
5637 tag_cmd = TRUE; |
7 | 5638 if (curbuf->b_help) |
5639 STRCPY(buf, "he! "); | |
5640 else | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5641 { |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5642 if (g_cmd) |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5643 STRCPY(buf, "tj "); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5644 else |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5645 sprintf((char *)buf, "%ldta ", cap->count0); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5646 } |
7 | 5647 } |
5648 | |
5649 /* | |
5650 * Now grab the chars in the identifier | |
5651 */ | |
1712 | 5652 if (cmdchar == 'K' && !kp_help) |
5653 { | |
1728 | 5654 ptr = vim_strnsave(ptr, n); |
10330
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5655 if (kp_ex) |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5656 /* 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
|
5657 p = vim_strsave_fnameescape(ptr, FALSE); |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5658 else |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5659 /* 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
|
5660 p = vim_strsave_shellescape(ptr, TRUE, TRUE); |
1728 | 5661 vim_free(ptr); |
1712 | 5662 if (p == NULL) |
5663 { | |
5664 vim_free(buf); | |
5665 return; | |
5666 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5667 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
|
5668 if (newbuf == NULL) |
1712 | 5669 { |
5670 vim_free(buf); | |
5671 vim_free(p); | |
5672 return; | |
5673 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5674 buf = newbuf; |
1712 | 5675 STRCAT(buf, p); |
5676 vim_free(p); | |
5677 } | |
7 | 5678 else |
1712 | 5679 { |
5680 if (cmdchar == '*') | |
5681 aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\"); | |
5682 else if (cmdchar == '#') | |
5683 aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\"); | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5684 else if (tag_cmd) |
2603 | 5685 { |
5686 if (curbuf->b_help) | |
5687 /* ":help" handles unescaped argument */ | |
5688 aux_ptr = (char_u *)""; | |
5689 else | |
5690 aux_ptr = (char_u *)"\\|\"\n["; | |
5691 } | |
1712 | 5692 else |
5693 aux_ptr = (char_u *)"\\|\"\n*?["; | |
5694 | |
5695 p = buf + STRLEN(buf); | |
5696 while (n-- > 0) | |
5697 { | |
5698 /* put a backslash before \ and some others */ | |
5699 if (vim_strchr(aux_ptr, *ptr) != NULL) | |
5700 *p++ = '\\'; | |
5701 /* When current byte is a part of multibyte character, copy all | |
5702 * bytes of that character. */ | |
5703 if (has_mbyte) | |
5704 { | |
5705 int i; | |
5706 int len = (*mb_ptr2len)(ptr) - 1; | |
5707 | |
5708 for (i = 0; i < len && n >= 1; ++i, --n) | |
5709 *p++ = *ptr++; | |
5710 } | |
5711 *p++ = *ptr++; | |
5712 } | |
5713 *p = NUL; | |
5714 } | |
7 | 5715 |
5716 /* | |
5717 * Execute the command. | |
5718 */ | |
5719 if (cmdchar == '*' || cmdchar == '#') | |
5720 { | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5721 if (!g_cmd && (has_mbyte |
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5722 ? vim_iswordp(mb_prevptr(ml_get_curline(), ptr)) |
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5723 : vim_iswordc(ptr[-1]))) |
7 | 5724 STRCAT(buf, "\\>"); |
5725 #ifdef FEAT_CMDHIST | |
5726 /* put pattern in search history */ | |
2024 | 5727 init_history(); |
7 | 5728 add_to_history(HIST_SEARCH, buf, TRUE, NUL); |
5729 #endif | |
6620 | 5730 (void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0); |
7 | 5731 } |
5732 else | |
5733 do_cmdline_cmd(buf); | |
5734 | |
5735 vim_free(buf); | |
5736 } | |
5737 | |
5738 /* | |
5739 * Get visually selected text, within one line only. | |
5740 * Returns FAIL if more than one line selected. | |
5741 */ | |
344 | 5742 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5743 get_visual_text( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5744 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5745 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
|
5746 int *lenp) /* return: length of selected text */ |
7 | 5747 { |
5748 if (VIsual_mode != 'V') | |
5749 unadjust_for_sel(); | |
5750 if (VIsual.lnum != curwin->w_cursor.lnum) | |
5751 { | |
344 | 5752 if (cap != NULL) |
5753 clearopbeep(cap->oap); | |
7 | 5754 return FAIL; |
5755 } | |
5756 if (VIsual_mode == 'V') | |
5757 { | |
5758 *pp = ml_get_curline(); | |
5759 *lenp = (int)STRLEN(*pp); | |
5760 } | |
5761 else | |
5762 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5763 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 5764 { |
5765 *pp = ml_get_pos(&curwin->w_cursor); | |
5766 *lenp = VIsual.col - curwin->w_cursor.col + 1; | |
5767 } | |
5768 else | |
5769 { | |
5770 *pp = ml_get_pos(&VIsual); | |
5771 *lenp = curwin->w_cursor.col - VIsual.col + 1; | |
5772 } | |
5773 if (has_mbyte) | |
5774 /* Correct the length to include the whole last character. */ | |
474 | 5775 *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; |
7 | 5776 } |
5777 reset_VIsual_and_resel(); | |
5778 return OK; | |
5779 } | |
5780 | |
5781 /* | |
5782 * CTRL-T: backwards in tag stack | |
5783 */ | |
5784 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5785 nv_tagpop(cmdarg_T *cap) |
7 | 5786 { |
5787 if (!checkclearopq(cap->oap)) | |
5788 do_tag((char_u *)"", DT_POP, (int)cap->count1, FALSE, TRUE); | |
5789 } | |
5790 | |
5791 /* | |
5792 * Handle scrolling command 'H', 'L' and 'M'. | |
5793 */ | |
5794 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5795 nv_scroll(cmdarg_T *cap) |
7 | 5796 { |
5797 int used = 0; | |
5798 long n; | |
5799 #ifdef FEAT_FOLDING | |
5800 linenr_T lnum; | |
5801 #endif | |
5802 int half; | |
5803 | |
5804 cap->oap->motion_type = MLINE; | |
5805 setpcmark(); | |
5806 | |
5807 if (cap->cmdchar == 'L') | |
5808 { | |
5809 validate_botline(); /* make sure curwin->w_botline is valid */ | |
5810 curwin->w_cursor.lnum = curwin->w_botline - 1; | |
5811 if (cap->count1 - 1 >= curwin->w_cursor.lnum) | |
5812 curwin->w_cursor.lnum = 1; | |
5813 else | |
9 | 5814 { |
5815 #ifdef FEAT_FOLDING | |
5816 if (hasAnyFolding(curwin)) | |
5817 { | |
5818 /* Count a fold for one screen line. */ | |
5819 for (n = cap->count1 - 1; n > 0 | |
5820 && curwin->w_cursor.lnum > curwin->w_topline; --n) | |
5821 { | |
5822 (void)hasFolding(curwin->w_cursor.lnum, | |
5823 &curwin->w_cursor.lnum, NULL); | |
5824 --curwin->w_cursor.lnum; | |
5825 } | |
5826 } | |
5827 else | |
5828 #endif | |
5829 curwin->w_cursor.lnum -= cap->count1 - 1; | |
5830 } | |
7 | 5831 } |
5832 else | |
5833 { | |
5834 if (cap->cmdchar == 'M') | |
5835 { | |
5836 #ifdef FEAT_DIFF | |
5837 /* Don't count filler lines above the window. */ | |
5838 used -= diff_check_fill(curwin, curwin->w_topline) | |
5839 - curwin->w_topfill; | |
5840 #endif | |
5841 validate_botline(); /* make sure w_empty_rows is valid */ | |
5842 half = (curwin->w_height - curwin->w_empty_rows + 1) / 2; | |
5843 for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) | |
5844 { | |
5845 #ifdef FEAT_DIFF | |
5846 /* Count half he number of filler lines to be "below this | |
5847 * line" and half to be "above the next line". */ | |
5848 if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline | |
5849 + n) / 2 >= half) | |
5850 { | |
5851 --n; | |
5852 break; | |
5853 } | |
5854 #endif | |
5855 used += plines(curwin->w_topline + n); | |
5856 if (used >= half) | |
5857 break; | |
5858 #ifdef FEAT_FOLDING | |
5859 if (hasFolding(curwin->w_topline + n, NULL, &lnum)) | |
5860 n = lnum - curwin->w_topline; | |
5861 #endif | |
5862 } | |
5863 if (n > 0 && used > curwin->w_height) | |
5864 --n; | |
5865 } | |
9 | 5866 else /* (cap->cmdchar == 'H') */ |
5867 { | |
7 | 5868 n = cap->count1 - 1; |
9 | 5869 #ifdef FEAT_FOLDING |
5870 if (hasAnyFolding(curwin)) | |
5871 { | |
5872 /* Count a fold for one screen line. */ | |
5873 lnum = curwin->w_topline; | |
5874 while (n-- > 0 && lnum < curwin->w_botline - 1) | |
5875 { | |
7009 | 5876 (void)hasFolding(lnum, NULL, &lnum); |
9 | 5877 ++lnum; |
5878 } | |
5879 n = lnum - curwin->w_topline; | |
5880 } | |
5881 #endif | |
5882 } | |
7 | 5883 curwin->w_cursor.lnum = curwin->w_topline + n; |
5884 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
5885 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
5886 } | |
5887 | |
12646
b908a3682f6e
patch 8.0.1201: "yL" is affected by 'scrolloff'
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
5888 /* 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
|
5889 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
|
5890 cursor_correct(); |
7 | 5891 beginline(BL_SOL | BL_FIX); |
5892 } | |
5893 | |
5894 /* | |
5895 * Cursor right commands. | |
5896 */ | |
5897 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5898 nv_right(cmdarg_T *cap) |
7 | 5899 { |
5900 long n; | |
5735 | 5901 int past_line; |
7 | 5902 |
180 | 5903 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
5904 { | |
5905 /* <C-Right> and <S-Right> move a word or WORD right */ | |
5906 if (mod_mask & MOD_MASK_CTRL) | |
5907 cap->arg = TRUE; | |
5908 nv_wordcmd(cap); | |
5909 return; | |
5910 } | |
5911 | |
7 | 5912 cap->oap->motion_type = MCHAR; |
5913 cap->oap->inclusive = FALSE; | |
5735 | 5914 past_line = (VIsual_active && *p_sel != 'o'); |
5915 | |
7 | 5916 /* |
5735 | 5917 * In virtual edit mode, there's no such thing as "past_line", as lines |
5918 * are (theoretically) infinitely long. | |
7 | 5919 */ |
5920 if (virtual_active()) | |
5735 | 5921 past_line = 0; |
7 | 5922 |
5923 for (n = cap->count1; n > 0; --n) | |
5924 { | |
5735 | 5925 if ((!past_line && oneright() == FAIL) |
5926 || (past_line && *ml_get_cursor() == NUL) | |
1877 | 5927 ) |
7 | 5928 { |
5929 /* | |
714 | 5930 * <Space> wraps to next line if 'whichwrap' has 's'. |
5931 * 'l' wraps to next line if 'whichwrap' has 'l'. | |
5932 * CURS_RIGHT wraps to next line if 'whichwrap' has '>'. | |
7 | 5933 */ |
5934 if ( ((cap->cmdchar == ' ' | |
5935 && vim_strchr(p_ww, 's') != NULL) | |
5936 || (cap->cmdchar == 'l' | |
5937 && vim_strchr(p_ww, 'l') != NULL) | |
229 | 5938 || (cap->cmdchar == K_RIGHT |
7 | 5939 && vim_strchr(p_ww, '>') != NULL)) |
5940 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
5941 { | |
5942 /* When deleting we also count the NL as a character. | |
5943 * Set cap->oap->inclusive when last char in the line is | |
5944 * included, move to next line after that */ | |
714 | 5945 if ( cap->oap->op_type != OP_NOP |
7 | 5946 && !cap->oap->inclusive |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5947 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 5948 cap->oap->inclusive = TRUE; |
5949 else | |
5950 { | |
5951 ++curwin->w_cursor.lnum; | |
5952 curwin->w_cursor.col = 0; | |
5953 curwin->w_cursor.coladd = 0; | |
5954 curwin->w_set_curswant = TRUE; | |
5955 cap->oap->inclusive = FALSE; | |
5956 } | |
5957 continue; | |
5958 } | |
5959 if (cap->oap->op_type == OP_NOP) | |
5960 { | |
5961 /* Only beep and flush if not moved at all */ | |
5962 if (n == cap->count1) | |
5963 beep_flush(); | |
5964 } | |
5965 else | |
5966 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5967 if (!LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 5968 cap->oap->inclusive = TRUE; |
5969 } | |
5970 break; | |
5971 } | |
5735 | 5972 else if (past_line) |
7 | 5973 { |
5974 curwin->w_set_curswant = TRUE; | |
5975 if (virtual_active()) | |
5976 oneright(); | |
5977 else | |
5735 | 5978 { |
7 | 5979 if (has_mbyte) |
5980 curwin->w_cursor.col += | |
474 | 5981 (*mb_ptr2len)(ml_get_cursor()); |
7 | 5982 else |
5983 ++curwin->w_cursor.col; | |
5984 } | |
5985 } | |
5986 } | |
5987 #ifdef FEAT_FOLDING | |
5988 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
5989 && cap->oap->op_type == OP_NOP) | |
5990 foldOpenCursor(); | |
5991 #endif | |
5992 } | |
5993 | |
5994 /* | |
5995 * Cursor left commands. | |
5996 * | |
5997 * Returns TRUE when operator end should not be adjusted. | |
5998 */ | |
5999 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6000 nv_left(cmdarg_T *cap) |
7 | 6001 { |
6002 long n; | |
6003 | |
180 | 6004 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
6005 { | |
6006 /* <C-Left> and <S-Left> move a word or WORD left */ | |
6007 if (mod_mask & MOD_MASK_CTRL) | |
6008 cap->arg = 1; | |
6009 nv_bck_word(cap); | |
6010 return; | |
6011 } | |
6012 | |
7 | 6013 cap->oap->motion_type = MCHAR; |
6014 cap->oap->inclusive = FALSE; | |
6015 for (n = cap->count1; n > 0; --n) | |
6016 { | |
6017 if (oneleft() == FAIL) | |
6018 { | |
6019 /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'. | |
6020 * 'h' wraps to previous line if 'whichwrap' has 'h'. | |
6021 * CURS_LEFT wraps to previous line if 'whichwrap' has '<'. | |
6022 */ | |
6023 if ( (((cap->cmdchar == K_BS | |
6024 || cap->cmdchar == Ctrl_H) | |
6025 && vim_strchr(p_ww, 'b') != NULL) | |
6026 || (cap->cmdchar == 'h' | |
6027 && vim_strchr(p_ww, 'h') != NULL) | |
229 | 6028 || (cap->cmdchar == K_LEFT |
7 | 6029 && vim_strchr(p_ww, '<') != NULL)) |
6030 && curwin->w_cursor.lnum > 1) | |
6031 { | |
6032 --(curwin->w_cursor.lnum); | |
6033 coladvance((colnr_T)MAXCOL); | |
6034 curwin->w_set_curswant = TRUE; | |
6035 | |
6036 /* When the NL before the first char has to be deleted we | |
6037 * put the cursor on the NUL after the previous line. | |
6038 * This is a very special case, be careful! | |
1469 | 6039 * Don't adjust op_end now, otherwise it won't work. */ |
7 | 6040 if ( (cap->oap->op_type == OP_DELETE |
6041 || 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
|
6042 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6043 { |
5682 | 6044 char_u *cp = ml_get_cursor(); |
6045 | |
6046 if (*cp != NUL) | |
6047 { | |
6048 if (has_mbyte) | |
6049 curwin->w_cursor.col += (*mb_ptr2len)(cp); | |
6050 else | |
6051 ++curwin->w_cursor.col; | |
6052 } | |
7 | 6053 cap->retval |= CA_NO_ADJ_OP_END; |
6054 } | |
6055 continue; | |
6056 } | |
6057 /* Only beep and flush if not moved at all */ | |
6058 else if (cap->oap->op_type == OP_NOP && n == cap->count1) | |
6059 beep_flush(); | |
6060 break; | |
6061 } | |
6062 } | |
6063 #ifdef FEAT_FOLDING | |
6064 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
6065 && cap->oap->op_type == OP_NOP) | |
6066 foldOpenCursor(); | |
6067 #endif | |
6068 } | |
6069 | |
6070 /* | |
6071 * Cursor up commands. | |
6072 * cap->arg is TRUE for "-": Move cursor to first non-blank. | |
6073 */ | |
6074 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6075 nv_up(cmdarg_T *cap) |
7 | 6076 { |
180 | 6077 if (mod_mask & MOD_MASK_SHIFT) |
6078 { | |
6079 /* <S-Up> is page up */ | |
6080 cap->arg = BACKWARD; | |
6081 nv_page(cap); | |
6082 } | |
6083 else | |
6084 { | |
6085 cap->oap->motion_type = MLINE; | |
6086 if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
6087 clearopbeep(cap->oap); | |
6088 else if (cap->arg) | |
6089 beginline(BL_WHITE | BL_FIX); | |
6090 } | |
7 | 6091 } |
6092 | |
6093 /* | |
6094 * Cursor down commands. | |
6095 * cap->arg is TRUE for CR and "+": Move cursor to first non-blank. | |
6096 */ | |
6097 static void | |
10192
758f3d5a463d
commit https://github.com/vim/vim/commit/1b010058235fb803c1d4f42a02d2883921be8ef4
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
6098 nv_down(cmdarg_T *cap) |
7 | 6099 { |
180 | 6100 if (mod_mask & MOD_MASK_SHIFT) |
6101 { | |
6102 /* <S-Down> is page down */ | |
6103 cap->arg = FORWARD; | |
6104 nv_page(cap); | |
6105 } | |
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
|
6106 #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
|
6107 /* 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
|
6108 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
|
6109 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
|
6110 #endif |
180 | 6111 else |
7 | 6112 { |
6113 #ifdef FEAT_CMDWIN | |
6114 /* In the cmdline window a <CR> executes the command. */ | |
170 | 6115 if (cmdwin_type != 0 && cap->cmdchar == CAR) |
7 | 6116 cmdwin_result = CAR; |
6117 else | |
6118 #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
|
6119 #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
|
6120 /* 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
|
6121 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
|
6122 && 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
|
6123 { |
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
|
6124 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
|
6125 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
|
6126 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
|
6127 } |
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
|
6128 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
|
6129 #endif |
7 | 6130 { |
6131 cap->oap->motion_type = MLINE; | |
6132 if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
6133 clearopbeep(cap->oap); | |
6134 else if (cap->arg) | |
6135 beginline(BL_WHITE | BL_FIX); | |
6136 } | |
6137 } | |
6138 } | |
6139 | |
6140 #ifdef FEAT_SEARCHPATH | |
6141 /* | |
6142 * Grab the file name under the cursor and edit it. | |
6143 */ | |
6144 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6145 nv_gotofile(cmdarg_T *cap) |
7 | 6146 { |
6147 char_u *ptr; | |
681 | 6148 linenr_T lnum = -1; |
7 | 6149 |
633 | 6150 if (text_locked()) |
7 | 6151 { |
6152 clearopbeep(cap->oap); | |
633 | 6153 text_locked_msg(); |
7 | 6154 return; |
6155 } | |
819 | 6156 if (curbuf_locked()) |
6157 { | |
6158 clearop(cap->oap); | |
6159 return; | |
6160 } | |
7 | 6161 |
681 | 6162 ptr = grab_file_name(cap->count1, &lnum); |
7 | 6163 |
6164 if (ptr != NULL) | |
6165 { | |
6166 /* 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
|
6167 if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !buf_hide(curbuf)) |
7009 | 6168 (void)autowrite(curbuf, FALSE); |
7 | 6169 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
|
6170 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
|
6171 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
|
6172 && cap->nchar == 'F' && lnum >= 0) |
681 | 6173 { |
6174 curwin->w_cursor.lnum = lnum; | |
6175 check_cursor_lnum(); | |
6176 beginline(BL_SOL | BL_FIX); | |
6177 } | |
7 | 6178 vim_free(ptr); |
6179 } | |
6180 else | |
6181 clearop(cap->oap); | |
6182 } | |
6183 #endif | |
6184 | |
6185 /* | |
6186 * <End> command: to end of current line or last line. | |
6187 */ | |
6188 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6189 nv_end(cmdarg_T *cap) |
7 | 6190 { |
180 | 6191 if (cap->arg || (mod_mask & MOD_MASK_CTRL)) /* CTRL-END = goto last line */ |
6192 { | |
6193 cap->arg = TRUE; | |
7 | 6194 nv_goto(cap); |
6195 cap->count1 = 1; /* to end of current line */ | |
6196 } | |
6197 nv_dollar(cap); | |
6198 } | |
6199 | |
6200 /* | |
6201 * Handle the "$" command. | |
6202 */ | |
6203 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6204 nv_dollar(cmdarg_T *cap) |
7 | 6205 { |
6206 cap->oap->motion_type = MCHAR; | |
6207 cap->oap->inclusive = TRUE; | |
6208 /* In virtual mode when off the edge of a line and an operator | |
6209 * is pending (whew!) keep the cursor where it is. | |
6210 * Otherwise, send it to the end of the line. */ | |
6211 if (!virtual_active() || gchar_cursor() != NUL | |
6212 || cap->oap->op_type == OP_NOP) | |
6213 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
6214 if (cursor_down((long)(cap->count1 - 1), | |
6215 cap->oap->op_type == OP_NOP) == FAIL) | |
6216 clearopbeep(cap->oap); | |
6217 #ifdef FEAT_FOLDING | |
6218 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6219 foldOpenCursor(); | |
6220 #endif | |
6221 } | |
6222 | |
6223 /* | |
6224 * Implementation of '?' and '/' commands. | |
6225 * If cap->arg is TRUE don't set PC mark. | |
6226 */ | |
6227 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6228 nv_search(cmdarg_T *cap) |
7 | 6229 { |
6230 oparg_T *oap = cap->oap; | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6231 pos_T save_cursor = curwin->w_cursor; |
7 | 6232 |
6233 if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13) | |
6234 { | |
6235 /* Translate "g??" to "g?g?" */ | |
6236 cap->cmdchar = 'g'; | |
6237 cap->nchar = '?'; | |
6238 nv_operator(cap); | |
6239 return; | |
6240 } | |
6241 | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6242 /* 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
|
6243 * start position. */ |
7 | 6244 cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0); |
6245 | |
6246 if (cap->searchbuf == NULL) | |
6247 { | |
6248 clearop(oap); | |
6249 return; | |
6250 } | |
6251 | |
6620 | 6252 (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
|
6253 (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
|
6254 ? 0 : SEARCH_MARK); |
7 | 6255 } |
6256 | |
6257 /* | |
6258 * Handle "N" and "n" commands. | |
6259 * cap->arg is SEARCH_REV for "N", 0 for "n". | |
6260 */ | |
6261 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6262 nv_next(cmdarg_T *cap) |
7 | 6263 { |
6620 | 6264 pos_T old = curwin->w_cursor; |
6265 int i = normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
6266 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6267 if (i == 1 && EQUAL_POS(old, curwin->w_cursor)) |
6620 | 6268 { |
6269 /* Avoid getting stuck on the current cursor position, which can | |
6270 * happen when an offset is given and the cursor is on the last char | |
6271 * in the buffer: Repeat with count + 1. */ | |
6272 cap->count1 += 1; | |
6273 (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
6274 cap->count1 -= 1; | |
6275 } | |
7 | 6276 } |
6277 | |
6278 /* | |
6279 * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat). | |
6280 * Uses only cap->count1 and cap->oap from "cap". | |
6620 | 6281 * Return 0 for failure, 1 for found, 2 for found and line offset added. |
6282 */ | |
6283 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6284 normal_search( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6285 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6286 int dir, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6287 char_u *pat, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6288 int opt) /* extra flags for do_search() */ |
7 | 6289 { |
6290 int i; | |
6291 | |
6292 cap->oap->motion_type = MCHAR; | |
6293 cap->oap->inclusive = FALSE; | |
6294 cap->oap->use_reg_one = TRUE; | |
6295 curwin->w_set_curswant = TRUE; | |
6296 | |
6297 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
|
6298 opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL, NULL); |
7 | 6299 if (i == 0) |
6300 clearop(cap->oap); | |
6301 else | |
6302 { | |
6303 if (i == 2) | |
6304 cap->oap->motion_type = MLINE; | |
6305 curwin->w_cursor.coladd = 0; | |
6306 #ifdef FEAT_FOLDING | |
6307 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
6308 foldOpenCursor(); | |
6309 #endif | |
6310 } | |
6311 | |
6312 /* "/$" will put the cursor after the end of the line, may need to | |
6313 * correct that here */ | |
6314 check_cursor(); | |
6620 | 6315 return i; |
7 | 6316 } |
6317 | |
6318 /* | |
6319 * Character search commands. | |
6320 * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for | |
6321 * ',' and FALSE for ';'. | |
6322 * cap->nchar is NUL for ',' and ';' (repeat the search) | |
6323 */ | |
6324 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6325 nv_csearch(cmdarg_T *cap) |
7 | 6326 { |
6327 int t_cmd; | |
6328 | |
6329 if (cap->cmdchar == 't' || cap->cmdchar == 'T') | |
6330 t_cmd = TRUE; | |
6331 else | |
6332 t_cmd = FALSE; | |
6333 | |
6334 cap->oap->motion_type = MCHAR; | |
6335 if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL) | |
6336 clearopbeep(cap->oap); | |
6337 else | |
6338 { | |
6339 curwin->w_set_curswant = TRUE; | |
6340 /* Include a Tab for "tx" and for "dfx". */ | |
6341 if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD | |
6342 && (t_cmd || cap->oap->op_type != OP_NOP)) | |
6343 { | |
6344 colnr_T scol, ecol; | |
6345 | |
6346 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
6347 curwin->w_cursor.coladd = ecol - scol; | |
6348 } | |
6349 else | |
6350 curwin->w_cursor.coladd = 0; | |
6351 adjust_for_sel(cap); | |
6352 #ifdef FEAT_FOLDING | |
6353 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6354 foldOpenCursor(); | |
6355 #endif | |
6356 } | |
6357 } | |
6358 | |
6359 /* | |
6360 * "[" and "]" commands. | |
6361 * cap->arg is BACKWARD for "[" and FORWARD for "]". | |
6362 */ | |
6363 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6364 nv_brackets(cmdarg_T *cap) |
7 | 6365 { |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
6366 pos_T new_pos = {0, 0, 0}; |
7 | 6367 pos_T prev_pos; |
6368 pos_T *pos = NULL; /* init for GCC */ | |
6369 pos_T old_pos; /* cursor position before command */ | |
6370 int flag; | |
6371 long n; | |
6372 int findc; | |
6373 int c; | |
6374 | |
6375 cap->oap->motion_type = MCHAR; | |
6376 cap->oap->inclusive = FALSE; | |
6377 old_pos = curwin->w_cursor; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6378 curwin->w_cursor.coladd = 0; // TODO: don't do this for an error. |
7 | 6379 |
6380 #ifdef FEAT_SEARCHPATH | |
6381 /* | |
6382 * "[f" or "]f" : Edit file under the cursor (same as "gf") | |
6383 */ | |
6384 if (cap->nchar == 'f') | |
6385 nv_gotofile(cap); | |
6386 else | |
6387 #endif | |
6388 | |
6389 #ifdef FEAT_FIND_ID | |
6390 /* | |
1188 | 6391 * Find the occurrence(s) of the identifier or define under cursor |
6392 * in current and included files or jump to the first occurrence. | |
7 | 6393 * |
6394 * search list jump | |
6395 * fwd bwd fwd bwd fwd bwd | |
6396 * identifier "]i" "[i" "]I" "[I" "]^I" "[^I" | |
6397 * define "]d" "[d" "]D" "[D" "]^D" "[^D" | |
6398 */ | |
6399 if (vim_strchr((char_u *) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6400 # ifdef EBCDIC |
7 | 6401 "iI\005dD\067", |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6402 # else |
7 | 6403 "iI\011dD\004", |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6404 # endif |
7 | 6405 cap->nchar) != NULL) |
6406 { | |
6407 char_u *ptr; | |
6408 int len; | |
6409 | |
6410 if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) | |
6411 clearop(cap->oap); | |
6412 else | |
6413 { | |
6414 find_pattern_in_path(ptr, 0, len, TRUE, | |
6415 cap->count0 == 0 ? !isupper(cap->nchar) : FALSE, | |
6416 ((cap->nchar & 0xf) == ('d' & 0xf)) ? FIND_DEFINE : FIND_ANY, | |
6417 cap->count1, | |
6418 isupper(cap->nchar) ? ACTION_SHOW_ALL : | |
6419 islower(cap->nchar) ? ACTION_SHOW : ACTION_GOTO, | |
6420 cap->cmdchar == ']' ? curwin->w_cursor.lnum + 1 : (linenr_T)1, | |
6421 (linenr_T)MAXLNUM); | |
6422 curwin->w_set_curswant = TRUE; | |
6423 } | |
6424 } | |
6425 else | |
6426 #endif | |
6427 | |
6428 /* | |
6429 * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')' | |
6430 * "[#", "]#": go to start/end of Nth innermost #if..#endif construct. | |
6431 * "[/", "[*", "]/", "]*": go to Nth comment start/end. | |
6432 * "[m" or "]m" search for prev/next start of (Java) method. | |
6433 * "[M" or "]M" search for prev/next end of (Java) method. | |
6434 */ | |
6435 if ( (cap->cmdchar == '[' | |
6436 && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL) | |
6437 || (cap->cmdchar == ']' | |
6438 && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) | |
6439 { | |
6440 if (cap->nchar == '*') | |
6441 cap->nchar = '/'; | |
6442 prev_pos.lnum = 0; | |
6443 if (cap->nchar == 'm' || cap->nchar == 'M') | |
6444 { | |
6445 if (cap->cmdchar == '[') | |
6446 findc = '{'; | |
6447 else | |
6448 findc = '}'; | |
6449 n = 9999; | |
6450 } | |
6451 else | |
6452 { | |
6453 findc = cap->nchar; | |
6454 n = cap->count1; | |
6455 } | |
6456 for ( ; n > 0; --n) | |
6457 { | |
6458 if ((pos = findmatchlimit(cap->oap, findc, | |
6459 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) | |
6460 { | |
6461 if (new_pos.lnum == 0) /* nothing found */ | |
6462 { | |
6463 if (cap->nchar != 'm' && cap->nchar != 'M') | |
6464 clearopbeep(cap->oap); | |
6465 } | |
6466 else | |
6467 pos = &new_pos; /* use last one found */ | |
6468 break; | |
6469 } | |
6470 prev_pos = new_pos; | |
6471 curwin->w_cursor = *pos; | |
6472 new_pos = *pos; | |
6473 } | |
6474 curwin->w_cursor = old_pos; | |
6475 | |
6476 /* | |
6477 * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only | |
6478 * brought us to the match for "[m" and "]M" when inside a method. | |
6479 * Try finding the '{' or '}' we want to be at. | |
6480 * Also repeat for the given count. | |
6481 */ | |
6482 if (cap->nchar == 'm' || cap->nchar == 'M') | |
6483 { | |
6484 /* norm is TRUE for "]M" and "[m" */ | |
6485 int norm = ((findc == '{') == (cap->nchar == 'm')); | |
6486 | |
6487 n = cap->count1; | |
6488 /* found a match: we were inside a method */ | |
6489 if (prev_pos.lnum != 0) | |
6490 { | |
6491 pos = &prev_pos; | |
6492 curwin->w_cursor = prev_pos; | |
6493 if (norm) | |
6494 --n; | |
6495 } | |
6496 else | |
6497 pos = NULL; | |
6498 while (n > 0) | |
6499 { | |
6500 for (;;) | |
6501 { | |
6502 if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0) | |
6503 { | |
6504 /* if not found anything, that's an error */ | |
6505 if (pos == NULL) | |
6506 clearopbeep(cap->oap); | |
6507 n = 0; | |
6508 break; | |
6509 } | |
6510 c = gchar_cursor(); | |
6511 if (c == '{' || c == '}') | |
6512 { | |
6513 /* Must have found end/start of class: use it. | |
6514 * Or found the place to be at. */ | |
6515 if ((c == findc && norm) || (n == 1 && !norm)) | |
6516 { | |
6517 new_pos = curwin->w_cursor; | |
6518 pos = &new_pos; | |
6519 n = 0; | |
6520 } | |
6521 /* if no match found at all, we started outside of the | |
6522 * class and we're inside now. Just go on. */ | |
6523 else if (new_pos.lnum == 0) | |
6524 { | |
6525 new_pos = curwin->w_cursor; | |
6526 pos = &new_pos; | |
6527 } | |
6528 /* found start/end of other method: go to match */ | |
6529 else if ((pos = findmatchlimit(cap->oap, findc, | |
6530 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, | |
6531 0)) == NULL) | |
6532 n = 0; | |
6533 else | |
6534 curwin->w_cursor = *pos; | |
6535 break; | |
6536 } | |
6537 } | |
6538 --n; | |
6539 } | |
6540 curwin->w_cursor = old_pos; | |
6541 if (pos == NULL && new_pos.lnum != 0) | |
6542 clearopbeep(cap->oap); | |
6543 } | |
6544 if (pos != NULL) | |
6545 { | |
6546 setpcmark(); | |
6547 curwin->w_cursor = *pos; | |
6548 curwin->w_set_curswant = TRUE; | |
6549 #ifdef FEAT_FOLDING | |
6550 if ((fdo_flags & FDO_BLOCK) && KeyTyped | |
6551 && cap->oap->op_type == OP_NOP) | |
6552 foldOpenCursor(); | |
6553 #endif | |
6554 } | |
6555 } | |
6556 | |
6557 /* | |
6558 * "[[", "[]", "]]" and "][": move to start or end of function | |
6559 */ | |
6560 else if (cap->nchar == '[' || cap->nchar == ']') | |
6561 { | |
6562 if (cap->nchar == cap->cmdchar) /* "]]" or "[[" */ | |
6563 flag = '{'; | |
6564 else | |
6565 flag = '}'; /* "][" or "[]" */ | |
6566 | |
6567 curwin->w_set_curswant = TRUE; | |
6568 /* | |
6569 * Imitate strange Vi behaviour: When using "]]" with an operator | |
6570 * we also stop at '}'. | |
6571 */ | |
503 | 6572 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, flag, |
7 | 6573 (cap->oap->op_type != OP_NOP |
6574 && cap->arg == FORWARD && flag == '{'))) | |
6575 clearopbeep(cap->oap); | |
6576 else | |
6577 { | |
6578 if (cap->oap->op_type == OP_NOP) | |
6579 beginline(BL_WHITE | BL_FIX); | |
6580 #ifdef FEAT_FOLDING | |
6581 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6582 foldOpenCursor(); | |
6583 #endif | |
6584 } | |
6585 } | |
6586 | |
6587 /* | |
6588 * "[p", "[P", "]P" and "]p": put with indent adjustment | |
6589 */ | |
6590 else if (cap->nchar == 'p' || cap->nchar == 'P') | |
6591 { | |
1312 | 6592 if (!checkclearop(cap->oap)) |
7 | 6593 { |
5708 | 6594 int dir = (cap->cmdchar == ']' && cap->nchar == 'p') |
6595 ? FORWARD : BACKWARD; | |
6596 int regname = cap->oap->regname; | |
6597 int was_visual = VIsual_active; | |
6598 int line_count = curbuf->b_ml.ml_line_count; | |
6599 pos_T start, end; | |
6600 | |
6601 if (VIsual_active) | |
6602 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6603 start = LTOREQ_POS(VIsual, curwin->w_cursor) |
5708 | 6604 ? 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
|
6605 end = EQUAL_POS(start,VIsual) ? curwin->w_cursor : VIsual; |
5708 | 6606 curwin->w_cursor = (dir == BACKWARD ? start : end); |
6607 } | |
6608 # ifdef FEAT_CLIPBOARD | |
6609 adjust_clip_reg(®name); | |
6610 # endif | |
7 | 6611 prep_redo_cmd(cap); |
5708 | 6612 |
6613 do_put(regname, dir, cap->count1, PUT_FIXINDENT); | |
6614 if (was_visual) | |
6615 { | |
6616 VIsual = start; | |
6617 curwin->w_cursor = end; | |
6618 if (dir == BACKWARD) | |
6619 { | |
6620 /* adjust lines */ | |
6621 VIsual.lnum += curbuf->b_ml.ml_line_count - line_count; | |
6622 curwin->w_cursor.lnum += | |
6623 curbuf->b_ml.ml_line_count - line_count; | |
6624 } | |
6625 | |
6626 VIsual_active = TRUE; | |
6627 if (VIsual_mode == 'V') | |
6628 { | |
6629 /* delete visually selected lines */ | |
6630 cap->cmdchar = 'd'; | |
6631 cap->nchar = NUL; | |
6632 cap->oap->regname = regname; | |
6633 nv_operator(cap); | |
6634 do_pending_operator(cap, 0, FALSE); | |
6635 } | |
6636 if (VIsual_active) | |
6637 { | |
6638 end_visual_mode(); | |
6639 redraw_later(SOME_VALID); | |
6640 } | |
6641 } | |
7 | 6642 } |
6643 } | |
6644 | |
6645 /* | |
6646 * "['", "[`", "]'" and "]`": jump to next mark | |
6647 */ | |
6648 else if (cap->nchar == '\'' || cap->nchar == '`') | |
6649 { | |
6650 pos = &curwin->w_cursor; | |
6651 for (n = cap->count1; n > 0; --n) | |
6652 { | |
6653 prev_pos = *pos; | |
6654 pos = getnextmark(pos, cap->cmdchar == '[' ? BACKWARD : FORWARD, | |
6655 cap->nchar == '\''); | |
6656 if (pos == NULL) | |
6657 break; | |
6658 } | |
6659 if (pos == NULL) | |
6660 pos = &prev_pos; | |
6661 nv_cursormark(cap, cap->nchar == '\'', pos); | |
6662 } | |
6663 | |
6664 #ifdef FEAT_MOUSE | |
6665 /* | |
6666 * [ or ] followed by a middle mouse click: put selected text with | |
6667 * indent adjustment. Any other button just does as usual. | |
6668 */ | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
6669 else if (cap->nchar >= K_RIGHTRELEASE && cap->nchar <= K_LEFTMOUSE) |
7 | 6670 { |
6671 (void)do_mouse(cap->oap, cap->nchar, | |
6672 (cap->cmdchar == ']') ? FORWARD : BACKWARD, | |
6673 cap->count1, PUT_FIXINDENT); | |
6674 } | |
6675 #endif /* FEAT_MOUSE */ | |
6676 | |
6677 #ifdef FEAT_FOLDING | |
6678 /* | |
6679 * "[z" and "]z": move to start or end of open fold. | |
6680 */ | |
6681 else if (cap->nchar == 'z') | |
6682 { | |
6683 if (foldMoveTo(FALSE, cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
6684 cap->count1) == FAIL) | |
6685 clearopbeep(cap->oap); | |
6686 } | |
6687 #endif | |
6688 | |
6689 #ifdef FEAT_DIFF | |
6690 /* | |
6691 * "[c" and "]c": move to next or previous diff-change. | |
6692 */ | |
6693 else if (cap->nchar == 'c') | |
6694 { | |
6695 if (diff_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
6696 cap->count1) == FAIL) | |
6697 clearopbeep(cap->oap); | |
6698 } | |
6699 #endif | |
6700 | |
737 | 6701 #ifdef FEAT_SPELL |
236 | 6702 /* |
6703 * "[s", "[S", "]s" and "]S": move to next spell error. | |
6704 */ | |
6705 else if (cap->nchar == 's' || cap->nchar == 'S') | |
6706 { | |
249 | 6707 setpcmark(); |
6708 for (n = 0; n < cap->count1; ++n) | |
498 | 6709 if (spell_move_to(curwin, cap->cmdchar == ']' ? FORWARD : BACKWARD, |
6710 cap->nchar == 's' ? TRUE : FALSE, FALSE, NULL) == 0) | |
249 | 6711 { |
6712 clearopbeep(cap->oap); | |
6713 break; | |
6714 } | |
13088
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
6715 else |
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
6716 curwin->w_set_curswant = TRUE; |
819 | 6717 # ifdef FEAT_FOLDING |
6718 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
6719 foldOpenCursor(); | |
6720 # endif | |
236 | 6721 } |
6722 #endif | |
6723 | |
7 | 6724 /* Not a valid cap->nchar. */ |
6725 else | |
6726 clearopbeep(cap->oap); | |
6727 } | |
6728 | |
6729 /* | |
6730 * Handle Normal mode "%" command. | |
6731 */ | |
6732 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6733 nv_percent(cmdarg_T *cap) |
7 | 6734 { |
6735 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
|
6736 #if defined(FEAT_FOLDING) |
7 | 6737 linenr_T lnum = curwin->w_cursor.lnum; |
6738 #endif | |
6739 | |
6740 cap->oap->inclusive = TRUE; | |
6741 if (cap->count0) /* {cnt}% : goto {cnt} percentage in file */ | |
6742 { | |
6743 if (cap->count0 > 100) | |
6744 clearopbeep(cap->oap); | |
6745 else | |
6746 { | |
6747 cap->oap->motion_type = MLINE; | |
6748 setpcmark(); | |
6749 /* Round up, so CTRL-G will give same value. Watch out for a | |
6750 * large line count, the line number must not go negative! */ | |
6751 if (curbuf->b_ml.ml_line_count > 1000000) | |
6752 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) | |
6753 / 100L * cap->count0; | |
6754 else | |
6755 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count * | |
6756 cap->count0 + 99L) / 100L; | |
6757 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
6758 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
6759 beginline(BL_SOL | BL_FIX); | |
6760 } | |
6761 } | |
6762 else /* "%" : go to matching paren */ | |
6763 { | |
6764 cap->oap->motion_type = MCHAR; | |
6765 cap->oap->use_reg_one = TRUE; | |
6766 if ((pos = findmatch(cap->oap, NUL)) == NULL) | |
6767 clearopbeep(cap->oap); | |
6768 else | |
6769 { | |
6770 setpcmark(); | |
6771 curwin->w_cursor = *pos; | |
6772 curwin->w_set_curswant = TRUE; | |
6773 curwin->w_cursor.coladd = 0; | |
6774 adjust_for_sel(cap); | |
6775 } | |
6776 } | |
6777 #ifdef FEAT_FOLDING | |
6778 if (cap->oap->op_type == OP_NOP | |
6779 && lnum != curwin->w_cursor.lnum | |
6780 && (fdo_flags & FDO_PERCENT) | |
6781 && KeyTyped) | |
6782 foldOpenCursor(); | |
6783 #endif | |
6784 } | |
6785 | |
6786 /* | |
6787 * Handle "(" and ")" commands. | |
6788 * cap->arg is BACKWARD for "(" and FORWARD for ")". | |
6789 */ | |
6790 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6791 nv_brace(cmdarg_T *cap) |
7 | 6792 { |
6793 cap->oap->motion_type = MCHAR; | |
6794 cap->oap->use_reg_one = TRUE; | |
620 | 6795 /* The motion used to be inclusive for "(", but that is not what Vi does. */ |
6796 cap->oap->inclusive = FALSE; | |
7 | 6797 curwin->w_set_curswant = TRUE; |
6798 | |
6799 if (findsent(cap->arg, cap->count1) == FAIL) | |
6800 clearopbeep(cap->oap); | |
6801 else | |
6802 { | |
1505 | 6803 /* Don't leave the cursor on the NUL past end of line. */ |
6804 adjust_cursor(cap->oap); | |
7 | 6805 curwin->w_cursor.coladd = 0; |
6806 #ifdef FEAT_FOLDING | |
6807 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6808 foldOpenCursor(); | |
6809 #endif | |
6810 } | |
6811 } | |
6812 | |
6813 /* | |
6814 * "m" command: Mark a position. | |
6815 */ | |
6816 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6817 nv_mark(cmdarg_T *cap) |
7 | 6818 { |
6819 if (!checkclearop(cap->oap)) | |
6820 { | |
6821 if (setmark(cap->nchar) == FAIL) | |
6822 clearopbeep(cap->oap); | |
6823 } | |
6824 } | |
6825 | |
6826 /* | |
6827 * "{" and "}" commands. | |
6828 * cmd->arg is BACKWARD for "{" and FORWARD for "}". | |
6829 */ | |
6830 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6831 nv_findpar(cmdarg_T *cap) |
7 | 6832 { |
6833 cap->oap->motion_type = MCHAR; | |
6834 cap->oap->inclusive = FALSE; | |
6835 cap->oap->use_reg_one = TRUE; | |
6836 curwin->w_set_curswant = TRUE; | |
503 | 6837 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, FALSE)) |
7 | 6838 clearopbeep(cap->oap); |
6839 else | |
6840 { | |
6841 curwin->w_cursor.coladd = 0; | |
6842 #ifdef FEAT_FOLDING | |
6843 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6844 foldOpenCursor(); | |
6845 #endif | |
6846 } | |
6847 } | |
6848 | |
6849 /* | |
6850 * "u" command: Undo or make lower case. | |
6851 */ | |
6852 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6853 nv_undo(cmdarg_T *cap) |
7 | 6854 { |
5735 | 6855 if (cap->oap->op_type == OP_LOWER || VIsual_active) |
7 | 6856 { |
6857 /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */ | |
6858 cap->cmdchar = 'g'; | |
6859 cap->nchar = 'u'; | |
6860 nv_operator(cap); | |
6861 } | |
6862 else | |
6863 nv_kundo(cap); | |
6864 } | |
6865 | |
6866 /* | |
6867 * <Undo> command. | |
6868 */ | |
6869 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6870 nv_kundo(cmdarg_T *cap) |
7 | 6871 { |
6872 if (!checkclearopq(cap->oap)) | |
6873 { | |
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
|
6874 #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
|
6875 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
|
6876 { |
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
|
6877 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
|
6878 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
|
6879 } |
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
|
6880 #endif |
7 | 6881 u_undo((int)cap->count1); |
6882 curwin->w_set_curswant = TRUE; | |
6883 } | |
6884 } | |
6885 | |
6886 /* | |
6887 * Handle the "r" command. | |
6888 */ | |
6889 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6890 nv_replace(cmdarg_T *cap) |
7 | 6891 { |
6892 char_u *ptr; | |
6893 int had_ctrl_v; | |
6894 long n; | |
6895 | |
6896 if (checkclearop(cap->oap)) | |
6897 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
|
6898 #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
|
6899 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
|
6900 { |
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
|
6901 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
|
6902 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
|
6903 } |
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
|
6904 #endif |
7 | 6905 |
6906 /* get another character */ | |
6907 if (cap->nchar == Ctrl_V) | |
6908 { | |
6909 had_ctrl_v = Ctrl_V; | |
6910 cap->nchar = get_literal(); | |
6911 /* Don't redo a multibyte character with CTRL-V. */ | |
6912 if (cap->nchar > DEL) | |
6913 had_ctrl_v = NUL; | |
6914 } | |
6915 else | |
6916 had_ctrl_v = NUL; | |
6917 | |
1343 | 6918 /* Abort if the character is a special key. */ |
6919 if (IS_SPECIAL(cap->nchar)) | |
6920 { | |
6921 clearopbeep(cap->oap); | |
6922 return; | |
6923 } | |
6924 | |
7 | 6925 /* Visual mode "r" */ |
6926 if (VIsual_active) | |
6927 { | |
1797 | 6928 if (got_int) |
6929 reset_VIsual(); | |
5428 | 6930 if (had_ctrl_v) |
6931 { | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
6932 /* 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
|
6933 * 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
|
6934 if (cap->nchar == CAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
6935 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
|
6936 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
|
6937 cap->nchar = REPLACE_NL_NCHAR; |
5428 | 6938 } |
7 | 6939 nv_operator(cap); |
6940 return; | |
6941 } | |
6942 | |
6943 /* Break tabs, etc. */ | |
6944 if (virtual_active()) | |
6945 { | |
6946 if (u_save_cursor() == FAIL) | |
6947 return; | |
6948 if (gchar_cursor() == NUL) | |
6949 { | |
6950 /* Add extra space and put the cursor on the first one. */ | |
6951 coladvance_force((colnr_T)(getviscol() + cap->count1)); | |
6952 curwin->w_cursor.col -= cap->count1; | |
6953 } | |
6954 else if (gchar_cursor() == TAB) | |
6955 coladvance_force(getviscol()); | |
6956 } | |
6957 | |
1343 | 6958 /* Abort if not enough characters to replace. */ |
7 | 6959 ptr = ml_get_cursor(); |
1343 | 6960 if (STRLEN(ptr) < (unsigned)cap->count1 |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
6961 || (has_mbyte && mb_charlen(ptr) < cap->count1)) |
7 | 6962 { |
6963 clearopbeep(cap->oap); | |
6964 return; | |
6965 } | |
6966 | |
6967 /* | |
6968 * Replacing with a TAB is done by edit() when it is complicated because | |
6969 * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB. | |
6970 * Other characters are done below to avoid problems with things like | |
6971 * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC). | |
6972 */ | |
6973 if (had_ctrl_v != Ctrl_V && cap->nchar == '\t' && (curbuf->b_p_et || p_sta)) | |
6974 { | |
6975 stuffnumReadbuff(cap->count1); | |
6976 stuffcharReadbuff('R'); | |
6977 stuffcharReadbuff('\t'); | |
6978 stuffcharReadbuff(ESC); | |
6979 return; | |
6980 } | |
6981 | |
6982 /* save line for undo */ | |
6983 if (u_save_cursor() == FAIL) | |
6984 return; | |
6985 | |
6986 if (had_ctrl_v != Ctrl_V && (cap->nchar == '\r' || cap->nchar == '\n')) | |
6987 { | |
6988 /* | |
6989 * Replace character(s) by a single newline. | |
6990 * Strange vi behaviour: Only one newline is inserted. | |
6991 * Delete the characters here. | |
6992 * Insert the newline with an insert command, takes care of | |
6993 * autoindent. The insert command depends on being on the last | |
6994 * character of a line or not. | |
6995 */ | |
6996 (void)del_chars(cap->count1, FALSE); /* delete the characters */ | |
6997 stuffcharReadbuff('\r'); | |
6998 stuffcharReadbuff(ESC); | |
6999 | |
7000 /* Give 'r' to edit(), to get the redo command right. */ | |
7001 invoke_edit(cap, TRUE, 'r', FALSE); | |
7002 } | |
7003 else | |
7004 { | |
7005 prep_redo(cap->oap->regname, cap->count1, | |
7006 NUL, 'r', NUL, had_ctrl_v, cap->nchar); | |
7007 | |
7008 curbuf->b_op_start = curwin->w_cursor; | |
7009 if (has_mbyte) | |
7010 { | |
7011 int old_State = State; | |
7012 | |
7013 if (cap->ncharC1 != 0) | |
7014 AppendCharToRedobuff(cap->ncharC1); | |
7015 if (cap->ncharC2 != 0) | |
7016 AppendCharToRedobuff(cap->ncharC2); | |
7017 | |
7018 /* This is slow, but it handles replacing a single-byte with a | |
7019 * multi-byte and the other way around. Also handles adding | |
7020 * composing characters for utf-8. */ | |
7021 for (n = cap->count1; n > 0; --n) | |
7022 { | |
7023 State = REPLACE; | |
3501 | 7024 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7025 { | |
7026 int c = ins_copychar(curwin->w_cursor.lnum | |
7027 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7028 if (c != NUL) | |
7029 ins_char(c); | |
7030 else | |
7031 /* will be decremented further down */ | |
7032 ++curwin->w_cursor.col; | |
7033 } | |
7034 else | |
7035 ins_char(cap->nchar); | |
7 | 7036 State = old_State; |
7037 if (cap->ncharC1 != 0) | |
7038 ins_char(cap->ncharC1); | |
7039 if (cap->ncharC2 != 0) | |
7040 ins_char(cap->ncharC2); | |
7041 } | |
7042 } | |
7043 else | |
7044 { | |
7045 /* | |
7046 * Replace the characters within one line. | |
7047 */ | |
7048 for (n = cap->count1; n > 0; --n) | |
7049 { | |
7050 /* | |
7051 * Get ptr again, because u_save and/or showmatch() will have | |
7052 * released the line. At the same time we let know that the | |
7053 * line will be changed. | |
7054 */ | |
7055 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); | |
3501 | 7056 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7057 { | |
7058 int c = ins_copychar(curwin->w_cursor.lnum | |
7059 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7060 if (c != NUL) | |
7061 ptr[curwin->w_cursor.col] = c; | |
7062 } | |
7063 else | |
7064 ptr[curwin->w_cursor.col] = cap->nchar; | |
7 | 7065 if (p_sm && msg_silent == 0) |
7066 showmatch(cap->nchar); | |
7067 ++curwin->w_cursor.col; | |
7068 } | |
7069 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7070 if (netbeans_active()) |
7 | 7071 { |
2210 | 7072 colnr_T start = (colnr_T)(curwin->w_cursor.col - cap->count1); |
7 | 7073 |
33 | 7074 netbeans_removed(curbuf, curwin->w_cursor.lnum, start, |
2210 | 7075 (long)cap->count1); |
7 | 7076 netbeans_inserted(curbuf, curwin->w_cursor.lnum, start, |
33 | 7077 &ptr[start], (int)cap->count1); |
7 | 7078 } |
7079 #endif | |
7080 | |
7081 /* mark the buffer as changed and prepare for displaying */ | |
7082 changed_bytes(curwin->w_cursor.lnum, | |
7083 (colnr_T)(curwin->w_cursor.col - cap->count1)); | |
7084 } | |
7085 --curwin->w_cursor.col; /* cursor on the last replaced char */ | |
7086 /* if the character on the left of the current cursor is a multi-byte | |
7087 * character, move two characters left */ | |
7088 if (has_mbyte) | |
7089 mb_adjust_cursor(); | |
7090 curbuf->b_op_end = curwin->w_cursor; | |
7091 curwin->w_set_curswant = TRUE; | |
7092 set_last_insert(cap->nchar); | |
7093 } | |
7094 } | |
7095 | |
7096 /* | |
7097 * 'o': Exchange start and end of Visual area. | |
7098 * 'O': same, but in block mode exchange left and right corners. | |
7099 */ | |
7100 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7101 v_swap_corners(int cmdchar) |
7 | 7102 { |
7103 pos_T old_cursor; | |
7104 colnr_T left, right; | |
7105 | |
7106 if (cmdchar == 'O' && VIsual_mode == Ctrl_V) | |
7107 { | |
7108 old_cursor = curwin->w_cursor; | |
7109 getvcols(curwin, &old_cursor, &VIsual, &left, &right); | |
7110 curwin->w_cursor.lnum = VIsual.lnum; | |
7111 coladvance(left); | |
7112 VIsual = curwin->w_cursor; | |
7113 | |
7114 curwin->w_cursor.lnum = old_cursor.lnum; | |
7115 curwin->w_curswant = right; | |
7116 /* 'selection "exclusive" and cursor at right-bottom corner: move it | |
7117 * right one column */ | |
7118 if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') | |
7119 ++curwin->w_curswant; | |
7120 coladvance(curwin->w_curswant); | |
7121 if (curwin->w_cursor.col == old_cursor.col | |
7122 && (!virtual_active() | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
7123 || curwin->w_cursor.coladd == old_cursor.coladd)) |
7 | 7124 { |
7125 curwin->w_cursor.lnum = VIsual.lnum; | |
7126 if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') | |
7127 ++right; | |
7128 coladvance(right); | |
7129 VIsual = curwin->w_cursor; | |
7130 | |
7131 curwin->w_cursor.lnum = old_cursor.lnum; | |
7132 coladvance(left); | |
7133 curwin->w_curswant = left; | |
7134 } | |
7135 } | |
7136 else | |
7137 { | |
7138 old_cursor = curwin->w_cursor; | |
7139 curwin->w_cursor = VIsual; | |
7140 VIsual = old_cursor; | |
7141 curwin->w_set_curswant = TRUE; | |
7142 } | |
7143 } | |
7144 | |
7145 /* | |
7146 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE). | |
7147 */ | |
7148 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7149 nv_Replace(cmdarg_T *cap) |
7 | 7150 { |
7151 if (VIsual_active) /* "R" is replace lines */ | |
7152 { | |
7153 cap->cmdchar = 'c'; | |
7154 cap->nchar = NUL; | |
4213 | 7155 VIsual_mode_orig = VIsual_mode; /* remember original area for gv */ |
7 | 7156 VIsual_mode = 'V'; |
7157 nv_operator(cap); | |
7158 } | |
5735 | 7159 else if (!checkclearopq(cap->oap)) |
7 | 7160 { |
7161 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
|
7162 emsg(_(e_modifiable)); |
7 | 7163 else |
7164 { | |
7165 if (virtual_active()) | |
7166 coladvance(getviscol()); | |
7167 invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE); | |
7168 } | |
7169 } | |
7170 } | |
7171 | |
7172 /* | |
7173 * "gr". | |
7174 */ | |
7175 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7176 nv_vreplace(cmdarg_T *cap) |
7 | 7177 { |
7178 if (VIsual_active) | |
7179 { | |
7180 cap->cmdchar = 'r'; | |
7181 cap->nchar = cap->extra_char; | |
7182 nv_replace(cap); /* Do same as "r" in Visual mode for now */ | |
7183 } | |
5735 | 7184 else if (!checkclearopq(cap->oap)) |
7 | 7185 { |
7186 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
|
7187 emsg(_(e_modifiable)); |
7 | 7188 else |
7189 { | |
7190 if (cap->extra_char == Ctrl_V) /* get another character */ | |
7191 cap->extra_char = get_literal(); | |
7192 stuffcharReadbuff(cap->extra_char); | |
7193 stuffcharReadbuff(ESC); | |
7194 if (virtual_active()) | |
7195 coladvance(getviscol()); | |
7196 invoke_edit(cap, TRUE, 'v', FALSE); | |
7197 } | |
7198 } | |
7199 } | |
7200 | |
7201 /* | |
7202 * Swap case for "~" command, when it does not work like an operator. | |
7203 */ | |
7204 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7205 n_swapchar(cmdarg_T *cap) |
7 | 7206 { |
7207 long n; | |
7208 pos_T startpos; | |
7209 int did_change = 0; | |
7210 #ifdef FEAT_NETBEANS_INTG | |
7211 pos_T pos; | |
7212 char_u *ptr; | |
7213 int count; | |
7214 #endif | |
7215 | |
7216 if (checkclearopq(cap->oap)) | |
7217 return; | |
7218 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7219 if (LINEEMPTY(curwin->w_cursor.lnum) && vim_strchr(p_ww, '~') == NULL) |
7 | 7220 { |
7221 clearopbeep(cap->oap); | |
7222 return; | |
7223 } | |
7224 | |
7225 prep_redo_cmd(cap); | |
7226 | |
7227 if (u_save_cursor() == FAIL) | |
7228 return; | |
7229 | |
7230 startpos = curwin->w_cursor; | |
7231 #ifdef FEAT_NETBEANS_INTG | |
7232 pos = startpos; | |
7233 #endif | |
7234 for (n = cap->count1; n > 0; --n) | |
7235 { | |
7236 did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor); | |
7237 inc_cursor(); | |
7238 if (gchar_cursor() == NUL) | |
7239 { | |
7240 if (vim_strchr(p_ww, '~') != NULL | |
7241 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
7242 { | |
7243 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7244 if (netbeans_active()) |
7 | 7245 { |
7246 if (did_change) | |
7247 { | |
7248 ptr = ml_get(pos.lnum); | |
835 | 7249 count = (int)STRLEN(ptr) - pos.col; |
33 | 7250 netbeans_removed(curbuf, pos.lnum, pos.col, |
7251 (long)count); | |
7 | 7252 netbeans_inserted(curbuf, pos.lnum, pos.col, |
33 | 7253 &ptr[pos.col], count); |
7 | 7254 } |
7255 pos.col = 0; | |
7256 pos.lnum++; | |
7257 } | |
7258 #endif | |
7259 ++curwin->w_cursor.lnum; | |
7260 curwin->w_cursor.col = 0; | |
7261 if (n > 1) | |
7262 { | |
7263 if (u_savesub(curwin->w_cursor.lnum) == FAIL) | |
7264 break; | |
7265 u_clearline(); | |
7266 } | |
7267 } | |
7268 else | |
7269 break; | |
7270 } | |
7271 } | |
7272 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7273 if (did_change && netbeans_active()) |
7 | 7274 { |
7275 ptr = ml_get(pos.lnum); | |
7276 count = curwin->w_cursor.col - pos.col; | |
33 | 7277 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7278 netbeans_inserted(curbuf, pos.lnum, pos.col, &ptr[pos.col], count); | |
7 | 7279 } |
7280 #endif | |
7281 | |
7282 | |
7283 check_cursor(); | |
7284 curwin->w_set_curswant = TRUE; | |
7285 if (did_change) | |
7286 { | |
7287 changed_lines(startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1, | |
7288 0L); | |
7289 curbuf->b_op_start = startpos; | |
7290 curbuf->b_op_end = curwin->w_cursor; | |
7291 if (curbuf->b_op_end.col > 0) | |
7292 --curbuf->b_op_end.col; | |
7293 } | |
7294 } | |
7295 | |
7296 /* | |
7297 * Move cursor to mark. | |
7298 */ | |
7299 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7300 nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos) |
7 | 7301 { |
7302 if (check_mark(pos) == FAIL) | |
7303 clearop(cap->oap); | |
7304 else | |
7305 { | |
7306 if (cap->cmdchar == '\'' | |
7307 || cap->cmdchar == '`' | |
7308 || cap->cmdchar == '[' | |
7309 || cap->cmdchar == ']') | |
7310 setpcmark(); | |
7311 curwin->w_cursor = *pos; | |
7312 if (flag) | |
7313 beginline(BL_WHITE | BL_FIX); | |
7314 else | |
7315 check_cursor(); | |
7316 } | |
7317 cap->oap->motion_type = flag ? MLINE : MCHAR; | |
7318 if (cap->cmdchar == '`') | |
7319 cap->oap->use_reg_one = TRUE; | |
7320 cap->oap->inclusive = FALSE; /* ignored if not MCHAR */ | |
7321 curwin->w_set_curswant = TRUE; | |
7322 } | |
7323 | |
7324 /* | |
7325 * Handle commands that are operators in Visual mode. | |
7326 */ | |
7327 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7328 v_visop(cmdarg_T *cap) |
7 | 7329 { |
7330 static char_u trans[] = "YyDdCcxdXdAAIIrr"; | |
7331 | |
7332 /* Uppercase means linewise, except in block mode, then "D" deletes till | |
4352 | 7333 * the end of the line, and "C" replaces till EOL */ |
7 | 7334 if (isupper(cap->cmdchar)) |
7335 { | |
7336 if (VIsual_mode != Ctrl_V) | |
4213 | 7337 { |
7338 VIsual_mode_orig = VIsual_mode; | |
7 | 7339 VIsual_mode = 'V'; |
4213 | 7340 } |
7 | 7341 else if (cap->cmdchar == 'C' || cap->cmdchar == 'D') |
7342 curwin->w_curswant = MAXCOL; | |
7343 } | |
7344 cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1); | |
7345 nv_operator(cap); | |
7346 } | |
7347 | |
7348 /* | |
7349 * "s" and "S" commands. | |
7350 */ | |
7351 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7352 nv_subst(cmdarg_T *cap) |
7 | 7353 { |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7354 #ifdef FEAT_TERMINAL |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7355 /* 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
|
7356 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
|
7357 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7358 #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
|
7359 #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
|
7360 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
|
7361 { |
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
|
7362 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
|
7363 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
|
7364 } |
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
|
7365 #endif |
7 | 7366 if (VIsual_active) /* "vs" and "vS" are the same as "vc" */ |
7367 { | |
7368 if (cap->cmdchar == 'S') | |
4213 | 7369 { |
7370 VIsual_mode_orig = VIsual_mode; | |
7 | 7371 VIsual_mode = 'V'; |
4213 | 7372 } |
7 | 7373 cap->cmdchar = 'c'; |
7374 nv_operator(cap); | |
7375 } | |
7376 else | |
7377 nv_optrans(cap); | |
7378 } | |
7379 | |
7380 /* | |
7381 * Abbreviated commands. | |
7382 */ | |
7383 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7384 nv_abbrev(cmdarg_T *cap) |
7 | 7385 { |
7386 if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) | |
7387 cap->cmdchar = 'x'; /* DEL key behaves like 'x' */ | |
7388 | |
7389 /* in Visual mode these commands are operators */ | |
7390 if (VIsual_active) | |
7391 v_visop(cap); | |
7392 else | |
7393 nv_optrans(cap); | |
7394 } | |
7395 | |
7396 /* | |
7397 * Translate a command into another command. | |
7398 */ | |
7399 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7400 nv_optrans(cmdarg_T *cap) |
7 | 7401 { |
7402 static char_u *(ar[8]) = {(char_u *)"dl", (char_u *)"dh", | |
7403 (char_u *)"d$", (char_u *)"c$", | |
7404 (char_u *)"cl", (char_u *)"cc", | |
7405 (char_u *)"yy", (char_u *)":s\r"}; | |
7406 static char_u *str = (char_u *)"xXDCsSY&"; | |
7407 | |
7408 if (!checkclearopq(cap->oap)) | |
7409 { | |
164 | 7410 /* In Vi "2D" doesn't delete the next line. Can't translate it |
7411 * either, because "2." should also not use the count. */ | |
7412 if (cap->cmdchar == 'D' && vim_strchr(p_cpo, CPO_HASH) != NULL) | |
7413 { | |
7414 cap->oap->start = curwin->w_cursor; | |
7415 cap->oap->op_type = OP_DELETE; | |
1490 | 7416 #ifdef FEAT_EVAL |
7417 set_op_var(OP_DELETE); | |
7418 #endif | |
164 | 7419 cap->count1 = 1; |
7420 nv_dollar(cap); | |
7421 finish_op = TRUE; | |
7422 ResetRedobuff(); | |
7423 AppendCharToRedobuff('D'); | |
7424 } | |
7425 else | |
7426 { | |
7427 if (cap->count0) | |
7428 stuffnumReadbuff(cap->count0); | |
7429 stuffReadbuff(ar[(int)(vim_strchr(str, cap->cmdchar) - str)]); | |
7430 } | |
7 | 7431 } |
7432 cap->opcount = 0; | |
7433 } | |
7434 | |
7435 /* | |
7436 * "'" and "`" commands. Also for "g'" and "g`". | |
7437 * cap->arg is TRUE for "'" and "g'". | |
7438 */ | |
7439 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7440 nv_gomark(cmdarg_T *cap) |
7 | 7441 { |
7442 pos_T *pos; | |
7443 int c; | |
7444 #ifdef FEAT_FOLDING | |
4017 | 7445 pos_T old_cursor = curwin->w_cursor; |
7 | 7446 int old_KeyTyped = KeyTyped; /* getting file may reset it */ |
7447 #endif | |
7448 | |
7449 if (cap->cmdchar == 'g') | |
7450 c = cap->extra_char; | |
7451 else | |
7452 c = cap->nchar; | |
7453 pos = getmark(c, (cap->oap->op_type == OP_NOP)); | |
7454 if (pos == (pos_T *)-1) /* jumped to other file */ | |
7455 { | |
7456 if (cap->arg) | |
7457 { | |
7458 check_cursor_lnum(); | |
7459 beginline(BL_WHITE | BL_FIX); | |
7460 } | |
7461 else | |
7462 check_cursor(); | |
7463 } | |
7464 else | |
7465 nv_cursormark(cap, cap->arg, pos); | |
7466 | |
7467 /* May need to clear the coladd that a mark includes. */ | |
7468 if (!virtual_active()) | |
7469 curwin->w_cursor.coladd = 0; | |
12164
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
7470 check_cursor_col(); |
7 | 7471 #ifdef FEAT_FOLDING |
7472 if (cap->oap->op_type == OP_NOP | |
4057 | 7473 && pos != NULL |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7474 && (pos == (pos_T *)-1 || !EQUAL_POS(old_cursor, *pos)) |
7 | 7475 && (fdo_flags & FDO_MARK) |
7476 && old_KeyTyped) | |
7477 foldOpenCursor(); | |
7478 #endif | |
7479 } | |
7480 | |
7481 /* | |
7482 * Handle CTRL-O, CTRL-I, "g;" and "g," commands. | |
7483 */ | |
7484 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7485 nv_pcmark(cmdarg_T *cap) |
7 | 7486 { |
7487 #ifdef FEAT_JUMPLIST | |
7488 pos_T *pos; | |
7489 # ifdef FEAT_FOLDING | |
7490 linenr_T lnum = curwin->w_cursor.lnum; | |
7491 int old_KeyTyped = KeyTyped; /* getting file may reset it */ | |
7492 # endif | |
7493 | |
7494 if (!checkclearopq(cap->oap)) | |
7495 { | |
7496 if (cap->cmdchar == 'g') | |
7497 pos = movechangelist((int)cap->count1); | |
7498 else | |
7499 pos = movemark((int)cap->count1); | |
7500 if (pos == (pos_T *)-1) /* jump to other file */ | |
7501 { | |
7502 curwin->w_set_curswant = TRUE; | |
7503 check_cursor(); | |
7504 } | |
7505 else if (pos != NULL) /* can jump */ | |
7506 nv_cursormark(cap, FALSE, pos); | |
7507 else if (cap->cmdchar == 'g') | |
7508 { | |
7509 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
|
7510 emsg(_("E664: changelist is empty")); |
7 | 7511 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
|
7512 emsg(_("E662: At start of changelist")); |
7 | 7513 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
7514 emsg(_("E663: At end of changelist")); |
7 | 7515 } |
7516 else | |
7517 clearopbeep(cap->oap); | |
7518 # ifdef FEAT_FOLDING | |
7519 if (cap->oap->op_type == OP_NOP | |
7520 && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum) | |
7521 && (fdo_flags & FDO_MARK) | |
7522 && old_KeyTyped) | |
7523 foldOpenCursor(); | |
7524 # endif | |
7525 } | |
7526 #else | |
7527 clearopbeep(cap->oap); | |
7528 #endif | |
7529 } | |
7530 | |
7531 /* | |
7532 * Handle '"' command. | |
7533 */ | |
7534 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7535 nv_regname(cmdarg_T *cap) |
7 | 7536 { |
7537 if (checkclearop(cap->oap)) | |
7538 return; | |
7539 #ifdef FEAT_EVAL | |
7540 if (cap->nchar == '=') | |
7541 cap->nchar = get_expr_register(); | |
7542 #endif | |
7543 if (cap->nchar != NUL && valid_yank_reg(cap->nchar, FALSE)) | |
7544 { | |
7545 cap->oap->regname = cap->nchar; | |
7546 cap->opcount = cap->count0; /* remember count before '"' */ | |
7547 #ifdef FEAT_EVAL | |
7548 set_reg_var(cap->oap->regname); | |
7549 #endif | |
7550 } | |
7551 else | |
7552 clearopbeep(cap->oap); | |
7553 } | |
7554 | |
7555 /* | |
7556 * Handle "v", "V" and "CTRL-V" commands. | |
7557 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg | |
7558 * is TRUE. | |
167 | 7559 * Handle CTRL-Q just like CTRL-V. |
7 | 7560 */ |
7561 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7562 nv_visual(cmdarg_T *cap) |
7 | 7563 { |
167 | 7564 if (cap->cmdchar == Ctrl_Q) |
7565 cap->cmdchar = Ctrl_V; | |
7566 | |
7 | 7567 /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it |
7568 * characterwise, linewise, or blockwise. */ | |
7569 if (cap->oap->op_type != OP_NOP) | |
7570 { | |
15279
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
7571 motion_force = cap->oap->motion_force = cap->cmdchar; |
7 | 7572 finish_op = FALSE; /* operator doesn't finish now but later */ |
7573 return; | |
7574 } | |
7575 | |
7576 VIsual_select = cap->arg; | |
7577 if (VIsual_active) /* change Visual mode */ | |
7578 { | |
7579 if (VIsual_mode == cap->cmdchar) /* stop visual mode */ | |
7580 end_visual_mode(); | |
7581 else /* toggle char/block mode */ | |
7582 { /* or char/line mode */ | |
7583 VIsual_mode = cap->cmdchar; | |
7584 showmode(); | |
7585 } | |
7586 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
7587 } | |
7588 else /* start Visual mode */ | |
7589 { | |
7590 check_visual_highlight(); | |
3537 | 7591 if (cap->count0 > 0 && resel_VIsual_mode != NUL) |
7592 { | |
7593 /* use previously selected part */ | |
7 | 7594 VIsual = curwin->w_cursor; |
7595 | |
7596 VIsual_active = TRUE; | |
7597 VIsual_reselect = TRUE; | |
7598 if (!cap->arg) | |
7599 /* start Select mode when 'selectmode' contains "cmd" */ | |
7600 may_start_select('c'); | |
7601 #ifdef FEAT_MOUSE | |
7602 setmouse(); | |
7603 #endif | |
641 | 7604 if (p_smd && msg_silent == 0) |
7 | 7605 redraw_cmdline = TRUE; /* show visual mode later */ |
7606 /* | |
7607 * For V and ^V, we multiply the number of lines even if there | |
7608 * was only one -- webb | |
7609 */ | |
7610 if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) | |
7611 { | |
7612 curwin->w_cursor.lnum += | |
7613 resel_VIsual_line_count * cap->count0 - 1; | |
7614 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
7615 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7616 } | |
7617 VIsual_mode = resel_VIsual_mode; | |
7618 if (VIsual_mode == 'v') | |
7619 { | |
7620 if (resel_VIsual_line_count <= 1) | |
3125 | 7621 { |
7622 validate_virtcol(); | |
7623 curwin->w_curswant = curwin->w_virtcol | |
7624 + resel_VIsual_vcol * cap->count0 - 1; | |
7625 } | |
7 | 7626 else |
3125 | 7627 curwin->w_curswant = resel_VIsual_vcol; |
7628 coladvance(curwin->w_curswant); | |
7 | 7629 } |
3125 | 7630 if (resel_VIsual_vcol == MAXCOL) |
7 | 7631 { |
7632 curwin->w_curswant = MAXCOL; | |
7633 coladvance((colnr_T)MAXCOL); | |
7634 } | |
7635 else if (VIsual_mode == Ctrl_V) | |
7636 { | |
7637 validate_virtcol(); | |
7638 curwin->w_curswant = curwin->w_virtcol | |
3125 | 7639 + resel_VIsual_vcol * cap->count0 - 1; |
7 | 7640 coladvance(curwin->w_curswant); |
7641 } | |
7642 else | |
7643 curwin->w_set_curswant = TRUE; | |
7644 redraw_curbuf_later(INVERTED); /* show the inversion */ | |
7645 } | |
7646 else | |
7647 { | |
7648 if (!cap->arg) | |
7649 /* start Select mode when 'selectmode' contains "cmd" */ | |
7650 may_start_select('c'); | |
7651 n_start_visual_mode(cap->cmdchar); | |
3537 | 7652 if (VIsual_mode != 'V' && *p_sel == 'e') |
7653 ++cap->count1; /* include one more char */ | |
7654 if (cap->count0 > 0 && --cap->count1 > 0) | |
7655 { | |
7656 /* With a count select that many characters or lines. */ | |
7657 if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) | |
7658 nv_right(cap); | |
7659 else if (VIsual_mode == 'V') | |
7660 nv_down(cap); | |
7661 } | |
7 | 7662 } |
7663 } | |
7664 } | |
7665 | |
7666 /* | |
7667 * Start selection for Shift-movement keys. | |
7668 */ | |
7669 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7670 start_selection(void) |
7 | 7671 { |
7672 /* if 'selectmode' contains "key", start Select mode */ | |
7673 may_start_select('k'); | |
7674 n_start_visual_mode('v'); | |
7675 } | |
7676 | |
7677 /* | |
7678 * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu. | |
7679 */ | |
7680 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7681 may_start_select(int c) |
7 | 7682 { |
7683 VIsual_select = (stuff_empty() && typebuf_typed() | |
7684 && (vim_strchr(p_slm, c) != NULL)); | |
7685 } | |
7686 | |
7687 /* | |
7688 * Start Visual mode "c". | |
7689 * Should set VIsual_select before calling this. | |
7690 */ | |
7691 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7692 n_start_visual_mode(int c) |
7 | 7693 { |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7694 #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
|
7695 /* Check for redraw before changing the state. */ |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13772
diff
changeset
|
7696 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
|
7697 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7698 |
7 | 7699 VIsual_mode = c; |
7700 VIsual_active = TRUE; | |
7701 VIsual_reselect = TRUE; | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
7702 |
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
7703 // Corner case: the 0 position in a tab may change when going into |
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
7704 // virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting. |
7 | 7705 if (c == Ctrl_V && (ve_flags & VE_BLOCK) && gchar_cursor() == TAB) |
3742 | 7706 { |
7707 validate_virtcol(); | |
7 | 7708 coladvance(curwin->w_virtcol); |
3742 | 7709 } |
7 | 7710 VIsual = curwin->w_cursor; |
7711 | |
7712 #ifdef FEAT_FOLDING | |
7713 foldAdjustVisual(); | |
7714 #endif | |
7715 | |
7716 #ifdef FEAT_MOUSE | |
7717 setmouse(); | |
7718 #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
|
7719 #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
|
7720 /* Check for redraw after changing the state. */ |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13772
diff
changeset
|
7721 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
|
7722 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7723 |
641 | 7724 if (p_smd && msg_silent == 0) |
7 | 7725 redraw_cmdline = TRUE; /* show visual mode later */ |
7726 #ifdef FEAT_CLIPBOARD | |
7727 /* Make sure the clipboard gets updated. Needed because start and | |
7728 * end may still be the same, and the selection needs to be owned */ | |
7729 clip_star.vmode = NUL; | |
7730 #endif | |
7731 | |
7732 /* Only need to redraw this line, unless still need to redraw an old | |
7733 * Visual area (when 'lazyredraw' is set). */ | |
7734 if (curwin->w_redr_type < INVERTED) | |
7735 { | |
7736 curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
7737 curwin->w_old_visual_lnum = curwin->w_cursor.lnum; | |
7738 } | |
7739 } | |
7740 | |
7741 | |
7742 /* | |
7743 * CTRL-W: Window commands | |
7744 */ | |
7745 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7746 nv_window(cmdarg_T *cap) |
7 | 7747 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7748 if (cap->nchar == ':') |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7749 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7750 /* "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
|
7751 cap->cmdchar = ':'; |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7752 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
|
7753 nv_colon(cap); |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7754 } |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7755 else if (!checkclearop(cap->oap)) |
7 | 7756 do_window(cap->nchar, cap->count0, NUL); /* everything is in window.c */ |
7757 } | |
7758 | |
7759 /* | |
7760 * CTRL-Z: Suspend | |
7761 */ | |
7762 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7763 nv_suspend(cmdarg_T *cap) |
7 | 7764 { |
7765 clearop(cap->oap); | |
7766 if (VIsual_active) | |
7767 end_visual_mode(); /* stop Visual mode */ | |
7768 do_cmdline_cmd((char_u *)"st"); | |
7769 } | |
7770 | |
7771 /* | |
7772 * Commands starting with "g". | |
7773 */ | |
7774 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7775 nv_g_cmd(cmdarg_T *cap) |
7 | 7776 { |
7777 oparg_T *oap = cap->oap; | |
7778 pos_T tpos; | |
7779 int i; | |
7780 int flag = FALSE; | |
7781 | |
7782 switch (cap->nchar) | |
7783 { | |
6868 | 7784 case Ctrl_A: |
7785 case Ctrl_X: | |
7 | 7786 #ifdef MEM_PROFILE |
7787 /* | |
7788 * "g^A": dump log of used memory. | |
7789 */ | |
6868 | 7790 if (!VIsual_active && cap->nchar == Ctrl_A) |
7791 vim_mem_profile_dump(); | |
7792 else | |
7793 #endif | |
7794 /* | |
7795 * "g^A/g^X": sequentially increment visually selected region | |
7796 */ | |
7797 if (VIsual_active) | |
7798 { | |
7799 cap->arg = TRUE; | |
7800 cap->cmdchar = cap->nchar; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
7801 cap->nchar = NUL; |
6868 | 7802 nv_addsub(cap); |
7803 } | |
7804 else | |
7805 clearopbeep(oap); | |
7 | 7806 break; |
7807 | |
7808 /* | |
7809 * "gR": Enter virtual replace mode. | |
7810 */ | |
7811 case 'R': | |
7812 cap->arg = TRUE; | |
7813 nv_Replace(cap); | |
7814 break; | |
7815 | |
7816 case 'r': | |
7817 nv_vreplace(cap); | |
7818 break; | |
7819 | |
7820 case '&': | |
7821 do_cmdline_cmd((char_u *)"%s//~/&"); | |
7822 break; | |
7823 | |
7824 /* | |
7825 * "gv": Reselect the previous Visual area. If Visual already active, | |
7826 * exchange previous and current Visual area. | |
7827 */ | |
7828 case 'v': | |
7829 if (checkclearop(oap)) | |
7830 break; | |
7831 | |
690 | 7832 if ( curbuf->b_visual.vi_start.lnum == 0 |
7833 || curbuf->b_visual.vi_start.lnum > curbuf->b_ml.ml_line_count | |
7834 || curbuf->b_visual.vi_end.lnum == 0) | |
7 | 7835 beep_flush(); |
7836 else | |
7837 { | |
7838 /* set w_cursor to the start of the Visual area, tpos to the end */ | |
7839 if (VIsual_active) | |
7840 { | |
7841 i = VIsual_mode; | |
690 | 7842 VIsual_mode = curbuf->b_visual.vi_mode; |
7843 curbuf->b_visual.vi_mode = i; | |
7 | 7844 # ifdef FEAT_EVAL |
7845 curbuf->b_visual_mode_eval = i; | |
7846 # endif | |
7847 i = curwin->w_curswant; | |
690 | 7848 curwin->w_curswant = curbuf->b_visual.vi_curswant; |
7849 curbuf->b_visual.vi_curswant = i; | |
7850 | |
7851 tpos = curbuf->b_visual.vi_end; | |
7852 curbuf->b_visual.vi_end = curwin->w_cursor; | |
7853 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7854 curbuf->b_visual.vi_start = VIsual; | |
7 | 7855 } |
7856 else | |
7857 { | |
690 | 7858 VIsual_mode = curbuf->b_visual.vi_mode; |
7859 curwin->w_curswant = curbuf->b_visual.vi_curswant; | |
7860 tpos = curbuf->b_visual.vi_end; | |
7861 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7 | 7862 } |
7863 | |
7864 VIsual_active = TRUE; | |
7865 VIsual_reselect = TRUE; | |
7866 | |
7867 /* Set Visual to the start and w_cursor to the end of the Visual | |
7868 * area. Make sure they are on an existing character. */ | |
7869 check_cursor(); | |
7870 VIsual = curwin->w_cursor; | |
7871 curwin->w_cursor = tpos; | |
7872 check_cursor(); | |
7873 update_topline(); | |
7874 /* | |
7875 * When called from normal "g" command: start Select mode when | |
7876 * 'selectmode' contains "cmd". When called for K_SELECT, always | |
7877 * start Select mode. | |
7878 */ | |
7879 if (cap->arg) | |
7880 VIsual_select = TRUE; | |
7881 else | |
7882 may_start_select('c'); | |
7883 #ifdef FEAT_MOUSE | |
7884 setmouse(); | |
7885 #endif | |
7886 #ifdef FEAT_CLIPBOARD | |
7887 /* Make sure the clipboard gets updated. Needed because start and | |
7888 * end are still the same, and the selection needs to be owned */ | |
7889 clip_star.vmode = NUL; | |
7890 #endif | |
7891 redraw_curbuf_later(INVERTED); | |
7892 showmode(); | |
7893 } | |
7894 break; | |
7895 /* | |
7896 * "gV": Don't reselect the previous Visual area after a Select mode | |
7897 * mapping of menu. | |
7898 */ | |
7899 case 'V': | |
7900 VIsual_reselect = FALSE; | |
7901 break; | |
7902 | |
7903 /* | |
7904 * "gh": start Select mode. | |
7905 * "gH": start Select line mode. | |
7906 * "g^H": start Select block mode. | |
7907 */ | |
7908 case K_BS: | |
7909 cap->nchar = Ctrl_H; | |
7910 /* FALLTHROUGH */ | |
7911 case 'h': | |
7912 case 'H': | |
7913 case Ctrl_H: | |
7914 # ifdef EBCDIC | |
7915 /* EBCDIC: 'v'-'h' != '^v'-'^h' */ | |
7916 if (cap->nchar == Ctrl_H) | |
7917 cap->cmdchar = Ctrl_V; | |
7918 else | |
7919 # endif | |
7920 cap->cmdchar = cap->nchar + ('v' - 'h'); | |
7921 cap->arg = TRUE; | |
7922 nv_visual(cap); | |
7923 break; | |
3701 | 7924 |
7925 /* "gn", "gN" visually select next/previous search match | |
7926 * "gn" selects next match | |
7927 * "gN" selects previous match | |
7928 */ | |
7929 case 'N': | |
7930 case 'n': | |
7931 if (!current_search(cap->count1, cap->nchar == 'n')) | |
3896 | 7932 clearopbeep(oap); |
3701 | 7933 break; |
7 | 7934 |
7935 /* | |
7936 * "gj" and "gk" two new funny movement keys -- up and down | |
7937 * movement based on *screen* line rather than *file* line. | |
7938 */ | |
7939 case 'j': | |
7940 case K_DOWN: | |
7941 /* with 'nowrap' it works just like the normal "j" command; also when | |
7942 * in a closed fold */ | |
7943 if (!curwin->w_p_wrap | |
7944 #ifdef FEAT_FOLDING | |
7945 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
7946 #endif | |
7947 ) | |
7948 { | |
7949 oap->motion_type = MLINE; | |
7950 i = cursor_down(cap->count1, oap->op_type == OP_NOP); | |
7951 } | |
7952 else | |
7953 i = nv_screengo(oap, FORWARD, cap->count1); | |
7954 if (i == FAIL) | |
7955 clearopbeep(oap); | |
7956 break; | |
7957 | |
7958 case 'k': | |
7959 case K_UP: | |
7960 /* with 'nowrap' it works just like the normal "k" command; also when | |
7961 * in a closed fold */ | |
7962 if (!curwin->w_p_wrap | |
7963 #ifdef FEAT_FOLDING | |
7964 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
7965 #endif | |
7966 ) | |
7967 { | |
7968 oap->motion_type = MLINE; | |
7969 i = cursor_up(cap->count1, oap->op_type == OP_NOP); | |
7970 } | |
7971 else | |
7972 i = nv_screengo(oap, BACKWARD, cap->count1); | |
7973 if (i == FAIL) | |
7974 clearopbeep(oap); | |
7975 break; | |
7976 | |
7977 /* | |
7978 * "gJ": join two lines without inserting a space. | |
7979 */ | |
7980 case 'J': | |
7981 nv_join(cap); | |
7982 break; | |
7983 | |
7984 /* | |
7985 * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines. | |
7986 * "gm": middle of "g0" and "g$". | |
7987 */ | |
7988 case '^': | |
7989 flag = TRUE; | |
7990 /* FALLTHROUGH */ | |
7991 | |
7992 case '0': | |
7993 case 'm': | |
7994 case K_HOME: | |
7995 case K_KHOME: | |
7996 oap->motion_type = MCHAR; | |
7997 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
|
7998 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 7999 { |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8000 int width1 = curwin->w_width - curwin_col_off(); |
7 | 8001 int width2 = width1 + curwin_col_off2(); |
8002 | |
8003 validate_virtcol(); | |
8004 i = 0; | |
8005 if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0) | |
8006 i = (curwin->w_virtcol - width1) / width2 * width2 + width1; | |
8007 } | |
8008 else | |
8009 i = curwin->w_leftcol; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2139
diff
changeset
|
8010 /* 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
|
8011 * '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
|
8012 * to the left. */ |
7 | 8013 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
|
8014 i += (curwin->w_width - curwin_col_off() |
7 | 8015 + ((curwin->w_p_wrap && i > 0) |
8016 ? curwin_col_off2() : 0)) / 2; | |
8017 coladvance((colnr_T)i); | |
8018 if (flag) | |
8019 { | |
8020 do | |
8021 i = gchar_cursor(); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
8022 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
|
8023 curwin->w_valid &= ~VALID_WCOL; |
7 | 8024 } |
8025 curwin->w_set_curswant = TRUE; | |
8026 break; | |
8027 | |
8028 case '_': | |
8029 /* "g_": to the last non-blank character in the line or <count> lines | |
8030 * downward. */ | |
8031 cap->oap->motion_type = MCHAR; | |
8032 cap->oap->inclusive = TRUE; | |
8033 curwin->w_curswant = MAXCOL; | |
8034 if (cursor_down((long)(cap->count1 - 1), | |
8035 cap->oap->op_type == OP_NOP) == FAIL) | |
8036 clearopbeep(cap->oap); | |
8037 else | |
8038 { | |
8039 char_u *ptr = ml_get_curline(); | |
8040 | |
8041 /* In Visual mode we may end up after the line. */ | |
8042 if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) | |
8043 --curwin->w_cursor.col; | |
8044 | |
8045 /* Decrease the cursor column until it's on a non-blank. */ | |
8046 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
|
8047 && VIM_ISWHITE(ptr[curwin->w_cursor.col])) |
7 | 8048 --curwin->w_cursor.col; |
8049 curwin->w_set_curswant = TRUE; | |
2040
70c67b1bb1f1
updated for version 7.2.329
Bram Moolenaar <bram@zimbu.org>
parents:
2024
diff
changeset
|
8050 adjust_for_sel(cap); |
7 | 8051 } |
8052 break; | |
8053 | |
8054 case '$': | |
8055 case K_END: | |
8056 case K_KEND: | |
8057 { | |
8058 int col_off = curwin_col_off(); | |
8059 | |
8060 oap->motion_type = MCHAR; | |
8061 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
|
8062 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 8063 { |
8064 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
8065 if (cap->count1 == 1) | |
8066 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8067 int width1 = curwin->w_width - col_off; |
7 | 8068 int width2 = width1 + curwin_col_off2(); |
8069 | |
8070 validate_virtcol(); | |
8071 i = width1 - 1; | |
8072 if (curwin->w_virtcol >= (colnr_T)width1) | |
8073 i += ((curwin->w_virtcol - width1) / width2 + 1) | |
8074 * width2; | |
8075 coladvance((colnr_T)i); | |
5162
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8076 |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8077 /* Make sure we stick in this column. */ |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8078 validate_virtcol(); |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8079 curwin->w_curswant = curwin->w_virtcol; |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8080 curwin->w_set_curswant = FALSE; |
7 | 8081 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) |
8082 { | |
8083 /* | |
8084 * Check for landing on a character that got split at | |
8085 * the end of the line. We do not want to advance to | |
8086 * the next screen line. | |
8087 */ | |
8088 if (curwin->w_virtcol > (colnr_T)i) | |
8089 --curwin->w_cursor.col; | |
8090 } | |
8091 } | |
8092 else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == FAIL) | |
8093 clearopbeep(oap); | |
8094 } | |
8095 else | |
8096 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8097 i = curwin->w_leftcol + curwin->w_width - col_off - 1; |
7 | 8098 coladvance((colnr_T)i); |
40 | 8099 |
8100 /* Make sure we stick in this column. */ | |
8101 validate_virtcol(); | |
8102 curwin->w_curswant = curwin->w_virtcol; | |
8103 curwin->w_set_curswant = FALSE; | |
7 | 8104 } |
8105 } | |
8106 break; | |
8107 | |
8108 /* | |
8109 * "g*" and "g#", like "*" and "#" but without using "\<" and "\>" | |
8110 */ | |
8111 case '*': | |
8112 case '#': | |
8113 #if POUND != '#' | |
8114 case POUND: /* pound sign (sometimes equal to '#') */ | |
8115 #endif | |
8116 case Ctrl_RSB: /* :tag or :tselect for current identifier */ | |
8117 case ']': /* :tselect for current identifier */ | |
8118 nv_ident(cap); | |
8119 break; | |
8120 | |
8121 /* | |
8122 * ge and gE: go back to end of word | |
8123 */ | |
8124 case 'e': | |
8125 case 'E': | |
8126 oap->motion_type = MCHAR; | |
8127 curwin->w_set_curswant = TRUE; | |
8128 oap->inclusive = TRUE; | |
8129 if (bckend_word(cap->count1, cap->nchar == 'E', FALSE) == FAIL) | |
8130 clearopbeep(oap); | |
8131 break; | |
8132 | |
8133 /* | |
8134 * "g CTRL-G": display info about cursor position | |
8135 */ | |
8136 case Ctrl_G: | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7311
diff
changeset
|
8137 cursor_pos_info(NULL); |
7 | 8138 break; |
8139 | |
8140 /* | |
8141 * "gi": start Insert at the last position. | |
8142 */ | |
8143 case 'i': | |
8144 if (curbuf->b_last_insert.lnum != 0) | |
8145 { | |
8146 curwin->w_cursor = curbuf->b_last_insert; | |
8147 check_cursor_lnum(); | |
8148 i = (int)STRLEN(ml_get_curline()); | |
8149 if (curwin->w_cursor.col > (colnr_T)i) | |
8150 { | |
8151 if (virtual_active()) | |
8152 curwin->w_cursor.coladd += curwin->w_cursor.col - i; | |
8153 curwin->w_cursor.col = i; | |
8154 } | |
8155 } | |
8156 cap->cmdchar = 'i'; | |
8157 nv_edit(cap); | |
8158 break; | |
8159 | |
8160 /* | |
8161 * "gI": Start insert in column 1. | |
8162 */ | |
8163 case 'I': | |
8164 beginline(0); | |
8165 if (!checkclearopq(oap)) | |
8166 invoke_edit(cap, FALSE, 'g', FALSE); | |
8167 break; | |
8168 | |
8169 #ifdef FEAT_SEARCHPATH | |
8170 /* | |
8171 * "gf": goto file, edit file under cursor | |
8172 * "]f" and "[f": can also be used. | |
8173 */ | |
8174 case 'f': | |
681 | 8175 case 'F': |
7 | 8176 nv_gotofile(cap); |
8177 break; | |
8178 #endif | |
8179 | |
8180 /* "g'm" and "g`m": jump to mark without setting pcmark */ | |
8181 case '\'': | |
8182 cap->arg = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
8183 /* FALLTHROUGH */ |
7 | 8184 case '`': |
8185 nv_gomark(cap); | |
8186 break; | |
8187 | |
8188 /* | |
8189 * "gs": Goto sleep. | |
8190 */ | |
8191 case 's': | |
8192 do_sleep(cap->count1 * 1000L); | |
8193 break; | |
8194 | |
8195 /* | |
8196 * "ga": Display the ascii value of the character under the | |
8197 * cursor. It is displayed in decimal, hex, and octal. -- webb | |
8198 */ | |
8199 case 'a': | |
8200 do_ascii(NULL); | |
8201 break; | |
8202 | |
8203 /* | |
8204 * "g8": Display the bytes used for the UTF-8 character under the | |
8205 * cursor. It is displayed in hex. | |
775 | 8206 * "8g8" finds illegal byte sequence. |
7 | 8207 */ |
8208 case '8': | |
775 | 8209 if (cap->count0 == 8) |
8210 utf_find_illegal(); | |
8211 else | |
8212 show_utf8(); | |
7 | 8213 break; |
8214 | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
8215 /* "g<": show scrollback text */ |
447 | 8216 case '<': |
8217 show_sb_text(); | |
8218 break; | |
8219 | |
7 | 8220 /* |
8221 * "gg": Goto the first line in file. With a count it goes to | |
8222 * that line number like for "G". -- webb | |
8223 */ | |
8224 case 'g': | |
8225 cap->arg = FALSE; | |
8226 nv_goto(cap); | |
8227 break; | |
8228 | |
8229 /* | |
8230 * Two-character operators: | |
8231 * "gq" Format text | |
8232 * "gw" Format text and keep cursor position | |
8233 * "g~" Toggle the case of the text. | |
8234 * "gu" Change text to lower case. | |
8235 * "gU" Change text to upper case. | |
8236 * "g?" rot13 encoding | |
602 | 8237 * "g@" call 'operatorfunc' |
7 | 8238 */ |
8239 case 'q': | |
8240 case 'w': | |
8241 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
|
8242 /* FALLTHROUGH */ |
7 | 8243 case '~': |
8244 case 'u': | |
8245 case 'U': | |
8246 case '?': | |
602 | 8247 case '@': |
7 | 8248 nv_operator(cap); |
8249 break; | |
8250 | |
8251 /* | |
1188 | 8252 * "gd": Find first occurrence of pattern under the cursor in the |
7 | 8253 * current function |
8254 * "gD": idem, but in the current file. | |
8255 */ | |
8256 case 'd': | |
8257 case 'D': | |
523 | 8258 nv_gd(oap, cap->nchar, (int)cap->count0); |
7 | 8259 break; |
8260 | |
8261 #ifdef FEAT_MOUSE | |
8262 /* | |
8263 * g<*Mouse> : <C-*mouse> | |
8264 */ | |
8265 case K_MIDDLEMOUSE: | |
8266 case K_MIDDLEDRAG: | |
8267 case K_MIDDLERELEASE: | |
8268 case K_LEFTMOUSE: | |
8269 case K_LEFTDRAG: | |
8270 case K_LEFTRELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
8271 case K_MOUSEMOVE: |
7 | 8272 case K_RIGHTMOUSE: |
8273 case K_RIGHTDRAG: | |
8274 case K_RIGHTRELEASE: | |
8275 case K_X1MOUSE: | |
8276 case K_X1DRAG: | |
8277 case K_X1RELEASE: | |
8278 case K_X2MOUSE: | |
8279 case K_X2DRAG: | |
8280 case K_X2RELEASE: | |
8281 mod_mask = MOD_MASK_CTRL; | |
8282 (void)do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0); | |
8283 break; | |
8284 #endif | |
8285 | |
8286 case K_IGNORE: | |
8287 break; | |
8288 | |
8289 /* | |
8290 * "gP" and "gp": same as "P" and "p" but leave cursor just after new text | |
8291 */ | |
8292 case 'p': | |
8293 case 'P': | |
8294 nv_put(cap); | |
8295 break; | |
8296 | |
8297 #ifdef FEAT_BYTEOFF | |
8298 /* "go": goto byte count from start of buffer */ | |
8299 case 'o': | |
8300 goto_byte(cap->count0); | |
8301 break; | |
8302 #endif | |
8303 | |
8304 /* "gQ": improved Ex mode */ | |
8305 case 'Q': | |
633 | 8306 if (text_locked()) |
7 | 8307 { |
8308 clearopbeep(cap->oap); | |
633 | 8309 text_locked_msg(); |
7 | 8310 break; |
8311 } | |
631 | 8312 |
7 | 8313 if (!checkclearopq(oap)) |
8314 do_exmode(TRUE); | |
8315 break; | |
8316 | |
8317 #ifdef FEAT_JUMPLIST | |
8318 case ',': | |
8319 nv_pcmark(cap); | |
8320 break; | |
8321 | |
8322 case ';': | |
8323 cap->count1 = -cap->count1; | |
8324 nv_pcmark(cap); | |
8325 break; | |
8326 #endif | |
8327 | |
667 | 8328 case 't': |
3630 | 8329 if (!checkclearop(oap)) |
8330 goto_tabpage((int)cap->count0); | |
667 | 8331 break; |
682 | 8332 case 'T': |
3630 | 8333 if (!checkclearop(oap)) |
8334 goto_tabpage(-(int)cap->count1); | |
682 | 8335 break; |
667 | 8336 |
750 | 8337 case '+': |
8338 case '-': /* "g+" and "g-": undo or redo along the timeline */ | |
8339 if (!checkclearopq(oap)) | |
771 | 8340 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
|
8341 FALSE, FALSE, FALSE); |
750 | 8342 break; |
8343 | |
7 | 8344 default: |
8345 clearopbeep(oap); | |
8346 break; | |
8347 } | |
8348 } | |
8349 | |
8350 /* | |
8351 * Handle "o" and "O" commands. | |
8352 */ | |
8353 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8354 n_opencmd(cmdarg_T *cap) |
7 | 8355 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8356 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8357 linenr_T oldline = curwin->w_cursor.lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8358 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8359 |
7 | 8360 if (!checkclearopq(cap->oap)) |
8361 { | |
8362 #ifdef FEAT_FOLDING | |
8363 if (cap->cmdchar == 'O') | |
8364 /* Open above the first line of a folded sequence of lines */ | |
8365 (void)hasFolding(curwin->w_cursor.lnum, | |
8366 &curwin->w_cursor.lnum, NULL); | |
8367 else | |
8368 /* Open below the last line of a folded sequence of lines */ | |
8369 (void)hasFolding(curwin->w_cursor.lnum, | |
8370 NULL, &curwin->w_cursor.lnum); | |
8371 #endif | |
8372 if (u_save((linenr_T)(curwin->w_cursor.lnum - | |
8373 (cap->cmdchar == 'O' ? 1 : 0)), | |
8374 (linenr_T)(curwin->w_cursor.lnum + | |
8375 (cap->cmdchar == 'o' ? 1 : 0)) | |
8376 ) == OK | |
8377 && open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD, | |
8378 #ifdef FEAT_COMMENTS | |
8379 has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM : | |
8380 #endif | |
13772
cc21507ee4b1
patch 8.0.1758: open_line() returns TRUE/FALSE for success/failure
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
8381 0, 0) == OK) |
7 | 8382 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8383 #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
|
8384 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
|
8385 redrawWinline(curwin, oldline); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8386 #endif |
6834 | 8387 #ifdef FEAT_SYN_HL |
6821 | 8388 if (curwin->w_p_cul) |
8389 /* force redraw of cursorline */ | |
8390 curwin->w_valid &= ~VALID_CROW; | |
6834 | 8391 #endif |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
8392 /* 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
|
8393 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
|
8394 cap->count1 = 1; |
7 | 8395 invoke_edit(cap, FALSE, cap->cmdchar, TRUE); |
8396 } | |
8397 } | |
8398 } | |
8399 | |
8400 /* | |
8401 * "." command: redo last change. | |
8402 */ | |
8403 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8404 nv_dot(cmdarg_T *cap) |
7 | 8405 { |
8406 if (!checkclearopq(cap->oap)) | |
8407 { | |
8408 /* | |
8409 * If "restart_edit" is TRUE, the last but one command is repeated | |
8410 * instead of the last command (inserting text). This is used for | |
8411 * CTRL-O <.> in insert mode. | |
8412 */ | |
8413 if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == FAIL) | |
8414 clearopbeep(cap->oap); | |
8415 } | |
8416 } | |
8417 | |
8418 /* | |
8419 * CTRL-R: undo undo | |
8420 */ | |
8421 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8422 nv_redo(cmdarg_T *cap) |
7 | 8423 { |
8424 if (!checkclearopq(cap->oap)) | |
8425 { | |
8426 u_redo((int)cap->count1); | |
8427 curwin->w_set_curswant = TRUE; | |
8428 } | |
8429 } | |
8430 | |
8431 /* | |
8432 * Handle "U" command. | |
8433 */ | |
8434 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8435 nv_Undo(cmdarg_T *cap) |
7 | 8436 { |
8437 /* In Visual mode and typing "gUU" triggers an operator */ | |
5735 | 8438 if (cap->oap->op_type == OP_UPPER || VIsual_active) |
7 | 8439 { |
8440 /* translate "gUU" to "gUgU" */ | |
8441 cap->cmdchar = 'g'; | |
8442 cap->nchar = 'U'; | |
8443 nv_operator(cap); | |
8444 } | |
8445 else if (!checkclearopq(cap->oap)) | |
8446 { | |
8447 u_undoline(); | |
8448 curwin->w_set_curswant = TRUE; | |
8449 } | |
8450 } | |
8451 | |
8452 /* | |
8453 * '~' command: If tilde is not an operator and Visual is off: swap case of a | |
8454 * single character. | |
8455 */ | |
8456 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8457 nv_tilde(cmdarg_T *cap) |
7 | 8458 { |
5735 | 8459 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
|
8460 { |
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
|
8461 #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
|
8462 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
|
8463 { |
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
|
8464 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
|
8465 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
|
8466 } |
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
|
8467 #endif |
7 | 8468 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
|
8469 } |
7 | 8470 else |
8471 nv_operator(cap); | |
8472 } | |
8473 | |
8474 /* | |
8475 * Handle an operator command. | |
8476 * The actual work is done by do_pending_operator(). | |
8477 */ | |
8478 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8479 nv_operator(cmdarg_T *cap) |
7 | 8480 { |
8481 int op_type; | |
8482 | |
8483 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
|
8484 #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
|
8485 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
|
8486 { |
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
|
8487 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
|
8488 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
|
8489 } |
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
|
8490 #endif |
7 | 8491 |
8492 if (op_type == cap->oap->op_type) /* double operator works on lines */ | |
8493 nv_lineop(cap); | |
8494 else if (!checkclearop(cap->oap)) | |
8495 { | |
8496 cap->oap->start = curwin->w_cursor; | |
8497 cap->oap->op_type = op_type; | |
1490 | 8498 #ifdef FEAT_EVAL |
8499 set_op_var(op_type); | |
8500 #endif | |
8501 } | |
8502 } | |
8503 | |
8504 #ifdef FEAT_EVAL | |
8505 /* | |
8506 * Set v:operator to the characters for "optype". | |
8507 */ | |
8508 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8509 set_op_var(int optype) |
1490 | 8510 { |
8511 char_u opchars[3]; | |
8512 | |
8513 if (optype == OP_NOP) | |
8514 set_vim_var_string(VV_OP, NULL, 0); | |
8515 else | |
8516 { | |
8517 opchars[0] = get_op_char(optype); | |
8518 opchars[1] = get_extra_op_char(optype); | |
8519 opchars[2] = NUL; | |
8520 set_vim_var_string(VV_OP, opchars, -1); | |
8521 } | |
8522 } | |
8523 #endif | |
7 | 8524 |
8525 /* | |
8526 * Handle linewise operator "dd", "yy", etc. | |
8527 * | |
8528 * "_" is is a strange motion command that helps make operators more logical. | |
8529 * It is actually implemented, but not documented in the real Vi. This motion | |
8530 * command actually refers to "the current line". Commands like "dd" and "yy" | |
8531 * are really an alternate form of "d_" and "y_". It does accept a count, so | |
8532 * "d3_" works to delete 3 lines. | |
8533 */ | |
8534 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8535 nv_lineop(cmdarg_T *cap) |
7 | 8536 { |
8537 cap->oap->motion_type = MLINE; | |
8538 if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL) | |
8539 clearopbeep(cap->oap); | |
4011 | 8540 else if ( (cap->oap->op_type == OP_DELETE /* only with linewise motions */ |
8541 && cap->oap->motion_force != 'v' | |
8542 && cap->oap->motion_force != Ctrl_V) | |
7 | 8543 || cap->oap->op_type == OP_LSHIFT |
8544 || cap->oap->op_type == OP_RSHIFT) | |
8545 beginline(BL_SOL | BL_FIX); | |
8546 else if (cap->oap->op_type != OP_YANK) /* 'Y' does not move cursor */ | |
8547 beginline(BL_WHITE | BL_FIX); | |
8548 } | |
8549 | |
8550 /* | |
8551 * <Home> command. | |
8552 */ | |
8553 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8554 nv_home(cmdarg_T *cap) |
7 | 8555 { |
180 | 8556 /* CTRL-HOME is like "gg" */ |
8557 if (mod_mask & MOD_MASK_CTRL) | |
8558 nv_goto(cap); | |
8559 else | |
8560 { | |
8561 cap->count0 = 1; | |
8562 nv_pipe(cap); | |
8563 } | |
229 | 8564 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8565 one-character line). */ | |
7 | 8566 } |
8567 | |
8568 /* | |
8569 * "|" command. | |
8570 */ | |
8571 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8572 nv_pipe(cmdarg_T *cap) |
7 | 8573 { |
8574 cap->oap->motion_type = MCHAR; | |
8575 cap->oap->inclusive = FALSE; | |
8576 beginline(0); | |
8577 if (cap->count0 > 0) | |
8578 { | |
8579 coladvance((colnr_T)(cap->count0 - 1)); | |
8580 curwin->w_curswant = (colnr_T)(cap->count0 - 1); | |
8581 } | |
8582 else | |
8583 curwin->w_curswant = 0; | |
8584 /* keep curswant at the column where we wanted to go, not where | |
2667 | 8585 * we ended; differs if line is too short */ |
7 | 8586 curwin->w_set_curswant = FALSE; |
8587 } | |
8588 | |
8589 /* | |
8590 * Handle back-word command "b" and "B". | |
8591 * cap->arg is 1 for "B" | |
8592 */ | |
8593 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8594 nv_bck_word(cmdarg_T *cap) |
7 | 8595 { |
8596 cap->oap->motion_type = MCHAR; | |
8597 cap->oap->inclusive = FALSE; | |
8598 curwin->w_set_curswant = TRUE; | |
8599 if (bck_word(cap->count1, cap->arg, FALSE) == FAIL) | |
8600 clearopbeep(cap->oap); | |
8601 #ifdef FEAT_FOLDING | |
8602 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8603 foldOpenCursor(); | |
8604 #endif | |
8605 } | |
8606 | |
8607 /* | |
8608 * Handle word motion commands "e", "E", "w" and "W". | |
8609 * cap->arg is TRUE for "E" and "W". | |
8610 */ | |
8611 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8612 nv_wordcmd(cmdarg_T *cap) |
7 | 8613 { |
8614 int n; | |
8615 int word_end; | |
8616 int flag = FALSE; | |
1573 | 8617 pos_T startpos = curwin->w_cursor; |
7 | 8618 |
8619 /* | |
8620 * Set inclusive for the "E" and "e" command. | |
8621 */ | |
8622 if (cap->cmdchar == 'e' || cap->cmdchar == 'E') | |
8623 word_end = TRUE; | |
8624 else | |
8625 word_end = FALSE; | |
8626 cap->oap->inclusive = word_end; | |
8627 | |
8628 /* | |
8629 * "cw" and "cW" are a special case. | |
8630 */ | |
8631 if (!word_end && cap->oap->op_type == OP_CHANGE) | |
8632 { | |
8633 n = gchar_cursor(); | |
8634 if (n != NUL) /* not an empty line */ | |
8635 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
8636 if (VIM_ISWHITE(n)) |
7 | 8637 { |
8638 /* | |
8639 * Reproduce a funny Vi behaviour: "cw" on a blank only | |
8640 * changes one character, not all blanks until the start of | |
8641 * the next word. Only do this when the 'w' flag is included | |
8642 * in 'cpoptions'. | |
8643 */ | |
8644 if (cap->count1 == 1 && vim_strchr(p_cpo, CPO_CW) != NULL) | |
8645 { | |
8646 cap->oap->inclusive = TRUE; | |
8647 cap->oap->motion_type = MCHAR; | |
8648 return; | |
8649 } | |
8650 } | |
8651 else | |
8652 { | |
8653 /* | |
8654 * This is a little strange. To match what the real Vi does, | |
8655 * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided | |
8656 * that we are not on a space or a TAB. This seems impolite | |
8657 * at first, but it's really more what we mean when we say | |
8658 * 'cw'. | |
8659 * Another strangeness: When standing on the end of a word | |
4352 | 8660 * "ce" will change until the end of the next word, but "cw" |
7 | 8661 * will change only one character! This is done by setting |
8662 * flag. | |
8663 */ | |
8664 cap->oap->inclusive = TRUE; | |
8665 word_end = TRUE; | |
8666 flag = TRUE; | |
8667 } | |
8668 } | |
8669 } | |
8670 | |
8671 cap->oap->motion_type = MCHAR; | |
8672 curwin->w_set_curswant = TRUE; | |
8673 if (word_end) | |
8674 n = end_word(cap->count1, cap->arg, flag, FALSE); | |
8675 else | |
8676 n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP); | |
8677 | |
1573 | 8678 /* Don't leave the cursor on the NUL past the end of line. Unless we |
8679 * 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
|
8680 if (LT_POS(startpos, curwin->w_cursor)) |
1505 | 8681 adjust_cursor(cap->oap); |
7 | 8682 |
8683 if (n == FAIL && cap->oap->op_type == OP_NOP) | |
8684 clearopbeep(cap->oap); | |
8685 else | |
8686 { | |
8687 adjust_for_sel(cap); | |
8688 #ifdef FEAT_FOLDING | |
8689 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8690 foldOpenCursor(); | |
8691 #endif | |
8692 } | |
8693 } | |
8694 | |
8695 /* | |
1505 | 8696 * Used after a movement command: If the cursor ends up on the NUL after the |
8697 * end of the line, may move it back to the last character and make the motion | |
8698 * inclusive. | |
8699 */ | |
8700 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8701 adjust_cursor(oparg_T *oap) |
1505 | 8702 { |
8703 /* The cursor cannot remain on the NUL when: | |
8704 * - the column is > 0 | |
8705 * - not in Visual mode or 'selection' is "o" | |
8706 * - 'virtualedit' is not "all" and not "onemore". | |
8707 */ | |
8708 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL | |
8709 && (!VIsual_active || *p_sel == 'o') | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
8710 && !virtual_active() && (ve_flags & VE_ONEMORE) == 0) |
1505 | 8711 { |
8712 --curwin->w_cursor.col; | |
8713 /* prevent cursor from moving on the trail byte */ | |
8714 if (has_mbyte) | |
8715 mb_adjust_cursor(); | |
8716 oap->inclusive = TRUE; | |
8717 } | |
8718 } | |
8719 | |
8720 /* | |
7 | 8721 * "0" and "^" commands. |
8722 * cap->arg is the argument for beginline(). | |
8723 */ | |
8724 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8725 nv_beginline(cmdarg_T *cap) |
7 | 8726 { |
8727 cap->oap->motion_type = MCHAR; | |
8728 cap->oap->inclusive = FALSE; | |
8729 beginline(cap->arg); | |
8730 #ifdef FEAT_FOLDING | |
8731 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8732 foldOpenCursor(); | |
8733 #endif | |
557 | 8734 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8735 one-character line). */ | |
7 | 8736 } |
8737 | |
8738 /* | |
8739 * In exclusive Visual mode, may include the last character. | |
8740 */ | |
8741 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8742 adjust_for_sel(cmdarg_T *cap) |
7 | 8743 { |
8744 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
|
8745 && gchar_cursor() != NUL && LT_POS(VIsual, curwin->w_cursor)) |
7 | 8746 { |
8747 if (has_mbyte) | |
8748 inc_cursor(); | |
8749 else | |
8750 ++curwin->w_cursor.col; | |
8751 cap->oap->inclusive = FALSE; | |
8752 } | |
8753 } | |
8754 | |
8755 /* | |
8756 * Exclude last character at end of Visual area for 'selection' == "exclusive". | |
8757 * Should check VIsual_mode before calling this. | |
8758 * Returns TRUE when backed up to the previous line. | |
8759 */ | |
8760 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8761 unadjust_for_sel(void) |
7 | 8762 { |
8763 pos_T *pp; | |
8764 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8765 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
|
8766 { |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8767 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 8768 pp = &curwin->w_cursor; |
8769 else | |
8770 pp = &VIsual; | |
8771 if (pp->coladd > 0) | |
8772 --pp->coladd; | |
8773 else | |
8774 if (pp->col > 0) | |
8775 { | |
8776 --pp->col; | |
2933 | 8777 mb_adjustpos(curbuf, pp); |
7 | 8778 } |
8779 else if (pp->lnum > 1) | |
8780 { | |
8781 --pp->lnum; | |
8782 pp->col = (colnr_T)STRLEN(ml_get(pp->lnum)); | |
8783 return TRUE; | |
8784 } | |
8785 } | |
8786 return FALSE; | |
8787 } | |
8788 | |
8789 /* | |
8790 * SELECT key in Normal or Visual mode: end of Select mode mapping. | |
8791 */ | |
8792 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8793 nv_select(cmdarg_T *cap) |
7 | 8794 { |
8795 if (VIsual_active) | |
8796 VIsual_select = TRUE; | |
8797 else if (VIsual_reselect) | |
8798 { | |
8799 cap->nchar = 'v'; /* fake "gv" command */ | |
8800 cap->arg = TRUE; | |
8801 nv_g_cmd(cap); | |
8802 } | |
8803 } | |
8804 | |
8805 | |
8806 /* | |
8807 * "G", "gg", CTRL-END, CTRL-HOME. | |
8808 * cap->arg is TRUE for "G". | |
8809 */ | |
8810 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8811 nv_goto(cmdarg_T *cap) |
7 | 8812 { |
8813 linenr_T lnum; | |
8814 | |
8815 if (cap->arg) | |
8816 lnum = curbuf->b_ml.ml_line_count; | |
8817 else | |
8818 lnum = 1L; | |
8819 cap->oap->motion_type = MLINE; | |
8820 setpcmark(); | |
8821 | |
8822 /* When a count is given, use it instead of the default lnum */ | |
8823 if (cap->count0 != 0) | |
8824 lnum = cap->count0; | |
8825 if (lnum < 1L) | |
8826 lnum = 1L; | |
8827 else if (lnum > curbuf->b_ml.ml_line_count) | |
8828 lnum = curbuf->b_ml.ml_line_count; | |
8829 curwin->w_cursor.lnum = lnum; | |
8830 beginline(BL_SOL | BL_FIX); | |
8831 #ifdef FEAT_FOLDING | |
8832 if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8833 foldOpenCursor(); | |
8834 #endif | |
8835 } | |
8836 | |
8837 /* | |
8838 * CTRL-\ in Normal mode. | |
8839 */ | |
8840 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8841 nv_normal(cmdarg_T *cap) |
7 | 8842 { |
8843 if (cap->nchar == Ctrl_N || cap->nchar == Ctrl_G) | |
8844 { | |
8845 clearop(cap->oap); | |
643 | 8846 if (restart_edit != 0 && mode_displayed) |
7 | 8847 clear_cmdline = TRUE; /* unshow mode later */ |
8848 restart_edit = 0; | |
8849 #ifdef FEAT_CMDWIN | |
8850 if (cmdwin_type != 0) | |
8851 cmdwin_result = Ctrl_C; | |
8852 #endif | |
8853 if (VIsual_active) | |
8854 { | |
8855 end_visual_mode(); /* stop Visual */ | |
8856 redraw_curbuf_later(INVERTED); | |
8857 } | |
8858 /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */ | |
8859 if (cap->nchar == Ctrl_G && p_im) | |
8860 restart_edit = 'a'; | |
8861 } | |
8862 else | |
8863 clearopbeep(cap->oap); | |
8864 } | |
8865 | |
8866 /* | |
8867 * ESC in Normal mode: beep, but don't flush buffers. | |
8868 * Don't even beep if we are canceling a command. | |
8869 */ | |
8870 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8871 nv_esc(cmdarg_T *cap) |
7 | 8872 { |
8873 int no_reason; | |
8874 | |
8875 no_reason = (cap->oap->op_type == OP_NOP | |
8876 && cap->opcount == 0 | |
8877 && cap->count0 == 0 | |
8878 && cap->oap->regname == 0 | |
8879 && !p_im); | |
8880 | |
8881 if (cap->arg) /* TRUE for CTRL-C */ | |
8882 { | |
8883 if (restart_edit == 0 | |
8884 #ifdef FEAT_CMDWIN | |
8885 && cmdwin_type == 0 | |
8886 #endif | |
8887 && !VIsual_active | |
8888 && no_reason) | |
16089
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
8889 { |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
8890 if (anyBufIsChanged()) |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
8891 msg(_("Type :qa! and press <Enter> to abandon all changes and exit Vim")); |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
8892 else |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
8893 msg(_("Type :qa and press <Enter> to exit Vim")); |
4411c38f3d16
patch 8.1.1049: when user tries to exit with CTRL-C message is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
8894 } |
7 | 8895 |
8896 /* Don't reset "restart_edit" when 'insertmode' is set, it won't be | |
8897 * set again below when halfway a mapping. */ | |
8898 if (!p_im) | |
8899 restart_edit = 0; | |
8900 #ifdef FEAT_CMDWIN | |
8901 if (cmdwin_type != 0) | |
8902 { | |
8903 cmdwin_result = K_IGNORE; | |
8904 got_int = FALSE; /* don't stop executing autocommands et al. */ | |
8905 return; | |
8906 } | |
8907 #endif | |
8908 } | |
8909 | |
8910 if (VIsual_active) | |
8911 { | |
8912 end_visual_mode(); /* stop Visual */ | |
8913 check_cursor_col(); /* make sure cursor is not beyond EOL */ | |
8914 curwin->w_set_curswant = TRUE; | |
8915 redraw_curbuf_later(INVERTED); | |
8916 } | |
5735 | 8917 else if (no_reason) |
6949 | 8918 vim_beep(BO_ESC); |
7 | 8919 clearop(cap->oap); |
8920 | |
8921 /* A CTRL-C is often used at the start of a menu. When 'insertmode' is | |
8922 * 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
|
8923 if (restart_edit == 0 && goto_im() && ex_normal_busy == 0) |
7 | 8924 restart_edit = 'a'; |
8925 } | |
8926 | |
8927 /* | |
8928 * 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
|
8929 * Also handle K_PS, start bracketed paste. |
7 | 8930 */ |
8931 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8932 nv_edit(cmdarg_T *cap) |
7 | 8933 { |
8934 /* <Insert> is equal to "i" */ | |
8935 if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) | |
8936 cap->cmdchar = 'i'; | |
8937 | |
8938 /* in Visual mode "A" and "I" are an operator */ | |
8939 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
|
8940 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
8941 #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
|
8942 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
|
8943 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
8944 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
|
8945 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
|
8946 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
|
8947 return; |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
8948 } |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
8949 #endif |
7 | 8950 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
|
8951 } |
7 | 8952 |
8953 /* in Visual mode and after an operator "a" and "i" are for text objects */ | |
5735 | 8954 else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') |
8955 && (cap->oap->op_type != OP_NOP || VIsual_active)) | |
7 | 8956 { |
8957 #ifdef FEAT_TEXTOBJ | |
8958 nv_object(cap); | |
8959 #else | |
8960 clearopbeep(cap->oap); | |
8961 #endif | |
8962 } | |
11892
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
8963 #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
|
8964 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
|
8965 { |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
8966 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
|
8967 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
|
8968 return; |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
8969 } |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
8970 #endif |
7 | 8971 else if (!curbuf->b_p_ma && !p_im) |
8972 { | |
8973 /* 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
|
8974 emsg(_(e_modifiable)); |
7 | 8975 clearop(cap->oap); |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
8976 if (cap->cmdchar == K_PS) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
8977 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
8978 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 8979 } |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
8980 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
|
8981 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
8982 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
|
8983 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
|
8984 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
8985 /* 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
|
8986 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
|
8987 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
8988 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
|
8989 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
|
8990 } |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
8991 else |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
8992 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
|
8993 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
|
8994 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
|
8995 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
|
8996 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
|
8997 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
|
8998 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
8999 /* 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
|
9000 * 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
|
9001 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
|
9002 && 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
|
9003 inc_cursor(); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9004 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9005 /* 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
|
9006 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
|
9007 } |
7 | 9008 else if (!checkclearopq(cap->oap)) |
9009 { | |
9010 switch (cap->cmdchar) | |
9011 { | |
9012 case 'A': /* "A"ppend after the line */ | |
9013 curwin->w_set_curswant = TRUE; | |
9014 if (ve_flags == VE_ALL) | |
9015 { | |
9016 int save_State = State; | |
9017 | |
4352 | 9018 /* Pretend Insert mode here to allow the cursor on the |
7 | 9019 * character past the end of the line */ |
9020 State = INSERT; | |
9021 coladvance((colnr_T)MAXCOL); | |
9022 State = save_State; | |
9023 } | |
9024 else | |
9025 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor()); | |
9026 break; | |
9027 | |
9028 case 'I': /* "I"nsert before the first non-blank */ | |
164 | 9029 if (vim_strchr(p_cpo, CPO_INSEND) == NULL) |
9030 beginline(BL_WHITE); | |
9031 else | |
9032 beginline(BL_WHITE|BL_FIX); | |
7 | 9033 break; |
9034 | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9035 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
|
9036 /* 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
|
9037 * 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
|
9038 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
|
9039 break; |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
9040 /* FALLTHROUGH */ |
10813
09eb5fd275e0
patch 8.0.0296: bracketed paste can only append, not insert
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
9041 |
7 | 9042 case 'a': /* "a"ppend is like "i"nsert on the next character. */ |
9043 /* increment coladd when in virtual space, increment the | |
9044 * column otherwise, also to append after an unprintable char */ | |
9045 if (virtual_active() | |
9046 && (curwin->w_cursor.coladd > 0 | |
9047 || *ml_get_cursor() == NUL | |
9048 || *ml_get_cursor() == TAB)) | |
9049 curwin->w_cursor.coladd++; | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
9050 else if (*ml_get_cursor() != NUL) |
7 | 9051 inc_cursor(); |
9052 break; | |
9053 } | |
9054 | |
9055 if (curwin->w_cursor.coladd && cap->cmdchar != 'A') | |
9056 { | |
9057 int save_State = State; | |
9058 | |
4352 | 9059 /* Pretend Insert mode here to allow the cursor on the |
7 | 9060 * character past the end of the line */ |
9061 State = INSERT; | |
9062 coladvance(getviscol()); | |
9063 State = save_State; | |
9064 } | |
9065 | |
9066 invoke_edit(cap, FALSE, cap->cmdchar, FALSE); | |
9067 } | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9068 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
|
9069 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9070 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 9071 } |
9072 | |
9073 /* | |
9074 * Invoke edit() and take care of "restart_edit" and the return value. | |
9075 */ | |
9076 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9077 invoke_edit( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9078 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9079 int repl, /* "r" or "gr" command */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9080 int cmd, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9081 int startln) |
7 | 9082 { |
9083 int restart_edit_save = 0; | |
9084 | |
9085 /* Complicated: When the user types "a<C-O>a" we don't want to do Insert | |
9086 * mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow | |
9087 * it. */ | |
9088 if (repl || !stuff_empty()) | |
9089 restart_edit_save = restart_edit; | |
9090 else | |
9091 restart_edit_save = 0; | |
9092 | |
9093 /* Always reset "restart_edit", this is not a restarted edit. */ | |
9094 restart_edit = 0; | |
9095 | |
9096 if (edit(cmd, startln, cap->count1)) | |
9097 cap->retval |= CA_COMMAND_BUSY; | |
9098 | |
9099 if (restart_edit == 0) | |
9100 restart_edit = restart_edit_save; | |
9101 } | |
9102 | |
9103 #ifdef FEAT_TEXTOBJ | |
9104 /* | |
9105 * "a" or "i" while an operator is pending or in Visual mode: object motion. | |
9106 */ | |
9107 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9108 nv_object( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9109 cmdarg_T *cap) |
7 | 9110 { |
9111 int flag; | |
9112 int include; | |
9113 char_u *mps_save; | |
9114 | |
9115 if (cap->cmdchar == 'i') | |
9116 include = FALSE; /* "ix" = inner object: exclude white space */ | |
9117 else | |
9118 include = TRUE; /* "ax" = an object: include white space */ | |
9119 | |
9120 /* Make sure (), [], {} and <> are in 'matchpairs' */ | |
9121 mps_save = curbuf->b_p_mps; | |
9122 curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>"; | |
9123 | |
9124 switch (cap->nchar) | |
9125 { | |
9126 case 'w': /* "aw" = a word */ | |
9127 flag = current_word(cap->oap, cap->count1, include, FALSE); | |
9128 break; | |
9129 case 'W': /* "aW" = a WORD */ | |
9130 flag = current_word(cap->oap, cap->count1, include, TRUE); | |
9131 break; | |
9132 case 'b': /* "ab" = a braces block */ | |
9133 case '(': | |
9134 case ')': | |
9135 flag = current_block(cap->oap, cap->count1, include, '(', ')'); | |
9136 break; | |
9137 case 'B': /* "aB" = a Brackets block */ | |
9138 case '{': | |
9139 case '}': | |
9140 flag = current_block(cap->oap, cap->count1, include, '{', '}'); | |
9141 break; | |
9142 case '[': /* "a[" = a [] block */ | |
9143 case ']': | |
9144 flag = current_block(cap->oap, cap->count1, include, '[', ']'); | |
9145 break; | |
9146 case '<': /* "a<" = a <> block */ | |
9147 case '>': | |
9148 flag = current_block(cap->oap, cap->count1, include, '<', '>'); | |
9149 break; | |
420 | 9150 case 't': /* "at" = a tag block (xml and html) */ |
6661 | 9151 /* Do not adjust oap->end in do_pending_operator() |
9152 * otherwise there are different results for 'dit' | |
9153 * (note leading whitespace in last line): | |
9154 * 1) <b> 2) <b> | |
9155 * foobar foobar | |
9156 * </b> </b> | |
9157 */ | |
9158 cap->retval |= CA_NO_ADJ_OP_END; | |
420 | 9159 flag = current_tagblock(cap->oap, cap->count1, include); |
9160 break; | |
7 | 9161 case 'p': /* "ap" = a paragraph */ |
9162 flag = current_par(cap->oap, cap->count1, include, 'p'); | |
9163 break; | |
9164 case 's': /* "as" = a sentence */ | |
9165 flag = current_sent(cap->oap, cap->count1, include); | |
9166 break; | |
12 | 9167 case '"': /* "a"" = a double quoted string */ |
9168 case '\'': /* "a'" = a single quoted string */ | |
9169 case '`': /* "a`" = a backtick quoted string */ | |
9170 flag = current_quote(cap->oap, cap->count1, include, | |
9171 cap->nchar); | |
9172 break; | |
7 | 9173 #if 0 /* TODO */ |
9174 case 'S': /* "aS" = a section */ | |
9175 case 'f': /* "af" = a filename */ | |
9176 case 'u': /* "au" = a URL */ | |
9177 #endif | |
9178 default: | |
9179 flag = FAIL; | |
9180 break; | |
9181 } | |
9182 | |
9183 curbuf->b_p_mps = mps_save; | |
9184 if (flag == FAIL) | |
9185 clearopbeep(cap->oap); | |
9186 adjust_cursor_col(); | |
9187 curwin->w_set_curswant = TRUE; | |
9188 } | |
9189 #endif | |
9190 | |
9191 /* | |
9192 * "q" command: Start/stop recording. | |
9193 * "q:", "q/", "q?": edit command-line in command-line window. | |
9194 */ | |
9195 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9196 nv_record(cmdarg_T *cap) |
7 | 9197 { |
9198 if (cap->oap->op_type == OP_FORMAT) | |
9199 { | |
9200 /* "gqq" is the same as "gqgq": format line */ | |
9201 cap->cmdchar = 'g'; | |
9202 cap->nchar = 'q'; | |
9203 nv_operator(cap); | |
9204 } | |
9205 else if (!checkclearop(cap->oap)) | |
9206 { | |
9207 #ifdef FEAT_CMDWIN | |
9208 if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?') | |
9209 { | |
9210 stuffcharReadbuff(cap->nchar); | |
9211 stuffcharReadbuff(K_CMDWIN); | |
9212 } | |
9213 else | |
9214 #endif | |
9215 /* (stop) recording into a named register, unless executing a | |
9216 * 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
|
9217 if (reg_executing == 0 && do_record(cap->nchar) == FAIL) |
7 | 9218 clearopbeep(cap->oap); |
9219 } | |
9220 } | |
9221 | |
9222 /* | |
9223 * Handle the "@r" command. | |
9224 */ | |
9225 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9226 nv_at(cmdarg_T *cap) |
7 | 9227 { |
9228 if (checkclearop(cap->oap)) | |
9229 return; | |
9230 #ifdef FEAT_EVAL | |
9231 if (cap->nchar == '=') | |
9232 { | |
9233 if (get_expr_register() == NUL) | |
9234 return; | |
9235 } | |
9236 #endif | |
9237 while (cap->count1-- && !got_int) | |
9238 { | |
1034 | 9239 if (do_execreg(cap->nchar, FALSE, FALSE, FALSE) == FAIL) |
7 | 9240 { |
9241 clearopbeep(cap->oap); | |
9242 break; | |
9243 } | |
9244 line_breakcheck(); | |
9245 } | |
9246 } | |
9247 | |
9248 /* | |
9249 * Handle the CTRL-U and CTRL-D commands. | |
9250 */ | |
9251 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9252 nv_halfpage(cmdarg_T *cap) |
7 | 9253 { |
9254 if ((cap->cmdchar == Ctrl_U && curwin->w_cursor.lnum == 1) | |
9255 || (cap->cmdchar == Ctrl_D | |
9256 && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)) | |
9257 clearopbeep(cap->oap); | |
9258 else if (!checkclearop(cap->oap)) | |
9259 halfpage(cap->cmdchar == Ctrl_D, cap->count0); | |
9260 } | |
9261 | |
9262 /* | |
9263 * Handle "J" or "gJ" command. | |
9264 */ | |
9265 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9266 nv_join(cmdarg_T *cap) |
7 | 9267 { |
9268 if (VIsual_active) /* join the visual lines */ | |
9269 nv_operator(cap); | |
5735 | 9270 else if (!checkclearop(cap->oap)) |
7 | 9271 { |
9272 if (cap->count0 <= 1) | |
9273 cap->count0 = 2; /* default for join is two lines! */ | |
9274 if (curwin->w_cursor.lnum + cap->count0 - 1 > | |
9275 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
|
9276 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9277 /* 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
|
9278 if (cap->count0 <= 2) |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9279 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9280 clearopbeep(cap->oap); |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9281 return; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9282 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9283 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
|
9284 - curwin->w_cursor.lnum + 1; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9285 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9286 |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9287 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
|
9288 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
|
9289 (void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE, TRUE); |
7 | 9290 } |
9291 } | |
9292 | |
9293 /* | |
9294 * "P", "gP", "p" and "gp" commands. | |
9295 */ | |
9296 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9297 nv_put(cmdarg_T *cap) |
7 | 9298 { |
9299 int regname = 0; | |
9300 void *reg1 = NULL, *reg2 = NULL; | |
84 | 9301 int empty = FALSE; |
236 | 9302 int was_visual = FALSE; |
7 | 9303 int dir; |
9304 int flags = 0; | |
9305 | |
9306 if (cap->oap->op_type != OP_NOP) | |
9307 { | |
9308 #ifdef FEAT_DIFF | |
9309 /* "dp" is ":diffput" */ | |
9310 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') | |
9311 { | |
9312 clearop(cap->oap); | |
6314 | 9313 nv_diffgetput(TRUE, cap->opcount); |
7 | 9314 } |
9315 else | |
9316 #endif | |
9317 clearopbeep(cap->oap); | |
9318 } | |
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
|
9319 #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
|
9320 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
|
9321 { |
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
|
9322 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
|
9323 } |
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
|
9324 #endif |
7 | 9325 else |
9326 { | |
9327 dir = (cap->cmdchar == 'P' | |
9328 || (cap->cmdchar == 'g' && cap->nchar == 'P')) | |
9329 ? BACKWARD : FORWARD; | |
9330 prep_redo_cmd(cap); | |
9331 if (cap->cmdchar == 'g') | |
9332 flags |= PUT_CURSEND; | |
9333 | |
9334 if (VIsual_active) | |
9335 { | |
9336 /* Putting in Visual mode: The put text replaces the selected | |
9337 * text. First delete the selected text, then put the new text. | |
9338 * Need to save and restore the registers that the delete | |
9339 * overwrites if the old contents is being put. | |
9340 */ | |
236 | 9341 was_visual = TRUE; |
7 | 9342 regname = cap->oap->regname; |
5735 | 9343 #ifdef FEAT_CLIPBOARD |
7 | 9344 adjust_clip_reg(®name); |
5735 | 9345 #endif |
5682 | 9346 if (regname == 0 || regname == '"' |
4013 | 9347 || VIM_ISDIGIT(regname) || regname == '-' |
5735 | 9348 #ifdef FEAT_CLIPBOARD |
7 | 9349 || (clip_unnamed && (regname == '*' || regname == '+')) |
5735 | 9350 #endif |
7 | 9351 |
9352 ) | |
9353 { | |
4013 | 9354 /* The delete is going to overwrite the register we want to |
7 | 9355 * put, save it first. */ |
9356 reg1 = get_register(regname, TRUE); | |
9357 } | |
9358 | |
9359 /* Now delete the selected text. */ | |
9360 cap->cmdchar = 'd'; | |
9361 cap->nchar = NUL; | |
9362 cap->oap->regname = NUL; | |
9363 nv_operator(cap); | |
9364 do_pending_operator(cap, 0, FALSE); | |
84 | 9365 empty = (curbuf->b_ml.ml_flags & ML_EMPTY); |
7 | 9366 |
9367 /* delete PUT_LINE_BACKWARD; */ | |
9368 cap->oap->regname = regname; | |
9369 | |
9370 if (reg1 != NULL) | |
9371 { | |
9372 /* Delete probably changed the register we want to put, save | |
9373 * it first. Then put back what was there before the delete. */ | |
9374 reg2 = get_register(regname, FALSE); | |
9375 put_register(regname, reg1); | |
9376 } | |
9377 | |
9378 /* When deleted a linewise Visual area, put the register as | |
9379 * lines to avoid it joined with the next line. When deletion was | |
9380 * characterwise, split a line when putting lines. */ | |
9381 if (VIsual_mode == 'V') | |
9382 flags |= PUT_LINE; | |
9383 else if (VIsual_mode == 'v') | |
9384 flags |= PUT_LINE_SPLIT; | |
9385 if (VIsual_mode == Ctrl_V && dir == FORWARD) | |
9386 flags |= PUT_LINE_FORWARD; | |
9387 dir = BACKWARD; | |
9388 if ((VIsual_mode != 'V' | |
9389 && curwin->w_cursor.col < curbuf->b_op_start.col) | |
9390 || (VIsual_mode == 'V' | |
9391 && curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) | |
9392 /* cursor is at the end of the line or end of file, put | |
9393 * forward. */ | |
9394 dir = FORWARD; | |
5365 | 9395 /* May have been reset in do_put(). */ |
9396 VIsual_active = TRUE; | |
7 | 9397 } |
9398 do_put(cap->oap->regname, dir, cap->count1, flags); | |
9399 | |
9400 /* If a register was saved, put it back now. */ | |
9401 if (reg2 != NULL) | |
9402 put_register(regname, reg2); | |
236 | 9403 |
9404 /* What to reselect with "gv"? Selecting the just put text seems to | |
9405 * be the most useful, since the original text was removed. */ | |
9406 if (was_visual) | |
9407 { | |
690 | 9408 curbuf->b_visual.vi_start = curbuf->b_op_start; |
9409 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
|
9410 /* need to adjust cursor position */ |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
9411 if (*p_sel == 'e') |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
9412 inc(&curbuf->b_visual.vi_end); |
236 | 9413 } |
9414 | |
84 | 9415 /* When all lines were selected and deleted do_put() leaves an empty |
236 | 9416 * line that needs to be deleted now. */ |
84 | 9417 if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) |
817 | 9418 { |
84 | 9419 ml_delete(curbuf->b_ml.ml_line_count, TRUE); |
817 | 9420 |
9421 /* If the cursor was in that line, move it to the end of the last | |
9422 * line. */ | |
9423 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
9424 { | |
9425 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
9426 coladvance((colnr_T)MAXCOL); | |
9427 } | |
9428 } | |
7 | 9429 auto_format(FALSE, TRUE); |
9430 } | |
9431 } | |
9432 | |
9433 /* | |
9434 * "o" and "O" commands. | |
9435 */ | |
9436 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9437 nv_open(cmdarg_T *cap) |
7 | 9438 { |
9439 #ifdef FEAT_DIFF | |
9440 /* "do" is ":diffget" */ | |
9441 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') | |
9442 { | |
9443 clearop(cap->oap); | |
6314 | 9444 nv_diffgetput(FALSE, cap->opcount); |
7 | 9445 } |
9446 else | |
9447 #endif | |
9448 if (VIsual_active) /* switch start and end of visual */ | |
9449 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
|
9450 #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
|
9451 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
|
9452 { |
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
|
9453 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
|
9454 } |
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
|
9455 #endif |
7 | 9456 else |
9457 n_opencmd(cap); | |
9458 } | |
9459 | |
9460 #ifdef FEAT_NETBEANS_INTG | |
9461 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9462 nv_nbcmd(cmdarg_T *cap) |
7 | 9463 { |
9464 netbeans_keycommand(cap->nchar); | |
9465 } | |
9466 #endif | |
9467 | |
9468 #ifdef FEAT_DND | |
9469 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9470 nv_drop(cmdarg_T *cap UNUSED) |
7 | 9471 { |
9472 do_put('~', BACKWARD, 1L, PUT_CURSEND); | |
9473 } | |
9474 #endif | |
203 | 9475 |
9476 /* | |
9477 * Trigger CursorHold event. | |
9478 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the | |
9479 * input buffer. "did_cursorhold" is set to avoid retriggering. | |
9480 */ | |
9481 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9482 nv_cursorhold(cmdarg_T *cap) |
203 | 9483 { |
9484 apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); | |
9485 did_cursorhold = TRUE; | |
226 | 9486 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
9487 } | |
6866 | 9488 |
9489 /* | |
7001 | 9490 * Calculate start/end virtual columns for operating in block mode. |
6866 | 9491 */ |
9492 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9493 get_op_vcol( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9494 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9495 colnr_T redo_VIsual_vcol, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9496 int initial) /* when TRUE adjust position for 'selectmode' */ |
6866 | 9497 { |
9498 colnr_T start, end; | |
9499 | |
7001 | 9500 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
|
9501 || (!initial && oap->end.col < curwin->w_width)) |
6866 | 9502 return; |
9503 | |
7143
fe6d525d12f4
commit https://github.com/vim/vim/commit/10ad1d90da8c464e1bf08bf23d92d4888378a8a1
Christian Brabandt <cb@256bit.org>
parents:
7090
diff
changeset
|
9504 oap->block_mode = TRUE; |
6866 | 9505 |
9506 /* prevent from moving onto a trail byte */ | |
9507 if (has_mbyte) | |
9508 mb_adjustpos(curwin->w_buffer, &oap->end); | |
9509 | |
9510 getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol); | |
6961 | 9511 |
9512 if (!redo_VIsual_busy) | |
9513 { | |
9514 getvvcol(curwin, &(oap->end), &start, NULL, &end); | |
9515 | |
9516 if (start < oap->start_vcol) | |
9517 oap->start_vcol = start; | |
9518 if (end > oap->end_vcol) | |
9519 { | |
9520 if (initial && *p_sel == 'e' && start >= 1 | |
9521 && start - 1 >= oap->end_vcol) | |
9522 oap->end_vcol = start - 1; | |
9523 else | |
9524 oap->end_vcol = end; | |
9525 } | |
9526 } | |
9527 | |
6866 | 9528 /* if '$' was used, get oap->end_vcol from longest line */ |
9529 if (curwin->w_curswant == MAXCOL) | |
9530 { | |
9531 curwin->w_cursor.col = MAXCOL; | |
9532 oap->end_vcol = 0; | |
9533 for (curwin->w_cursor.lnum = oap->start.lnum; | |
9534 curwin->w_cursor.lnum <= oap->end.lnum; | |
9535 ++curwin->w_cursor.lnum) | |
9536 { | |
9537 getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end); | |
9538 if (end > oap->end_vcol) | |
9539 oap->end_vcol = end; | |
9540 } | |
9541 } | |
9542 else if (redo_VIsual_busy) | |
9543 oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1; | |
9544 /* | |
9545 * Correct oap->end.col and oap->start.col to be the | |
9546 * upper-left and lower-right corner of the block area. | |
9547 * | |
9548 * (Actually, this does convert column positions into character | |
9549 * positions) | |
9550 */ | |
9551 curwin->w_cursor.lnum = oap->end.lnum; | |
9552 coladvance(oap->end_vcol); | |
9553 oap->end = curwin->w_cursor; | |
9554 | |
9555 curwin->w_cursor = oap->start; | |
9556 coladvance(oap->start_vcol); | |
9557 oap->start = curwin->w_cursor; | |
9558 } |