Mercurial > vim
annotate src/normal.c @ 18128:aeabc666a119 v8.1.2059
patch 8.1.2059: fix for "x" deleting a fold has side effects
Commit: https://github.com/vim/vim/commit/56ebbabea1d8409ba67127b9674f6c714739c8e0
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Sep 20 13:40:14 2019 +0200
patch 8.1.2059: fix for "x" deleting a fold has side effects
Problem: Fix for "x" deleting a fold has side effects.
Solution: Fix it where the fold is included.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 20 Sep 2019 13:45:04 +0200 |
parents | 90b0af9ba4ff |
children | 1868ec23360e |
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 |
16606
7e733046db1d
patch 8.1.1306: Borland support is outdated and doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
16598
diff
changeset
|
30 static int nv_compare(const void *s1, const void *s2); |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
31 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
|
32 static void op_function(oparg_T *oap); |
5735 | 33 #if defined(FEAT_MOUSE) |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
34 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
|
35 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
|
36 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
|
37 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
38 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
|
39 static void clearop(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
40 static void clearopbeep(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
41 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
|
42 static void may_clear_cmdline(void); |
7 | 43 #ifdef FEAT_CMDL_INFO |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
44 static void del_from_showcmd(int); |
7 | 45 #endif |
46 | |
47 /* | |
48 * nv_*(): functions called to handle Normal and Visual mode commands. | |
49 * n_*(): functions called to handle Normal mode commands. | |
50 * v_*(): functions called to handle Visual mode commands. | |
51 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 static void nv_page(cmdarg_T *cap); |
7 | 58 #ifdef FEAT_MOUSE |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
59 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
|
60 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
|
61 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
62 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
|
63 static void nv_zet(cmdarg_T *cap); |
7 | 64 #ifdef FEAT_GUI |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
65 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
|
66 static void nv_hor_scrollbar(cmdarg_T *cap); |
7 | 67 #endif |
685 | 68 #ifdef FEAT_GUI_TABLINE |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
69 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
|
70 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
|
71 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 static void nv_operator(cmdarg_T *cap); |
1490 | 120 #ifdef FEAT_EVAL |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
121 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
|
122 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 static int unadjust_for_sel(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 static void invoke_edit(cmdarg_T *cap, int repl, int cmd, int startln); |
7 | 138 #ifdef FEAT_TEXTOBJ |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
139 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
|
140 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
141 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
|
142 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
|
143 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
|
144 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
|
145 static void nv_put(cmdarg_T *cap); |
16742
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
146 static void nv_put_opt(cmdarg_T *cap, int fix_indent); |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
147 static void nv_open(cmdarg_T *cap); |
7 | 148 #ifdef FEAT_NETBEANS_INTG |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
149 static void nv_nbcmd(cmdarg_T *cap); |
7 | 150 #endif |
151 #ifdef FEAT_DND | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
152 static void nv_drop(cmdarg_T *cap); |
7 | 153 #endif |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
154 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
|
155 static void get_op_vcol(oparg_T *oap, colnr_T col, int initial); |
7 | 156 |
1728 | 157 static char *e_noident = N_("E349: No identifier under cursor"); |
158 | |
7 | 159 /* |
160 * Function to be called for a Normal or Visual mode command. | |
161 * The argument is a cmdarg_T. | |
162 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
163 typedef void (*nv_func_T)(cmdarg_T *cap); |
7 | 164 |
165 /* Values for cmd_flags. */ | |
166 #define NV_NCH 0x01 /* may need to get a second char */ | |
167 #define NV_NCH_NOP (0x02|NV_NCH) /* get second char when no operator pending */ | |
168 #define NV_NCH_ALW (0x04|NV_NCH) /* always get a second char */ | |
169 #define NV_LANG 0x08 /* second char needs language adjustment */ | |
170 | |
171 #define NV_SS 0x10 /* may start selection */ | |
172 #define NV_SSS 0x20 /* may start selection with shift modifier */ | |
173 #define NV_STS 0x40 /* may stop selection without shift modif. */ | |
174 #define NV_RL 0x80 /* 'rightleft' modifies command */ | |
175 #define NV_KEEPREG 0x100 /* don't clear regname */ | |
176 #define NV_NCW 0x200 /* not allowed in command-line window */ | |
177 | |
178 /* | |
179 * Generally speaking, every Normal mode command should either clear any | |
180 * pending operator (with *clearop*()), or set the motion type variable | |
181 * oap->motion_type. | |
182 * | |
183 * When a cursor motion command is made, it is marked as being a character or | |
184 * line oriented motion. Then, if an operator is in effect, the operation | |
185 * becomes character or line oriented accordingly. | |
186 */ | |
187 | |
188 /* | |
189 * This table contains one entry for every Normal or Visual mode command. | |
190 * The order doesn't matter, init_normal_cmds() will create a sorted index. | |
191 * It is faster when all keys from zero to '~' are present. | |
192 */ | |
193 static const struct nv_cmd | |
194 { | |
195 int cmd_char; /* (first) command character */ | |
196 nv_func_T cmd_func; /* function for this command */ | |
197 short_u cmd_flags; /* NV_ flags */ | |
198 short cmd_arg; /* value for ca.arg */ | |
199 } nv_cmds[] = | |
200 { | |
201 {NUL, nv_error, 0, 0}, | |
202 {Ctrl_A, nv_addsub, 0, 0}, | |
203 {Ctrl_B, nv_page, NV_STS, BACKWARD}, | |
204 {Ctrl_C, nv_esc, 0, TRUE}, | |
205 {Ctrl_D, nv_halfpage, 0, 0}, | |
206 {Ctrl_E, nv_scroll_line, 0, TRUE}, | |
207 {Ctrl_F, nv_page, NV_STS, FORWARD}, | |
208 {Ctrl_G, nv_ctrlg, 0, 0}, | |
209 {Ctrl_H, nv_ctrlh, 0, 0}, | |
210 {Ctrl_I, nv_pcmark, 0, 0}, | |
211 {NL, nv_down, 0, FALSE}, | |
212 {Ctrl_K, nv_error, 0, 0}, | |
213 {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
|
214 {CAR, nv_down, 0, TRUE}, |
7 | 215 {Ctrl_N, nv_down, NV_STS, FALSE}, |
216 {Ctrl_O, nv_ctrlo, 0, 0}, | |
217 {Ctrl_P, nv_up, NV_STS, FALSE}, | |
167 | 218 {Ctrl_Q, nv_visual, 0, FALSE}, |
7 | 219 {Ctrl_R, nv_redo, 0, 0}, |
220 {Ctrl_S, nv_ignore, 0, 0}, | |
221 {Ctrl_T, nv_tagpop, NV_NCW, 0}, | |
222 {Ctrl_U, nv_halfpage, 0, 0}, | |
223 {Ctrl_V, nv_visual, 0, FALSE}, | |
224 {'V', nv_visual, 0, FALSE}, | |
225 {'v', nv_visual, 0, FALSE}, | |
226 {Ctrl_W, nv_window, 0, 0}, | |
227 {Ctrl_X, nv_addsub, 0, 0}, | |
228 {Ctrl_Y, nv_scroll_line, 0, FALSE}, | |
229 {Ctrl_Z, nv_suspend, 0, 0}, | |
230 {ESC, nv_esc, 0, FALSE}, | |
231 {Ctrl_BSL, nv_normal, NV_NCH_ALW, 0}, | |
232 {Ctrl_RSB, nv_ident, NV_NCW, 0}, | |
233 {Ctrl_HAT, nv_hat, NV_NCW, 0}, | |
234 {Ctrl__, nv_error, 0, 0}, | |
235 {' ', nv_right, 0, 0}, | |
236 {'!', nv_operator, 0, 0}, | |
237 {'"', nv_regname, NV_NCH_NOP|NV_KEEPREG, 0}, | |
238 {'#', nv_ident, 0, 0}, | |
239 {'$', nv_dollar, 0, 0}, | |
240 {'%', nv_percent, 0, 0}, | |
241 {'&', nv_optrans, 0, 0}, | |
242 {'\'', nv_gomark, NV_NCH_ALW, TRUE}, | |
243 {'(', nv_brace, 0, BACKWARD}, | |
244 {')', nv_brace, 0, FORWARD}, | |
245 {'*', nv_ident, 0, 0}, | |
246 {'+', nv_down, 0, TRUE}, | |
247 {',', nv_csearch, 0, TRUE}, | |
248 {'-', nv_up, 0, TRUE}, | |
249 {'.', nv_dot, NV_KEEPREG, 0}, | |
250 {'/', nv_search, 0, FALSE}, | |
251 {'0', nv_beginline, 0, 0}, | |
252 {'1', nv_ignore, 0, 0}, | |
253 {'2', nv_ignore, 0, 0}, | |
254 {'3', nv_ignore, 0, 0}, | |
255 {'4', nv_ignore, 0, 0}, | |
256 {'5', nv_ignore, 0, 0}, | |
257 {'6', nv_ignore, 0, 0}, | |
258 {'7', nv_ignore, 0, 0}, | |
259 {'8', nv_ignore, 0, 0}, | |
260 {'9', nv_ignore, 0, 0}, | |
261 {':', nv_colon, 0, 0}, | |
262 {';', nv_csearch, 0, FALSE}, | |
263 {'<', nv_operator, NV_RL, 0}, | |
264 {'=', nv_operator, 0, 0}, | |
265 {'>', nv_operator, NV_RL, 0}, | |
266 {'?', nv_search, 0, FALSE}, | |
267 {'@', nv_at, NV_NCH_NOP, FALSE}, | |
268 {'A', nv_edit, 0, 0}, | |
269 {'B', nv_bck_word, 0, 1}, | |
270 {'C', nv_abbrev, NV_KEEPREG, 0}, | |
271 {'D', nv_abbrev, NV_KEEPREG, 0}, | |
272 {'E', nv_wordcmd, 0, TRUE}, | |
273 {'F', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
274 {'G', nv_goto, 0, TRUE}, | |
275 {'H', nv_scroll, 0, 0}, | |
276 {'I', nv_edit, 0, 0}, | |
277 {'J', nv_join, 0, 0}, | |
278 {'K', nv_ident, 0, 0}, | |
279 {'L', nv_scroll, 0, 0}, | |
280 {'M', nv_scroll, 0, 0}, | |
281 {'N', nv_next, 0, SEARCH_REV}, | |
282 {'O', nv_open, 0, 0}, | |
283 {'P', nv_put, 0, 0}, | |
284 {'Q', nv_exmode, NV_NCW, 0}, | |
285 {'R', nv_Replace, 0, FALSE}, | |
286 {'S', nv_subst, NV_KEEPREG, 0}, | |
287 {'T', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
288 {'U', nv_Undo, 0, 0}, | |
289 {'W', nv_wordcmd, 0, TRUE}, | |
290 {'X', nv_abbrev, NV_KEEPREG, 0}, | |
291 {'Y', nv_abbrev, NV_KEEPREG, 0}, | |
292 {'Z', nv_Zet, NV_NCH_NOP|NV_NCW, 0}, | |
293 {'[', nv_brackets, NV_NCH_ALW, BACKWARD}, | |
294 {'\\', nv_error, 0, 0}, | |
295 {']', nv_brackets, NV_NCH_ALW, FORWARD}, | |
296 {'^', nv_beginline, 0, BL_WHITE | BL_FIX}, | |
297 {'_', nv_lineop, 0, 0}, | |
298 {'`', nv_gomark, NV_NCH_ALW, FALSE}, | |
299 {'a', nv_edit, NV_NCH, 0}, | |
300 {'b', nv_bck_word, 0, 0}, | |
301 {'c', nv_operator, 0, 0}, | |
302 {'d', nv_operator, 0, 0}, | |
303 {'e', nv_wordcmd, 0, FALSE}, | |
304 {'f', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
305 {'g', nv_g_cmd, NV_NCH_ALW, FALSE}, | |
306 {'h', nv_left, NV_RL, 0}, | |
307 {'i', nv_edit, NV_NCH, 0}, | |
308 {'j', nv_down, 0, FALSE}, | |
309 {'k', nv_up, 0, FALSE}, | |
310 {'l', nv_right, NV_RL, 0}, | |
311 {'m', nv_mark, NV_NCH_NOP, 0}, | |
312 {'n', nv_next, 0, 0}, | |
313 {'o', nv_open, 0, 0}, | |
314 {'p', nv_put, 0, 0}, | |
315 {'q', nv_record, NV_NCH, 0}, | |
316 {'r', nv_replace, NV_NCH_NOP|NV_LANG, 0}, | |
317 {'s', nv_subst, NV_KEEPREG, 0}, | |
318 {'t', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
319 {'u', nv_undo, 0, 0}, | |
320 {'w', nv_wordcmd, 0, FALSE}, | |
321 {'x', nv_abbrev, NV_KEEPREG, 0}, | |
322 {'y', nv_operator, 0, 0}, | |
323 {'z', nv_zet, NV_NCH_ALW, 0}, | |
324 {'{', nv_findpar, 0, BACKWARD}, | |
325 {'|', nv_pipe, 0, 0}, | |
326 {'}', nv_findpar, 0, FORWARD}, | |
327 {'~', nv_tilde, 0, 0}, | |
328 | |
329 /* pound sign */ | |
330 {POUND, nv_ident, 0, 0}, | |
331 #ifdef FEAT_MOUSE | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
332 {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
|
333 {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
|
334 {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
|
335 {K_MOUSERIGHT, nv_mousescroll, 0, MSCR_RIGHT}, |
7 | 336 {K_LEFTMOUSE, nv_mouse, 0, 0}, |
337 {K_LEFTMOUSE_NM, nv_mouse, 0, 0}, | |
338 {K_LEFTDRAG, nv_mouse, 0, 0}, | |
339 {K_LEFTRELEASE, nv_mouse, 0, 0}, | |
340 {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
|
341 {K_MOUSEMOVE, nv_mouse, 0, 0}, |
7 | 342 {K_MIDDLEMOUSE, nv_mouse, 0, 0}, |
343 {K_MIDDLEDRAG, nv_mouse, 0, 0}, | |
344 {K_MIDDLERELEASE, nv_mouse, 0, 0}, | |
345 {K_RIGHTMOUSE, nv_mouse, 0, 0}, | |
346 {K_RIGHTDRAG, nv_mouse, 0, 0}, | |
347 {K_RIGHTRELEASE, nv_mouse, 0, 0}, | |
348 {K_X1MOUSE, nv_mouse, 0, 0}, | |
349 {K_X1DRAG, nv_mouse, 0, 0}, | |
350 {K_X1RELEASE, nv_mouse, 0, 0}, | |
351 {K_X2MOUSE, nv_mouse, 0, 0}, | |
352 {K_X2DRAG, nv_mouse, 0, 0}, | |
353 {K_X2RELEASE, nv_mouse, 0, 0}, | |
354 #endif | |
819 | 355 {K_IGNORE, nv_ignore, NV_KEEPREG, 0}, |
620 | 356 {K_NOP, nv_nop, 0, 0}, |
7 | 357 {K_INS, nv_edit, 0, 0}, |
358 {K_KINS, nv_edit, 0, 0}, | |
359 {K_BS, nv_ctrlh, 0, 0}, | |
360 {K_UP, nv_up, NV_SSS|NV_STS, FALSE}, | |
361 {K_S_UP, nv_page, NV_SS, BACKWARD}, | |
362 {K_DOWN, nv_down, NV_SSS|NV_STS, FALSE}, | |
363 {K_S_DOWN, nv_page, NV_SS, FORWARD}, | |
364 {K_LEFT, nv_left, NV_SSS|NV_STS|NV_RL, 0}, | |
365 {K_S_LEFT, nv_bck_word, NV_SS|NV_RL, 0}, | |
366 {K_C_LEFT, nv_bck_word, NV_SSS|NV_RL|NV_STS, 1}, | |
367 {K_RIGHT, nv_right, NV_SSS|NV_STS|NV_RL, 0}, | |
368 {K_S_RIGHT, nv_wordcmd, NV_SS|NV_RL, FALSE}, | |
369 {K_C_RIGHT, nv_wordcmd, NV_SSS|NV_RL|NV_STS, TRUE}, | |
370 {K_PAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
371 {K_KPAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
372 {K_PAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
373 {K_KPAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
374 {K_END, nv_end, NV_SSS|NV_STS, FALSE}, | |
375 {K_KEND, nv_end, NV_SSS|NV_STS, FALSE}, | |
376 {K_S_END, nv_end, NV_SS, FALSE}, | |
377 {K_C_END, nv_end, NV_SSS|NV_STS, TRUE}, | |
378 {K_HOME, nv_home, NV_SSS|NV_STS, 0}, | |
379 {K_KHOME, nv_home, NV_SSS|NV_STS, 0}, | |
380 {K_S_HOME, nv_home, NV_SS, 0}, | |
381 {K_C_HOME, nv_goto, NV_SSS|NV_STS, FALSE}, | |
382 {K_DEL, nv_abbrev, 0, 0}, | |
383 {K_KDEL, nv_abbrev, 0, 0}, | |
384 {K_UNDO, nv_kundo, 0, 0}, | |
385 {K_HELP, nv_help, NV_NCW, 0}, | |
386 {K_F1, nv_help, NV_NCW, 0}, | |
387 {K_XF1, nv_help, NV_NCW, 0}, | |
388 {K_SELECT, nv_select, 0, 0}, | |
389 #ifdef FEAT_GUI | |
390 {K_VER_SCROLLBAR, nv_ver_scrollbar, 0, 0}, | |
391 {K_HOR_SCROLLBAR, nv_hor_scrollbar, 0, 0}, | |
392 #endif | |
685 | 393 #ifdef FEAT_GUI_TABLINE |
394 {K_TABLINE, nv_tabline, 0, 0}, | |
686 | 395 {K_TABMENU, nv_tabmenu, 0, 0}, |
685 | 396 #endif |
7 | 397 #ifdef FEAT_NETBEANS_INTG |
398 {K_F21, nv_nbcmd, NV_NCH_ALW, 0}, | |
399 #endif | |
400 #ifdef FEAT_DND | |
401 {K_DROP, nv_drop, NV_STS, 0}, | |
402 #endif | |
819 | 403 {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
|
404 {K_PS, nv_edit, 0, 0}, |
7 | 405 }; |
406 | |
407 /* Number of commands in nv_cmds[]. */ | |
408 #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd)) | |
409 | |
410 /* Sorted index of commands in nv_cmds[]. */ | |
411 static short nv_cmd_idx[NV_CMDS_SIZE]; | |
412 | |
413 /* The highest index for which | |
414 * nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] */ | |
415 static int nv_max_linear; | |
416 | |
417 /* | |
418 * Compare functions for qsort() below, that checks the command character | |
419 * through the index in nv_cmd_idx[]. | |
420 */ | |
421 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
422 nv_compare(const void *s1, const void *s2) |
7 | 423 { |
424 int c1, c2; | |
425 | |
426 /* The commands are sorted on absolute value. */ | |
427 c1 = nv_cmds[*(const short *)s1].cmd_char; | |
428 c2 = nv_cmds[*(const short *)s2].cmd_char; | |
429 if (c1 < 0) | |
430 c1 = -c1; | |
431 if (c2 < 0) | |
432 c2 = -c2; | |
433 return c1 - c2; | |
434 } | |
435 | |
436 /* | |
437 * Initialize the nv_cmd_idx[] table. | |
438 */ | |
439 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
440 init_normal_cmds(void) |
7 | 441 { |
442 int i; | |
443 | |
444 /* Fill the index table with a one to one relation. */ | |
1877 | 445 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 446 nv_cmd_idx[i] = i; |
447 | |
448 /* Sort the commands by the command character. */ | |
449 qsort((void *)&nv_cmd_idx, (size_t)NV_CMDS_SIZE, sizeof(short), nv_compare); | |
450 | |
451 /* Find the first entry that can't be indexed by the command character. */ | |
1877 | 452 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 453 if (i != nv_cmds[nv_cmd_idx[i]].cmd_char) |
454 break; | |
455 nv_max_linear = i - 1; | |
456 } | |
457 | |
458 /* | |
459 * Search for a command in the commands table. | |
460 * Returns -1 for invalid command. | |
461 */ | |
462 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
463 find_command(int cmdchar) |
7 | 464 { |
465 int i; | |
466 int idx; | |
467 int top, bot; | |
468 int c; | |
469 | |
470 /* A multi-byte character is never a command. */ | |
471 if (cmdchar >= 0x100) | |
472 return -1; | |
473 | |
474 /* We use the absolute value of the character. Special keys have a | |
475 * negative value, but are sorted on their absolute value. */ | |
476 if (cmdchar < 0) | |
477 cmdchar = -cmdchar; | |
478 | |
479 /* If the character is in the first part: The character is the index into | |
480 * nv_cmd_idx[]. */ | |
481 if (cmdchar <= nv_max_linear) | |
482 return nv_cmd_idx[cmdchar]; | |
483 | |
484 /* Perform a binary search. */ | |
485 bot = nv_max_linear + 1; | |
486 top = NV_CMDS_SIZE - 1; | |
487 idx = -1; | |
488 while (bot <= top) | |
489 { | |
490 i = (top + bot) / 2; | |
491 c = nv_cmds[nv_cmd_idx[i]].cmd_char; | |
492 if (c < 0) | |
493 c = -c; | |
494 if (cmdchar == c) | |
495 { | |
496 idx = nv_cmd_idx[i]; | |
497 break; | |
498 } | |
499 if (cmdchar > c) | |
500 bot = i + 1; | |
501 else | |
502 top = i - 1; | |
503 } | |
504 return idx; | |
505 } | |
506 | |
507 /* | |
508 * Execute a command in Normal mode. | |
509 */ | |
510 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
511 normal_cmd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
512 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
513 int toplevel UNUSED) /* TRUE when called from main() */ |
7 | 514 { |
515 cmdarg_T ca; /* command arguments */ | |
516 int c; | |
517 int ctrl_w = FALSE; /* got CTRL-W command */ | |
518 int old_col = curwin->w_curswant; | |
519 #ifdef FEAT_CMDL_INFO | |
520 int need_flushbuf; /* need to call out_flush() */ | |
521 #endif | |
522 pos_T old_pos; /* cursor position before command */ | |
523 int mapped_len; | |
524 static int old_mapped_len = 0; | |
525 int idx; | |
1751 | 526 #ifdef FEAT_EVAL |
527 int set_prevcount = FALSE; | |
528 #endif | |
7 | 529 |
530 vim_memset(&ca, 0, sizeof(ca)); /* also resets ca.retval */ | |
531 ca.oap = oap; | |
1692 | 532 |
533 /* Use a count remembered from before entering an operator. After typing | |
534 * "3d" we return from normal_cmd() and come back here, the "3" is | |
535 * remembered in "opcount". */ | |
7 | 536 ca.opcount = opcount; |
537 | |
538 /* | |
539 * If there is an operator pending, then the command we take this time | |
540 * will terminate it. Finish_op tells us to finish the operation before | |
541 * returning this time (unless the operation was cancelled). | |
542 */ | |
543 #ifdef CURSOR_SHAPE | |
544 c = finish_op; | |
545 #endif | |
546 finish_op = (oap->op_type != OP_NOP); | |
547 #ifdef CURSOR_SHAPE | |
548 if (finish_op != c) | |
549 { | |
550 ui_cursor_shape(); /* may show different cursor shape */ | |
551 # ifdef FEAT_MOUSESHAPE | |
552 update_mouseshape(-1); | |
553 # endif | |
554 } | |
555 #endif | |
556 | |
1692 | 557 /* When not finishing an operator and no register name typed, reset the |
558 * count. */ | |
7 | 559 if (!finish_op && !oap->regname) |
1751 | 560 { |
7 | 561 ca.opcount = 0; |
1751 | 562 #ifdef FEAT_EVAL |
563 set_prevcount = TRUE; | |
564 #endif | |
565 } | |
7 | 566 |
1692 | 567 /* Restore counts from before receiving K_CURSORHOLD. This means after |
568 * typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not | |
569 * "3 * 2". */ | |
570 if (oap->prev_opcount > 0 || oap->prev_count0 > 0) | |
571 { | |
572 ca.opcount = oap->prev_opcount; | |
573 ca.count0 = oap->prev_count0; | |
574 oap->prev_opcount = 0; | |
575 oap->prev_count0 = 0; | |
576 } | |
577 | |
7 | 578 mapped_len = typebuf_maplen(); |
579 | |
580 State = NORMAL_BUSY; | |
581 #ifdef USE_ON_FLY_SCROLL | |
582 dont_scroll = FALSE; /* allow scrolling here */ | |
583 #endif | |
584 | |
2667 | 585 #ifdef FEAT_EVAL |
586 /* Set v:count here, when called from main() and not a stuffed | |
587 * command, so that v:count can be used in an expression mapping | |
5649 | 588 * when there is no count. Do set it for redo. */ |
589 if (toplevel && readbuf1_empty()) | |
2667 | 590 set_vcount_ca(&ca, &set_prevcount); |
591 #endif | |
592 | |
7 | 593 /* |
594 * Get the command character from the user. | |
595 */ | |
596 c = safe_vgetc(); | |
7703
39251e981d1f
commit https://github.com/vim/vim/commit/25281634cda03ce302aaf9f906a9520b5f81f91e
Christian Brabandt <cb@256bit.org>
parents:
7578
diff
changeset
|
597 LANGMAP_ADJUST(c, get_real_state() != SELECTMODE); |
7 | 598 |
599 /* | |
600 * If a mapping was started in Visual or Select mode, remember the length | |
601 * of the mapping. This is used below to not return to Insert mode for as | |
602 * long as the mapping is being executed. | |
603 */ | |
604 if (restart_edit == 0) | |
605 old_mapped_len = 0; | |
606 else if (old_mapped_len | |
819 | 607 || (VIsual_active && mapped_len == 0 && typebuf_maplen() > 0)) |
7 | 608 old_mapped_len = typebuf_maplen(); |
609 | |
610 if (c == NUL) | |
611 c = K_ZERO; | |
612 | |
613 /* | |
614 * In Select mode, typed text replaces the selection. | |
615 */ | |
616 if (VIsual_active | |
617 && VIsual_select | |
618 && (vim_isprintc(c) || c == NL || c == CAR || c == K_KENTER)) | |
619 { | |
275 | 620 /* Fake a "c"hange command. When "restart_edit" is set (e.g., because |
621 * 'insertmode' is set) fake a "d"elete command, Insert mode will | |
622 * restart automatically. | |
1051 | 623 * Insert the typed character in the typeahead buffer, so that it can |
624 * be mapped in Insert mode. Required for ":lmap" to work. */ | |
852 | 625 ins_char_typebuf(c); |
275 | 626 if (restart_edit != 0) |
627 c = 'd'; | |
628 else | |
629 c = 'c'; | |
695 | 630 msg_nowait = TRUE; /* don't delay going to insert mode */ |
4472 | 631 old_mapped_len = 0; /* do go to Insert mode */ |
7 | 632 } |
633 | |
634 #ifdef FEAT_CMDL_INFO | |
635 need_flushbuf = add_to_showcmd(c); | |
636 #endif | |
637 | |
638 getcount: | |
639 if (!(VIsual_active && VIsual_select)) | |
640 { | |
641 /* | |
642 * Handle a count before a command and compute ca.count0. | |
643 * Note that '0' is a command and not the start of a count, but it's | |
644 * part of a count after other digits. | |
645 */ | |
646 while ( (c >= '1' && c <= '9') | |
647 || (ca.count0 != 0 && (c == K_DEL || c == K_KDEL || c == '0'))) | |
648 { | |
649 if (c == K_DEL || c == K_KDEL) | |
650 { | |
651 ca.count0 /= 10; | |
652 #ifdef FEAT_CMDL_INFO | |
653 del_from_showcmd(4); /* delete the digit and ~@% */ | |
654 #endif | |
655 } | |
656 else | |
657 ca.count0 = ca.count0 * 10 + (c - '0'); | |
658 if (ca.count0 < 0) /* got too large! */ | |
659 ca.count0 = 999999999L; | |
1425 | 660 #ifdef FEAT_EVAL |
661 /* Set v:count here, when called from main() and not a stuffed | |
662 * command, so that v:count can be used in an expression mapping | |
5649 | 663 * right after the count. Do set it for redo. */ |
664 if (toplevel && readbuf1_empty()) | |
2667 | 665 set_vcount_ca(&ca, &set_prevcount); |
1425 | 666 #endif |
7 | 667 if (ctrl_w) |
668 { | |
669 ++no_mapping; | |
670 ++allow_keys; /* no mapping for nchar, but keys */ | |
671 } | |
672 ++no_zero_mapping; /* don't map zero here */ | |
1389 | 673 c = plain_vgetc(); |
7 | 674 LANGMAP_ADJUST(c, TRUE); |
675 --no_zero_mapping; | |
676 if (ctrl_w) | |
677 { | |
678 --no_mapping; | |
679 --allow_keys; | |
680 } | |
681 #ifdef FEAT_CMDL_INFO | |
682 need_flushbuf |= add_to_showcmd(c); | |
683 #endif | |
684 } | |
685 | |
686 /* | |
687 * If we got CTRL-W there may be a/another count | |
688 */ | |
689 if (c == Ctrl_W && !ctrl_w && oap->op_type == OP_NOP) | |
690 { | |
691 ctrl_w = TRUE; | |
692 ca.opcount = ca.count0; /* remember first count */ | |
693 ca.count0 = 0; | |
694 ++no_mapping; | |
695 ++allow_keys; /* no mapping for nchar, but keys */ | |
1389 | 696 c = plain_vgetc(); /* get next character */ |
7 | 697 LANGMAP_ADJUST(c, TRUE); |
698 --no_mapping; | |
699 --allow_keys; | |
700 #ifdef FEAT_CMDL_INFO | |
701 need_flushbuf |= add_to_showcmd(c); | |
702 #endif | |
703 goto getcount; /* jump back */ | |
704 } | |
705 } | |
706 | |
1692 | 707 if (c == K_CURSORHOLD) |
708 { | |
709 /* Save the count values so that ca.opcount and ca.count0 are exactly | |
710 * the same when coming back here after handling K_CURSORHOLD. */ | |
711 oap->prev_opcount = ca.opcount; | |
712 oap->prev_count0 = ca.count0; | |
713 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
714 else if (ca.opcount != 0) |
1692 | 715 { |
716 /* | |
717 * If we're in the middle of an operator (including after entering a | |
718 * yank buffer with '"') AND we had a count before the operator, then | |
719 * that count overrides the current value of ca.count0. | |
720 * What this means effectively, is that commands like "3dw" get turned | |
721 * into "d3w" which makes things fall into place pretty neatly. | |
722 * If you give a count before AND after the operator, they are | |
723 * multiplied. | |
724 */ | |
7 | 725 if (ca.count0) |
726 ca.count0 *= ca.opcount; | |
727 else | |
728 ca.count0 = ca.opcount; | |
729 } | |
730 | |
731 /* | |
732 * Always remember the count. It will be set to zero (on the next call, | |
733 * above) when there is no pending operator. | |
734 * When called from main(), save the count for use by the "count" built-in | |
735 * variable. | |
736 */ | |
737 ca.opcount = ca.count0; | |
738 ca.count1 = (ca.count0 == 0 ? 1 : ca.count0); | |
739 | |
740 #ifdef FEAT_EVAL | |
741 /* | |
742 * Only set v:count when called from main() and not a stuffed command. | |
5649 | 743 * Do set it for redo. |
7 | 744 */ |
5649 | 745 if (toplevel && readbuf1_empty()) |
1751 | 746 set_vcount(ca.count0, ca.count1, set_prevcount); |
7 | 747 #endif |
748 | |
749 /* | |
750 * Find the command character in the table of commands. | |
751 * For CTRL-W we already got nchar when looking for a count. | |
752 */ | |
753 if (ctrl_w) | |
754 { | |
755 ca.nchar = c; | |
756 ca.cmdchar = Ctrl_W; | |
757 } | |
758 else | |
759 ca.cmdchar = c; | |
760 idx = find_command(ca.cmdchar); | |
761 if (idx < 0) | |
762 { | |
763 /* Not a known command: beep. */ | |
764 clearopbeep(oap); | |
765 goto normal_end; | |
766 } | |
631 | 767 |
633 | 768 if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW)) |
631 | 769 { |
5848 | 770 /* This command is not allowed while editing a cmdline: beep. */ |
7 | 771 clearopbeep(oap); |
633 | 772 text_locked_msg(); |
7 | 773 goto normal_end; |
774 } | |
819 | 775 if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked()) |
776 goto normal_end; | |
7 | 777 |
778 /* | |
779 * In Visual/Select mode, a few keys are handled in a special way. | |
780 */ | |
781 if (VIsual_active) | |
782 { | |
783 /* when 'keymodel' contains "stopsel" may stop Select/Visual mode */ | |
784 if (km_stopsel | |
785 && (nv_cmds[idx].cmd_flags & NV_STS) | |
786 && !(mod_mask & MOD_MASK_SHIFT)) | |
787 { | |
788 end_visual_mode(); | |
789 redraw_curbuf_later(INVERTED); | |
790 } | |
791 | |
792 /* Keys that work different when 'keymodel' contains "startsel" */ | |
793 if (km_startsel) | |
794 { | |
795 if (nv_cmds[idx].cmd_flags & NV_SS) | |
796 { | |
797 unshift_special(&ca); | |
798 idx = find_command(ca.cmdchar); | |
840 | 799 if (idx < 0) |
800 { | |
801 /* Just in case */ | |
802 clearopbeep(oap); | |
803 goto normal_end; | |
804 } | |
7 | 805 } |
806 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
807 && (mod_mask & MOD_MASK_SHIFT)) | |
808 mod_mask &= ~MOD_MASK_SHIFT; | |
809 } | |
810 } | |
811 | |
812 #ifdef FEAT_RIGHTLEFT | |
813 if (curwin->w_p_rl && KeyTyped && !KeyStuffed | |
814 && (nv_cmds[idx].cmd_flags & NV_RL)) | |
815 { | |
816 /* Invert horizontal movements and operations. Only when typed by the | |
817 * user directly, not when the result of a mapping or "x" translated | |
818 * to "dl". */ | |
819 switch (ca.cmdchar) | |
820 { | |
821 case 'l': ca.cmdchar = 'h'; break; | |
822 case K_RIGHT: ca.cmdchar = K_LEFT; break; | |
823 case K_S_RIGHT: ca.cmdchar = K_S_LEFT; break; | |
824 case K_C_RIGHT: ca.cmdchar = K_C_LEFT; break; | |
825 case 'h': ca.cmdchar = 'l'; break; | |
826 case K_LEFT: ca.cmdchar = K_RIGHT; break; | |
827 case K_S_LEFT: ca.cmdchar = K_S_RIGHT; break; | |
828 case K_C_LEFT: ca.cmdchar = K_C_RIGHT; break; | |
829 case '>': ca.cmdchar = '<'; break; | |
830 case '<': ca.cmdchar = '>'; break; | |
831 } | |
832 idx = find_command(ca.cmdchar); | |
833 } | |
834 #endif | |
835 | |
836 /* | |
837 * Get an additional character if we need one. | |
838 */ | |
839 if ((nv_cmds[idx].cmd_flags & NV_NCH) | |
840 && (((nv_cmds[idx].cmd_flags & NV_NCH_NOP) == NV_NCH_NOP | |
841 && oap->op_type == OP_NOP) | |
842 || (nv_cmds[idx].cmd_flags & NV_NCH_ALW) == NV_NCH_ALW | |
843 || (ca.cmdchar == 'q' | |
844 && 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
|
845 && 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
|
846 && reg_executing == 0) |
7 | 847 || ((ca.cmdchar == 'a' || ca.cmdchar == 'i') |
5735 | 848 && (oap->op_type != OP_NOP || VIsual_active)))) |
7 | 849 { |
850 int *cp; | |
851 int repl = FALSE; /* get character for replace mode */ | |
852 int lit = FALSE; /* get extra character literally */ | |
853 int langmap_active = FALSE; /* using :lmap mappings */ | |
854 int lang; /* getting a text character */ | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
855 #ifdef HAVE_INPUT_METHOD |
7 | 856 int save_smd; /* saved value of p_smd */ |
857 #endif | |
858 | |
859 ++no_mapping; | |
860 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1343 | 861 /* Don't generate a CursorHold event here, most commands can't handle |
862 * it, e.g., nv_replace(), nv_csearch(). */ | |
863 did_cursorhold = TRUE; | |
7 | 864 if (ca.cmdchar == 'g') |
865 { | |
866 /* | |
867 * For 'g' get the next character now, so that we can check for | |
868 * "gr", "g'" and "g`". | |
869 */ | |
1389 | 870 ca.nchar = plain_vgetc(); |
7 | 871 LANGMAP_ADJUST(ca.nchar, TRUE); |
872 #ifdef FEAT_CMDL_INFO | |
873 need_flushbuf |= add_to_showcmd(ca.nchar); | |
874 #endif | |
875 if (ca.nchar == 'r' || ca.nchar == '\'' || ca.nchar == '`' | |
5523 | 876 || ca.nchar == Ctrl_BSL) |
7 | 877 { |
878 cp = &ca.extra_char; /* need to get a third character */ | |
879 if (ca.nchar != 'r') | |
880 lit = TRUE; /* get it literally */ | |
881 else | |
882 repl = TRUE; /* get it in replace mode */ | |
883 } | |
884 else | |
885 cp = NULL; /* no third character needed */ | |
886 } | |
887 else | |
888 { | |
889 if (ca.cmdchar == 'r') /* get it in replace mode */ | |
890 repl = TRUE; | |
891 cp = &ca.nchar; | |
892 } | |
893 lang = (repl || (nv_cmds[idx].cmd_flags & NV_LANG)); | |
894 | |
895 /* | |
896 * Get a second or third character. | |
897 */ | |
898 if (cp != NULL) | |
899 { | |
900 #ifdef CURSOR_SHAPE | |
901 if (repl) | |
902 { | |
903 State = REPLACE; /* pretend Replace mode */ | |
904 ui_cursor_shape(); /* show different cursor shape */ | |
905 } | |
906 #endif | |
907 if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) | |
908 { | |
909 /* Allow mappings defined with ":lmap". */ | |
910 --no_mapping; | |
911 --allow_keys; | |
912 if (repl) | |
913 State = LREPLACE; | |
914 else | |
915 State = LANGMAP; | |
916 langmap_active = TRUE; | |
917 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
918 #ifdef HAVE_INPUT_METHOD |
7 | 919 save_smd = p_smd; |
920 p_smd = FALSE; /* Don't let the IM code show the mode here */ | |
921 if (lang && curbuf->b_p_iminsert == B_IMODE_IM) | |
922 im_set_active(TRUE); | |
923 #endif | |
924 | |
1389 | 925 *cp = plain_vgetc(); |
7 | 926 |
927 if (langmap_active) | |
928 { | |
929 /* Undo the decrement done above */ | |
930 ++no_mapping; | |
931 ++allow_keys; | |
932 State = NORMAL_BUSY; | |
933 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13369
diff
changeset
|
934 #ifdef HAVE_INPUT_METHOD |
7 | 935 if (lang) |
936 { | |
937 if (curbuf->b_p_iminsert != B_IMODE_LMAP) | |
938 im_save_status(&curbuf->b_p_iminsert); | |
939 im_set_active(FALSE); | |
940 } | |
941 p_smd = save_smd; | |
942 #endif | |
943 #ifdef CURSOR_SHAPE | |
944 State = NORMAL_BUSY; | |
945 #endif | |
946 #ifdef FEAT_CMDL_INFO | |
947 need_flushbuf |= add_to_showcmd(*cp); | |
948 #endif | |
949 | |
950 if (!lit) | |
951 { | |
952 #ifdef FEAT_DIGRAPHS | |
953 /* Typing CTRL-K gets a digraph. */ | |
954 if (*cp == Ctrl_K | |
955 && ((nv_cmds[idx].cmd_flags & NV_LANG) | |
956 || cp == &ca.extra_char) | |
957 && vim_strchr(p_cpo, CPO_DIGRAPH) == NULL) | |
958 { | |
959 c = get_digraph(FALSE); | |
960 if (c > 0) | |
961 { | |
962 *cp = c; | |
963 # ifdef FEAT_CMDL_INFO | |
964 /* Guessing how to update showcmd here... */ | |
965 del_from_showcmd(3); | |
966 need_flushbuf |= add_to_showcmd(*cp); | |
967 # endif | |
968 } | |
969 } | |
970 #endif | |
971 | |
972 /* adjust chars > 127, except after "tTfFr" commands */ | |
973 LANGMAP_ADJUST(*cp, !lang); | |
974 #ifdef FEAT_RIGHTLEFT | |
975 /* adjust Hebrew mapped char */ | |
976 if (p_hkmap && lang && KeyTyped) | |
977 *cp = hkmap(*cp); | |
978 #endif | |
979 } | |
980 | |
981 /* | |
982 * When the next character is CTRL-\ a following CTRL-N means the | |
983 * command is aborted and we go to Normal mode. | |
984 */ | |
985 if (cp == &ca.extra_char | |
986 && ca.nchar == Ctrl_BSL | |
987 && (ca.extra_char == Ctrl_N || ca.extra_char == Ctrl_G)) | |
988 { | |
989 ca.cmdchar = Ctrl_BSL; | |
990 ca.nchar = ca.extra_char; | |
991 idx = find_command(ca.cmdchar); | |
992 } | |
3908 | 993 else if ((ca.nchar == 'n' || ca.nchar == 'N') && ca.cmdchar == 'g') |
3896 | 994 ca.oap->op_type = get_op_type(*cp, NUL); |
7 | 995 else if (*cp == Ctrl_BSL) |
996 { | |
997 long towait = (p_ttm >= 0 ? p_ttm : p_tm); | |
998 | |
999 /* There is a busy wait here when typing "f<C-\>" and then | |
1000 * something different from CTRL-N. Can't be avoided. */ | |
1001 while ((c = vpeekc()) <= 0 && towait > 0L) | |
1002 { | |
1003 do_sleep(towait > 50L ? 50L : towait); | |
1004 towait -= 50L; | |
1005 } | |
1006 if (c > 0) | |
1007 { | |
1389 | 1008 c = plain_vgetc(); |
7 | 1009 if (c != Ctrl_N && c != Ctrl_G) |
1010 vungetc(c); | |
1011 else | |
1012 { | |
1013 ca.cmdchar = Ctrl_BSL; | |
1014 ca.nchar = c; | |
1015 idx = find_command(ca.cmdchar); | |
1016 } | |
1017 } | |
1018 } | |
1019 | |
1020 /* When getting a text character and the next character is a | |
1021 * multi-byte character, it could be a composing character. | |
6071 | 1022 * However, don't wait for it to arrive. Also, do enable mapping, |
1023 * because if it's put back with vungetc() it's too late to apply | |
1024 * mapping. */ | |
1025 --no_mapping; | |
7 | 1026 while (enc_utf8 && lang && (c = vpeekc()) > 0 |
1027 && (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) | |
1028 { | |
1389 | 1029 c = plain_vgetc(); |
7 | 1030 if (!utf_iscomposing(c)) |
1031 { | |
1032 vungetc(c); /* it wasn't, put it back */ | |
1033 break; | |
1034 } | |
1035 else if (ca.ncharC1 == 0) | |
1036 ca.ncharC1 = c; | |
1037 else | |
1038 ca.ncharC2 = c; | |
1039 } | |
6071 | 1040 ++no_mapping; |
7 | 1041 } |
1042 --no_mapping; | |
1043 --allow_keys; | |
1044 } | |
1045 | |
1046 #ifdef FEAT_CMDL_INFO | |
1047 /* | |
1048 * Flush the showcmd characters onto the screen so we can see them while | |
1049 * the command is being executed. Only do this when the shown command was | |
1050 * actually displayed, otherwise this will slow down a lot when executing | |
1051 * mappings. | |
1052 */ | |
1053 if (need_flushbuf) | |
1054 out_flush(); | |
1055 #endif | |
1727 | 1056 if (ca.cmdchar != K_IGNORE) |
1057 did_cursorhold = FALSE; | |
7 | 1058 |
1059 State = NORMAL; | |
1060 | |
1061 if (ca.nchar == ESC) | |
1062 { | |
1063 clearop(oap); | |
1064 if (restart_edit == 0 && goto_im()) | |
1065 restart_edit = 'a'; | |
1066 goto normal_end; | |
1067 } | |
1068 | |
24 | 1069 if (ca.cmdchar != K_IGNORE) |
1070 { | |
1071 msg_didout = FALSE; /* don't scroll screen up for normal command */ | |
1072 msg_col = 0; | |
1073 } | |
7 | 1074 |
1075 old_pos = curwin->w_cursor; /* remember where cursor was */ | |
1076 | |
1077 /* When 'keymodel' contains "startsel" some keys start Select/Visual | |
1078 * mode. */ | |
1079 if (!VIsual_active && km_startsel) | |
1080 { | |
1081 if (nv_cmds[idx].cmd_flags & NV_SS) | |
1082 { | |
1083 start_selection(); | |
1084 unshift_special(&ca); | |
1085 idx = find_command(ca.cmdchar); | |
1086 } | |
1087 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
1088 && (mod_mask & MOD_MASK_SHIFT)) | |
1089 { | |
1090 start_selection(); | |
1091 mod_mask &= ~MOD_MASK_SHIFT; | |
1092 } | |
1093 } | |
1094 | |
1095 /* | |
1096 * Execute the command! | |
1097 * Call the command function found in the commands table. | |
1098 */ | |
1099 ca.arg = nv_cmds[idx].cmd_arg; | |
1100 (nv_cmds[idx].cmd_func)(&ca); | |
1101 | |
1102 /* | |
1103 * If we didn't start or finish an operator, reset oap->regname, unless we | |
1104 * need it later. | |
1105 */ | |
1106 if (!finish_op | |
1107 && !oap->op_type | |
1108 && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) | |
1109 { | |
1110 clearop(oap); | |
1111 #ifdef FEAT_EVAL | |
2821 | 1112 { |
1113 int regname = 0; | |
2829 | 1114 |
2821 | 1115 /* Adjust the register according to 'clipboard', so that when |
1116 * "unnamed" is present it becomes '*' or '+' instead of '"'. */ | |
2829 | 1117 # ifdef FEAT_CLIPBOARD |
2821 | 1118 adjust_clip_reg(®name); |
2829 | 1119 # endif |
2821 | 1120 set_reg_var(regname); |
1121 } | |
7 | 1122 #endif |
1123 } | |
1124 | |
570 | 1125 /* Get the length of mapped chars again after typing a count, second |
36 | 1126 * character or "z333<cr>". */ |
1127 if (old_mapped_len > 0) | |
1128 old_mapped_len = typebuf_maplen(); | |
1129 | |
7 | 1130 /* |
1131 * If an operation is pending, handle it... | |
1132 */ | |
1133 do_pending_operator(&ca, old_col, FALSE); | |
1134 | |
1135 /* | |
1136 * Wait for a moment when a message is displayed that will be overwritten | |
1137 * by the mode message. | |
1138 * In Visual mode and with "^O" in Insert mode, a short message will be | |
1139 * overwritten by the mode message. Wait a bit, until a key is hit. | |
1140 * In Visual mode, it's more important to keep the Visual area updated | |
1141 * than keeping a message (e.g. from a /pat search). | |
1142 * Only do this if the command was typed, not from a mapping. | |
1143 * Don't wait when emsg_silent is non-zero. | |
1144 * Also wait a bit after an error message, e.g. for "^O:". | |
1145 * Don't redraw the screen, it would remove the message. | |
1146 */ | |
1147 if ( ((p_smd | |
641 | 1148 && msg_silent == 0 |
7 | 1149 && (restart_edit != 0 |
1150 || (VIsual_active | |
1151 && old_pos.lnum == curwin->w_cursor.lnum | |
1152 && old_pos.col == curwin->w_cursor.col) | |
1153 ) | |
1154 && (clear_cmdline | |
1155 || redraw_cmdline) | |
1156 && (msg_didout || (msg_didany && msg_scroll)) | |
1157 && !msg_nowait | |
1158 && KeyTyped) | |
1159 || (restart_edit != 0 | |
1160 && !VIsual_active | |
1161 && (msg_scroll | |
1162 || emsg_on_display))) | |
1163 && oap->regname == 0 | |
1164 && !(ca.retval & CA_COMMAND_BUSY) | |
1165 && stuff_empty() | |
1166 && typebuf_typed() | |
1167 && emsg_silent == 0 | |
1168 && !did_wait_return | |
1169 && oap->op_type == OP_NOP) | |
1170 { | |
1171 int save_State = State; | |
1172 | |
1173 /* Draw the cursor with the right shape here */ | |
1174 if (restart_edit != 0) | |
1175 State = INSERT; | |
1176 | |
1177 /* If need to redraw, and there is a "keep_msg", redraw before the | |
1178 * delay */ | |
1179 if (must_redraw && keep_msg != NULL && !emsg_on_display) | |
1180 { | |
1181 char_u *kmsg; | |
1182 | |
1183 kmsg = keep_msg; | |
1184 keep_msg = NULL; | |
18045
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1185 // showmode() will clear keep_msg, but we want to use it anyway |
7 | 1186 update_screen(0); |
18045
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1187 // now reset it, otherwise it's put in the history again |
7 | 1188 keep_msg = kmsg; |
18045
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1189 |
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1190 kmsg = vim_strsave(keep_msg); |
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1191 if (kmsg != NULL) |
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1192 { |
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1193 msg_attr((char *)kmsg, keep_msg_attr); |
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1194 vim_free(kmsg); |
af0b4ffab794
patch 8.1.2018: using freed memory when out of memory and displaying message
Bram Moolenaar <Bram@vim.org>
parents:
17984
diff
changeset
|
1195 } |
7 | 1196 } |
1197 setcursor(); | |
1198 cursor_on(); | |
1199 out_flush(); | |
1200 if (msg_scroll || emsg_on_display) | |
1201 ui_delay(1000L, TRUE); /* wait at least one second */ | |
1202 ui_delay(3000L, FALSE); /* wait up to three seconds */ | |
1203 State = save_State; | |
1204 | |
1205 msg_scroll = FALSE; | |
1206 emsg_on_display = FALSE; | |
1207 } | |
1208 | |
1209 /* | |
1210 * Finish up after executing a Normal mode command. | |
1211 */ | |
1212 normal_end: | |
1213 | |
1214 msg_nowait = FALSE; | |
1215 | |
1216 /* Reset finish_op, in case it was set */ | |
1217 #ifdef CURSOR_SHAPE | |
1218 c = finish_op; | |
1219 #endif | |
1220 finish_op = FALSE; | |
1221 #ifdef CURSOR_SHAPE | |
1222 /* Redraw the cursor with another shape, if we were in Operator-pending | |
1223 * mode or did a replace command. */ | |
1224 if (c || ca.cmdchar == 'r') | |
1225 { | |
1226 ui_cursor_shape(); /* may show different cursor shape */ | |
1227 # ifdef FEAT_MOUSESHAPE | |
1228 update_mouseshape(-1); | |
1229 # endif | |
1230 } | |
1231 #endif | |
1232 | |
1233 #ifdef FEAT_CMDL_INFO | |
1692 | 1234 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
|
1235 && ca.cmdchar != K_CURSORHOLD) |
7 | 1236 clear_showcmd(); |
1237 #endif | |
1238 | |
1239 checkpcmark(); /* check if we moved since setting pcmark */ | |
1240 vim_free(ca.searchbuf); | |
1241 | |
1242 if (has_mbyte) | |
1243 mb_adjust_cursor(); | |
1244 | |
1245 if (curwin->w_p_scb && toplevel) | |
1246 { | |
1247 validate_cursor(); /* may need to update w_leftcol */ | |
1248 do_check_scrollbind(TRUE); | |
1249 } | |
13384
6740c499de13
patch 8.0.1566: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1250 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1251 if (curwin->w_p_crb && toplevel) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1252 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1253 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
|
1254 do_check_cursorbind(); |
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 |
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
|
1257 #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
|
1258 /* 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
|
1259 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
|
1260 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
|
1261 #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
|
1262 |
7 | 1263 /* |
1264 * May restart edit(), if we got here with CTRL-O in Insert mode (but not | |
1265 * if still inside a mapping that started in Visual mode). | |
1266 * May switch from Visual to Select mode after CTRL-O command. | |
1267 */ | |
1268 if ( oap->op_type == OP_NOP | |
1269 && ((restart_edit != 0 && !VIsual_active && old_mapped_len == 0) | |
1270 || restart_VIsual_select == 1) | |
1271 && !(ca.retval & CA_COMMAND_BUSY) | |
1272 && stuff_empty() | |
1273 && oap->regname == 0) | |
1274 { | |
1275 if (restart_VIsual_select == 1) | |
1276 { | |
1277 VIsual_select = TRUE; | |
1278 showmode(); | |
1279 restart_VIsual_select = 0; | |
1280 } | |
5735 | 1281 if (restart_edit != 0 && !VIsual_active && old_mapped_len == 0) |
7 | 1282 (void)edit(restart_edit, FALSE, 1L); |
1283 } | |
1284 | |
1285 if (restart_VIsual_select == 2) | |
1286 restart_VIsual_select = 1; | |
1287 | |
1288 /* Save count before an operator for next time. */ | |
1289 opcount = ca.opcount; | |
1290 } | |
1291 | |
2667 | 1292 #ifdef FEAT_EVAL |
1293 /* | |
1294 * Set v:count and v:count1 according to "cap". | |
1295 * Set v:prevcount only when "set_prevcount" is TRUE. | |
1296 */ | |
1297 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1298 set_vcount_ca(cmdarg_T *cap, int *set_prevcount) |
2667 | 1299 { |
1300 long count = cap->count0; | |
1301 | |
1302 /* multiply with cap->opcount the same way as above */ | |
1303 if (cap->opcount != 0) | |
1304 count = cap->opcount * (count == 0 ? 1 : count); | |
1305 set_vcount(count, count == 0 ? 1 : count, *set_prevcount); | |
1306 *set_prevcount = FALSE; /* only set v:prevcount once */ | |
1307 } | |
1308 #endif | |
1309 | |
7 | 1310 /* |
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
|
1311 * 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
|
1312 * "gui_yank" is true when yanking text for the clipboard. |
7 | 1313 */ |
1314 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1315 do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank) |
7 | 1316 { |
1317 oparg_T *oap = cap->oap; | |
1318 pos_T old_cursor; | |
1319 int empty_region_error; | |
1320 int restart_edit_save; | |
6266 | 1321 #ifdef FEAT_LINEBREAK |
1322 int lbr_saved = curwin->w_p_lbr; | |
1323 #endif | |
7 | 1324 |
1325 /* The visual area is remembered for redo */ | |
1326 static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ | |
1327 static linenr_T redo_VIsual_line_count; /* number of lines */ | |
3125 | 1328 static colnr_T redo_VIsual_vcol; /* number of cols or end column */ |
7 | 1329 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
|
1330 static int redo_VIsual_arg; /* extra argument */ |
7 | 1331 int include_line_break = FALSE; |
1332 | |
1333 #if defined(FEAT_CLIPBOARD) | |
1334 /* | |
1335 * Yank the visual area into the GUI selection register before we operate | |
1336 * on it and lose it forever. | |
1337 * Don't do it if a specific register was specified, so that ""x"*P works. | |
1338 * This could call do_pending_operator() recursively, but that's OK | |
1339 * because gui_yank will be TRUE for the nested call. | |
1340 */ | |
3674 | 1341 if ((clip_star.available || clip_plus.available) |
7 | 1342 && oap->op_type != OP_NOP |
1343 && !gui_yank | |
1344 && VIsual_active | |
1345 && !redo_VIsual_busy | |
1346 && oap->regname == 0) | |
1347 clip_auto_select(); | |
1348 #endif | |
1349 old_cursor = curwin->w_cursor; | |
1350 | |
1351 /* | |
1352 * If an operation is pending, handle it... | |
1353 */ | |
5735 | 1354 if ((finish_op || VIsual_active) && oap->op_type != OP_NOP) |
1355 { | |
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
|
1356 // 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
|
1357 // 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
|
1358 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
|
1359 |
6497 | 1360 #ifdef FEAT_LINEBREAK |
1361 /* Avoid a problem with unwanted linebreaks in block mode. */ | |
6866 | 1362 if (curwin->w_p_lbr) |
1363 curwin->w_valid &= ~VALID_VIRTCOL; | |
6497 | 1364 curwin->w_p_lbr = FALSE; |
1365 #endif | |
7 | 1366 oap->is_VIsual = VIsual_active; |
1367 if (oap->motion_force == 'V') | |
1368 oap->motion_type = MLINE; | |
1369 else if (oap->motion_force == 'v') | |
1370 { | |
1371 /* If the motion was linewise, "inclusive" will not have been set. | |
1372 * Use "exclusive" to be consistent. Makes "dvj" work nice. */ | |
1373 if (oap->motion_type == MLINE) | |
1374 oap->inclusive = FALSE; | |
1375 /* If the motion already was characterwise, toggle "inclusive" */ | |
1376 else if (oap->motion_type == MCHAR) | |
1377 oap->inclusive = !oap->inclusive; | |
1378 oap->motion_type = MCHAR; | |
1379 } | |
1380 else if (oap->motion_force == Ctrl_V) | |
1381 { | |
1382 /* 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
|
1383 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
|
1384 { |
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
1385 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
|
1386 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
|
1387 } |
7 | 1388 VIsual_mode = Ctrl_V; |
1389 VIsual_select = FALSE; | |
1390 VIsual_reselect = FALSE; | |
1391 } | |
1392 | |
4337 | 1393 /* Only redo yank when 'y' flag is in 'cpoptions'. */ |
1394 /* 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
|
1395 if ((redo_yank || oap->op_type != OP_YANK) |
4337 | 1396 && ((!VIsual_active || oap->motion_force) |
1397 /* Also redo Operator-pending Visual mode mappings */ | |
1398 || (VIsual_active && cap->cmdchar == ':' | |
1399 && oap->op_type != OP_COLON)) | |
164 | 1400 && cap->cmdchar != 'D' |
7 | 1401 #ifdef FEAT_FOLDING |
1402 && oap->op_type != OP_FOLD | |
1403 && oap->op_type != OP_FOLDOPEN | |
1404 && oap->op_type != OP_FOLDOPENREC | |
1405 && oap->op_type != OP_FOLDCLOSE | |
1406 && oap->op_type != OP_FOLDCLOSEREC | |
1407 && oap->op_type != OP_FOLDDEL | |
1408 && oap->op_type != OP_FOLDDELREC | |
1409 #endif | |
1410 ) | |
1411 { | |
1412 prep_redo(oap->regname, cap->count0, | |
1413 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1414 oap->motion_force, cap->cmdchar, cap->nchar); | |
1415 if (cap->cmdchar == '/' || cap->cmdchar == '?') /* was a search */ | |
1416 { | |
1417 /* | |
1418 * If 'cpoptions' does not contain 'r', insert the search | |
1419 * pattern to really repeat the same command. | |
1420 */ | |
1421 if (vim_strchr(p_cpo, CPO_REDO) == NULL) | |
620 | 1422 AppendToRedobuffLit(cap->searchbuf, -1); |
7 | 1423 AppendToRedobuff(NL_STR); |
1424 } | |
1425 else if (cap->cmdchar == ':') | |
1426 { | |
1427 /* do_cmdline() has stored the first typed line in | |
1428 * "repeat_cmdline". When several lines are typed repeating | |
1429 * won't be possible. */ | |
1430 if (repeat_cmdline == NULL) | |
1431 ResetRedobuff(); | |
1432 else | |
1433 { | |
620 | 1434 AppendToRedobuffLit(repeat_cmdline, -1); |
7 | 1435 AppendToRedobuff(NL_STR); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
1436 VIM_CLEAR(repeat_cmdline); |
7 | 1437 } |
1438 } | |
1439 } | |
1440 | |
1441 if (redo_VIsual_busy) | |
1442 { | |
3125 | 1443 /* Redo of an operation on a Visual area. Use the same size from |
1444 * redo_VIsual_line_count and redo_VIsual_vcol. */ | |
7 | 1445 oap->start = curwin->w_cursor; |
1446 curwin->w_cursor.lnum += redo_VIsual_line_count - 1; | |
1447 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
1448 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
1449 VIsual_mode = redo_VIsual_mode; | |
3125 | 1450 if (redo_VIsual_vcol == MAXCOL || VIsual_mode == 'v') |
7 | 1451 { |
3125 | 1452 if (VIsual_mode == 'v') |
1453 { | |
1454 if (redo_VIsual_line_count <= 1) | |
1455 { | |
1456 validate_virtcol(); | |
1457 curwin->w_curswant = | |
1458 curwin->w_virtcol + redo_VIsual_vcol - 1; | |
1459 } | |
1460 else | |
1461 curwin->w_curswant = redo_VIsual_vcol; | |
1462 } | |
7 | 1463 else |
3125 | 1464 { |
1465 curwin->w_curswant = MAXCOL; | |
1466 } | |
1467 coladvance(curwin->w_curswant); | |
7 | 1468 } |
1469 cap->count0 = redo_VIsual_count; | |
1470 if (redo_VIsual_count != 0) | |
1471 cap->count1 = redo_VIsual_count; | |
1472 else | |
1473 cap->count1 = 1; | |
1474 } | |
1475 else if (VIsual_active) | |
1476 { | |
999 | 1477 if (!gui_yank) |
1478 { | |
1479 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
1480 curbuf->b_visual.vi_start = VIsual; | |
1481 curbuf->b_visual.vi_end = curwin->w_cursor; | |
1482 curbuf->b_visual.vi_mode = VIsual_mode; | |
4213 | 1483 if (VIsual_mode_orig != NUL) |
1484 { | |
1485 curbuf->b_visual.vi_mode = VIsual_mode_orig; | |
1486 VIsual_mode_orig = NUL; | |
1487 } | |
999 | 1488 curbuf->b_visual.vi_curswant = curwin->w_curswant; |
7 | 1489 # ifdef FEAT_EVAL |
999 | 1490 curbuf->b_visual_mode_eval = VIsual_mode; |
7 | 1491 # endif |
999 | 1492 } |
7 | 1493 |
1494 /* In Select mode, a linewise selection is operated upon like a | |
6826 | 1495 * characterwise selection. |
1496 * Special case: gH<Del> deletes the last line. */ | |
1497 if (VIsual_select && VIsual_mode == 'V' | |
1498 && cap->oap->op_type != OP_DELETE) | |
7 | 1499 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1500 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 1501 { |
1502 VIsual.col = 0; | |
1503 curwin->w_cursor.col = | |
1504 (colnr_T)STRLEN(ml_get(curwin->w_cursor.lnum)); | |
1505 } | |
1506 else | |
1507 { | |
1508 curwin->w_cursor.col = 0; | |
1509 VIsual.col = (colnr_T)STRLEN(ml_get(VIsual.lnum)); | |
1510 } | |
1511 VIsual_mode = 'v'; | |
1512 } | |
1513 /* If 'selection' is "exclusive", backup one character for | |
1514 * charwise selections. */ | |
1515 else if (VIsual_mode == 'v') | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
1516 include_line_break = unadjust_for_sel(); |
7 | 1517 |
1518 oap->start = VIsual; | |
1519 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
|
1520 { |
7 | 1521 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
|
1522 oap->start.coladd = 0; |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1523 } |
7 | 1524 } |
1525 | |
1526 /* | |
1527 * Set oap->start to the first position of the operated text, oap->end | |
1528 * to the end of the operated text. w_cursor is equal to oap->start. | |
1529 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1530 if (LT_POS(oap->start, curwin->w_cursor)) |
7 | 1531 { |
1532 #ifdef FEAT_FOLDING | |
1533 /* Include folded lines completely. */ | |
1534 if (!VIsual_active) | |
1535 { | |
1536 if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL)) | |
1537 oap->start.col = 0; | |
18128
aeabc666a119
patch 8.1.2059: fix for "x" deleting a fold has side effects
Bram Moolenaar <Bram@vim.org>
parents:
18114
diff
changeset
|
1538 if ((curwin->w_cursor.col > 0 || oap->inclusive) |
aeabc666a119
patch 8.1.2059: fix for "x" deleting a fold has side effects
Bram Moolenaar <Bram@vim.org>
parents:
18114
diff
changeset
|
1539 && hasFolding(curwin->w_cursor.lnum, NULL, |
7 | 1540 &curwin->w_cursor.lnum)) |
1541 curwin->w_cursor.col = (colnr_T)STRLEN(ml_get_curline()); | |
1542 } | |
1543 #endif | |
1544 oap->end = curwin->w_cursor; | |
1545 curwin->w_cursor = oap->start; | |
1546 | |
1547 /* w_virtcol may have been updated; if the cursor goes back to its | |
1548 * previous position w_virtcol becomes invalid and isn't updated | |
1549 * automatically. */ | |
1550 curwin->w_valid &= ~VALID_VIRTCOL; | |
1551 } | |
1552 else | |
1553 { | |
1554 #ifdef FEAT_FOLDING | |
1555 /* Include folded lines completely. */ | |
1556 if (!VIsual_active && oap->motion_type == MLINE) | |
1557 { | |
1558 if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, | |
1559 NULL)) | |
1560 curwin->w_cursor.col = 0; | |
1561 if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) | |
1562 oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum)); | |
1563 } | |
1564 #endif | |
1565 oap->end = oap->start; | |
1566 oap->start = curwin->w_cursor; | |
1567 } | |
1568 | |
10154
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10110
diff
changeset
|
1569 /* 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
|
1570 check_pos(curwin->w_buffer, &oap->end); |
7 | 1571 oap->line_count = oap->end.lnum - oap->start.lnum + 1; |
1572 | |
1573 /* Set "virtual_op" before resetting VIsual_active. */ | |
1574 virtual_op = virtual_active(); | |
1575 | |
1576 if (VIsual_active || redo_VIsual_busy) | |
1577 { | |
6866 | 1578 get_op_vcol(oap, redo_VIsual_vcol, TRUE); |
7 | 1579 |
1580 if (!redo_VIsual_busy && !gui_yank) | |
1581 { | |
1582 /* | |
1583 * Prepare to reselect and redo Visual: this is based on the | |
1584 * size of the Visual text | |
1585 */ | |
1586 resel_VIsual_mode = VIsual_mode; | |
1587 if (curwin->w_curswant == MAXCOL) | |
3125 | 1588 resel_VIsual_vcol = MAXCOL; |
7 | 1589 else |
3125 | 1590 { |
1591 if (VIsual_mode != Ctrl_V) | |
1592 getvvcol(curwin, &(oap->end), | |
1593 NULL, NULL, &oap->end_vcol); | |
1594 if (VIsual_mode == Ctrl_V || oap->line_count <= 1) | |
1595 { | |
1596 if (VIsual_mode != Ctrl_V) | |
1597 getvvcol(curwin, &(oap->start), | |
1598 &oap->start_vcol, NULL, NULL); | |
1599 resel_VIsual_vcol = oap->end_vcol - oap->start_vcol + 1; | |
1600 } | |
1601 else | |
1602 resel_VIsual_vcol = oap->end_vcol; | |
1603 } | |
7 | 1604 resel_VIsual_line_count = oap->line_count; |
1605 } | |
1606 | |
1607 /* 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
|
1608 if ((redo_yank || oap->op_type != OP_YANK) |
7 | 1609 && oap->op_type != OP_COLON |
1610 #ifdef FEAT_FOLDING | |
1611 && oap->op_type != OP_FOLD | |
1612 && oap->op_type != OP_FOLDOPEN | |
1613 && oap->op_type != OP_FOLDOPENREC | |
1614 && oap->op_type != OP_FOLDCLOSE | |
1615 && oap->op_type != OP_FOLDCLOSEREC | |
1616 && oap->op_type != OP_FOLDDEL | |
1617 && oap->op_type != OP_FOLDDELREC | |
1618 #endif | |
1619 && oap->motion_force == NUL | |
1620 ) | |
1621 { | |
1622 /* Prepare for redoing. Only use the nchar field for "r", | |
1623 * otherwise it might be the second char of the operator. */ | |
3701 | 1624 if (cap->cmdchar == 'g' && (cap->nchar == 'n' |
1625 || cap->nchar == 'N')) | |
5523 | 1626 prep_redo(oap->regname, cap->count0, |
1627 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1628 oap->motion_force, cap->cmdchar, cap->nchar); | |
4337 | 1629 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
|
1630 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1631 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
|
1632 |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1633 /* 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
|
1634 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
|
1635 nchar = CAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1636 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
|
1637 nchar = NL; |
3701 | 1638 prep_redo(oap->regname, 0L, NUL, 'v', |
1639 get_op_char(oap->op_type), | |
1640 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
|
1641 nchar); |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1642 } |
7 | 1643 if (!redo_VIsual_busy) |
1644 { | |
1645 redo_VIsual_mode = resel_VIsual_mode; | |
3125 | 1646 redo_VIsual_vcol = resel_VIsual_vcol; |
7 | 1647 redo_VIsual_line_count = resel_VIsual_line_count; |
1648 redo_VIsual_count = cap->count0; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
1649 redo_VIsual_arg = cap->arg; |
7 | 1650 } |
1651 } | |
1652 | |
1653 /* | |
1654 * oap->inclusive defaults to TRUE. | |
1655 * If oap->end is on a NUL (empty line) oap->inclusive becomes | |
1656 * FALSE. This makes "d}P" and "v}dP" work the same. | |
1657 */ | |
1658 if (oap->motion_force == NUL || oap->motion_type == MLINE) | |
1659 oap->inclusive = TRUE; | |
1660 if (VIsual_mode == 'V') | |
1661 oap->motion_type = MLINE; | |
1662 else | |
1663 { | |
1664 oap->motion_type = MCHAR; | |
1665 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
|
1666 && (include_line_break || !virtual_op)) |
7 | 1667 { |
1668 oap->inclusive = FALSE; | |
1669 /* Try to include the newline, unless it's an operator | |
2957 | 1670 * that works on lines only. */ |
6826 | 1671 if (*p_sel != 'o' |
1672 && !op_on_lines(oap->op_type) | |
1673 && oap->end.lnum < curbuf->b_ml.ml_line_count) | |
7 | 1674 { |
6826 | 1675 ++oap->end.lnum; |
1676 oap->end.col = 0; | |
1677 oap->end.coladd = 0; | |
1678 ++oap->line_count; | |
7 | 1679 } |
1680 } | |
1681 } | |
1682 | |
1683 redo_VIsual_busy = FALSE; | |
592 | 1684 |
7 | 1685 /* |
1686 * Switch Visual off now, so screen updating does | |
1687 * not show inverted text when the screen is redrawn. | |
1688 * With OP_YANK and sometimes with OP_COLON and OP_FILTER there is | |
1689 * no screen redraw, so it is done here to remove the inverted | |
1690 * part. | |
1691 */ | |
1692 if (!gui_yank) | |
1693 { | |
1694 VIsual_active = FALSE; | |
5735 | 1695 #ifdef FEAT_MOUSE |
7 | 1696 setmouse(); |
1697 mouse_dragging = 0; | |
5735 | 1698 #endif |
6979 | 1699 may_clear_cmdline(); |
7 | 1700 if ((oap->op_type == OP_YANK |
1701 || oap->op_type == OP_COLON | |
592 | 1702 || oap->op_type == OP_FUNCTION |
7 | 1703 || oap->op_type == OP_FILTER) |
1704 && oap->motion_force == NUL) | |
6497 | 1705 { |
1706 #ifdef FEAT_LINEBREAK | |
1707 /* make sure redrawing is correct */ | |
1708 curwin->w_p_lbr = lbr_saved; | |
1709 #endif | |
7 | 1710 redraw_curbuf_later(INVERTED); |
6497 | 1711 } |
7 | 1712 } |
1713 } | |
1714 | |
1715 /* Include the trailing byte of a multi-byte char. */ | |
1716 if (has_mbyte && oap->inclusive) | |
1717 { | |
1718 int l; | |
1719 | |
474 | 1720 l = (*mb_ptr2len)(ml_get_pos(&oap->end)); |
7 | 1721 if (l > 1) |
1722 oap->end.col += l - 1; | |
1723 } | |
1724 curwin->w_set_curswant = TRUE; | |
1725 | |
1726 /* | |
1727 * oap->empty is set when start and end are the same. The inclusive | |
1728 * flag affects this too, unless yanking and the end is on a NUL. | |
1729 */ | |
1730 oap->empty = (oap->motion_type == MCHAR | |
1731 && (!oap->inclusive | |
1732 || (oap->op_type == OP_YANK | |
1733 && 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
|
1734 && EQUAL_POS(oap->start, oap->end) |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
1735 && !(virtual_op && oap->start.coladd != oap->end.coladd)); |
7 | 1736 /* |
1737 * For delete, change and yank, it's an error to operate on an | |
1738 * empty region, when 'E' included in 'cpoptions' (Vi compatible). | |
1739 */ | |
1740 empty_region_error = (oap->empty | |
1741 && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL); | |
1742 | |
1743 /* Force a redraw when operating on an empty Visual region, when | |
1744 * 'modifiable is off or creating a fold. */ | |
1745 if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma | |
5735 | 1746 #ifdef FEAT_FOLDING |
7 | 1747 || oap->op_type == OP_FOLD |
5735 | 1748 #endif |
7 | 1749 )) |
6497 | 1750 { |
1751 #ifdef FEAT_LINEBREAK | |
1752 curwin->w_p_lbr = lbr_saved; | |
1753 #endif | |
7 | 1754 redraw_curbuf_later(INVERTED); |
6497 | 1755 } |
7 | 1756 |
1757 /* | |
1758 * If the end of an operator is in column one while oap->motion_type | |
1759 * is MCHAR and oap->inclusive is FALSE, we put op_end after the last | |
1760 * character in the previous line. If op_start is on or before the | |
1761 * first non-blank in the line, the operator becomes linewise | |
1762 * (strange, but that's the way vi does it). | |
1763 */ | |
1764 if ( oap->motion_type == MCHAR | |
1765 && oap->inclusive == FALSE | |
1766 && !(cap->retval & CA_NO_ADJ_OP_END) | |
1767 && oap->end.col == 0 | |
1768 && (!oap->is_VIsual || *p_sel == 'o') | |
47 | 1769 && !oap->block_mode |
7 | 1770 && oap->line_count > 1) |
1771 { | |
1772 oap->end_adjusted = TRUE; /* remember that we did this */ | |
1773 --oap->line_count; | |
1774 --oap->end.lnum; | |
1775 if (inindent(0)) | |
1776 oap->motion_type = MLINE; | |
1777 else | |
1778 { | |
1779 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
1780 if (oap->end.col) | |
1781 { | |
1782 --oap->end.col; | |
1783 oap->inclusive = TRUE; | |
1784 } | |
1785 } | |
1786 } | |
1787 else | |
1788 oap->end_adjusted = FALSE; | |
1789 | |
1790 switch (oap->op_type) | |
1791 { | |
1792 case OP_LSHIFT: | |
1793 case OP_RSHIFT: | |
5735 | 1794 op_shift(oap, TRUE, oap->is_VIsual ? (int)cap->count1 : 1); |
7 | 1795 auto_format(FALSE, TRUE); |
1796 break; | |
1797 | |
1798 case OP_JOIN_NS: | |
1799 case OP_JOIN: | |
1800 if (oap->line_count < 2) | |
1801 oap->line_count = 2; | |
1802 if (curwin->w_cursor.lnum + oap->line_count - 1 > | |
1803 curbuf->b_ml.ml_line_count) | |
1804 beep_flush(); | |
1805 else | |
1806 { | |
5735 | 1807 (void)do_join(oap->line_count, oap->op_type == OP_JOIN, |
5848 | 1808 TRUE, TRUE, TRUE); |
7 | 1809 auto_format(FALSE, TRUE); |
1810 } | |
1811 break; | |
1812 | |
1813 case OP_DELETE: | |
1814 VIsual_reselect = FALSE; /* don't reselect now */ | |
1815 if (empty_region_error) | |
3324 | 1816 { |
6949 | 1817 vim_beep(BO_OPER); |
3324 | 1818 CancelRedo(); |
1819 } | |
7 | 1820 else |
1821 { | |
1822 (void)op_delete(oap); | |
1823 if (oap->motion_type == MLINE && has_format_option(FO_AUTO)) | |
1824 u_save_cursor(); /* cursor line wasn't saved yet */ | |
1825 auto_format(FALSE, TRUE); | |
1826 } | |
1827 break; | |
1828 | |
1829 case OP_YANK: | |
1830 if (empty_region_error) | |
1831 { | |
1832 if (!gui_yank) | |
3324 | 1833 { |
6949 | 1834 vim_beep(BO_OPER); |
3324 | 1835 CancelRedo(); |
1836 } | |
7 | 1837 } |
1838 else | |
6497 | 1839 { |
1840 #ifdef FEAT_LINEBREAK | |
1841 curwin->w_p_lbr = lbr_saved; | |
1842 #endif | |
7 | 1843 (void)op_yank(oap, FALSE, !gui_yank); |
6497 | 1844 } |
7 | 1845 check_cursor_col(); |
1846 break; | |
1847 | |
1848 case OP_CHANGE: | |
1849 VIsual_reselect = FALSE; /* don't reselect now */ | |
1850 if (empty_region_error) | |
3324 | 1851 { |
6949 | 1852 vim_beep(BO_OPER); |
3324 | 1853 CancelRedo(); |
1854 } | |
7 | 1855 else |
1856 { | |
1857 /* This is a new edit command, not a restart. Need to | |
1858 * remember it to make 'insertmode' work with mappings for | |
1859 * Visual mode. But do this only once and not when typed and | |
1860 * 'insertmode' isn't set. */ | |
1861 if (p_im || !KeyTyped) | |
1862 restart_edit_save = restart_edit; | |
1863 else | |
1864 restart_edit_save = 0; | |
1865 restart_edit = 0; | |
6497 | 1866 #ifdef FEAT_LINEBREAK |
1867 /* Restore linebreak, so that when the user edits it looks as | |
1868 * before. */ | |
6866 | 1869 if (curwin->w_p_lbr != lbr_saved) |
1870 { | |
1871 curwin->w_p_lbr = lbr_saved; | |
1872 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
1873 } | |
6497 | 1874 #endif |
7 | 1875 /* Reset finish_op now, don't want it set inside edit(). */ |
1876 finish_op = FALSE; | |
1877 if (op_change(oap)) /* will call edit() */ | |
1878 cap->retval |= CA_COMMAND_BUSY; | |
1879 if (restart_edit == 0) | |
1880 restart_edit = restart_edit_save; | |
1881 } | |
1882 break; | |
1883 | |
1884 case OP_FILTER: | |
1885 if (vim_strchr(p_cpo, CPO_FILTER) != NULL) | |
1886 AppendToRedobuff((char_u *)"!\r"); /* use any last used !cmd */ | |
1887 else | |
1888 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
|
1889 /* FALLTHROUGH */ |
7 | 1890 |
1891 case OP_INDENT: | |
1892 case OP_COLON: | |
1893 | |
1894 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
1895 /* | |
1896 * If 'equalprg' is empty, do the indenting internally. | |
1897 */ | |
1898 if (oap->op_type == OP_INDENT && *get_equalprg() == NUL) | |
1899 { | |
1900 # ifdef FEAT_LISP | |
1901 if (curbuf->b_p_lisp) | |
1902 { | |
1903 op_reindent(oap, get_lisp_indent); | |
1904 break; | |
1905 } | |
1906 # endif | |
1907 # ifdef FEAT_CINDENT | |
1908 op_reindent(oap, | |
1909 # ifdef FEAT_EVAL | |
1910 *curbuf->b_p_inde != NUL ? get_expr_indent : | |
1911 # endif | |
1912 get_c_indent); | |
1913 break; | |
1914 # endif | |
1915 } | |
1916 #endif | |
1917 | |
1918 op_colon(oap); | |
1919 break; | |
1920 | |
1921 case OP_TILDE: | |
1922 case OP_UPPER: | |
1923 case OP_LOWER: | |
1924 case OP_ROT13: | |
1925 if (empty_region_error) | |
3324 | 1926 { |
6949 | 1927 vim_beep(BO_OPER); |
3324 | 1928 CancelRedo(); |
1929 } | |
7 | 1930 else |
1931 op_tilde(oap); | |
1932 check_cursor_col(); | |
1933 break; | |
1934 | |
1935 case OP_FORMAT: | |
667 | 1936 #if defined(FEAT_EVAL) |
1937 if (*curbuf->b_p_fex != NUL) | |
1938 op_formatexpr(oap); /* use expression */ | |
1939 else | |
1940 #endif | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
1941 if (*p_fp != NUL || *curbuf->b_p_fp != NUL) |
7 | 1942 op_colon(oap); /* use external command */ |
1943 else | |
1944 op_format(oap, FALSE); /* use internal function */ | |
1945 break; | |
1946 | |
1947 case OP_FORMAT2: | |
1948 op_format(oap, TRUE); /* use internal function */ | |
1949 break; | |
1950 | |
592 | 1951 case OP_FUNCTION: |
10342
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1952 #ifdef FEAT_LINEBREAK |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1953 /* 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
|
1954 * before. */ |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1955 curwin->w_p_lbr = lbr_saved; |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
1956 #endif |
592 | 1957 op_function(oap); /* call 'operatorfunc' */ |
1958 break; | |
1959 | |
7 | 1960 case OP_INSERT: |
1961 case OP_APPEND: | |
1962 VIsual_reselect = FALSE; /* don't reselect now */ | |
1963 if (empty_region_error) | |
3324 | 1964 { |
6949 | 1965 vim_beep(BO_OPER); |
3324 | 1966 CancelRedo(); |
1967 } | |
7 | 1968 else |
1969 { | |
1970 /* This is a new edit command, not a restart. Need to | |
1971 * remember it to make 'insertmode' work with mappings for | |
1972 * Visual mode. But do this only once. */ | |
1973 restart_edit_save = restart_edit; | |
1974 restart_edit = 0; | |
6497 | 1975 #ifdef FEAT_LINEBREAK |
1976 /* Restore linebreak, so that when the user edits it looks as | |
1977 * before. */ | |
6866 | 1978 if (curwin->w_p_lbr != lbr_saved) |
1979 { | |
1980 curwin->w_p_lbr = lbr_saved; | |
1981 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
1982 } | |
6497 | 1983 #endif |
7 | 1984 op_insert(oap, cap->count1); |
6497 | 1985 #ifdef FEAT_LINEBREAK |
1986 /* Reset linebreak, so that formatting works correctly. */ | |
1987 curwin->w_p_lbr = FALSE; | |
1988 #endif | |
7 | 1989 |
1990 /* TODO: when inserting in several lines, should format all | |
1991 * the lines. */ | |
1992 auto_format(FALSE, TRUE); | |
1993 | |
1994 if (restart_edit == 0) | |
1995 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
|
1996 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
|
1997 cap->retval |= CA_COMMAND_BUSY; |
7 | 1998 } |
1999 break; | |
2000 | |
2001 case OP_REPLACE: | |
2002 VIsual_reselect = FALSE; /* don't reselect now */ | |
2003 if (empty_region_error) | |
3324 | 2004 { |
6949 | 2005 vim_beep(BO_OPER); |
3324 | 2006 CancelRedo(); |
2007 } | |
7 | 2008 else |
6497 | 2009 { |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15357
diff
changeset
|
2010 #ifdef FEAT_LINEBREAK |
6497 | 2011 /* Restore linebreak, so that when the user edits it looks as |
2012 * before. */ | |
6866 | 2013 if (curwin->w_p_lbr != lbr_saved) |
2014 { | |
2015 curwin->w_p_lbr = lbr_saved; | |
2016 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
2017 } | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15357
diff
changeset
|
2018 #endif |
7 | 2019 op_replace(oap, cap->nchar); |
6497 | 2020 } |
7 | 2021 break; |
2022 | |
2023 #ifdef FEAT_FOLDING | |
2024 case OP_FOLD: | |
2025 VIsual_reselect = FALSE; /* don't reselect now */ | |
2026 foldCreate(oap->start.lnum, oap->end.lnum); | |
2027 break; | |
2028 | |
2029 case OP_FOLDOPEN: | |
2030 case OP_FOLDOPENREC: | |
2031 case OP_FOLDCLOSE: | |
2032 case OP_FOLDCLOSEREC: | |
2033 VIsual_reselect = FALSE; /* don't reselect now */ | |
2034 opFoldRange(oap->start.lnum, oap->end.lnum, | |
2035 oap->op_type == OP_FOLDOPEN | |
2036 || oap->op_type == OP_FOLDOPENREC, | |
2037 oap->op_type == OP_FOLDOPENREC | |
2038 || oap->op_type == OP_FOLDCLOSEREC, | |
2039 oap->is_VIsual); | |
2040 break; | |
2041 | |
2042 case OP_FOLDDEL: | |
2043 case OP_FOLDDELREC: | |
2044 VIsual_reselect = FALSE; /* don't reselect now */ | |
2045 deleteFold(oap->start.lnum, oap->end.lnum, | |
2046 oap->op_type == OP_FOLDDELREC, oap->is_VIsual); | |
2047 break; | |
2048 #endif | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2049 case OP_NR_ADD: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2050 case OP_NR_SUB: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2051 if (empty_region_error) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2052 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2053 vim_beep(BO_OPER); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2054 CancelRedo(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2055 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2056 else |
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 VIsual_active = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2059 #ifdef FEAT_LINEBREAK |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2060 curwin->w_p_lbr = lbr_saved; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2061 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2062 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
|
2063 VIsual_active = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2064 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2065 check_cursor_col(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2066 break; |
7 | 2067 default: |
2068 clearopbeep(oap); | |
2069 } | |
2070 virtual_op = MAYBE; | |
2071 if (!gui_yank) | |
2072 { | |
2073 /* | |
2074 * if 'sol' not set, go back to old column for some commands | |
2075 */ | |
2076 if (!p_sol && oap->motion_type == MLINE && !oap->end_adjusted | |
2077 && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT | |
2078 || oap->op_type == OP_DELETE)) | |
6497 | 2079 { |
2080 #ifdef FEAT_LINEBREAK | |
2081 curwin->w_p_lbr = FALSE; | |
2082 #endif | |
7 | 2083 coladvance(curwin->w_curswant = old_col); |
6497 | 2084 } |
7 | 2085 } |
2086 else | |
2087 { | |
2088 curwin->w_cursor = old_cursor; | |
2089 } | |
2090 oap->block_mode = FALSE; | |
2091 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
|
2092 motion_force = NUL; |
7 | 2093 } |
6266 | 2094 #ifdef FEAT_LINEBREAK |
2095 curwin->w_p_lbr = lbr_saved; | |
2096 #endif | |
7 | 2097 } |
2098 | |
2099 /* | |
2100 * Handle indent and format operators and visual mode ":". | |
2101 */ | |
2102 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2103 op_colon(oparg_T *oap) |
7 | 2104 { |
2105 stuffcharReadbuff(':'); | |
2106 if (oap->is_VIsual) | |
2107 stuffReadbuff((char_u *)"'<,'>"); | |
2108 else | |
2109 { | |
2110 /* | |
2111 * Make the range look nice, so it can be repeated. | |
2112 */ | |
2113 if (oap->start.lnum == curwin->w_cursor.lnum) | |
2114 stuffcharReadbuff('.'); | |
2115 else | |
2116 stuffnumReadbuff((long)oap->start.lnum); | |
2117 if (oap->end.lnum != oap->start.lnum) | |
2118 { | |
2119 stuffcharReadbuff(','); | |
2120 if (oap->end.lnum == curwin->w_cursor.lnum) | |
2121 stuffcharReadbuff('.'); | |
2122 else if (oap->end.lnum == curbuf->b_ml.ml_line_count) | |
2123 stuffcharReadbuff('$'); | |
2124 else if (oap->start.lnum == curwin->w_cursor.lnum) | |
2125 { | |
2126 stuffReadbuff((char_u *)".+"); | |
2127 stuffnumReadbuff((long)oap->line_count - 1); | |
2128 } | |
2129 else | |
2130 stuffnumReadbuff((long)oap->end.lnum); | |
2131 } | |
2132 } | |
2133 if (oap->op_type != OP_COLON) | |
2134 stuffReadbuff((char_u *)"!"); | |
2135 if (oap->op_type == OP_INDENT) | |
2136 { | |
2137 #ifndef FEAT_CINDENT | |
2138 if (*get_equalprg() == NUL) | |
2139 stuffReadbuff((char_u *)"indent"); | |
2140 else | |
2141 #endif | |
2142 stuffReadbuff(get_equalprg()); | |
2143 stuffReadbuff((char_u *)"\n"); | |
2144 } | |
2145 else if (oap->op_type == OP_FORMAT) | |
2146 { | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2147 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
|
2148 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
|
2149 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
|
2150 stuffReadbuff(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 |
7 | 2152 stuffReadbuff((char_u *)"fmt"); |
216 | 2153 stuffReadbuff((char_u *)"\n']"); |
7 | 2154 } |
2155 | |
2156 /* | |
2157 * do_cmdline() does the rest | |
2158 */ | |
2159 } | |
2160 | |
592 | 2161 /* |
602 | 2162 * Handle the "g@" operator: call 'operatorfunc'. |
592 | 2163 */ |
690 | 2164 static void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2165 op_function(oparg_T *oap UNUSED) |
592 | 2166 { |
2167 #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
|
2168 typval_T argv[2]; |
3431 | 2169 int save_virtual_op = virtual_op; |
592 | 2170 |
2171 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
|
2172 emsg(_("E774: 'operatorfunc' is empty")); |
592 | 2173 else |
2174 { | |
2175 /* Set '[ and '] marks to text to be operated on. */ | |
2176 curbuf->b_op_start = oap->start; | |
2177 curbuf->b_op_end = oap->end; | |
2178 if (oap->motion_type != MLINE && !oap->inclusive) | |
2179 /* Exclude the end position. */ | |
2180 decl(&curbuf->b_op_end); | |
2181 | |
14071
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2182 argv[0].v_type = VAR_STRING; |
592 | 2183 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
|
2184 argv[0].vval.v_string = (char_u *)"block"; |
592 | 2185 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
|
2186 argv[0].vval.v_string = (char_u *)"line"; |
592 | 2187 else |
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 *)"char"; |
c1fcfafa8d1a
patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2189 argv[1].v_type = VAR_UNKNOWN; |
3431 | 2190 |
2191 /* Reset virtual_op so that 'virtualedit' can be changed in the | |
2192 * function. */ | |
2193 virtual_op = MAYBE; | |
2194 | |
14439
e4c553e9132b
patch 8.1.0233: "safe" argument of call_vim_function() is always FALSE
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
2195 (void)call_func_retnr(p_opfunc, 1, argv); |
3431 | 2196 |
2197 virtual_op = save_virtual_op; | |
592 | 2198 } |
2199 #else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2200 emsg(_("E775: Eval feature not available")); |
592 | 2201 #endif |
2202 } | |
2203 | |
7 | 2204 #if defined(FEAT_MOUSE) || defined(PROTO) |
2205 /* | |
2206 * Do the appropriate action for the current mouse click in the current mode. | |
2207 * Not used for Command-line mode. | |
2208 * | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2209 * Normal and Visual Mode: |
7 | 2210 * event modi- position visual change action |
2211 * fier cursor window | |
2212 * left press - yes end yes | |
2213 * 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
|
2214 * left press S yes end (popup: extend) yes "*" (2) |
7 | 2215 * left drag - yes start if moved no |
2216 * left relse - yes start if moved no | |
2217 * middle press - yes if not active no put register | |
2218 * middle press - yes if active no yank and put | |
2219 * right press - yes start or extend yes | |
2220 * right press S yes no change yes "#" (2) | |
2221 * right drag - yes extend no | |
2222 * right relse - yes extend no | |
2223 * | |
2224 * Insert or Replace Mode: | |
2225 * event modi- position visual change action | |
2226 * fier cursor window | |
2227 * left press - yes (cannot be active) yes | |
2228 * left press C yes (cannot be active) yes "CTRL-O^]" (2) | |
2229 * left press S yes (cannot be active) yes "CTRL-O*" (2) | |
2230 * left drag - yes start or extend (1) no CTRL-O (1) | |
2231 * left relse - yes start or extend (1) no CTRL-O (1) | |
2232 * middle press - no (cannot be active) no put register | |
2233 * right press - yes start or extend yes CTRL-O | |
2234 * right press S yes (cannot be active) yes "CTRL-O#" (2) | |
2235 * | |
2236 * (1) only if mouse pointer moved since press | |
2237 * (2) only if click is in same buffer | |
2238 * | |
2239 * Return TRUE if start_arrow() should be called for edit mode. | |
2240 */ | |
2241 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2242 do_mouse( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2243 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
|
2244 int c, /* K_LEFTMOUSE, etc */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2245 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
|
2246 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2247 int fixindent) /* PUT_FIXINDENT if fixing indent necessary */ |
7 | 2248 { |
2249 static int do_always = FALSE; /* ignore 'mouse' setting next time */ | |
2250 static int got_click = FALSE; /* got a click some time back */ | |
2251 | |
2252 int which_button; /* MOUSE_LEFT, _MIDDLE or _RIGHT */ | |
2253 int is_click; /* If FALSE it's a drag or release event */ | |
2254 int is_drag; /* If TRUE it's a drag event */ | |
2255 int jump_flags = 0; /* flags for jump_to_mouse() */ | |
2256 pos_T start_visual; | |
2257 int moved; /* Has cursor moved? */ | |
2258 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
|
2259 static int in_tab_line = FALSE; /* mouse clicked in tab line */ |
7 | 2260 int in_sep_line; /* mouse in vertical separator line */ |
2261 int c1, c2; | |
2262 #if defined(FEAT_FOLDING) | |
2263 pos_T save_cursor; | |
2264 #endif | |
2265 win_T *old_curwin = curwin; | |
2266 static pos_T orig_cursor; | |
2267 colnr_T leftcol, rightcol; | |
2268 pos_T end_visual; | |
2269 int diff; | |
2270 int old_active = VIsual_active; | |
2271 int old_mode = VIsual_mode; | |
2272 int regname; | |
2273 | |
2274 #if defined(FEAT_FOLDING) | |
2275 save_cursor = curwin->w_cursor; | |
2276 #endif | |
2277 | |
2278 /* | |
2279 * When GUI is active, always recognize mouse events, otherwise: | |
2280 * - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'. | |
2281 * - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'. | |
2282 * - For command line and insert mode 'mouse' is checked before calling | |
2283 * do_mouse(). | |
2284 */ | |
2285 if (do_always) | |
2286 do_always = FALSE; | |
2287 else | |
2288 #ifdef FEAT_GUI | |
2289 if (!gui.in_use) | |
2290 #endif | |
2291 { | |
2292 if (VIsual_active) | |
2293 { | |
2294 if (!mouse_has(MOUSE_VISUAL)) | |
2295 return FALSE; | |
2296 } | |
5735 | 2297 else if (State == NORMAL && !mouse_has(MOUSE_NORMAL)) |
7 | 2298 return FALSE; |
2299 } | |
2300 | |
4221 | 2301 for (;;) |
2302 { | |
2303 which_button = get_mouse_button(KEY2TERMCAP1(c), &is_click, &is_drag); | |
2304 if (is_drag) | |
2305 { | |
2306 /* If the next character is the same mouse event then use that | |
2307 * one. Speeds up dragging the status line. */ | |
2308 if (vpeekc() != NUL) | |
2309 { | |
2310 int nc; | |
2311 int save_mouse_row = mouse_row; | |
2312 int save_mouse_col = mouse_col; | |
2313 | |
2314 /* Need to get the character, peeking doesn't get the actual | |
2315 * one. */ | |
2316 nc = safe_vgetc(); | |
2317 if (c == nc) | |
2318 continue; | |
2319 vungetc(nc); | |
2320 mouse_row = save_mouse_row; | |
2321 mouse_col = save_mouse_col; | |
2322 } | |
2323 } | |
2324 break; | |
2325 } | |
7 | 2326 |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2327 if (c == K_MOUSEMOVE) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2328 { |
16598
fd0d29d63b85
patch 8.1.1302: v:beval_text is not tested in Visual mode
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2329 // 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
|
2330 #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
|
2331 ui_may_remove_balloon(); |
16598
fd0d29d63b85
patch 8.1.1302: v:beval_text is not tested in Visual mode
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
2332 if (p_bevalterm) |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2333 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2334 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
|
2335 bevalexpr_due_set = TRUE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2336 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2337 #endif |
17292
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
17225
diff
changeset
|
2338 #ifdef FEAT_TEXT_PROP |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
17225
diff
changeset
|
2339 popup_handle_mouse_moved(); |
8a095d343c59
patch 8.1.1645: cannot use a popup window for a balloon
Bram Moolenaar <Bram@vim.org>
parents:
17225
diff
changeset
|
2340 #endif |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2341 return FALSE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2342 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2343 |
7 | 2344 #ifdef FEAT_MOUSESHAPE |
2345 /* May have stopped dragging the status or separator line. The pointer is | |
2346 * most likely still on the status or separator line. */ | |
2347 if (!is_drag && drag_status_line) | |
2348 { | |
2349 drag_status_line = FALSE; | |
2350 update_mouseshape(SHAPE_IDX_STATUS); | |
2351 } | |
2352 if (!is_drag && drag_sep_line) | |
2353 { | |
2354 drag_sep_line = FALSE; | |
2355 update_mouseshape(SHAPE_IDX_VSEP); | |
2356 } | |
2357 #endif | |
2358 | |
2359 /* | |
2360 * Ignore drag and release events if we didn't get a click. | |
2361 */ | |
2362 if (is_click) | |
2363 got_click = TRUE; | |
2364 else | |
2365 { | |
2366 if (!got_click) /* didn't get click, ignore */ | |
2367 return FALSE; | |
2368 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
|
2369 { |
7 | 2370 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
|
2371 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
|
2372 { |
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 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
|
2374 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
|
2375 } |
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
|
2376 } |
7 | 2377 } |
2378 | |
2379 /* | |
2380 * CTRL right mouse button does CTRL-T | |
2381 */ | |
2382 if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) | |
2383 { | |
2384 if (State & INSERT) | |
2385 stuffcharReadbuff(Ctrl_O); | |
2386 if (count > 1) | |
2387 stuffnumReadbuff(count); | |
2388 stuffcharReadbuff(Ctrl_T); | |
2389 got_click = FALSE; /* ignore drag&release now */ | |
2390 return FALSE; | |
2391 } | |
2392 | |
2393 /* | |
2394 * CTRL only works with left mouse button | |
2395 */ | |
2396 if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT) | |
2397 return FALSE; | |
2398 | |
2399 /* | |
2400 * When a modifier is down, ignore drag and release events, as well as | |
2401 * multiple clicks and the middle mouse button. | |
2402 * Accept shift-leftmouse drags when 'mousemodel' is "popup.*". | |
2403 */ | |
179 | 2404 if ((mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT |
2405 | MOD_MASK_META)) | |
7 | 2406 && (!is_click |
2407 || (mod_mask & MOD_MASK_MULTI_CLICK) | |
2408 || which_button == MOUSE_MIDDLE) | |
598 | 2409 && !((mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT)) |
7 | 2410 && mouse_model_popup() |
2411 && which_button == MOUSE_LEFT) | |
598 | 2412 && !((mod_mask & MOD_MASK_ALT) |
2413 && !mouse_model_popup() | |
2414 && which_button == MOUSE_RIGHT) | |
7 | 2415 ) |
2416 return FALSE; | |
2417 | |
2418 /* | |
2419 * If the button press was used as the movement command for an operator | |
2420 * (eg "d<MOUSE>"), or it is the middle button that is held down, ignore | |
2421 * drag/release events. | |
2422 */ | |
2423 if (!is_click && which_button == MOUSE_MIDDLE) | |
2424 return FALSE; | |
2425 | |
2426 if (oap != NULL) | |
2427 regname = oap->regname; | |
2428 else | |
2429 regname = 0; | |
2430 | |
2431 /* | |
2432 * Middle mouse button does a 'put' of the selected text | |
2433 */ | |
2434 if (which_button == MOUSE_MIDDLE) | |
2435 { | |
2436 if (State == NORMAL) | |
2437 { | |
2438 /* | |
2439 * If an operator was pending, we don't know what the user wanted | |
2440 * to do. Go back to normal mode: Clear the operator and beep(). | |
2441 */ | |
2442 if (oap != NULL && oap->op_type != OP_NOP) | |
2443 { | |
2444 clearopbeep(oap); | |
2445 return FALSE; | |
2446 } | |
2447 | |
2448 /* | |
2449 * If visual was active, yank the highlighted text and put it | |
2450 * before the mouse pointer position. | |
1016 | 2451 * In Select mode replace the highlighted text with the clipboard. |
7 | 2452 */ |
2453 if (VIsual_active) | |
2454 { | |
1016 | 2455 if (VIsual_select) |
2456 { | |
2457 stuffcharReadbuff(Ctrl_G); | |
1019 | 2458 stuffReadbuff((char_u *)"\"+p"); |
1016 | 2459 } |
2460 else | |
2461 { | |
2462 stuffcharReadbuff('y'); | |
2463 stuffcharReadbuff(K_MIDDLEMOUSE); | |
2464 } | |
7 | 2465 do_always = TRUE; /* ignore 'mouse' setting next time */ |
2466 return FALSE; | |
2467 } | |
2468 /* | |
2469 * The rest is below jump_to_mouse() | |
2470 */ | |
2471 } | |
2472 | |
2473 else if ((State & INSERT) == 0) | |
2474 return FALSE; | |
2475 | |
2476 /* | |
2477 * Middle click in insert mode doesn't move the mouse, just insert the | |
2478 * contents of a register. '.' register is special, can't insert that | |
2479 * with do_put(). | |
2480 * Also paste at the cursor if the current mode isn't in 'mouse' (only | |
2481 * happens for the GUI). | |
2482 */ | |
2483 if ((State & INSERT) || !mouse_has(MOUSE_NORMAL)) | |
2484 { | |
2485 if (regname == '.') | |
2486 insert_reg(regname, TRUE); | |
2487 else | |
2488 { | |
2489 #ifdef FEAT_CLIPBOARD | |
2490 if (clip_star.available && regname == 0) | |
2491 regname = '*'; | |
2492 #endif | |
2493 if ((State & REPLACE_FLAG) && !yank_register_mline(regname)) | |
2494 insert_reg(regname, TRUE); | |
2495 else | |
2496 { | |
2497 do_put(regname, BACKWARD, 1L, fixindent | PUT_CURSEND); | |
2498 | |
2499 /* Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r */ | |
2500 AppendCharToRedobuff(Ctrl_R); | |
2501 AppendCharToRedobuff(fixindent ? Ctrl_P : Ctrl_O); | |
2502 AppendCharToRedobuff(regname == 0 ? '"' : regname); | |
2503 } | |
2504 } | |
2505 return FALSE; | |
2506 } | |
2507 } | |
2508 | |
2509 /* When dragging or button-up stay in the same window. */ | |
2510 if (!is_click) | |
2511 jump_flags |= MOUSE_FOCUS | MOUSE_DID_MOVE; | |
2512 | |
2513 start_visual.lnum = 0; | |
2514 | |
671 | 2515 /* Check for clicking in the tab page line. */ |
2516 if (mouse_row == 0 && firstwin->w_winrow > 0) | |
2517 { | |
1619 | 2518 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
|
2519 { |
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 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
|
2521 { |
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
|
2522 c1 = TabPageIdxs[mouse_col]; |
7090
052043fc57ab
commit https://github.com/vim/vim/commit/4a4b821085847651b71d8ad9fab9f180635cb453
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2523 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
|
2524 ? 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
|
2525 } |
1619 | 2526 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
|
2527 } |
671 | 2528 |
2529 /* click in a tab selects that tab page */ | |
2530 if (is_click | |
2531 # ifdef FEAT_CMDWIN | |
2532 && cmdwin_type == 0 | |
2533 # endif | |
681 | 2534 && mouse_col < Columns) |
2535 { | |
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
|
2536 in_tab_line = TRUE; |
681 | 2537 c1 = TabPageIdxs[mouse_col]; |
2538 if (c1 >= 0) | |
2539 { | |
682 | 2540 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) |
2541 { | |
2542 /* double click opens new page */ | |
681 | 2543 end_visual_mode(); |
682 | 2544 tabpage_new(); |
2545 tabpage_move(c1 == 0 ? 9999 : c1 - 1); | |
2546 } | |
2547 else | |
2548 { | |
2549 /* Go to specified tab page, or next one if not clicking | |
2550 * on a label. */ | |
2551 goto_tabpage(c1); | |
2552 | |
2553 /* It's like clicking on the status line of a window. */ | |
2554 if (curwin != old_curwin) | |
2555 end_visual_mode(); | |
2556 } | |
681 | 2557 } |
13762
9de2b25932eb
patch 8.0.1753: various warnings from a static analyser
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2558 else |
681 | 2559 { |
2560 tabpage_T *tp; | |
2561 | |
2562 /* Close the current or specified tab page. */ | |
2563 if (c1 == -999) | |
2564 tp = curtab; | |
2565 else | |
2566 tp = find_tabpage(-c1); | |
2567 if (tp == curtab) | |
2568 { | |
2569 if (first_tabpage->tp_next != NULL) | |
2570 tabpage_close(FALSE); | |
2571 } | |
2572 else if (tp != NULL) | |
2573 tabpage_close_other(tp, FALSE); | |
2574 } | |
2575 } | |
2576 return TRUE; | |
671 | 2577 } |
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
|
2578 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
|
2579 { |
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 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
|
2581 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
|
2582 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
|
2583 } |
6e563e1c8033
Make it possible to drag a tab page label to another position. (Paul B. Mahol)
Bram Moolenaar <bram@vim.org>
parents:
2324
diff
changeset
|
2584 |
7 | 2585 /* |
2586 * When 'mousemodel' is "popup" or "popup_setpos", translate mouse events: | |
2587 * right button up -> pop-up menu | |
2588 * shift-left button -> right button | |
598 | 2589 * alt-left button -> alt-right button |
7 | 2590 */ |
2591 if (mouse_model_popup()) | |
2592 { | |
2593 if (which_button == MOUSE_RIGHT | |
2594 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | |
2595 { | |
573 | 2596 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \ |
7 | 2597 || 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
|
2598 || 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
|
2599 || 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
|
2600 # ifdef FEAT_GUI |
7 | 2601 if (gui.in_use) |
2602 { | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2603 # 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
|
2604 || 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
|
2605 if (!is_click) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2606 /* 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
|
2607 * 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
|
2608 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2609 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2610 # 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
|
2611 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
|
2612 /* 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
|
2613 * 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
|
2614 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2615 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2616 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2617 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2618 # 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
|
2619 else |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2620 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2621 # 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
|
2622 if (!is_click) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2623 /* 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
|
2624 * 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
|
2625 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2626 #endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2627 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2628 jump_flags = 0; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2629 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
|
2630 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2631 /* 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
|
2632 * menu. */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2633 if (VIsual_active) |
7 | 2634 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2635 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
|
2636 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2637 /* |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2638 * 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
|
2639 * 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
|
2640 * negative here) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2641 */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2642 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
|
2643 || mouse_row |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2644 > (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
|
2645 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
|
2646 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
|
2647 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
|
2648 else |
7 | 2649 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2650 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
|
2651 && (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
|
2652 || 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
|
2653 || (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
|
2654 && (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
|
2655 || 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
|
2656 { |
7 | 2657 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
|
2658 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2659 else if (VIsual_mode == Ctrl_V) |
7 | 2660 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2661 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
|
2662 &leftcol, &rightcol); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2663 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
|
2664 if (m_pos.col < leftcol || m_pos.col > rightcol) |
7 | 2665 jump_flags = MOUSE_MAY_STOP_VIS; |
2666 } | |
2667 } | |
2668 } | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2669 else |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2670 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
|
2671 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2672 if (jump_flags) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2673 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2674 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
|
2675 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
|
2676 setcursor(); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2677 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
|
2678 } |
7 | 2679 # 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
|
2680 show_popupmenu(); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2681 got_click = FALSE; /* ignore release events */ |
7 | 2682 # endif |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2683 return (jump_flags & CURSOR_MOVED) != 0; |
7 | 2684 #else |
2685 return FALSE; | |
2686 #endif | |
2687 } | |
598 | 2688 if (which_button == MOUSE_LEFT |
2689 && (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT))) | |
7 | 2690 { |
2691 which_button = MOUSE_RIGHT; | |
2692 mod_mask &= ~MOD_MASK_SHIFT; | |
2693 } | |
2694 } | |
2695 | |
2696 if ((State & (NORMAL | INSERT)) | |
2697 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | |
2698 { | |
2699 if (which_button == MOUSE_LEFT) | |
2700 { | |
2701 if (is_click) | |
2702 { | |
2703 /* stop Visual mode for a left click in a window, but not when | |
2704 * on a status line */ | |
2705 if (VIsual_active) | |
2706 jump_flags |= MOUSE_MAY_STOP_VIS; | |
2707 } | |
2708 else if (mouse_has(MOUSE_VISUAL)) | |
2709 jump_flags |= MOUSE_MAY_VIS; | |
2710 } | |
2711 else if (which_button == MOUSE_RIGHT) | |
2712 { | |
2713 if (is_click && VIsual_active) | |
2714 { | |
2715 /* | |
2716 * Remember the start and end of visual before moving the | |
2717 * cursor. | |
2718 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2719 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 2720 { |
2721 start_visual = curwin->w_cursor; | |
2722 end_visual = VIsual; | |
2723 } | |
2724 else | |
2725 { | |
2726 start_visual = VIsual; | |
2727 end_visual = curwin->w_cursor; | |
2728 } | |
2729 } | |
2730 jump_flags |= MOUSE_FOCUS; | |
2731 if (mouse_has(MOUSE_VISUAL)) | |
2732 jump_flags |= MOUSE_MAY_VIS; | |
2733 } | |
2734 } | |
2735 | |
2736 /* | |
2737 * If an operator is pending, ignore all drags and releases until the | |
2738 * next mouse click. | |
2739 */ | |
2740 if (!is_drag && oap != NULL && oap->op_type != OP_NOP) | |
2741 { | |
2742 got_click = FALSE; | |
2743 oap->motion_type = MCHAR; | |
2744 } | |
2745 | |
2746 /* When releasing the button let jump_to_mouse() know. */ | |
2747 if (!is_click && !is_drag) | |
2748 jump_flags |= MOUSE_RELEASED; | |
2749 | |
2750 /* | |
2751 * JUMP! | |
2752 */ | |
2753 jump_flags = jump_to_mouse(jump_flags, | |
2754 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
|
2755 |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2756 #ifdef FEAT_MENU |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2757 /* 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
|
2758 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
|
2759 return FALSE; |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2760 #endif |
7 | 2761 moved = (jump_flags & CURSOR_MOVED); |
2762 in_status_line = (jump_flags & IN_STATUS_LINE); | |
2763 in_sep_line = (jump_flags & IN_SEP_LINE); | |
2764 | |
2765 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2766 if (isNetbeansBuffer(curbuf) |
7 | 2767 && !(jump_flags & (IN_STATUS_LINE | IN_SEP_LINE))) |
2768 { | |
2769 int key = KEY2TERMCAP1(c); | |
2770 | |
2771 if (key == (int)KE_LEFTRELEASE || key == (int)KE_MIDDLERELEASE | |
2772 || key == (int)KE_RIGHTRELEASE) | |
2773 netbeans_button_release(which_button); | |
2774 } | |
2775 #endif | |
2776 | |
2777 /* When jumping to another window, clear a pending operator. That's a bit | |
2778 * friendlier than beeping and not jumping to that window. */ | |
2779 if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP) | |
2780 clearop(oap); | |
2781 | |
2782 #ifdef FEAT_FOLDING | |
2783 if (mod_mask == 0 | |
2784 && !is_drag | |
2785 && (jump_flags & (MOUSE_FOLD_CLOSE | MOUSE_FOLD_OPEN)) | |
2786 && which_button == MOUSE_LEFT) | |
2787 { | |
2788 /* open or close a fold at this line */ | |
2789 if (jump_flags & MOUSE_FOLD_OPEN) | |
2790 openFold(curwin->w_cursor.lnum, 1L); | |
2791 else | |
2792 closeFold(curwin->w_cursor.lnum, 1L); | |
2793 /* don't move the cursor if still in the same window */ | |
2794 if (curwin == old_curwin) | |
2795 curwin->w_cursor = save_cursor; | |
2796 } | |
2797 #endif | |
2798 | |
2799 #if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN) | |
2800 if ((jump_flags & IN_OTHER_WIN) && !VIsual_active && clip_star.available) | |
2801 { | |
2802 clip_modeless(which_button, is_click, is_drag); | |
2803 return FALSE; | |
2804 } | |
2805 #endif | |
2806 | |
2807 /* Set global flag that we are extending the Visual area with mouse | |
1188 | 2808 * 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
|
2809 if (VIsual_active && is_drag && get_scrolloff_value()) |
7 | 2810 { |
2811 /* In the very first line, allow scrolling one line */ | |
2812 if (mouse_row == 0) | |
2813 mouse_dragging = 2; | |
2814 else | |
2815 mouse_dragging = 1; | |
2816 } | |
2817 | |
2818 /* When dragging the mouse above the window, scroll down. */ | |
2819 if (is_drag && mouse_row < 0 && !in_status_line) | |
2820 { | |
2821 scroll_redraw(FALSE, 1L); | |
2822 mouse_row = 0; | |
2823 } | |
2824 | |
2825 if (start_visual.lnum) /* right click in visual mode */ | |
2826 { | |
598 | 2827 /* When ALT is pressed make Visual mode blockwise. */ |
2828 if (mod_mask & MOD_MASK_ALT) | |
2829 VIsual_mode = Ctrl_V; | |
2830 | |
7 | 2831 /* |
2832 * In Visual-block mode, divide the area in four, pick up the corner | |
2833 * that is in the quarter that the cursor is in. | |
2834 */ | |
2835 if (VIsual_mode == Ctrl_V) | |
2836 { | |
2837 getvcols(curwin, &start_visual, &end_visual, &leftcol, &rightcol); | |
2838 if (curwin->w_curswant > (leftcol + rightcol) / 2) | |
2839 end_visual.col = leftcol; | |
2840 else | |
2841 end_visual.col = rightcol; | |
7009 | 2842 if (curwin->w_cursor.lnum >= |
7 | 2843 (start_visual.lnum + end_visual.lnum) / 2) |
2844 end_visual.lnum = start_visual.lnum; | |
2845 | |
2846 /* move VIsual to the right column */ | |
2847 start_visual = curwin->w_cursor; /* save the cursor pos */ | |
2848 curwin->w_cursor = end_visual; | |
2849 coladvance(end_visual.col); | |
2850 VIsual = curwin->w_cursor; | |
2851 curwin->w_cursor = start_visual; /* restore the cursor */ | |
2852 } | |
2853 else | |
2854 { | |
2855 /* | |
2856 * If the click is before the start of visual, change the start. | |
2857 * If the click is after the end of visual, change the end. If | |
2858 * the click is inside the visual, change the closest side. | |
2859 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2860 if (LT_POS(curwin->w_cursor, start_visual)) |
7 | 2861 VIsual = end_visual; |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2862 else if (LT_POS(end_visual, curwin->w_cursor)) |
7 | 2863 VIsual = start_visual; |
2864 else | |
2865 { | |
2866 /* In the same line, compare column number */ | |
2867 if (end_visual.lnum == start_visual.lnum) | |
2868 { | |
2869 if (curwin->w_cursor.col - start_visual.col > | |
2870 end_visual.col - curwin->w_cursor.col) | |
2871 VIsual = start_visual; | |
2872 else | |
2873 VIsual = end_visual; | |
2874 } | |
2875 | |
2876 /* In different lines, compare line number */ | |
2877 else | |
2878 { | |
2879 diff = (curwin->w_cursor.lnum - start_visual.lnum) - | |
2880 (end_visual.lnum - curwin->w_cursor.lnum); | |
2881 | |
2882 if (diff > 0) /* closest to end */ | |
2883 VIsual = start_visual; | |
2884 else if (diff < 0) /* closest to start */ | |
2885 VIsual = end_visual; | |
2886 else /* in the middle line */ | |
2887 { | |
2888 if (curwin->w_cursor.col < | |
2889 (start_visual.col + end_visual.col) / 2) | |
2890 VIsual = end_visual; | |
2891 else | |
2892 VIsual = start_visual; | |
2893 } | |
2894 } | |
2895 } | |
2896 } | |
2897 } | |
2898 /* | |
2899 * If Visual mode started in insert mode, execute "CTRL-O" | |
2900 */ | |
2901 else if ((State & INSERT) && VIsual_active) | |
2902 stuffcharReadbuff(Ctrl_O); | |
2903 | |
2904 /* | |
2905 * Middle mouse click: Put text before cursor. | |
2906 */ | |
2907 if (which_button == MOUSE_MIDDLE) | |
2908 { | |
2909 #ifdef FEAT_CLIPBOARD | |
2910 if (clip_star.available && regname == 0) | |
2911 regname = '*'; | |
2912 #endif | |
2913 if (yank_register_mline(regname)) | |
2914 { | |
2915 if (mouse_past_bottom) | |
2916 dir = FORWARD; | |
2917 } | |
2918 else if (mouse_past_eol) | |
2919 dir = FORWARD; | |
2920 | |
2921 if (fixindent) | |
2922 { | |
2923 c1 = (dir == BACKWARD) ? '[' : ']'; | |
2924 c2 = 'p'; | |
2925 } | |
2926 else | |
2927 { | |
2928 c1 = (dir == FORWARD) ? 'p' : 'P'; | |
2929 c2 = NUL; | |
2930 } | |
2931 prep_redo(regname, count, NUL, c1, NUL, c2, NUL); | |
2932 | |
2933 /* | |
2934 * Remember where the paste started, so in edit() Insstart can be set | |
2935 * to this position | |
2936 */ | |
2937 if (restart_edit != 0) | |
2938 where_paste_started = curwin->w_cursor; | |
2939 do_put(regname, dir, count, fixindent | PUT_CURSEND); | |
2940 } | |
2941 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
2942 #if defined(FEAT_QUICKFIX) |
7 | 2943 /* |
2944 * Ctrl-Mouse click or double click in a quickfix window jumps to the | |
2945 * error under the mouse pointer. | |
2946 */ | |
2947 else if (((mod_mask & MOD_MASK_CTRL) | |
2948 || (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
2949 && bt_quickfix(curbuf)) | |
2950 { | |
643 | 2951 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
|
2952 do_cmdline_cmd((char_u *)".cc"); |
643 | 2953 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
|
2954 do_cmdline_cmd((char_u *)".ll"); |
7 | 2955 got_click = FALSE; /* ignore drag&release now */ |
2956 } | |
2957 #endif | |
2958 | |
2959 /* | |
2960 * Ctrl-Mouse click (or double click in a help window) jumps to the tag | |
2961 * under the mouse pointer. | |
2962 */ | |
2963 else if ((mod_mask & MOD_MASK_CTRL) || (curbuf->b_help | |
2964 && (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)) | |
2965 { | |
2966 if (State & INSERT) | |
2967 stuffcharReadbuff(Ctrl_O); | |
2968 stuffcharReadbuff(Ctrl_RSB); | |
2969 got_click = FALSE; /* ignore drag&release now */ | |
2970 } | |
2971 | |
2972 /* | |
2973 * Shift-Mouse click searches for the next occurrence of the word under | |
2974 * the mouse pointer | |
2975 */ | |
2976 else if ((mod_mask & MOD_MASK_SHIFT)) | |
2977 { | |
5735 | 2978 if ((State & INSERT) || (VIsual_active && VIsual_select)) |
7 | 2979 stuffcharReadbuff(Ctrl_O); |
2980 if (which_button == MOUSE_LEFT) | |
2981 stuffcharReadbuff('*'); | |
2982 else /* MOUSE_RIGHT */ | |
2983 stuffcharReadbuff('#'); | |
2984 } | |
2985 | |
2986 /* Handle double clicks, unless on status line */ | |
2987 else if (in_status_line) | |
2988 { | |
2989 #ifdef FEAT_MOUSESHAPE | |
2990 if ((is_drag || is_click) && !drag_status_line) | |
2991 { | |
2992 drag_status_line = TRUE; | |
2993 update_mouseshape(-1); | |
2994 } | |
2995 #endif | |
2996 } | |
2997 else if (in_sep_line) | |
2998 { | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
2999 #ifdef FEAT_MOUSESHAPE |
7 | 3000 if ((is_drag || is_click) && !drag_sep_line) |
3001 { | |
3002 drag_sep_line = TRUE; | |
3003 update_mouseshape(-1); | |
3004 } | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3005 #endif |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3006 } |
7 | 3007 else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT)) |
3008 && mouse_has(MOUSE_VISUAL)) | |
3009 { | |
3010 if (is_click || !VIsual_active) | |
3011 { | |
3012 if (VIsual_active) | |
3013 orig_cursor = VIsual; | |
3014 else | |
3015 { | |
3016 check_visual_highlight(); | |
3017 VIsual = curwin->w_cursor; | |
3018 orig_cursor = VIsual; | |
3019 VIsual_active = TRUE; | |
3020 VIsual_reselect = TRUE; | |
3021 /* start Select mode if 'selectmode' contains "mouse" */ | |
3022 may_start_select('o'); | |
3023 setmouse(); | |
3024 } | |
3025 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
598 | 3026 { |
3027 /* Double click with ALT pressed makes it blockwise. */ | |
3028 if (mod_mask & MOD_MASK_ALT) | |
3029 VIsual_mode = Ctrl_V; | |
3030 else | |
3031 VIsual_mode = 'v'; | |
3032 } | |
7 | 3033 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK) |
3034 VIsual_mode = 'V'; | |
3035 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK) | |
3036 VIsual_mode = Ctrl_V; | |
3037 #ifdef FEAT_CLIPBOARD | |
3038 /* Make sure the clipboard gets updated. Needed because start and | |
3039 * end may still be the same, and the selection needs to be owned */ | |
3040 clip_star.vmode = NUL; | |
3041 #endif | |
3042 } | |
3043 /* | |
3044 * A double click selects a word or a block. | |
3045 */ | |
3046 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
3047 { | |
3048 pos_T *pos = NULL; | |
300 | 3049 int gc; |
7 | 3050 |
3051 if (is_click) | |
3052 { | |
3053 /* If the character under the cursor (skipping white space) is | |
3054 * not a word character, try finding a match and select a (), | |
3055 * {}, [], #if/#endif, etc. block. */ | |
3056 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
|
3057 while (gc = gchar_pos(&end_visual), VIM_ISWHITE(gc)) |
7 | 3058 inc(&end_visual); |
3059 if (oap != NULL) | |
3060 oap->motion_type = MCHAR; | |
3061 if (oap != NULL | |
3062 && VIsual_mode == 'v' | |
3063 && !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
|
3064 && EQUAL_POS(curwin->w_cursor, VIsual) |
7 | 3065 && (pos = findmatch(oap, NUL)) != NULL) |
3066 { | |
3067 curwin->w_cursor = *pos; | |
3068 if (oap->motion_type == MLINE) | |
3069 VIsual_mode = 'V'; | |
3070 else if (*p_sel == 'e') | |
3071 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3072 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 3073 ++VIsual.col; |
3074 else | |
3075 ++curwin->w_cursor.col; | |
3076 } | |
3077 } | |
3078 } | |
3079 | |
3080 if (pos == NULL && (is_click || is_drag)) | |
3081 { | |
3082 /* When not found a match or when dragging: extend to include | |
3083 * a word. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3084 if (LT_POS(curwin->w_cursor, orig_cursor)) |
7 | 3085 { |
3086 find_start_of_word(&curwin->w_cursor); | |
3087 find_end_of_word(&VIsual); | |
3088 } | |
3089 else | |
3090 { | |
3091 find_start_of_word(&VIsual); | |
3092 if (*p_sel == 'e' && *ml_get_cursor() != NUL) | |
3093 curwin->w_cursor.col += | |
474 | 3094 (*mb_ptr2len)(ml_get_cursor()); |
7 | 3095 find_end_of_word(&curwin->w_cursor); |
3096 } | |
3097 } | |
3098 curwin->w_set_curswant = TRUE; | |
3099 } | |
3100 if (is_click) | |
3101 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
3102 } | |
3103 else if (VIsual_active && !old_active) | |
598 | 3104 { |
3105 if (mod_mask & MOD_MASK_ALT) | |
3106 VIsual_mode = Ctrl_V; | |
3107 else | |
3108 VIsual_mode = 'v'; | |
3109 } | |
7 | 3110 |
3111 /* If Visual mode changed show it later. */ | |
643 | 3112 if ((!VIsual_active && old_active && mode_displayed) |
3113 || (VIsual_active && p_smd && msg_silent == 0 | |
3114 && (!old_active || VIsual_mode != old_mode))) | |
7 | 3115 redraw_cmdline = TRUE; |
3116 | |
3117 return moved; | |
3118 } | |
3119 | |
3120 /* | |
3121 * Move "pos" back to the start of the word it's in. | |
3122 */ | |
3123 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3124 find_start_of_word(pos_T *pos) |
7 | 3125 { |
3126 char_u *line; | |
3127 int cclass; | |
3128 int col; | |
3129 | |
3130 line = ml_get(pos->lnum); | |
3131 cclass = get_mouse_class(line + pos->col); | |
3132 | |
3133 while (pos->col > 0) | |
3134 { | |
3135 col = pos->col - 1; | |
3136 col -= (*mb_head_off)(line, line + col); | |
3137 if (get_mouse_class(line + col) != cclass) | |
3138 break; | |
3139 pos->col = col; | |
3140 } | |
3141 } | |
3142 | |
3143 /* | |
3144 * Move "pos" forward to the end of the word it's in. | |
3145 * When 'selection' is "exclusive", the position is just after the word. | |
3146 */ | |
3147 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3148 find_end_of_word(pos_T *pos) |
7 | 3149 { |
3150 char_u *line; | |
3151 int cclass; | |
3152 int col; | |
3153 | |
3154 line = ml_get(pos->lnum); | |
3155 if (*p_sel == 'e' && pos->col > 0) | |
3156 { | |
3157 --pos->col; | |
3158 pos->col -= (*mb_head_off)(line, line + pos->col); | |
3159 } | |
3160 cclass = get_mouse_class(line + pos->col); | |
3161 while (line[pos->col] != NUL) | |
3162 { | |
474 | 3163 col = pos->col + (*mb_ptr2len)(line + pos->col); |
7 | 3164 if (get_mouse_class(line + col) != cclass) |
3165 { | |
3166 if (*p_sel == 'e') | |
3167 pos->col = col; | |
3168 break; | |
3169 } | |
3170 pos->col = col; | |
3171 } | |
3172 } | |
3173 | |
3174 /* | |
3175 * Get class of a character for selection: same class means same word. | |
3176 * 0: blank | |
3177 * 1: punctuation groups | |
3178 * 2: normal word character | |
3179 * >2: multi-byte word character. | |
3180 */ | |
3181 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3182 get_mouse_class(char_u *p) |
7 | 3183 { |
3184 int c; | |
3185 | |
3186 if (has_mbyte && MB_BYTE2LEN(p[0]) > 1) | |
3187 return mb_get_class(p); | |
3188 | |
3189 c = *p; | |
3190 if (c == ' ' || c == '\t') | |
3191 return 0; | |
3192 | |
3193 if (vim_iswordc(c)) | |
3194 return 2; | |
3195 | |
3196 /* | |
3197 * There are a few special cases where we want certain combinations of | |
3198 * characters to be considered as a single word. These are things like | |
3199 * "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
3200 * character is in its own class. |
7 | 3201 */ |
3202 if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL) | |
3203 return 1; | |
3204 return c; | |
3205 } | |
3206 #endif /* FEAT_MOUSE */ | |
3207 | |
3208 /* | |
3209 * Check if highlighting for visual mode is possible, give a warning message | |
3210 * if not. | |
3211 */ | |
3212 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3213 check_visual_highlight(void) |
7 | 3214 { |
3215 static int did_check = FALSE; | |
3216 | |
3217 if (full_screen) | |
3218 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3219 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
|
3220 msg(_("Warning: terminal cannot highlight")); |
7 | 3221 did_check = TRUE; |
3222 } | |
3223 } | |
3224 | |
3225 /* | |
638 | 3226 * End Visual mode. |
7 | 3227 * This function should ALWAYS be called to end Visual mode, except from |
3228 * do_pending_operator(). | |
3229 */ | |
3230 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3231 end_visual_mode(void) |
7 | 3232 { |
3233 #ifdef FEAT_CLIPBOARD | |
3234 /* | |
3235 * If we are using the clipboard, then remember what was selected in case | |
3236 * we need to paste it somewhere while we still own the selection. | |
3237 * Only do this when the clipboard is already owned. Don't want to grab | |
3238 * the selection when hitting ESC. | |
3239 */ | |
3240 if (clip_star.available && clip_star.owned) | |
3241 clip_auto_select(); | |
3242 #endif | |
3243 | |
3244 VIsual_active = FALSE; | |
3245 #ifdef FEAT_MOUSE | |
3246 setmouse(); | |
3247 mouse_dragging = 0; | |
3248 #endif | |
3249 | |
3250 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
690 | 3251 curbuf->b_visual.vi_mode = VIsual_mode; |
3252 curbuf->b_visual.vi_start = VIsual; | |
3253 curbuf->b_visual.vi_end = curwin->w_cursor; | |
3254 curbuf->b_visual.vi_curswant = curwin->w_curswant; | |
7 | 3255 #ifdef FEAT_EVAL |
3256 curbuf->b_visual_mode_eval = VIsual_mode; | |
3257 #endif | |
3258 if (!virtual_active()) | |
3259 curwin->w_cursor.coladd = 0; | |
6979 | 3260 may_clear_cmdline(); |
7 | 3261 |
844 | 3262 adjust_cursor_eol(); |
7 | 3263 } |
3264 | |
3265 /* | |
3266 * Reset VIsual_active and VIsual_reselect. | |
3267 */ | |
3268 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3269 reset_VIsual_and_resel(void) |
7 | 3270 { |
3271 if (VIsual_active) | |
3272 { | |
3273 end_visual_mode(); | |
3274 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
3275 } | |
3276 VIsual_reselect = FALSE; | |
3277 } | |
3278 | |
3279 /* | |
3280 * Reset VIsual_active and VIsual_reselect if it's set. | |
3281 */ | |
3282 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3283 reset_VIsual(void) |
7 | 3284 { |
3285 if (VIsual_active) | |
3286 { | |
3287 end_visual_mode(); | |
3288 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
3289 VIsual_reselect = FALSE; | |
3290 } | |
3291 } | |
3292 | |
3293 /* | |
3294 * Check for a balloon-eval special item to include when searching for an | |
3295 * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid! | |
3296 * Returns TRUE if the character at "*ptr" should be included. | |
3297 * "dir" is FORWARD or BACKWARD, the direction of searching. | |
3298 * "*colp" is in/decremented if "ptr[-dir]" should also be included. | |
3299 * "bnp" points to a counter for square brackets. | |
3300 */ | |
3301 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3302 find_is_eval_item( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3303 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3304 int *colp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3305 int *bnp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3306 int dir) |
7 | 3307 { |
3308 /* Accept everything inside []. */ | |
3309 if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) | |
3310 ++*bnp; | |
3311 if (*bnp > 0) | |
3312 { | |
3313 if ((*ptr == '[' && dir == BACKWARD) || (*ptr == ']' && dir == FORWARD)) | |
3314 --*bnp; | |
3315 return TRUE; | |
3316 } | |
3317 | |
3318 /* skip over "s.var" */ | |
3319 if (*ptr == '.') | |
3320 return TRUE; | |
3321 | |
3322 /* two-character item: s->var */ | |
3323 if (ptr[dir == BACKWARD ? 0 : 1] == '>' | |
3324 && ptr[dir == BACKWARD ? -1 : 0] == '-') | |
3325 { | |
3326 *colp += dir; | |
3327 return TRUE; | |
3328 } | |
3329 return FALSE; | |
3330 } | |
3331 | |
3332 /* | |
3333 * Find the identifier under or to the right of the cursor. | |
3334 * "find_type" can have one of three values: | |
3335 * FIND_IDENT: find an identifier (keyword) | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3336 * FIND_STRING: find any non-white text |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3337 * FIND_IDENT + FIND_STRING: find any non-white text, identifier preferred. |
184 | 3338 * FIND_EVAL: find text useful for C program debugging |
7 | 3339 * |
3340 * There are three steps: | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3341 * 1. Search forward for the start of an identifier/text. Doesn't move if |
7 | 3342 * already on one. |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3343 * 2. Search backward for the start of this identifier/text. |
7 | 3344 * This doesn't match the real Vi but I like it a little better and it |
3345 * shouldn't bother anyone. | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3346 * 3. Search forward to the end of this identifier/text. |
7 | 3347 * When FIND_IDENT isn't defined, we backup until a blank. |
3348 * | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3349 * Returns the length of the text, or zero if no text is found. |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3350 * If text is found, a pointer to the text is put in "*text". This |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3351 * points into the current buffer line and is not always NUL terminated. |
7 | 3352 */ |
3353 int | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3354 find_ident_under_cursor(char_u **text, int find_type) |
7 | 3355 { |
3356 return find_ident_at_pos(curwin, curwin->w_cursor.lnum, | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3357 curwin->w_cursor.col, text, NULL, find_type); |
7 | 3358 } |
3359 | |
3360 /* | |
3361 * Like find_ident_under_cursor(), but for any window and any position. | |
3362 * However: Uses 'iskeyword' from the current window!. | |
3363 */ | |
3364 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3365 find_ident_at_pos( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3366 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3367 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3368 colnr_T startcol, |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3369 char_u **text, |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3370 int *textcol, // column where "text" starts, can be NULL |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3371 int find_type) |
7 | 3372 { |
3373 char_u *ptr; | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3374 int col = 0; // init to shut up GCC |
7 | 3375 int i; |
3376 int this_class = 0; | |
3377 int prev_class; | |
3378 int prevcol; | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3379 int bn = 0; // bracket nesting |
7 | 3380 |
3381 /* | |
3382 * if i == 0: try to find an identifier | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3383 * if i == 1: try to find any non-white text |
7 | 3384 */ |
3385 ptr = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3386 for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; ++i) | |
3387 { | |
3388 /* | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3389 * 1. skip to start of identifier/text |
7 | 3390 */ |
3391 col = startcol; | |
3392 if (has_mbyte) | |
3393 { | |
3394 while (ptr[col] != NUL) | |
3395 { | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3396 // Stop at a ']' to evaluate "a[x]". |
7 | 3397 if ((find_type & FIND_EVAL) && ptr[col] == ']') |
3398 break; | |
3399 this_class = mb_get_class(ptr + col); | |
3400 if (this_class != 0 && (i == 1 || this_class != 1)) | |
3401 break; | |
474 | 3402 col += (*mb_ptr2len)(ptr + col); |
7 | 3403 } |
3404 } | |
3405 else | |
3406 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
|
3407 && (i == 0 ? !vim_iswordc(ptr[col]) : VIM_ISWHITE(ptr[col])) |
7 | 3408 && (!(find_type & FIND_EVAL) || ptr[col] != ']') |
3409 ) | |
3410 ++col; | |
3411 | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3412 // When starting on a ']' count it, so that we include the '['. |
7 | 3413 bn = ptr[col] == ']'; |
3414 | |
3415 /* | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3416 * 2. Back up to start of identifier/text. |
7 | 3417 */ |
3418 if (has_mbyte) | |
3419 { | |
3420 /* Remember class of character under cursor. */ | |
3421 if ((find_type & FIND_EVAL) && ptr[col] == ']') | |
3422 this_class = mb_get_class((char_u *)"a"); | |
3423 else | |
3424 this_class = mb_get_class(ptr + col); | |
835 | 3425 while (col > 0 && this_class != 0) |
7 | 3426 { |
3427 prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1); | |
3428 prev_class = mb_get_class(ptr + prevcol); | |
3429 if (this_class != prev_class | |
3430 && (i == 0 | |
3431 || prev_class == 0 | |
3432 || (find_type & FIND_IDENT)) | |
3433 && (!(find_type & FIND_EVAL) | |
3434 || prevcol == 0 | |
3435 || !find_is_eval_item(ptr + prevcol, &prevcol, | |
3436 &bn, BACKWARD)) | |
3437 ) | |
3438 break; | |
3439 col = prevcol; | |
3440 } | |
3441 | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3442 // If we don't want just any old text, or we've found an |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3443 // identifier, stop searching. |
7 | 3444 if (this_class > 2) |
3445 this_class = 2; | |
3446 if (!(find_type & FIND_STRING) || this_class == 2) | |
3447 break; | |
3448 } | |
3449 else | |
3450 { | |
3451 while (col > 0 | |
3452 && ((i == 0 | |
3453 ? 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
|
3454 : (!VIM_ISWHITE(ptr[col - 1]) |
7 | 3455 && (!(find_type & FIND_IDENT) |
3456 || !vim_iswordc(ptr[col - 1])))) | |
3457 || ((find_type & FIND_EVAL) | |
3458 && col > 1 | |
3459 && find_is_eval_item(ptr + col - 1, &col, | |
3460 &bn, BACKWARD)) | |
3461 )) | |
3462 --col; | |
3463 | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3464 // If we don't want just any old text, or we've found an |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3465 // identifier, stop searching. |
7 | 3466 if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col])) |
3467 break; | |
3468 } | |
3469 } | |
3470 | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
3471 if (ptr[col] == NUL || (i == 0 |
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
3472 && (has_mbyte ? this_class != 2 : !vim_iswordc(ptr[col])))) |
7 | 3473 { |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3474 // didn't find an identifier or text |
16908
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3475 if ((find_type & FIND_NOERROR) == 0) |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3476 { |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3477 if (find_type & FIND_STRING) |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3478 emsg(_("E348: No string under cursor")); |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3479 else |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3480 emsg(_(e_noident)); |
df06694b761b
patch 8.1.1455: popup_atcursor() not completely implemented
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3481 } |
7 | 3482 return 0; |
3483 } | |
3484 ptr += col; | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3485 *text = ptr; |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3486 if (textcol != NULL) |
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3487 *textcol = col; |
7 | 3488 |
3489 /* | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3490 * 3. Find the end if the identifier/text. |
7 | 3491 */ |
3492 bn = 0; | |
3493 startcol -= col; | |
3494 col = 0; | |
3495 if (has_mbyte) | |
3496 { | |
17316
8813e1626e0a
patch 8.1.1657: Terminal: screen updates from 'balloonexpr' are not displayed
Bram Moolenaar <Bram@vim.org>
parents:
17292
diff
changeset
|
3497 // Search for point of changing multibyte character class. |
7 | 3498 this_class = mb_get_class(ptr); |
3499 while (ptr[col] != NUL | |
3500 && ((i == 0 ? mb_get_class(ptr + col) == this_class | |
3501 : mb_get_class(ptr + col) != 0) | |
3502 || ((find_type & FIND_EVAL) | |
3503 && col <= (int)startcol | |
3504 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
3505 )) | |
474 | 3506 col += (*mb_ptr2len)(ptr + col); |
7 | 3507 } |
3508 else | |
3509 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
|
3510 : (ptr[col] != NUL && !VIM_ISWHITE(ptr[col]))) |
7 | 3511 || ((find_type & FIND_EVAL) |
3512 && col <= (int)startcol | |
3513 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
3514 ) | |
3515 ++col; | |
3516 | |
3517 return col; | |
3518 } | |
3519 | |
3520 /* | |
3521 * Prepare for redo of a normal command. | |
3522 */ | |
3523 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3524 prep_redo_cmd(cmdarg_T *cap) |
7 | 3525 { |
3526 prep_redo(cap->oap->regname, cap->count0, | |
3527 NUL, cap->cmdchar, NUL, NUL, cap->nchar); | |
3528 } | |
3529 | |
3530 /* | |
3531 * Prepare for redo of any command. | |
3532 * Note that only the last argument can be a multi-byte char. | |
3533 */ | |
3534 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3535 prep_redo( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3536 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3537 long num, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3538 int cmd1, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3539 int cmd2, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3540 int cmd3, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3541 int cmd4, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3542 int cmd5) |
7 | 3543 { |
3544 ResetRedobuff(); | |
3545 if (regname != 0) /* yank from specified buffer */ | |
3546 { | |
3547 AppendCharToRedobuff('"'); | |
3548 AppendCharToRedobuff(regname); | |
3549 } | |
3550 if (num) | |
3551 AppendNumberToRedobuff(num); | |
3552 | |
3553 if (cmd1 != NUL) | |
3554 AppendCharToRedobuff(cmd1); | |
3555 if (cmd2 != NUL) | |
3556 AppendCharToRedobuff(cmd2); | |
3557 if (cmd3 != NUL) | |
3558 AppendCharToRedobuff(cmd3); | |
3559 if (cmd4 != NUL) | |
3560 AppendCharToRedobuff(cmd4); | |
3561 if (cmd5 != NUL) | |
3562 AppendCharToRedobuff(cmd5); | |
3563 } | |
3564 | |
3565 /* | |
3566 * check for operator active and clear it | |
3567 * | |
3568 * return TRUE if operator was active | |
3569 */ | |
3570 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3571 checkclearop(oparg_T *oap) |
7 | 3572 { |
3573 if (oap->op_type == OP_NOP) | |
3574 return FALSE; | |
3575 clearopbeep(oap); | |
3576 return TRUE; | |
3577 } | |
3578 | |
3579 /* | |
1131 | 3580 * Check for operator or Visual active. Clear active operator. |
7 | 3581 * |
1131 | 3582 * Return TRUE if operator or Visual was active. |
7 | 3583 */ |
3584 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3585 checkclearopq(oparg_T *oap) |
7 | 3586 { |
5735 | 3587 if (oap->op_type == OP_NOP && !VIsual_active) |
7 | 3588 return FALSE; |
3589 clearopbeep(oap); | |
3590 return TRUE; | |
3591 } | |
3592 | |
3593 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3594 clearop(oparg_T *oap) |
7 | 3595 { |
3596 oap->op_type = OP_NOP; | |
3597 oap->regname = 0; | |
3598 oap->motion_force = NUL; | |
3599 oap->use_reg_one = FALSE; | |
3600 } | |
3601 | |
3602 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3603 clearopbeep(oparg_T *oap) |
7 | 3604 { |
3605 clearop(oap); | |
3606 beep_flush(); | |
3607 } | |
3608 | |
3609 /* | |
3610 * Remove the shift modifier from a special key. | |
3611 */ | |
3612 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3613 unshift_special(cmdarg_T *cap) |
7 | 3614 { |
3615 switch (cap->cmdchar) | |
3616 { | |
3617 case K_S_RIGHT: cap->cmdchar = K_RIGHT; break; | |
3618 case K_S_LEFT: cap->cmdchar = K_LEFT; break; | |
3619 case K_S_UP: cap->cmdchar = K_UP; break; | |
3620 case K_S_DOWN: cap->cmdchar = K_DOWN; break; | |
3621 case K_S_HOME: cap->cmdchar = K_HOME; break; | |
3622 case K_S_END: cap->cmdchar = K_END; break; | |
3623 } | |
3624 cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask); | |
3625 } | |
3626 | |
6979 | 3627 /* |
3628 * If the mode is currently displayed clear the command line or update the | |
3629 * command displayed. | |
3630 */ | |
3631 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3632 may_clear_cmdline(void) |
6979 | 3633 { |
3634 if (mode_displayed) | |
3635 clear_cmdline = TRUE; /* unshow visual mode later */ | |
3636 #ifdef FEAT_CMDL_INFO | |
3637 else | |
3638 clear_showcmd(); | |
3639 #endif | |
3640 } | |
3641 | |
7 | 3642 #if defined(FEAT_CMDL_INFO) || defined(PROTO) |
3643 /* | |
3644 * Routines for displaying a partly typed command | |
3645 */ | |
3646 | |
5735 | 3647 #define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 |
7 | 3648 static char_u showcmd_buf[SHOWCMD_BUFLEN]; |
3649 static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */ | |
3650 static int showcmd_is_clear = TRUE; | |
3651 static int showcmd_visual = FALSE; | |
3652 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
3653 static void display_showcmd(void); |
7 | 3654 |
3655 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3656 clear_showcmd(void) |
7 | 3657 { |
3658 if (!p_sc) | |
3659 return; | |
3660 | |
3661 if (VIsual_active && !char_avail()) | |
3662 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3663 int cursor_bot = LT_POS(VIsual, curwin->w_cursor); |
7 | 3664 long lines; |
3665 colnr_T leftcol, rightcol; | |
3666 linenr_T top, bot; | |
3667 | |
3668 /* Show the size of the Visual area. */ | |
1866 | 3669 if (cursor_bot) |
7 | 3670 { |
3671 top = VIsual.lnum; | |
3672 bot = curwin->w_cursor.lnum; | |
3673 } | |
3674 else | |
3675 { | |
3676 top = curwin->w_cursor.lnum; | |
3677 bot = VIsual.lnum; | |
3678 } | |
3679 # ifdef FEAT_FOLDING | |
3680 /* Include closed folds as a whole. */ | |
7009 | 3681 (void)hasFolding(top, &top, NULL); |
3682 (void)hasFolding(bot, NULL, &bot); | |
7 | 3683 # endif |
3684 lines = bot - top + 1; | |
3685 | |
3686 if (VIsual_mode == Ctrl_V) | |
3687 { | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3688 # ifdef FEAT_LINEBREAK |
1866 | 3689 char_u *saved_sbr = p_sbr; |
3690 | |
3691 /* Make 'sbr' empty for a moment to get the correct size. */ | |
3692 p_sbr = empty_option; | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3693 # endif |
7 | 3694 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
|
3695 # ifdef FEAT_LINEBREAK |
1866 | 3696 p_sbr = saved_sbr; |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3697 # endif |
7 | 3698 sprintf((char *)showcmd_buf, "%ldx%ld", lines, |
3699 (long)(rightcol - leftcol + 1)); | |
3700 } | |
3701 else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum) | |
3702 sprintf((char *)showcmd_buf, "%ld", lines); | |
3703 else | |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3704 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3705 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
|
3706 int l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3707 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
|
3708 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
|
3709 |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3710 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
|
3711 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3712 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
|
3713 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
|
3714 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3715 else |
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 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
|
3718 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
|
3719 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3720 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
|
3721 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3722 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
|
3723 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
|
3724 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3725 ++bytes; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3726 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3727 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
|
3728 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3729 bytes += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3730 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3731 s += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3732 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3733 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
|
3734 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
|
3735 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3736 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
|
3737 } |
7 | 3738 showcmd_buf[SHOWCMD_COLS] = NUL; /* truncate */ |
3739 showcmd_visual = TRUE; | |
3740 } | |
3741 else | |
3742 { | |
3743 showcmd_buf[0] = NUL; | |
3744 showcmd_visual = FALSE; | |
3745 | |
3746 /* Don't actually display something if there is nothing to clear. */ | |
3747 if (showcmd_is_clear) | |
3748 return; | |
3749 } | |
3750 | |
3751 display_showcmd(); | |
3752 } | |
3753 | |
3754 /* | |
3755 * Add 'c' to string of shown command chars. | |
3756 * Return TRUE if output has been written (and setcursor() has been called). | |
3757 */ | |
3758 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3759 add_to_showcmd(int c) |
7 | 3760 { |
3761 char_u *p; | |
3762 int old_len; | |
3763 int extra_len; | |
3764 int overflow; | |
3765 #if defined(FEAT_MOUSE) | |
3766 int i; | |
3767 static int ignore[] = | |
3768 { | |
660 | 3769 # ifdef FEAT_GUI |
7 | 3770 K_VER_SCROLLBAR, K_HOR_SCROLLBAR, |
3771 K_LEFTMOUSE_NM, K_LEFTRELEASE_NM, | |
660 | 3772 # endif |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
3773 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
|
3774 K_LEFTMOUSE, K_LEFTDRAG, K_LEFTRELEASE, K_MOUSEMOVE, |
7 | 3775 K_MIDDLEMOUSE, K_MIDDLEDRAG, K_MIDDLERELEASE, |
3776 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
|
3777 K_MOUSEDOWN, K_MOUSEUP, K_MOUSELEFT, K_MOUSERIGHT, |
7 | 3778 K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE, |
631 | 3779 K_CURSORHOLD, |
7 | 3780 0 |
3781 }; | |
3782 #endif | |
3783 | |
641 | 3784 if (!p_sc || msg_silent != 0) |
7 | 3785 return FALSE; |
3786 | |
3787 if (showcmd_visual) | |
3788 { | |
3789 showcmd_buf[0] = NUL; | |
3790 showcmd_visual = FALSE; | |
3791 } | |
3792 | |
3793 #if defined(FEAT_MOUSE) | |
3794 /* Ignore keys that are scrollbar updates and mouse clicks */ | |
3795 if (IS_SPECIAL(c)) | |
3796 for (i = 0; ignore[i] != 0; ++i) | |
3797 if (ignore[i] == c) | |
3798 return FALSE; | |
3799 #endif | |
3800 | |
3801 p = transchar(c); | |
5535 | 3802 if (*p == ' ') |
3803 STRCPY(p, "<20>"); | |
7 | 3804 old_len = (int)STRLEN(showcmd_buf); |
3805 extra_len = (int)STRLEN(p); | |
3806 overflow = old_len + extra_len - SHOWCMD_COLS; | |
3807 if (overflow > 0) | |
1362 | 3808 mch_memmove(showcmd_buf, showcmd_buf + overflow, |
3809 old_len - overflow + 1); | |
7 | 3810 STRCAT(showcmd_buf, p); |
3811 | |
3812 if (char_avail()) | |
3813 return FALSE; | |
3814 | |
3815 display_showcmd(); | |
3816 | |
3817 return TRUE; | |
3818 } | |
3819 | |
3820 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3821 add_to_showcmd_c(int c) |
7 | 3822 { |
3823 if (!add_to_showcmd(c)) | |
3824 setcursor(); | |
3825 } | |
3826 | |
3827 /* | |
3828 * Delete 'len' characters from the end of the shown command. | |
3829 */ | |
3830 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3831 del_from_showcmd(int len) |
7 | 3832 { |
3833 int old_len; | |
3834 | |
3835 if (!p_sc) | |
3836 return; | |
3837 | |
3838 old_len = (int)STRLEN(showcmd_buf); | |
3839 if (len > old_len) | |
3840 len = old_len; | |
3841 showcmd_buf[old_len - len] = NUL; | |
3842 | |
3843 if (!char_avail()) | |
3844 display_showcmd(); | |
3845 } | |
3846 | |
3847 /* | |
3848 * push_showcmd() and pop_showcmd() are used when waiting for the user to type | |
3849 * something and there is a partial mapping. | |
3850 */ | |
3851 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3852 push_showcmd(void) |
7 | 3853 { |
3854 if (p_sc) | |
3855 STRCPY(old_showcmd_buf, showcmd_buf); | |
3856 } | |
3857 | |
3858 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3859 pop_showcmd(void) |
7 | 3860 { |
3861 if (!p_sc) | |
3862 return; | |
3863 | |
3864 STRCPY(showcmd_buf, old_showcmd_buf); | |
3865 | |
3866 display_showcmd(); | |
3867 } | |
3868 | |
3869 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3870 display_showcmd(void) |
7 | 3871 { |
3872 int len; | |
3873 | |
3874 cursor_off(); | |
3875 | |
3876 len = (int)STRLEN(showcmd_buf); | |
3877 if (len == 0) | |
3878 showcmd_is_clear = TRUE; | |
3879 else | |
3880 { | |
3881 screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0); | |
3882 showcmd_is_clear = FALSE; | |
3883 } | |
3884 | |
3885 /* | |
1188 | 3886 * clear the rest of an old message by outputting up to SHOWCMD_COLS |
3887 * spaces | |
7 | 3888 */ |
3889 screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0); | |
3890 | |
3891 setcursor(); /* put cursor back where it belongs */ | |
3892 } | |
3893 #endif | |
3894 | |
3895 /* | |
3896 * When "check" is FALSE, prepare for commands that scroll the window. | |
3897 * When "check" is TRUE, take care of scroll-binding after the window has | |
3898 * scrolled. Called from normal_cmd() and edit(). | |
3899 */ | |
3900 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3901 do_check_scrollbind(int check) |
7 | 3902 { |
3903 static win_T *old_curwin = NULL; | |
3904 static linenr_T old_topline = 0; | |
3905 #ifdef FEAT_DIFF | |
3906 static int old_topfill = 0; | |
3907 #endif | |
3908 static buf_T *old_buf = NULL; | |
3909 static colnr_T old_leftcol = 0; | |
3910 | |
3911 if (check && curwin->w_p_scb) | |
3912 { | |
3913 /* If a ":syncbind" command was just used, don't scroll, only reset | |
3914 * the values. */ | |
3915 if (did_syncbind) | |
3916 did_syncbind = FALSE; | |
3917 else if (curwin == old_curwin) | |
3918 { | |
3919 /* | |
3920 * Synchronize other windows, as necessary according to | |
3921 * 'scrollbind'. Don't do this after an ":edit" command, except | |
3922 * when 'diff' is set. | |
3923 */ | |
3924 if ((curwin->w_buffer == old_buf | |
3925 #ifdef FEAT_DIFF | |
3926 || curwin->w_p_diff | |
3927 #endif | |
3928 ) | |
3929 && (curwin->w_topline != old_topline | |
3930 #ifdef FEAT_DIFF | |
3931 || curwin->w_topfill != old_topfill | |
3932 #endif | |
3933 || curwin->w_leftcol != old_leftcol)) | |
3934 { | |
3935 check_scrollbind(curwin->w_topline - old_topline, | |
3936 (long)(curwin->w_leftcol - old_leftcol)); | |
3937 } | |
3938 } | |
3939 else if (vim_strchr(p_sbo, 'j')) /* jump flag set in 'scrollopt' */ | |
3940 { | |
3941 /* | |
3942 * When switching between windows, make sure that the relative | |
3943 * vertical offset is valid for the new window. The relative | |
3944 * offset is invalid whenever another 'scrollbind' window has | |
3945 * scrolled to a point that would force the current window to | |
3946 * scroll past the beginning or end of its buffer. When the | |
3947 * resync is performed, some of the other 'scrollbind' windows may | |
3948 * need to jump so that the current window's relative position is | |
3949 * visible on-screen. | |
3950 */ | |
3951 check_scrollbind(curwin->w_topline - curwin->w_scbind_pos, 0L); | |
3952 } | |
3953 curwin->w_scbind_pos = curwin->w_topline; | |
3954 } | |
3955 | |
3956 old_curwin = curwin; | |
3957 old_topline = curwin->w_topline; | |
3958 #ifdef FEAT_DIFF | |
3959 old_topfill = curwin->w_topfill; | |
3960 #endif | |
3961 old_buf = curwin->w_buffer; | |
3962 old_leftcol = curwin->w_leftcol; | |
3963 } | |
3964 | |
3965 /* | |
3966 * Synchronize any windows that have "scrollbind" set, based on the | |
3967 * number of rows by which the current window has changed | |
3968 * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>) | |
3969 */ | |
3970 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3971 check_scrollbind(linenr_T topline_diff, long leftcol_diff) |
7 | 3972 { |
3973 int want_ver; | |
3974 int want_hor; | |
3975 win_T *old_curwin = curwin; | |
3976 buf_T *old_curbuf = curbuf; | |
3977 int old_VIsual_select = VIsual_select; | |
3978 int old_VIsual_active = VIsual_active; | |
3979 colnr_T tgt_leftcol = curwin->w_leftcol; | |
3980 long topline; | |
3981 long y; | |
3982 | |
3983 /* | |
3984 * check 'scrollopt' string for vertical and horizontal scroll options | |
3985 */ | |
3986 want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0); | |
3987 #ifdef FEAT_DIFF | |
3988 want_ver |= old_curwin->w_p_diff; | |
3989 #endif | |
3990 want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0)); | |
3991 | |
3992 /* | |
3993 * loop through the scrollbound windows and scroll accordingly | |
3994 */ | |
3995 VIsual_select = VIsual_active = 0; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9399
diff
changeset
|
3996 FOR_ALL_WINDOWS(curwin) |
7 | 3997 { |
3998 curbuf = curwin->w_buffer; | |
3999 /* skip original window and windows with 'noscrollbind' */ | |
4000 if (curwin != old_curwin && curwin->w_p_scb) | |
4001 { | |
4002 /* | |
4003 * do the vertical scroll | |
4004 */ | |
4005 if (want_ver) | |
4006 { | |
4007 #ifdef FEAT_DIFF | |
4008 if (old_curwin->w_p_diff && curwin->w_p_diff) | |
4009 { | |
4010 diff_set_topline(old_curwin, curwin); | |
4011 } | |
4012 else | |
4013 #endif | |
4014 { | |
4015 curwin->w_scbind_pos += topline_diff; | |
4016 topline = curwin->w_scbind_pos; | |
4017 if (topline > curbuf->b_ml.ml_line_count) | |
4018 topline = curbuf->b_ml.ml_line_count; | |
4019 if (topline < 1) | |
4020 topline = 1; | |
4021 | |
4022 y = topline - curwin->w_topline; | |
4023 if (y > 0) | |
4024 scrollup(y, FALSE); | |
4025 else | |
4026 scrolldown(-y, FALSE); | |
4027 } | |
4028 | |
4029 redraw_later(VALID); | |
4030 cursor_correct(); | |
4031 curwin->w_redr_status = TRUE; | |
4032 } | |
4033 | |
4034 /* | |
4035 * do the horizontal scroll | |
4036 */ | |
4037 if (want_hor && curwin->w_leftcol != tgt_leftcol) | |
4038 { | |
4039 curwin->w_leftcol = tgt_leftcol; | |
4040 leftcol_changed(); | |
4041 } | |
4042 } | |
4043 } | |
4044 | |
4045 /* | |
4046 * reset current-window | |
4047 */ | |
4048 VIsual_select = old_VIsual_select; | |
4049 VIsual_active = old_VIsual_active; | |
4050 curwin = old_curwin; | |
4051 curbuf = old_curbuf; | |
4052 } | |
4053 | |
4054 /* | |
4055 * Command character that's ignored. | |
4056 * 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
|
4057 * xon/xoff. |
7 | 4058 */ |
4059 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4060 nv_ignore(cmdarg_T *cap) |
7 | 4061 { |
226 | 4062 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
7 | 4063 } |
4064 | |
4065 /* | |
620 | 4066 * Command character that doesn't do anything, but unlike nv_ignore() does |
4067 * start edit(). Used for "startinsert" executed while starting up. | |
4068 */ | |
4069 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4070 nv_nop(cmdarg_T *cap UNUSED) |
620 | 4071 { |
4072 } | |
4073 | |
4074 /* | |
7 | 4075 * Command character doesn't exist. |
4076 */ | |
4077 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4078 nv_error(cmdarg_T *cap) |
7 | 4079 { |
4080 clearopbeep(cap->oap); | |
4081 } | |
4082 | |
4083 /* | |
4084 * <Help> and <F1> commands. | |
4085 */ | |
4086 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4087 nv_help(cmdarg_T *cap) |
7 | 4088 { |
4089 if (!checkclearopq(cap->oap)) | |
4090 ex_help(NULL); | |
4091 } | |
4092 | |
4093 /* | |
4094 * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor. | |
4095 */ | |
4096 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4097 nv_addsub(cmdarg_T *cap) |
7 | 4098 { |
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
|
4099 #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
|
4100 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
|
4101 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
|
4102 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
|
4103 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4104 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
|
4105 { |
7578
fdae4c496775
commit https://github.com/vim/vim/commit/ef2b5036b3005f1ce15d146dce72379a9834c56d
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
4106 prep_redo_cmd(cap); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4107 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
|
4108 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
|
4109 cap->oap->op_type = OP_NOP; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4110 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4111 else if (VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4112 nv_operator(cap); |
6868 | 4113 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4114 clearop(cap->oap); |
7 | 4115 } |
4116 | |
4117 /* | |
4118 * CTRL-F, CTRL-B, etc: Scroll page up or down. | |
4119 */ | |
4120 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4121 nv_page(cmdarg_T *cap) |
7 | 4122 { |
4123 if (!checkclearop(cap->oap)) | |
819 | 4124 { |
4125 if (mod_mask & MOD_MASK_CTRL) | |
4126 { | |
4127 /* <C-PageUp>: tab page back; <C-PageDown>: tab page forward */ | |
4128 if (cap->arg == BACKWARD) | |
4129 goto_tabpage(-(int)cap->count1); | |
4130 else | |
4131 goto_tabpage((int)cap->count0); | |
4132 } | |
4133 else | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
4134 (void)onepage(cap->arg, cap->count1); |
819 | 4135 } |
7 | 4136 } |
4137 | |
4138 /* | |
4139 * Implementation of "gd" and "gD" command. | |
4140 */ | |
4141 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4142 nv_gd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4143 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4144 int nchar, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4145 int thisblock) /* 1 for "1gd" and "1gD" */ |
7 | 4146 { |
4147 int len; | |
503 | 4148 char_u *ptr; |
4149 | |
4150 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
|
4151 || 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
|
4152 == FAIL) |
503 | 4153 clearopbeep(oap); |
4154 #ifdef FEAT_FOLDING | |
4155 else if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) | |
4156 foldOpenCursor(); | |
4157 #endif | |
4158 } | |
4159 | |
4160 /* | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4161 * 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
|
4162 * otherwise. |
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 static int |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4165 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
|
4166 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4167 int i; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4168 int incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4169 int instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4170 int prev = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4171 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4172 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
|
4173 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4174 if (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 if (prev != '\\' && line[i] == instring) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4177 instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4178 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4179 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
|
4180 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4181 instring = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4182 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4183 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4184 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4185 if (incomment) |
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 if (prev == '*' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4188 incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4189 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4190 else if (prev == '/' && line[i] == '*') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4191 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4192 incomment = TRUE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4193 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4194 else if (prev == '/' && line[i] == '/') |
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 return FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4197 } |
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 prev = line[i]; |
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 return incomment == FALSE && instring == 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4204 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4205 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4206 /* |
523 | 4207 * Search for variable declaration of "ptr[len]". |
4208 * When "locally" is TRUE in the current function ("gd"), otherwise in the | |
4209 * current file ("gD"). | |
4210 * When "thisblock" is TRUE check the {} block scope. | |
503 | 4211 * Return FAIL when not found. |
4212 */ | |
4213 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4214 find_decl( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4215 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4216 int len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4217 int locally, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4218 int thisblock, |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4219 int flags_arg) /* flags passed to searchit() */ |
503 | 4220 { |
7 | 4221 char_u *pat; |
4222 pos_T old_pos; | |
503 | 4223 pos_T par_pos; |
4224 pos_T found_pos; | |
7 | 4225 int t; |
4226 int save_p_ws; | |
4227 int save_p_scs; | |
503 | 4228 int retval = OK; |
944 | 4229 int incll; |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4230 int searchflags = flags_arg; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4231 int valid; |
503 | 4232 |
4233 if ((pat = alloc(len + 7)) == NULL) | |
4234 return FAIL; | |
268 | 4235 |
4236 /* Put "\V" before the pattern to avoid that the special meaning of "." | |
4237 * and "~" causes trouble. */ | |
4238 sprintf((char *)pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", | |
4239 len, ptr); | |
7 | 4240 old_pos = curwin->w_cursor; |
4241 save_p_ws = p_ws; | |
4242 save_p_scs = p_scs; | |
4243 p_ws = FALSE; /* don't wrap around end of file now */ | |
4244 p_scs = FALSE; /* don't switch ignorecase off now */ | |
4245 | |
4246 /* | |
4247 * With "gD" go to line 1. | |
4248 * With "gd" Search back for the start of the current function, then go | |
4249 * back until a blank line. If this fails go to line 1. | |
4250 */ | |
944 | 4251 if (!locally || !findpar(&incll, BACKWARD, 1L, '{', FALSE)) |
7 | 4252 { |
4253 setpcmark(); /* Set in findpar() otherwise */ | |
4254 curwin->w_cursor.lnum = 1; | |
539 | 4255 par_pos = curwin->w_cursor; |
7 | 4256 } |
4257 else | |
4258 { | |
539 | 4259 par_pos = curwin->w_cursor; |
7 | 4260 while (curwin->w_cursor.lnum > 1 && *skipwhite(ml_get_curline()) != NUL) |
4261 --curwin->w_cursor.lnum; | |
4262 } | |
4263 curwin->w_cursor.col = 0; | |
4264 | |
4265 /* 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
|
4266 CLEAR_POS(&found_pos); |
503 | 4267 for (;;) |
4268 { | |
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
|
4269 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
|
4270 pat, 1L, searchflags, RE_LAST, (linenr_T)0, NULL, NULL); |
503 | 4271 if (curwin->w_cursor.lnum >= old_pos.lnum) |
4272 t = FAIL; /* match after start is failure too */ | |
523 | 4273 |
718 | 4274 if (thisblock && t != FAIL) |
523 | 4275 { |
4276 pos_T *pos; | |
4277 | |
4278 /* Check that the block the match is in doesn't end before the | |
4279 * position where we started the search from. */ | |
4280 if ((pos = findmatchlimit(NULL, '}', FM_FORWARD, | |
4281 (int)(old_pos.lnum - curwin->w_cursor.lnum + 1))) != NULL | |
4282 && pos->lnum < old_pos.lnum) | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4283 { |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4284 /* 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
|
4285 * Skip to the end. */ |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4286 curwin->w_cursor = *pos; |
523 | 4287 continue; |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4288 } |
523 | 4289 } |
4290 | |
503 | 4291 if (t == FAIL) |
4292 { | |
4293 /* If we previously found a valid position, use it. */ | |
4294 if (found_pos.lnum != 0) | |
4295 { | |
4296 curwin->w_cursor = found_pos; | |
4297 t = OK; | |
4298 } | |
4299 break; | |
4300 } | |
7 | 4301 #ifdef FEAT_COMMENTS |
3562 | 4302 if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0) |
503 | 4303 { |
4304 /* Ignore this line, continue at start of next line. */ | |
4305 ++curwin->w_cursor.lnum; | |
4306 curwin->w_cursor.col = 0; | |
4307 continue; | |
4308 } | |
4309 #endif | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4310 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
|
4311 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4312 /* 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
|
4313 * 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
|
4314 if (!valid && found_pos.lnum != 0) |
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 curwin->w_cursor = found_pos; |
503 | 4317 break; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4318 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4319 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4320 /* 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
|
4321 if (valid && !locally) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4322 break; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4323 if (valid && curwin->w_cursor.lnum >= par_pos.lnum) |
503 | 4324 { |
4325 /* If we previously found a valid position, use it. */ | |
4326 if (found_pos.lnum != 0) | |
4327 curwin->w_cursor = found_pos; | |
4328 break; | |
4329 } | |
4330 | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4331 /* 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
|
4332 * 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
|
4333 * 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
|
4334 if (!valid) |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4335 CLEAR_POS(&found_pos); |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4336 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4337 found_pos = curwin->w_cursor; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4338 /* 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
|
4339 * position. */ |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4340 searchflags &= ~SEARCH_START; |
503 | 4341 } |
4342 | |
4343 if (t == FAIL) | |
4344 { | |
4345 retval = FAIL; | |
7 | 4346 curwin->w_cursor = old_pos; |
4347 } | |
4348 else | |
4349 { | |
4350 curwin->w_set_curswant = TRUE; | |
4351 /* "n" searches forward now */ | |
4352 reset_search_dir(); | |
4353 } | |
4354 | |
4355 vim_free(pat); | |
4356 p_ws = save_p_ws; | |
4357 p_scs = save_p_scs; | |
503 | 4358 |
4359 return retval; | |
7 | 4360 } |
4361 | |
4362 /* | |
4363 * Move 'dist' lines in direction 'dir', counting lines by *screen* | |
4364 * lines rather than lines in the file. | |
4365 * 'dist' must be positive. | |
4366 * | |
4367 * Return OK if able to move cursor, FAIL otherwise. | |
4368 */ | |
4369 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4370 nv_screengo(oparg_T *oap, int dir, long dist) |
7 | 4371 { |
4372 int linelen = linetabsize(ml_get_curline()); | |
4373 int retval = OK; | |
4374 int atend = FALSE; | |
4375 int n; | |
4376 int col_off1; /* margin offset for first screen line */ | |
4377 int col_off2; /* margin offset for wrapped screen line */ | |
4378 int width1; /* text width for first screen line */ | |
4379 int width2; /* test width for wrapped screen line */ | |
4380 | |
4381 oap->motion_type = MCHAR; | |
5192
c28202427d71
updated for version 7.4a.022
Bram Moolenaar <bram@vim.org>
parents:
5162
diff
changeset
|
4382 oap->inclusive = (curwin->w_curswant == MAXCOL); |
7 | 4383 |
4384 col_off1 = curwin_col_off(); | |
4385 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
|
4386 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
|
4387 width2 = curwin->w_width - col_off2; |
6559 | 4388 if (width2 == 0) |
4389 width2 = 1; /* avoid divide by zero */ | |
7 | 4390 |
4391 if (curwin->w_width != 0) | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4392 { |
7 | 4393 /* |
4394 * Instead of sticking at the last character of the buffer line we | |
4395 * try to stick in the last column of the screen. | |
4396 */ | |
4397 if (curwin->w_curswant == MAXCOL) | |
4398 { | |
4399 atend = TRUE; | |
4400 validate_virtcol(); | |
4401 if (width1 <= 0) | |
4402 curwin->w_curswant = 0; | |
4403 else | |
4404 { | |
4405 curwin->w_curswant = width1 - 1; | |
4406 if (curwin->w_virtcol > curwin->w_curswant) | |
4407 curwin->w_curswant += ((curwin->w_virtcol | |
4408 - curwin->w_curswant - 1) / width2 + 1) * width2; | |
4409 } | |
4410 } | |
4411 else | |
4412 { | |
4413 if (linelen > width1) | |
4414 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
4415 else | |
4416 n = width1; | |
4417 if (curwin->w_curswant > (colnr_T)n + 1) | |
4418 curwin->w_curswant -= ((curwin->w_curswant - n) / width2 + 1) | |
4419 * width2; | |
4420 } | |
4421 | |
4422 while (dist--) | |
4423 { | |
4424 if (dir == BACKWARD) | |
4425 { | |
4426 if ((long)curwin->w_curswant >= width2) | |
4427 /* move back within line */ | |
4428 curwin->w_curswant -= width2; | |
4429 else | |
4430 { | |
4431 /* to previous line */ | |
4432 if (curwin->w_cursor.lnum == 1) | |
4433 { | |
4434 retval = FAIL; | |
4435 break; | |
4436 } | |
4437 --curwin->w_cursor.lnum; | |
4438 #ifdef FEAT_FOLDING | |
4439 /* Move to the start of a closed fold. Don't do that when | |
4440 * 'foldopen' contains "all": it will open in a moment. */ | |
4441 if (!(fdo_flags & FDO_ALL)) | |
4442 (void)hasFolding(curwin->w_cursor.lnum, | |
4443 &curwin->w_cursor.lnum, NULL); | |
4444 #endif | |
4445 linelen = linetabsize(ml_get_curline()); | |
4446 if (linelen > width1) | |
4447 curwin->w_curswant += (((linelen - width1 - 1) / width2) | |
4448 + 1) * width2; | |
4449 } | |
4450 } | |
4451 else /* dir == FORWARD */ | |
4452 { | |
4453 if (linelen > width1) | |
4454 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
4455 else | |
4456 n = width1; | |
4457 if (curwin->w_curswant + width2 < (colnr_T)n) | |
4458 /* move forward within line */ | |
4459 curwin->w_curswant += width2; | |
4460 else | |
4461 { | |
4462 /* to next line */ | |
4463 #ifdef FEAT_FOLDING | |
4464 /* Move to the end of a closed fold. */ | |
4465 (void)hasFolding(curwin->w_cursor.lnum, NULL, | |
4466 &curwin->w_cursor.lnum); | |
4467 #endif | |
4468 if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
4469 { | |
4470 retval = FAIL; | |
4471 break; | |
4472 } | |
4473 curwin->w_cursor.lnum++; | |
4474 curwin->w_curswant %= width2; | |
2911 | 4475 linelen = linetabsize(ml_get_curline()); |
7 | 4476 } |
4477 } | |
4478 } | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4479 } |
7 | 4480 |
5600 | 4481 if (virtual_active() && atend) |
4482 coladvance(MAXCOL); | |
4483 else | |
4484 coladvance(curwin->w_curswant); | |
7 | 4485 |
4486 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
4487 { | |
6178 | 4488 colnr_T virtcol; |
4489 | |
7 | 4490 /* |
4491 * Check for landing on a character that got split at the end of the | |
4492 * last line. We want to advance a screenline, not end up in the same | |
4493 * screenline or move two screenlines. | |
4494 */ | |
4495 validate_virtcol(); | |
6178 | 4496 virtcol = curwin->w_virtcol; |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4497 #if defined(FEAT_LINEBREAK) |
6178 | 4498 if (virtcol > (colnr_T)width1 && *p_sbr != NUL) |
4499 virtcol -= vim_strsize(p_sbr); | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4500 #endif |
6178 | 4501 |
4502 if (virtcol > curwin->w_curswant | |
7 | 4503 && (curwin->w_curswant < (colnr_T)width1 |
4504 ? (curwin->w_curswant > (colnr_T)width1 / 2) | |
4505 : ((curwin->w_curswant - width1) % width2 | |
4506 > (colnr_T)width2 / 2))) | |
4507 --curwin->w_cursor.col; | |
4508 } | |
4509 | |
4510 if (atend) | |
4511 curwin->w_curswant = MAXCOL; /* stick in the last column */ | |
4512 | |
4513 return retval; | |
4514 } | |
4515 | |
4516 #ifdef FEAT_MOUSE | |
4517 /* | |
4518 * Mouse scroll wheel: Default action is to scroll three lines, or one page | |
4519 * 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
|
4520 * 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
|
4521 * K_MOUSELEFT (cap->arg == -1) or K_MOUSERIGHT (cap->arg == -2) |
7 | 4522 */ |
4523 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4524 nv_mousescroll(cmdarg_T *cap) |
7 | 4525 { |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4526 win_T *old_curwin = curwin, *wp; |
7 | 4527 |
4162 | 4528 if (mouse_row >= 0 && mouse_col >= 0) |
7 | 4529 { |
4530 int row, col; | |
4531 | |
4532 row = mouse_row; | |
4533 col = mouse_col; | |
4534 | |
4535 /* find the window at the pointer coordinates */ | |
17196
983950357c40
patch 8.1.1597: cannot scroll a popup window with the mouse
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4536 wp = mouse_find_win(&row, &col, FIND_POPUP); |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4537 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
|
4538 return; |
17196
983950357c40
patch 8.1.1597: cannot scroll a popup window with the mouse
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4539 #ifdef FEAT_TEXT_PROP |
17225
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17216
diff
changeset
|
4540 if (WIN_IS_POPUP(wp) && !wp->w_has_scrollbar) |
17196
983950357c40
patch 8.1.1597: cannot scroll a popup window with the mouse
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4541 return; |
983950357c40
patch 8.1.1597: cannot scroll a popup window with the mouse
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4542 #endif |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4543 curwin = wp; |
7 | 4544 curbuf = curwin->w_buffer; |
4545 } | |
4546 | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4547 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
|
4548 { |
11983
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4549 # 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
|
4550 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
|
4551 /* 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
|
4552 * 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
|
4553 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
|
4554 else |
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4555 # endif |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4556 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
|
4557 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4558 (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
|
4559 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4560 else |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4561 { |
17196
983950357c40
patch 8.1.1597: cannot scroll a popup window with the mouse
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4562 // Don't scroll more than half the window height. |
983950357c40
patch 8.1.1597: cannot scroll a popup window with the mouse
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4563 if (curwin->w_height < 6) |
983950357c40
patch 8.1.1597: cannot scroll a popup window with the mouse
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4564 { |
983950357c40
patch 8.1.1597: cannot scroll a popup window with the mouse
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4565 cap->count1 = curwin->w_height / 2; |
983950357c40
patch 8.1.1597: cannot scroll a popup window with the mouse
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4566 if (cap->count1 == 0) |
983950357c40
patch 8.1.1597: cannot scroll a popup window with the mouse
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4567 cap->count1 = 1; |
983950357c40
patch 8.1.1597: cannot scroll a popup window with the mouse
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4568 } |
983950357c40
patch 8.1.1597: cannot scroll a popup window with the mouse
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4569 else |
983950357c40
patch 8.1.1597: cannot scroll a popup window with the mouse
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4570 cap->count1 = 3; |
983950357c40
patch 8.1.1597: cannot scroll a popup window with the mouse
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4571 cap->count0 = cap->count1; |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4572 nv_scroll_line(cap); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4573 } |
17196
983950357c40
patch 8.1.1597: cannot scroll a popup window with the mouse
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4574 #ifdef FEAT_TEXT_PROP |
17225
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17216
diff
changeset
|
4575 if (WIN_IS_POPUP(curwin)) |
17216
11f3cf51d43b
patch 8.1.1608: the evalfunc.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17200
diff
changeset
|
4576 popup_set_firstline(curwin); |
17196
983950357c40
patch 8.1.1597: cannot scroll a popup window with the mouse
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4577 #endif |
2409
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 # ifdef FEAT_GUI |
7 | 4580 else |
4581 { | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4582 /* 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
|
4583 if (!curwin->w_p_wrap) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4584 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4585 int val, step = 6; |
2416
1a9c16dd76d4
Fix compiler warnings on 64 bit systems.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4586 |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4587 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
|
4588 step = curwin->w_width; |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4589 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
|
4590 if (val < 0) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4591 val = 0; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4592 |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4593 gui_do_horiz_scroll(val, TRUE); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4594 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4595 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4596 # 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
|
4597 # 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
|
4598 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
|
4599 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
|
4600 # endif |
7 | 4601 |
4602 curwin->w_redr_status = TRUE; | |
4603 | |
4604 curwin = old_curwin; | |
4605 curbuf = curwin->w_buffer; | |
4606 } | |
4607 | |
4608 /* | |
4609 * Mouse clicks and drags. | |
4610 */ | |
4611 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4612 nv_mouse(cmdarg_T *cap) |
7 | 4613 { |
4614 (void)do_mouse(cap->oap, cap->cmdchar, BACKWARD, cap->count1, 0); | |
4615 } | |
4616 #endif | |
4617 | |
4618 /* | |
4619 * Handle CTRL-E and CTRL-Y commands: scroll a line up or down. | |
4620 * cap->arg must be TRUE for CTRL-E. | |
4621 */ | |
4622 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4623 nv_scroll_line(cmdarg_T *cap) |
7 | 4624 { |
4625 if (!checkclearop(cap->oap)) | |
4626 scroll_redraw(cap->arg, cap->count1); | |
4627 } | |
4628 | |
4629 /* | |
4630 * Scroll "count" lines up or down, and redraw. | |
4631 */ | |
4632 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4633 scroll_redraw(int up, long count) |
7 | 4634 { |
4635 linenr_T prev_topline = curwin->w_topline; | |
4636 #ifdef FEAT_DIFF | |
4637 int prev_topfill = curwin->w_topfill; | |
4638 #endif | |
4639 linenr_T prev_lnum = curwin->w_cursor.lnum; | |
4640 | |
4641 if (up) | |
4642 scrollup(count, TRUE); | |
4643 else | |
4644 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
|
4645 if (get_scrolloff_value()) |
7 | 4646 { |
4647 /* Adjust the cursor position for 'scrolloff'. Mark w_topline as | |
4648 * valid, otherwise the screen jumps back at the end of the file. */ | |
4649 cursor_correct(); | |
4650 check_cursor_moved(curwin); | |
4651 curwin->w_valid |= VALID_TOPLINE; | |
4652 | |
4653 /* If moved back to where we were, at least move the cursor, otherwise | |
4654 * we get stuck at one position. Don't move the cursor up if the | |
4655 * first line of the buffer is already on the screen */ | |
4656 while (curwin->w_topline == prev_topline | |
4657 #ifdef FEAT_DIFF | |
4658 && curwin->w_topfill == prev_topfill | |
4659 #endif | |
4660 ) | |
4661 { | |
4662 if (up) | |
4663 { | |
4664 if (curwin->w_cursor.lnum > prev_lnum | |
4665 || cursor_down(1L, FALSE) == FAIL) | |
4666 break; | |
4667 } | |
4668 else | |
4669 { | |
4670 if (curwin->w_cursor.lnum < prev_lnum | |
4671 || prev_topline == 1L | |
4672 || cursor_up(1L, FALSE) == FAIL) | |
4673 break; | |
4674 } | |
4675 /* Mark w_topline as valid, otherwise the screen jumps back at the | |
4676 * end of the file. */ | |
4677 check_cursor_moved(curwin); | |
4678 curwin->w_valid |= VALID_TOPLINE; | |
4679 } | |
4680 } | |
4681 if (curwin->w_cursor.lnum != prev_lnum) | |
4682 coladvance(curwin->w_curswant); | |
4683 redraw_later(VALID); | |
4684 } | |
4685 | |
4686 /* | |
4687 * Commands that start with "z". | |
4688 */ | |
4689 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4690 nv_zet(cmdarg_T *cap) |
7 | 4691 { |
4692 long n; | |
4693 colnr_T col; | |
4694 int nchar = cap->nchar; | |
4695 #ifdef FEAT_FOLDING | |
4696 long old_fdl = curwin->w_p_fdl; | |
4697 int old_fen = curwin->w_p_fen; | |
4698 #endif | |
737 | 4699 #ifdef FEAT_SPELL |
710 | 4700 int undo = FALSE; |
4701 #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
|
4702 long siso = get_sidescrolloff_value(); |
7 | 4703 |
4704 if (VIM_ISDIGIT(nchar)) | |
4705 { | |
4706 /* | |
4707 * "z123{nchar}": edit the count before obtaining {nchar} | |
4708 */ | |
4709 if (checkclearop(cap->oap)) | |
4710 return; | |
4711 n = nchar - '0'; | |
4712 for (;;) | |
4713 { | |
4714 #ifdef USE_ON_FLY_SCROLL | |
4715 dont_scroll = TRUE; /* disallow scrolling here */ | |
4716 #endif | |
4717 ++no_mapping; | |
4718 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 4719 nchar = plain_vgetc(); |
7 | 4720 LANGMAP_ADJUST(nchar, TRUE); |
4721 --no_mapping; | |
4722 --allow_keys; | |
4723 #ifdef FEAT_CMDL_INFO | |
4724 (void)add_to_showcmd(nchar); | |
4725 #endif | |
4726 if (nchar == K_DEL || nchar == K_KDEL) | |
4727 n /= 10; | |
4728 else if (VIM_ISDIGIT(nchar)) | |
4729 n = n * 10 + (nchar - '0'); | |
4730 else if (nchar == CAR) | |
4731 { | |
4732 #ifdef FEAT_GUI | |
4733 need_mouse_correct = TRUE; | |
4734 #endif | |
4735 win_setheight((int)n); | |
4736 break; | |
4737 } | |
4738 else if (nchar == 'l' | |
4739 || nchar == 'h' | |
4740 || nchar == K_LEFT | |
229 | 4741 || nchar == K_RIGHT) |
7 | 4742 { |
4743 cap->count1 = n ? n * cap->count1 : cap->count1; | |
4744 goto dozet; | |
4745 } | |
4746 else | |
4747 { | |
4748 clearopbeep(cap->oap); | |
4749 break; | |
4750 } | |
4751 } | |
4752 cap->oap->op_type = OP_NOP; | |
4753 return; | |
4754 } | |
4755 | |
4756 dozet: | |
4757 if ( | |
4758 #ifdef FEAT_FOLDING | |
4759 /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" | |
4760 * and "zC" only in Visual mode. "zj" and "zk" are motion | |
4761 * commands. */ | |
4762 cap->nchar != 'f' && cap->nchar != 'F' | |
4763 && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) | |
4764 && cap->nchar != 'j' && cap->nchar != 'k' | |
4765 && | |
4766 #endif | |
4767 checkclearop(cap->oap)) | |
4768 return; | |
4769 | |
4770 /* | |
4771 * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb": | |
4772 * If line number given, set cursor. | |
4773 */ | |
4774 if ((vim_strchr((char_u *)"+\r\nt.z^-b", nchar) != NULL) | |
4775 && cap->count0 | |
4776 && cap->count0 != curwin->w_cursor.lnum) | |
4777 { | |
4778 setpcmark(); | |
4779 if (cap->count0 > curbuf->b_ml.ml_line_count) | |
4780 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4781 else | |
4782 curwin->w_cursor.lnum = cap->count0; | |
22 | 4783 check_cursor_col(); |
7 | 4784 } |
4785 | |
4786 switch (nchar) | |
4787 { | |
4788 /* "z+", "z<CR>" and "zt": put cursor at top of screen */ | |
4789 case '+': | |
4790 if (cap->count0 == 0) | |
4791 { | |
4792 /* No count given: put cursor at the line below screen */ | |
4793 validate_botline(); /* make sure w_botline is valid */ | |
4794 if (curwin->w_botline > curbuf->b_ml.ml_line_count) | |
4795 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4796 else | |
4797 curwin->w_cursor.lnum = curwin->w_botline; | |
4798 } | |
4799 /* FALLTHROUGH */ | |
4800 case NL: | |
4801 case CAR: | |
4802 case K_KENTER: | |
4803 beginline(BL_WHITE | BL_FIX); | |
4804 /* FALLTHROUGH */ | |
4805 | |
4806 case 't': scroll_cursor_top(0, TRUE); | |
4807 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4808 set_fraction(curwin); |
7 | 4809 break; |
4810 | |
4811 /* "z." and "zz": put cursor in middle of screen */ | |
4812 case '.': beginline(BL_WHITE | BL_FIX); | |
4813 /* FALLTHROUGH */ | |
4814 | |
4815 case 'z': scroll_cursor_halfway(TRUE); | |
4816 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4817 set_fraction(curwin); |
7 | 4818 break; |
4819 | |
4820 /* "z^", "z-" and "zb": put cursor at bottom of screen */ | |
4821 case '^': /* Strange Vi behavior: <count>z^ finds line at top of window | |
4822 * when <count> is at bottom of window, and puts that one at | |
4823 * bottom of window. */ | |
4824 if (cap->count0 != 0) | |
4825 { | |
4826 scroll_cursor_bot(0, TRUE); | |
4827 curwin->w_cursor.lnum = curwin->w_topline; | |
4828 } | |
4829 else if (curwin->w_topline == 1) | |
4830 curwin->w_cursor.lnum = 1; | |
4831 else | |
4832 curwin->w_cursor.lnum = curwin->w_topline - 1; | |
4833 /* FALLTHROUGH */ | |
4834 case '-': | |
4835 beginline(BL_WHITE | BL_FIX); | |
4836 /* FALLTHROUGH */ | |
4837 | |
4838 case 'b': scroll_cursor_bot(0, TRUE); | |
4839 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4840 set_fraction(curwin); |
7 | 4841 break; |
4842 | |
4843 /* "zH" - scroll screen right half-page */ | |
4844 case 'H': | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
4845 cap->count1 *= curwin->w_width / 2; |
7 | 4846 /* FALLTHROUGH */ |
4847 | |
4848 /* "zh" - scroll screen to the right */ | |
4849 case 'h': | |
4850 case K_LEFT: | |
4851 if (!curwin->w_p_wrap) | |
4852 { | |
4853 if ((colnr_T)cap->count1 > curwin->w_leftcol) | |
4854 curwin->w_leftcol = 0; | |
4855 else | |
4856 curwin->w_leftcol -= (colnr_T)cap->count1; | |
4857 leftcol_changed(); | |
4858 } | |
4859 break; | |
4860 | |
4861 /* "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
|
4862 case 'L': cap->count1 *= curwin->w_width / 2; |
7 | 4863 /* FALLTHROUGH */ |
4864 | |
4865 /* "zl" - scroll screen to the left */ | |
4866 case 'l': | |
4867 case K_RIGHT: | |
4868 if (!curwin->w_p_wrap) | |
4869 { | |
4870 /* scroll the window left */ | |
4871 curwin->w_leftcol += (colnr_T)cap->count1; | |
4872 leftcol_changed(); | |
4873 } | |
4874 break; | |
4875 | |
4876 /* "zs" - scroll screen, cursor at the start */ | |
4877 case 's': if (!curwin->w_p_wrap) | |
4878 { | |
4879 #ifdef FEAT_FOLDING | |
4880 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4881 col = 0; /* like the cursor is in col 0 */ | |
4882 else | |
4883 #endif | |
4884 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
|
4885 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
|
4886 col -= siso; |
7 | 4887 else |
4888 col = 0; | |
4889 if (curwin->w_leftcol != col) | |
4890 { | |
4891 curwin->w_leftcol = col; | |
4892 redraw_later(NOT_VALID); | |
4893 } | |
4894 } | |
4895 break; | |
4896 | |
4897 /* "ze" - scroll screen, cursor at the end */ | |
4898 case 'e': if (!curwin->w_p_wrap) | |
4899 { | |
4900 #ifdef FEAT_FOLDING | |
4901 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4902 col = 0; /* like the cursor is in col 0 */ | |
4903 else | |
4904 #endif | |
4905 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
|
4906 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
|
4907 if ((long)col + siso < n) |
7 | 4908 col = 0; |
4909 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
|
4910 col = col + siso - n + 1; |
7 | 4911 if (curwin->w_leftcol != col) |
4912 { | |
4913 curwin->w_leftcol = col; | |
4914 redraw_later(NOT_VALID); | |
4915 } | |
4916 } | |
4917 break; | |
4918 | |
4919 #ifdef FEAT_FOLDING | |
4920 /* "zF": create fold command */ | |
4921 /* "zf": create fold operator */ | |
4922 case 'F': | |
4923 case 'f': if (foldManualAllowed(TRUE)) | |
4924 { | |
4925 cap->nchar = 'f'; | |
4926 nv_operator(cap); | |
4927 curwin->w_p_fen = TRUE; | |
4928 | |
4929 /* "zF" is like "zfzf" */ | |
4930 if (nchar == 'F' && cap->oap->op_type == OP_FOLD) | |
4931 { | |
4932 nv_operator(cap); | |
4933 finish_op = TRUE; | |
4934 } | |
4935 } | |
4936 else | |
4937 clearopbeep(cap->oap); | |
4938 break; | |
4939 | |
4940 /* "zd": delete fold at cursor */ | |
4941 /* "zD": delete fold at cursor recursively */ | |
4942 case 'd': | |
4943 case 'D': if (foldManualAllowed(FALSE)) | |
4944 { | |
4945 if (VIsual_active) | |
4946 nv_operator(cap); | |
4947 else | |
4948 deleteFold(curwin->w_cursor.lnum, | |
4949 curwin->w_cursor.lnum, nchar == 'D', FALSE); | |
4950 } | |
4951 break; | |
4952 | |
4352 | 4953 /* "zE": erase all folds */ |
7 | 4954 case 'E': if (foldmethodIsManual(curwin)) |
4955 { | |
4956 clearFolding(curwin); | |
4957 changed_window_setting(); | |
4958 } | |
4959 else if (foldmethodIsMarker(curwin)) | |
4960 deleteFold((linenr_T)1, curbuf->b_ml.ml_line_count, | |
4961 TRUE, FALSE); | |
4962 else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
4963 emsg(_("E352: Cannot erase folds with current 'foldmethod'")); |
7 | 4964 break; |
4965 | |
4966 /* "zn": fold none: reset 'foldenable' */ | |
4967 case 'n': curwin->w_p_fen = FALSE; | |
4968 break; | |
4969 | |
4970 /* "zN": fold Normal: set 'foldenable' */ | |
4971 case 'N': curwin->w_p_fen = TRUE; | |
4972 break; | |
4973 | |
4974 /* "zi": invert folding: toggle 'foldenable' */ | |
4975 case 'i': curwin->w_p_fen = !curwin->w_p_fen; | |
4976 break; | |
4977 | |
4978 /* "za": open closed fold or close open fold at cursor */ | |
4979 case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4980 openFold(curwin->w_cursor.lnum, cap->count1); | |
4981 else | |
4982 { | |
4983 closeFold(curwin->w_cursor.lnum, cap->count1); | |
4984 curwin->w_p_fen = TRUE; | |
4985 } | |
4986 break; | |
4987 | |
4988 /* "zA": open fold at cursor recursively */ | |
4989 case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4990 openFoldRecurse(curwin->w_cursor.lnum); | |
4991 else | |
4992 { | |
4993 closeFoldRecurse(curwin->w_cursor.lnum); | |
4994 curwin->w_p_fen = TRUE; | |
4995 } | |
4996 break; | |
4997 | |
4998 /* "zo": open fold at cursor or Visual area */ | |
4999 case 'o': if (VIsual_active) | |
5000 nv_operator(cap); | |
5001 else | |
5002 openFold(curwin->w_cursor.lnum, cap->count1); | |
5003 break; | |
5004 | |
5005 /* "zO": open fold recursively */ | |
5006 case 'O': if (VIsual_active) | |
5007 nv_operator(cap); | |
5008 else | |
5009 openFoldRecurse(curwin->w_cursor.lnum); | |
5010 break; | |
5011 | |
5012 /* "zc": close fold at cursor or Visual area */ | |
5013 case 'c': if (VIsual_active) | |
5014 nv_operator(cap); | |
5015 else | |
5016 closeFold(curwin->w_cursor.lnum, cap->count1); | |
5017 curwin->w_p_fen = TRUE; | |
5018 break; | |
5019 | |
5020 /* "zC": close fold recursively */ | |
5021 case 'C': if (VIsual_active) | |
5022 nv_operator(cap); | |
5023 else | |
5024 closeFoldRecurse(curwin->w_cursor.lnum); | |
5025 curwin->w_p_fen = TRUE; | |
5026 break; | |
5027 | |
5028 /* "zv": open folds at the cursor */ | |
5029 case 'v': foldOpenCursor(); | |
5030 break; | |
5031 | |
5032 /* "zx": re-apply 'foldlevel' and open folds at the cursor */ | |
5033 case 'x': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5034 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5035 newFoldLevel(); /* update right now */ |
7 | 5036 foldOpenCursor(); |
5037 break; | |
5038 | |
5039 /* "zX": undo manual opens/closes, re-apply 'foldlevel' */ | |
5040 case 'X': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5041 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5042 old_fdl = -1; /* force an update */ |
7 | 5043 break; |
5044 | |
5045 /* "zm": fold more */ | |
5046 case 'm': if (curwin->w_p_fdl > 0) | |
6725 | 5047 { |
5048 curwin->w_p_fdl -= cap->count1; | |
5049 if (curwin->w_p_fdl < 0) | |
5050 curwin->w_p_fdl = 0; | |
5051 } | |
7 | 5052 old_fdl = -1; /* force an update */ |
5053 curwin->w_p_fen = TRUE; | |
5054 break; | |
5055 | |
5056 /* "zM": close all folds */ | |
5057 case 'M': curwin->w_p_fdl = 0; | |
5058 old_fdl = -1; /* force an update */ | |
5059 curwin->w_p_fen = TRUE; | |
5060 break; | |
5061 | |
5062 /* "zr": reduce folding */ | |
6725 | 5063 case 'r': curwin->w_p_fdl += cap->count1; |
5064 { | |
5065 int d = getDeepestNesting(); | |
5066 | |
5067 if (curwin->w_p_fdl >= d) | |
5068 curwin->w_p_fdl = d; | |
5069 } | |
7 | 5070 break; |
5071 | |
5072 /* "zR": open all folds */ | |
5073 case 'R': curwin->w_p_fdl = getDeepestNesting(); | |
5074 old_fdl = -1; /* force an update */ | |
5075 break; | |
5076 | |
5077 case 'j': /* "zj" move to next fold downwards */ | |
5078 case 'k': /* "zk" move to next fold upwards */ | |
5079 if (foldMoveTo(TRUE, nchar == 'j' ? FORWARD : BACKWARD, | |
5080 cap->count1) == FAIL) | |
5081 clearopbeep(cap->oap); | |
5082 break; | |
5083 | |
5084 #endif /* FEAT_FOLDING */ | |
5085 | |
737 | 5086 #ifdef FEAT_SPELL |
710 | 5087 case 'u': /* "zug" and "zuw": undo "zg" and "zw" */ |
5088 ++no_mapping; | |
5089 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 5090 nchar = plain_vgetc(); |
710 | 5091 LANGMAP_ADJUST(nchar, TRUE); |
5092 --no_mapping; | |
5093 --allow_keys; | |
5094 #ifdef FEAT_CMDL_INFO | |
5095 (void)add_to_showcmd(nchar); | |
5096 #endif | |
5097 if (vim_strchr((char_u *)"gGwW", nchar) == NULL) | |
5098 { | |
5099 clearopbeep(cap->oap); | |
5100 break; | |
5101 } | |
5102 undo = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
5103 /* FALLTHROUGH */ |
710 | 5104 |
310 | 5105 case 'g': /* "zg": add good word to word list */ |
5106 case 'w': /* "zw": add wrong word to word list */ | |
381 | 5107 case 'G': /* "zG": add good word to temp word list */ |
5108 case 'W': /* "zW": add wrong word to temp word list */ | |
310 | 5109 { |
5110 char_u *ptr = NULL; | |
5111 int len; | |
5112 | |
5113 if (checkclearop(cap->oap)) | |
5114 break; | |
5115 if (VIsual_active && get_visual_text(cap, &ptr, &len) | |
5116 == FAIL) | |
5117 return; | |
501 | 5118 if (ptr == NULL) |
5119 { | |
5120 pos_T pos = curwin->w_cursor; | |
5121 | |
5374 | 5122 /* Find bad word under the cursor. When 'spell' is |
5123 * off this fails and find_ident_under_cursor() is | |
5124 * used below. */ | |
5125 emsg_off++; | |
534 | 5126 len = spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL); |
5374 | 5127 emsg_off--; |
501 | 5128 if (len != 0 && curwin->w_cursor.col <= pos.col) |
5129 ptr = ml_get_pos(&curwin->w_cursor); | |
5130 curwin->w_cursor = pos; | |
5131 } | |
5132 | |
310 | 5133 if (ptr == NULL && (len = find_ident_under_cursor(&ptr, |
5134 FIND_IDENT)) == 0) | |
5135 return; | |
17682
3dbff5d37520
patch 8.1.1838: there is :spellwrong and :spellgood but not :spellrare
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
5136 spell_add_word(ptr, len, nchar == 'w' || nchar == 'W' |
3dbff5d37520
patch 8.1.1838: there is :spellwrong and :spellgood but not :spellrare
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
5137 ? SPELL_ADD_BAD : SPELL_ADD_GOOD, |
710 | 5138 (nchar == 'G' || nchar == 'W') |
5139 ? 0 : (int)cap->count1, | |
5140 undo); | |
310 | 5141 } |
316 | 5142 break; |
323 | 5143 |
584 | 5144 case '=': /* "z=": suggestions for a badly spelled word */ |
638 | 5145 if (!checkclearop(cap->oap)) |
485 | 5146 spell_suggest((int)cap->count0); |
323 | 5147 break; |
310 | 5148 #endif |
5149 | |
7 | 5150 default: clearopbeep(cap->oap); |
5151 } | |
5152 | |
5153 #ifdef FEAT_FOLDING | |
5154 /* Redraw when 'foldenable' changed */ | |
5155 if (old_fen != curwin->w_p_fen) | |
5156 { | |
5157 # ifdef FEAT_DIFF | |
5158 win_T *wp; | |
5159 | |
5160 if (foldmethodIsDiff(curwin) && curwin->w_p_scb) | |
5161 { | |
5162 /* Adjust 'foldenable' in diff-synced windows. */ | |
5163 FOR_ALL_WINDOWS(wp) | |
5164 { | |
5165 if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) | |
5166 { | |
5167 wp->w_p_fen = curwin->w_p_fen; | |
5168 changed_window_setting_win(wp); | |
5169 } | |
5170 } | |
5171 } | |
5172 # endif | |
5173 changed_window_setting(); | |
5174 } | |
5175 | |
5176 /* Redraw when 'foldlevel' changed. */ | |
5177 if (old_fdl != curwin->w_p_fdl) | |
5178 newFoldLevel(); | |
5179 #endif | |
5180 } | |
5181 | |
5182 #ifdef FEAT_GUI | |
5183 /* | |
5184 * Vertical scrollbar movement. | |
5185 */ | |
5186 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5187 nv_ver_scrollbar(cmdarg_T *cap) |
7 | 5188 { |
5189 if (cap->oap->op_type != OP_NOP) | |
5190 clearopbeep(cap->oap); | |
5191 | |
5192 /* Even if an operator was pending, we still want to scroll */ | |
5193 gui_do_scroll(); | |
5194 } | |
5195 | |
5196 /* | |
5197 * Horizontal scrollbar movement. | |
5198 */ | |
5199 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5200 nv_hor_scrollbar(cmdarg_T *cap) |
7 | 5201 { |
5202 if (cap->oap->op_type != OP_NOP) | |
5203 clearopbeep(cap->oap); | |
5204 | |
5205 /* 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
|
5206 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 5207 } |
5208 #endif | |
5209 | |
690 | 5210 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
685 | 5211 /* |
5212 * Click in GUI tab. | |
5213 */ | |
5214 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5215 nv_tabline(cmdarg_T *cap) |
685 | 5216 { |
5217 if (cap->oap->op_type != OP_NOP) | |
5218 clearopbeep(cap->oap); | |
5219 | |
5220 /* Even if an operator was pending, we still want to jump tabs. */ | |
5221 goto_tabpage(current_tab); | |
5222 } | |
686 | 5223 |
5224 /* | |
5225 * Selected item in tab line menu. | |
5226 */ | |
5227 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5228 nv_tabmenu(cmdarg_T *cap) |
686 | 5229 { |
5230 if (cap->oap->op_type != OP_NOP) | |
5231 clearopbeep(cap->oap); | |
5232 | |
5233 /* Even if an operator was pending, we still want to jump tabs. */ | |
690 | 5234 handle_tabmenu(); |
5235 } | |
5236 | |
5237 /* | |
5238 * Handle selecting an item of the GUI tab line menu. | |
5239 * Used in Normal and Insert mode. | |
5240 */ | |
5241 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5242 handle_tabmenu(void) |
690 | 5243 { |
686 | 5244 switch (current_tabmenu) |
5245 { | |
5246 case TABLINE_MENU_CLOSE: | |
5247 if (current_tab == 0) | |
5248 do_cmdline_cmd((char_u *)"tabclose"); | |
5249 else | |
5250 { | |
5251 vim_snprintf((char *)IObuff, IOSIZE, "tabclose %d", | |
5252 current_tab); | |
5253 do_cmdline_cmd(IObuff); | |
5254 } | |
5255 break; | |
5256 | |
5257 case TABLINE_MENU_NEW: | |
6631 | 5258 if (current_tab == 0) |
5259 do_cmdline_cmd((char_u *)"$tabnew"); | |
5260 else | |
5261 { | |
5262 vim_snprintf((char *)IObuff, IOSIZE, "%dtabnew", | |
5263 current_tab - 1); | |
5264 do_cmdline_cmd(IObuff); | |
5265 } | |
686 | 5266 break; |
5267 | |
5268 case TABLINE_MENU_OPEN: | |
6631 | 5269 if (current_tab == 0) |
5270 do_cmdline_cmd((char_u *)"browse $tabnew"); | |
5271 else | |
5272 { | |
5273 vim_snprintf((char *)IObuff, IOSIZE, "browse %dtabnew", | |
5274 current_tab - 1); | |
5275 do_cmdline_cmd(IObuff); | |
5276 } | |
686 | 5277 break; |
5278 } | |
5279 } | |
685 | 5280 #endif |
5281 | |
7 | 5282 /* |
5283 * "Q" command. | |
5284 */ | |
5285 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5286 nv_exmode(cmdarg_T *cap) |
7 | 5287 { |
5288 /* | |
5289 * Ignore 'Q' in Visual mode, just give a beep. | |
5290 */ | |
5291 if (VIsual_active) | |
6949 | 5292 vim_beep(BO_EX); |
5735 | 5293 else if (!checkclearop(cap->oap)) |
7 | 5294 do_exmode(FALSE); |
5295 } | |
5296 | |
5297 /* | |
5298 * Handle a ":" command. | |
5299 */ | |
5300 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5301 nv_colon(cmdarg_T *cap) |
7 | 5302 { |
5303 int old_p_im; | |
4256 | 5304 int cmd_result; |
7 | 5305 |
5306 if (VIsual_active) | |
5307 nv_operator(cap); | |
5308 else | |
5309 { | |
5310 if (cap->oap->op_type != OP_NOP) | |
5311 { | |
5312 /* Using ":" as a movement is characterwise exclusive. */ | |
5313 cap->oap->motion_type = MCHAR; | |
5314 cap->oap->inclusive = FALSE; | |
5315 } | |
5316 else if (cap->count0) | |
5317 { | |
5318 /* translate "count:" into ":.,.+(count - 1)" */ | |
5319 stuffcharReadbuff('.'); | |
5320 if (cap->count0 > 1) | |
5321 { | |
5322 stuffReadbuff((char_u *)",.+"); | |
5323 stuffnumReadbuff((long)cap->count0 - 1L); | |
5324 } | |
5325 } | |
5326 | |
5327 /* When typing, don't type below an old message */ | |
5328 if (KeyTyped) | |
5329 compute_cmdrow(); | |
5330 | |
5331 old_p_im = p_im; | |
5332 | |
5333 /* get a command line and execute it */ | |
4256 | 5334 cmd_result = do_cmdline(NULL, getexline, NULL, |
7 | 5335 cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0); |
5336 | |
5337 /* If 'insertmode' changed, enter or exit Insert mode */ | |
5338 if (p_im != old_p_im) | |
5339 { | |
5340 if (p_im) | |
5341 restart_edit = 'i'; | |
5342 else | |
5343 restart_edit = 0; | |
5344 } | |
5345 | |
4256 | 5346 if (cmd_result == FAIL) |
5347 /* The Ex command failed, do not execute the operator. */ | |
5348 clearop(cap->oap); | |
5349 else if (cap->oap->op_type != OP_NOP | |
7 | 5350 && (cap->oap->start.lnum > curbuf->b_ml.ml_line_count |
5351 || cap->oap->start.col > | |
4256 | 5352 (colnr_T)STRLEN(ml_get(cap->oap->start.lnum)) |
5353 || did_emsg | |
5354 )) | |
5355 /* The start of the operator has become invalid by the Ex command. | |
5356 */ | |
7 | 5357 clearopbeep(cap->oap); |
5358 } | |
5359 } | |
5360 | |
5361 /* | |
5362 * Handle CTRL-G command. | |
5363 */ | |
5364 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5365 nv_ctrlg(cmdarg_T *cap) |
7 | 5366 { |
5367 if (VIsual_active) /* toggle Selection/Visual mode */ | |
5368 { | |
5369 VIsual_select = !VIsual_select; | |
5370 showmode(); | |
5371 } | |
5735 | 5372 else if (!checkclearop(cap->oap)) |
7 | 5373 /* print full name if count given or :cd used */ |
5374 fileinfo((int)cap->count0, FALSE, TRUE); | |
5375 } | |
5376 | |
5377 /* | |
5378 * Handle CTRL-H <Backspace> command. | |
5379 */ | |
5380 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5381 nv_ctrlh(cmdarg_T *cap) |
7 | 5382 { |
5383 if (VIsual_active && VIsual_select) | |
5384 { | |
5385 cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */ | |
5386 v_visop(cap); | |
5387 } | |
5388 else | |
5389 nv_left(cap); | |
5390 } | |
5391 | |
5392 /* | |
5393 * CTRL-L: clear screen and redraw. | |
5394 */ | |
5395 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5396 nv_clear(cmdarg_T *cap) |
7 | 5397 { |
5398 if (!checkclearop(cap->oap)) | |
5399 { | |
5400 #if defined(__BEOS__) && !USE_THREAD_FOR_INPUT_WITH_TIMEOUT | |
5401 /* | |
5402 * Right now, the BeBox doesn't seem to have an easy way to detect | |
5403 * window resizing, so we cheat and make the user detect it | |
5404 * manually with CTRL-L instead | |
5405 */ | |
5406 ui_get_shellsize(); | |
5407 #endif | |
5408 #ifdef FEAT_SYN_HL | |
5409 /* 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
|
5410 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
|
5411 # ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5412 { |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5413 win_T *wp; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5414 |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5415 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
|
5416 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
|
5417 } |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5418 # endif |
7 | 5419 #endif |
5420 redraw_later(CLEAR); | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
5421 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
5422 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
5423 if (!gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
5424 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
5425 resize_console_buf(); |
15866
6ddcd10aa7af
patch 8.1.0940: MS-Windows console resizing not handled properly
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
5426 #endif |
7 | 5427 } |
5428 } | |
5429 | |
5430 /* | |
5431 * CTRL-O: In Select mode: switch to Visual mode for one command. | |
5432 * Otherwise: Go to older pcmark. | |
5433 */ | |
5434 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5435 nv_ctrlo(cmdarg_T *cap) |
7 | 5436 { |
5437 if (VIsual_active && VIsual_select) | |
5438 { | |
5439 VIsual_select = FALSE; | |
5440 showmode(); | |
5441 restart_VIsual_select = 2; /* restart Select mode later */ | |
5442 } | |
5443 else | |
5444 { | |
5445 cap->count1 = -cap->count1; | |
5446 nv_pcmark(cap); | |
5447 } | |
5448 } | |
5449 | |
5450 /* | |
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
|
5451 * 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
|
5452 * not named. |
7 | 5453 */ |
5454 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5455 nv_hat(cmdarg_T *cap) |
7 | 5456 { |
5457 if (!checkclearopq(cap->oap)) | |
5458 (void)buflist_getfile((int)cap->count0, (linenr_T)0, | |
5459 GETF_SETMARK|GETF_ALT, FALSE); | |
5460 } | |
5461 | |
5462 /* | |
5463 * "Z" commands. | |
5464 */ | |
5465 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5466 nv_Zet(cmdarg_T *cap) |
7 | 5467 { |
5468 if (!checkclearopq(cap->oap)) | |
5469 { | |
5470 switch (cap->nchar) | |
5471 { | |
5472 /* "ZZ": equivalent to ":x". */ | |
5473 case 'Z': do_cmdline_cmd((char_u *)"x"); | |
5474 break; | |
5475 | |
5476 /* "ZQ": equivalent to ":q!" (Elvis compatible). */ | |
5477 case 'Q': do_cmdline_cmd((char_u *)"q!"); | |
5478 break; | |
5479 | |
5480 default: clearopbeep(cap->oap); | |
5481 } | |
5482 } | |
5483 } | |
5484 | |
5485 /* | |
5486 * Call nv_ident() as if "c1" was used, with "c2" as next character. | |
5487 */ | |
5488 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5489 do_nv_ident(int c1, int c2) |
7 | 5490 { |
5491 oparg_T oa; | |
5492 cmdarg_T ca; | |
5493 | |
5494 clear_oparg(&oa); | |
5495 vim_memset(&ca, 0, sizeof(ca)); | |
5496 ca.oap = &oa; | |
5497 ca.cmdchar = c1; | |
5498 ca.nchar = c2; | |
5499 nv_ident(&ca); | |
5500 } | |
5501 | |
5502 /* | |
5503 * Handle the commands that use the word under the cursor. | |
5504 * [g] CTRL-] :ta to current identifier | |
5505 * [g] 'K' run program for current identifier | |
5506 * [g] '*' / to current identifier or string | |
5507 * [g] '#' ? to current identifier or string | |
5508 * g ']' :tselect for current identifier | |
5509 */ | |
5510 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5511 nv_ident(cmdarg_T *cap) |
7 | 5512 { |
5513 char_u *ptr = NULL; | |
5514 char_u *buf; | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5515 unsigned buflen; |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5516 char_u *newbuf; |
7 | 5517 char_u *p; |
5518 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
|
5519 int kp_help; /* 'keywordprg' is ":he" */ |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5520 int kp_ex; /* 'keywordprg' starts with ":" */ |
7 | 5521 int n = 0; /* init for GCC */ |
5522 int cmdchar; | |
5523 int g_cmd; /* "g" command */ | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5524 int tag_cmd = FALSE; |
7 | 5525 char_u *aux_ptr; |
5526 int isman; | |
5527 int isman_s; | |
5528 | |
5529 if (cap->cmdchar == 'g') /* "g*", "g#", "g]" and "gCTRL-]" */ | |
5530 { | |
5531 cmdchar = cap->nchar; | |
5532 g_cmd = TRUE; | |
5533 } | |
5534 else | |
5535 { | |
5536 cmdchar = cap->cmdchar; | |
5537 g_cmd = FALSE; | |
5538 } | |
5539 | |
5540 if (cmdchar == POUND) /* the pound sign, '#' for English keyboards */ | |
5541 cmdchar = '#'; | |
5542 | |
5543 /* | |
5544 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode. | |
5545 */ | |
5546 if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') | |
5547 { | |
5548 if (VIsual_active && get_visual_text(cap, &ptr, &n) == FAIL) | |
5549 return; | |
5550 if (checkclearopq(cap->oap)) | |
5551 return; | |
5552 } | |
5553 | |
5554 if (ptr == NULL && (n = find_ident_under_cursor(&ptr, | |
5555 (cmdchar == '*' || cmdchar == '#') | |
5556 ? FIND_IDENT|FIND_STRING : FIND_IDENT)) == 0) | |
5557 { | |
5558 clearop(cap->oap); | |
5559 return; | |
5560 } | |
5561 | |
5562 /* Allocate buffer to put the command in. Inserting backslashes can | |
5563 * double the length of the word. p_kp / curbuf->b_p_kp could be added | |
5564 * and some numbers. */ | |
5565 kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); | |
5566 kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 | |
5567 || 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
|
5568 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
|
5569 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
5570 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
|
5571 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
|
5572 } |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5573 kp_ex = (*kp == ':'); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5574 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
|
5575 buf = alloc(buflen); |
7 | 5576 if (buf == NULL) |
5577 return; | |
5578 buf[0] = NUL; | |
5579 | |
5580 switch (cmdchar) | |
5581 { | |
5582 case '*': | |
5583 case '#': | |
5584 /* | |
5585 * Put cursor at start of word, makes search skip the word | |
5586 * under the cursor. | |
5587 * Call setpcmark() first, so "*``" puts the cursor back where | |
5588 * it was. | |
5589 */ | |
5590 setpcmark(); | |
5591 curwin->w_cursor.col = (colnr_T) (ptr - ml_get_curline()); | |
5592 | |
5593 if (!g_cmd && vim_iswordp(ptr)) | |
5594 STRCPY(buf, "\\<"); | |
5595 no_smartcase = TRUE; /* don't use 'smartcase' now */ | |
5596 break; | |
5597 | |
5598 case 'K': | |
5599 if (kp_help) | |
5600 STRCPY(buf, "he! "); | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5601 else if (kp_ex) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5602 { |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5603 if (cap->count0 != 0) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5604 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
|
5605 kp, cap->count0); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5606 else |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5607 STRCPY(buf, kp); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5608 STRCAT(buf, " "); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5609 } |
7 | 5610 else |
5611 { | |
1712 | 5612 /* An external command will probably use an argument starting |
5613 * with "-" as an option. To avoid trouble we skip the "-". */ | |
1728 | 5614 while (*ptr == '-' && n > 0) |
5615 { | |
1712 | 5616 ++ptr; |
1728 | 5617 --n; |
5618 } | |
5619 if (n == 0) | |
5620 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
5621 emsg(_(e_noident)); /* found dashes only */ |
1728 | 5622 vim_free(buf); |
5623 return; | |
5624 } | |
1712 | 5625 |
7 | 5626 /* When a count is given, turn it into a range. Is this |
5627 * really what we want? */ | |
5628 isman = (STRCMP(kp, "man") == 0); | |
5629 isman_s = (STRCMP(kp, "man -s") == 0); | |
5630 if (cap->count0 != 0 && !(isman || isman_s)) | |
5631 sprintf((char *)buf, ".,.+%ld", cap->count0 - 1); | |
5632 | |
5633 STRCAT(buf, "! "); | |
5634 if (cap->count0 == 0 && isman_s) | |
5635 STRCAT(buf, "man"); | |
5636 else | |
5637 STRCAT(buf, kp); | |
5638 STRCAT(buf, " "); | |
5639 if (cap->count0 != 0 && (isman || isman_s)) | |
5640 { | |
5641 sprintf((char *)buf + STRLEN(buf), "%ld", cap->count0); | |
5642 STRCAT(buf, " "); | |
5643 } | |
5644 } | |
5645 break; | |
5646 | |
5647 case ']': | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5648 tag_cmd = TRUE; |
7 | 5649 #ifdef FEAT_CSCOPE |
5650 if (p_cst) | |
5651 STRCPY(buf, "cstag "); | |
5652 else | |
5653 #endif | |
5654 STRCPY(buf, "ts "); | |
5655 break; | |
5656 | |
5657 default: | |
2112
6b5d641bcdd4
updated for version 7.2.395
Bram Moolenaar <bram@zimbu.org>
parents:
2049
diff
changeset
|
5658 tag_cmd = TRUE; |
7 | 5659 if (curbuf->b_help) |
5660 STRCPY(buf, "he! "); | |
5661 else | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5662 { |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5663 if (g_cmd) |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5664 STRCPY(buf, "tj "); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5665 else |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5666 sprintf((char *)buf, "%ldta ", cap->count0); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5667 } |
7 | 5668 } |
5669 | |
5670 /* | |
5671 * Now grab the chars in the identifier | |
5672 */ | |
1712 | 5673 if (cmdchar == 'K' && !kp_help) |
5674 { | |
1728 | 5675 ptr = vim_strnsave(ptr, n); |
10330
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5676 if (kp_ex) |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5677 /* 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
|
5678 p = vim_strsave_fnameescape(ptr, FALSE); |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5679 else |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5680 /* 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
|
5681 p = vim_strsave_shellescape(ptr, TRUE, TRUE); |
1728 | 5682 vim_free(ptr); |
1712 | 5683 if (p == NULL) |
5684 { | |
5685 vim_free(buf); | |
5686 return; | |
5687 } | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16742
diff
changeset
|
5688 newbuf = vim_realloc(buf, STRLEN(buf) + STRLEN(p) + 1); |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5689 if (newbuf == NULL) |
1712 | 5690 { |
5691 vim_free(buf); | |
5692 vim_free(p); | |
5693 return; | |
5694 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5695 buf = newbuf; |
1712 | 5696 STRCAT(buf, p); |
5697 vim_free(p); | |
5698 } | |
7 | 5699 else |
1712 | 5700 { |
5701 if (cmdchar == '*') | |
5702 aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\"); | |
5703 else if (cmdchar == '#') | |
5704 aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\"); | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5705 else if (tag_cmd) |
2603 | 5706 { |
5707 if (curbuf->b_help) | |
5708 /* ":help" handles unescaped argument */ | |
5709 aux_ptr = (char_u *)""; | |
5710 else | |
5711 aux_ptr = (char_u *)"\\|\"\n["; | |
5712 } | |
1712 | 5713 else |
5714 aux_ptr = (char_u *)"\\|\"\n*?["; | |
5715 | |
5716 p = buf + STRLEN(buf); | |
5717 while (n-- > 0) | |
5718 { | |
5719 /* put a backslash before \ and some others */ | |
5720 if (vim_strchr(aux_ptr, *ptr) != NULL) | |
5721 *p++ = '\\'; | |
5722 /* When current byte is a part of multibyte character, copy all | |
5723 * bytes of that character. */ | |
5724 if (has_mbyte) | |
5725 { | |
5726 int i; | |
5727 int len = (*mb_ptr2len)(ptr) - 1; | |
5728 | |
5729 for (i = 0; i < len && n >= 1; ++i, --n) | |
5730 *p++ = *ptr++; | |
5731 } | |
5732 *p++ = *ptr++; | |
5733 } | |
5734 *p = NUL; | |
5735 } | |
7 | 5736 |
5737 /* | |
5738 * Execute the command. | |
5739 */ | |
5740 if (cmdchar == '*' || cmdchar == '#') | |
5741 { | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5742 if (!g_cmd && (has_mbyte |
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5743 ? 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
|
5744 : vim_iswordc(ptr[-1]))) |
7 | 5745 STRCAT(buf, "\\>"); |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17520
diff
changeset
|
5746 |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17520
diff
changeset
|
5747 // put pattern in search history |
2024 | 5748 init_history(); |
7 | 5749 add_to_history(HIST_SEARCH, buf, TRUE, NUL); |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17520
diff
changeset
|
5750 |
6620 | 5751 (void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0); |
7 | 5752 } |
5753 else | |
16447
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
5754 { |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
5755 g_tag_at_cursor = TRUE; |
7 | 5756 do_cmdline_cmd(buf); |
16447
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
5757 g_tag_at_cursor = FALSE; |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
5758 } |
7 | 5759 |
5760 vim_free(buf); | |
5761 } | |
5762 | |
5763 /* | |
5764 * Get visually selected text, within one line only. | |
5765 * Returns FAIL if more than one line selected. | |
5766 */ | |
344 | 5767 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5768 get_visual_text( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5769 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5770 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
|
5771 int *lenp) /* return: length of selected text */ |
7 | 5772 { |
5773 if (VIsual_mode != 'V') | |
5774 unadjust_for_sel(); | |
5775 if (VIsual.lnum != curwin->w_cursor.lnum) | |
5776 { | |
344 | 5777 if (cap != NULL) |
5778 clearopbeep(cap->oap); | |
7 | 5779 return FAIL; |
5780 } | |
5781 if (VIsual_mode == 'V') | |
5782 { | |
5783 *pp = ml_get_curline(); | |
5784 *lenp = (int)STRLEN(*pp); | |
5785 } | |
5786 else | |
5787 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5788 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 5789 { |
5790 *pp = ml_get_pos(&curwin->w_cursor); | |
5791 *lenp = VIsual.col - curwin->w_cursor.col + 1; | |
5792 } | |
5793 else | |
5794 { | |
5795 *pp = ml_get_pos(&VIsual); | |
5796 *lenp = curwin->w_cursor.col - VIsual.col + 1; | |
5797 } | |
5798 if (has_mbyte) | |
5799 /* Correct the length to include the whole last character. */ | |
474 | 5800 *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; |
7 | 5801 } |
5802 reset_VIsual_and_resel(); | |
5803 return OK; | |
5804 } | |
5805 | |
5806 /* | |
5807 * CTRL-T: backwards in tag stack | |
5808 */ | |
5809 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5810 nv_tagpop(cmdarg_T *cap) |
7 | 5811 { |
5812 if (!checkclearopq(cap->oap)) | |
5813 do_tag((char_u *)"", DT_POP, (int)cap->count1, FALSE, TRUE); | |
5814 } | |
5815 | |
5816 /* | |
5817 * Handle scrolling command 'H', 'L' and 'M'. | |
5818 */ | |
5819 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5820 nv_scroll(cmdarg_T *cap) |
7 | 5821 { |
5822 int used = 0; | |
5823 long n; | |
5824 #ifdef FEAT_FOLDING | |
5825 linenr_T lnum; | |
5826 #endif | |
5827 int half; | |
5828 | |
5829 cap->oap->motion_type = MLINE; | |
5830 setpcmark(); | |
5831 | |
5832 if (cap->cmdchar == 'L') | |
5833 { | |
5834 validate_botline(); /* make sure curwin->w_botline is valid */ | |
5835 curwin->w_cursor.lnum = curwin->w_botline - 1; | |
5836 if (cap->count1 - 1 >= curwin->w_cursor.lnum) | |
5837 curwin->w_cursor.lnum = 1; | |
5838 else | |
9 | 5839 { |
5840 #ifdef FEAT_FOLDING | |
5841 if (hasAnyFolding(curwin)) | |
5842 { | |
5843 /* Count a fold for one screen line. */ | |
5844 for (n = cap->count1 - 1; n > 0 | |
5845 && curwin->w_cursor.lnum > curwin->w_topline; --n) | |
5846 { | |
5847 (void)hasFolding(curwin->w_cursor.lnum, | |
5848 &curwin->w_cursor.lnum, NULL); | |
5849 --curwin->w_cursor.lnum; | |
5850 } | |
5851 } | |
5852 else | |
5853 #endif | |
5854 curwin->w_cursor.lnum -= cap->count1 - 1; | |
5855 } | |
7 | 5856 } |
5857 else | |
5858 { | |
5859 if (cap->cmdchar == 'M') | |
5860 { | |
5861 #ifdef FEAT_DIFF | |
5862 /* Don't count filler lines above the window. */ | |
5863 used -= diff_check_fill(curwin, curwin->w_topline) | |
5864 - curwin->w_topfill; | |
5865 #endif | |
5866 validate_botline(); /* make sure w_empty_rows is valid */ | |
5867 half = (curwin->w_height - curwin->w_empty_rows + 1) / 2; | |
5868 for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) | |
5869 { | |
5870 #ifdef FEAT_DIFF | |
5871 /* Count half he number of filler lines to be "below this | |
5872 * line" and half to be "above the next line". */ | |
5873 if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline | |
5874 + n) / 2 >= half) | |
5875 { | |
5876 --n; | |
5877 break; | |
5878 } | |
5879 #endif | |
5880 used += plines(curwin->w_topline + n); | |
5881 if (used >= half) | |
5882 break; | |
5883 #ifdef FEAT_FOLDING | |
5884 if (hasFolding(curwin->w_topline + n, NULL, &lnum)) | |
5885 n = lnum - curwin->w_topline; | |
5886 #endif | |
5887 } | |
5888 if (n > 0 && used > curwin->w_height) | |
5889 --n; | |
5890 } | |
9 | 5891 else /* (cap->cmdchar == 'H') */ |
5892 { | |
7 | 5893 n = cap->count1 - 1; |
9 | 5894 #ifdef FEAT_FOLDING |
5895 if (hasAnyFolding(curwin)) | |
5896 { | |
5897 /* Count a fold for one screen line. */ | |
5898 lnum = curwin->w_topline; | |
5899 while (n-- > 0 && lnum < curwin->w_botline - 1) | |
5900 { | |
7009 | 5901 (void)hasFolding(lnum, NULL, &lnum); |
9 | 5902 ++lnum; |
5903 } | |
5904 n = lnum - curwin->w_topline; | |
5905 } | |
5906 #endif | |
5907 } | |
7 | 5908 curwin->w_cursor.lnum = curwin->w_topline + n; |
5909 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
5910 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
5911 } | |
5912 | |
12646
b908a3682f6e
patch 8.0.1201: "yL" is affected by 'scrolloff'
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
5913 /* 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
|
5914 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
|
5915 cursor_correct(); |
7 | 5916 beginline(BL_SOL | BL_FIX); |
5917 } | |
5918 | |
5919 /* | |
5920 * Cursor right commands. | |
5921 */ | |
5922 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5923 nv_right(cmdarg_T *cap) |
7 | 5924 { |
5925 long n; | |
5735 | 5926 int past_line; |
7 | 5927 |
180 | 5928 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
5929 { | |
5930 /* <C-Right> and <S-Right> move a word or WORD right */ | |
5931 if (mod_mask & MOD_MASK_CTRL) | |
5932 cap->arg = TRUE; | |
5933 nv_wordcmd(cap); | |
5934 return; | |
5935 } | |
5936 | |
7 | 5937 cap->oap->motion_type = MCHAR; |
5938 cap->oap->inclusive = FALSE; | |
5735 | 5939 past_line = (VIsual_active && *p_sel != 'o'); |
5940 | |
7 | 5941 /* |
5735 | 5942 * In virtual edit mode, there's no such thing as "past_line", as lines |
5943 * are (theoretically) infinitely long. | |
7 | 5944 */ |
5945 if (virtual_active()) | |
5735 | 5946 past_line = 0; |
7 | 5947 |
5948 for (n = cap->count1; n > 0; --n) | |
5949 { | |
5735 | 5950 if ((!past_line && oneright() == FAIL) |
5951 || (past_line && *ml_get_cursor() == NUL) | |
1877 | 5952 ) |
7 | 5953 { |
5954 /* | |
714 | 5955 * <Space> wraps to next line if 'whichwrap' has 's'. |
5956 * 'l' wraps to next line if 'whichwrap' has 'l'. | |
5957 * CURS_RIGHT wraps to next line if 'whichwrap' has '>'. | |
7 | 5958 */ |
5959 if ( ((cap->cmdchar == ' ' | |
5960 && vim_strchr(p_ww, 's') != NULL) | |
5961 || (cap->cmdchar == 'l' | |
5962 && vim_strchr(p_ww, 'l') != NULL) | |
229 | 5963 || (cap->cmdchar == K_RIGHT |
7 | 5964 && vim_strchr(p_ww, '>') != NULL)) |
5965 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
5966 { | |
5967 /* When deleting we also count the NL as a character. | |
5968 * Set cap->oap->inclusive when last char in the line is | |
5969 * included, move to next line after that */ | |
714 | 5970 if ( cap->oap->op_type != OP_NOP |
7 | 5971 && !cap->oap->inclusive |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5972 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 5973 cap->oap->inclusive = TRUE; |
5974 else | |
5975 { | |
5976 ++curwin->w_cursor.lnum; | |
5977 curwin->w_cursor.col = 0; | |
5978 curwin->w_cursor.coladd = 0; | |
5979 curwin->w_set_curswant = TRUE; | |
5980 cap->oap->inclusive = FALSE; | |
5981 } | |
5982 continue; | |
5983 } | |
5984 if (cap->oap->op_type == OP_NOP) | |
5985 { | |
5986 /* Only beep and flush if not moved at all */ | |
5987 if (n == cap->count1) | |
5988 beep_flush(); | |
5989 } | |
5990 else | |
5991 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5992 if (!LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 5993 cap->oap->inclusive = TRUE; |
5994 } | |
5995 break; | |
5996 } | |
5735 | 5997 else if (past_line) |
7 | 5998 { |
5999 curwin->w_set_curswant = TRUE; | |
6000 if (virtual_active()) | |
6001 oneright(); | |
6002 else | |
5735 | 6003 { |
7 | 6004 if (has_mbyte) |
18128
aeabc666a119
patch 8.1.2059: fix for "x" deleting a fold has side effects
Bram Moolenaar <Bram@vim.org>
parents:
18114
diff
changeset
|
6005 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor()); |
7 | 6006 else |
6007 ++curwin->w_cursor.col; | |
6008 } | |
6009 } | |
6010 } | |
6011 #ifdef FEAT_FOLDING | |
6012 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
6013 && cap->oap->op_type == OP_NOP) | |
6014 foldOpenCursor(); | |
6015 #endif | |
6016 } | |
6017 | |
6018 /* | |
6019 * Cursor left commands. | |
6020 * | |
6021 * Returns TRUE when operator end should not be adjusted. | |
6022 */ | |
6023 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6024 nv_left(cmdarg_T *cap) |
7 | 6025 { |
6026 long n; | |
6027 | |
180 | 6028 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
6029 { | |
6030 /* <C-Left> and <S-Left> move a word or WORD left */ | |
6031 if (mod_mask & MOD_MASK_CTRL) | |
6032 cap->arg = 1; | |
6033 nv_bck_word(cap); | |
6034 return; | |
6035 } | |
6036 | |
7 | 6037 cap->oap->motion_type = MCHAR; |
6038 cap->oap->inclusive = FALSE; | |
6039 for (n = cap->count1; n > 0; --n) | |
6040 { | |
6041 if (oneleft() == FAIL) | |
6042 { | |
6043 /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'. | |
6044 * 'h' wraps to previous line if 'whichwrap' has 'h'. | |
6045 * CURS_LEFT wraps to previous line if 'whichwrap' has '<'. | |
6046 */ | |
6047 if ( (((cap->cmdchar == K_BS | |
6048 || cap->cmdchar == Ctrl_H) | |
6049 && vim_strchr(p_ww, 'b') != NULL) | |
6050 || (cap->cmdchar == 'h' | |
6051 && vim_strchr(p_ww, 'h') != NULL) | |
229 | 6052 || (cap->cmdchar == K_LEFT |
7 | 6053 && vim_strchr(p_ww, '<') != NULL)) |
6054 && curwin->w_cursor.lnum > 1) | |
6055 { | |
6056 --(curwin->w_cursor.lnum); | |
6057 coladvance((colnr_T)MAXCOL); | |
6058 curwin->w_set_curswant = TRUE; | |
6059 | |
6060 /* When the NL before the first char has to be deleted we | |
6061 * put the cursor on the NUL after the previous line. | |
6062 * This is a very special case, be careful! | |
1469 | 6063 * Don't adjust op_end now, otherwise it won't work. */ |
7 | 6064 if ( (cap->oap->op_type == OP_DELETE |
6065 || 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
|
6066 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6067 { |
5682 | 6068 char_u *cp = ml_get_cursor(); |
6069 | |
6070 if (*cp != NUL) | |
6071 { | |
6072 if (has_mbyte) | |
6073 curwin->w_cursor.col += (*mb_ptr2len)(cp); | |
6074 else | |
6075 ++curwin->w_cursor.col; | |
6076 } | |
7 | 6077 cap->retval |= CA_NO_ADJ_OP_END; |
6078 } | |
6079 continue; | |
6080 } | |
6081 /* Only beep and flush if not moved at all */ | |
6082 else if (cap->oap->op_type == OP_NOP && n == cap->count1) | |
6083 beep_flush(); | |
6084 break; | |
6085 } | |
6086 } | |
6087 #ifdef FEAT_FOLDING | |
6088 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
6089 && cap->oap->op_type == OP_NOP) | |
6090 foldOpenCursor(); | |
6091 #endif | |
6092 } | |
6093 | |
6094 /* | |
6095 * Cursor up commands. | |
6096 * cap->arg is TRUE for "-": Move cursor to first non-blank. | |
6097 */ | |
6098 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6099 nv_up(cmdarg_T *cap) |
7 | 6100 { |
180 | 6101 if (mod_mask & MOD_MASK_SHIFT) |
6102 { | |
6103 /* <S-Up> is page up */ | |
6104 cap->arg = BACKWARD; | |
6105 nv_page(cap); | |
6106 } | |
6107 else | |
6108 { | |
6109 cap->oap->motion_type = MLINE; | |
6110 if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
6111 clearopbeep(cap->oap); | |
6112 else if (cap->arg) | |
6113 beginline(BL_WHITE | BL_FIX); | |
6114 } | |
7 | 6115 } |
6116 | |
6117 /* | |
6118 * Cursor down commands. | |
6119 * cap->arg is TRUE for CR and "+": Move cursor to first non-blank. | |
6120 */ | |
6121 static void | |
10192
758f3d5a463d
commit https://github.com/vim/vim/commit/1b010058235fb803c1d4f42a02d2883921be8ef4
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
6122 nv_down(cmdarg_T *cap) |
7 | 6123 { |
180 | 6124 if (mod_mask & MOD_MASK_SHIFT) |
6125 { | |
6126 /* <S-Down> is page down */ | |
6127 cap->arg = FORWARD; | |
6128 nv_page(cap); | |
6129 } | |
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
|
6130 #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
|
6131 /* 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
|
6132 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
|
6133 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
|
6134 #endif |
180 | 6135 else |
7 | 6136 { |
6137 #ifdef FEAT_CMDWIN | |
6138 /* In the cmdline window a <CR> executes the command. */ | |
170 | 6139 if (cmdwin_type != 0 && cap->cmdchar == CAR) |
7 | 6140 cmdwin_result = CAR; |
6141 else | |
6142 #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
|
6143 #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
|
6144 /* 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
|
6145 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
|
6146 && 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
|
6147 { |
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
|
6148 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
|
6149 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
|
6150 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
|
6151 } |
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
|
6152 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
|
6153 #endif |
7 | 6154 { |
6155 cap->oap->motion_type = MLINE; | |
6156 if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
6157 clearopbeep(cap->oap); | |
6158 else if (cap->arg) | |
6159 beginline(BL_WHITE | BL_FIX); | |
6160 } | |
6161 } | |
6162 } | |
6163 | |
6164 #ifdef FEAT_SEARCHPATH | |
6165 /* | |
6166 * Grab the file name under the cursor and edit it. | |
6167 */ | |
6168 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6169 nv_gotofile(cmdarg_T *cap) |
7 | 6170 { |
6171 char_u *ptr; | |
681 | 6172 linenr_T lnum = -1; |
7 | 6173 |
633 | 6174 if (text_locked()) |
7 | 6175 { |
6176 clearopbeep(cap->oap); | |
633 | 6177 text_locked_msg(); |
7 | 6178 return; |
6179 } | |
819 | 6180 if (curbuf_locked()) |
6181 { | |
6182 clearop(cap->oap); | |
6183 return; | |
6184 } | |
7 | 6185 |
681 | 6186 ptr = grab_file_name(cap->count1, &lnum); |
7 | 6187 |
6188 if (ptr != NULL) | |
6189 { | |
6190 /* 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
|
6191 if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !buf_hide(curbuf)) |
7009 | 6192 (void)autowrite(curbuf, FALSE); |
7 | 6193 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
|
6194 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
|
6195 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
|
6196 && cap->nchar == 'F' && lnum >= 0) |
681 | 6197 { |
6198 curwin->w_cursor.lnum = lnum; | |
6199 check_cursor_lnum(); | |
6200 beginline(BL_SOL | BL_FIX); | |
6201 } | |
7 | 6202 vim_free(ptr); |
6203 } | |
6204 else | |
6205 clearop(cap->oap); | |
6206 } | |
6207 #endif | |
6208 | |
6209 /* | |
6210 * <End> command: to end of current line or last line. | |
6211 */ | |
6212 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6213 nv_end(cmdarg_T *cap) |
7 | 6214 { |
180 | 6215 if (cap->arg || (mod_mask & MOD_MASK_CTRL)) /* CTRL-END = goto last line */ |
6216 { | |
6217 cap->arg = TRUE; | |
7 | 6218 nv_goto(cap); |
6219 cap->count1 = 1; /* to end of current line */ | |
6220 } | |
6221 nv_dollar(cap); | |
6222 } | |
6223 | |
6224 /* | |
6225 * Handle the "$" command. | |
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_dollar(cmdarg_T *cap) |
7 | 6229 { |
6230 cap->oap->motion_type = MCHAR; | |
6231 cap->oap->inclusive = TRUE; | |
6232 /* In virtual mode when off the edge of a line and an operator | |
6233 * is pending (whew!) keep the cursor where it is. | |
6234 * Otherwise, send it to the end of the line. */ | |
6235 if (!virtual_active() || gchar_cursor() != NUL | |
6236 || cap->oap->op_type == OP_NOP) | |
6237 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
6238 if (cursor_down((long)(cap->count1 - 1), | |
6239 cap->oap->op_type == OP_NOP) == FAIL) | |
6240 clearopbeep(cap->oap); | |
6241 #ifdef FEAT_FOLDING | |
6242 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6243 foldOpenCursor(); | |
6244 #endif | |
6245 } | |
6246 | |
6247 /* | |
6248 * Implementation of '?' and '/' commands. | |
6249 * If cap->arg is TRUE don't set PC mark. | |
6250 */ | |
6251 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6252 nv_search(cmdarg_T *cap) |
7 | 6253 { |
6254 oparg_T *oap = cap->oap; | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6255 pos_T save_cursor = curwin->w_cursor; |
7 | 6256 |
6257 if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13) | |
6258 { | |
6259 /* Translate "g??" to "g?g?" */ | |
6260 cap->cmdchar = 'g'; | |
6261 cap->nchar = '?'; | |
6262 nv_operator(cap); | |
6263 return; | |
6264 } | |
6265 | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6266 /* 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
|
6267 * start position. */ |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17041
diff
changeset
|
6268 cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0, TRUE); |
7 | 6269 |
6270 if (cap->searchbuf == NULL) | |
6271 { | |
6272 clearop(oap); | |
6273 return; | |
6274 } | |
6275 | |
6620 | 6276 (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
|
6277 (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
|
6278 ? 0 : SEARCH_MARK); |
7 | 6279 } |
6280 | |
6281 /* | |
6282 * Handle "N" and "n" commands. | |
6283 * cap->arg is SEARCH_REV for "N", 0 for "n". | |
6284 */ | |
6285 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6286 nv_next(cmdarg_T *cap) |
7 | 6287 { |
6620 | 6288 pos_T old = curwin->w_cursor; |
6289 int i = normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
6290 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6291 if (i == 1 && EQUAL_POS(old, curwin->w_cursor)) |
6620 | 6292 { |
6293 /* Avoid getting stuck on the current cursor position, which can | |
6294 * happen when an offset is given and the cursor is on the last char | |
6295 * in the buffer: Repeat with count + 1. */ | |
6296 cap->count1 += 1; | |
6297 (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
6298 cap->count1 -= 1; | |
6299 } | |
7 | 6300 } |
6301 | |
6302 /* | |
6303 * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat). | |
6304 * Uses only cap->count1 and cap->oap from "cap". | |
6620 | 6305 * Return 0 for failure, 1 for found, 2 for found and line offset added. |
6306 */ | |
6307 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6308 normal_search( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6309 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6310 int dir, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6311 char_u *pat, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6312 int opt) /* extra flags for do_search() */ |
7 | 6313 { |
6314 int i; | |
6315 | |
6316 cap->oap->motion_type = MCHAR; | |
6317 cap->oap->inclusive = FALSE; | |
6318 cap->oap->use_reg_one = TRUE; | |
6319 curwin->w_set_curswant = TRUE; | |
6320 | |
6321 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
|
6322 opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL, NULL); |
7 | 6323 if (i == 0) |
6324 clearop(cap->oap); | |
6325 else | |
6326 { | |
6327 if (i == 2) | |
6328 cap->oap->motion_type = MLINE; | |
6329 curwin->w_cursor.coladd = 0; | |
6330 #ifdef FEAT_FOLDING | |
6331 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
6332 foldOpenCursor(); | |
6333 #endif | |
6334 } | |
6335 | |
6336 /* "/$" will put the cursor after the end of the line, may need to | |
6337 * correct that here */ | |
6338 check_cursor(); | |
6620 | 6339 return i; |
7 | 6340 } |
6341 | |
6342 /* | |
6343 * Character search commands. | |
6344 * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for | |
6345 * ',' and FALSE for ';'. | |
6346 * cap->nchar is NUL for ',' and ';' (repeat the search) | |
6347 */ | |
6348 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6349 nv_csearch(cmdarg_T *cap) |
7 | 6350 { |
6351 int t_cmd; | |
6352 | |
6353 if (cap->cmdchar == 't' || cap->cmdchar == 'T') | |
6354 t_cmd = TRUE; | |
6355 else | |
6356 t_cmd = FALSE; | |
6357 | |
6358 cap->oap->motion_type = MCHAR; | |
6359 if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL) | |
6360 clearopbeep(cap->oap); | |
6361 else | |
6362 { | |
6363 curwin->w_set_curswant = TRUE; | |
6364 /* Include a Tab for "tx" and for "dfx". */ | |
6365 if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD | |
6366 && (t_cmd || cap->oap->op_type != OP_NOP)) | |
6367 { | |
6368 colnr_T scol, ecol; | |
6369 | |
6370 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
6371 curwin->w_cursor.coladd = ecol - scol; | |
6372 } | |
6373 else | |
6374 curwin->w_cursor.coladd = 0; | |
6375 adjust_for_sel(cap); | |
6376 #ifdef FEAT_FOLDING | |
6377 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6378 foldOpenCursor(); | |
6379 #endif | |
6380 } | |
6381 } | |
6382 | |
6383 /* | |
6384 * "[" and "]" commands. | |
6385 * cap->arg is BACKWARD for "[" and FORWARD for "]". | |
6386 */ | |
6387 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6388 nv_brackets(cmdarg_T *cap) |
7 | 6389 { |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
6390 pos_T new_pos = {0, 0, 0}; |
7 | 6391 pos_T prev_pos; |
6392 pos_T *pos = NULL; /* init for GCC */ | |
6393 pos_T old_pos; /* cursor position before command */ | |
6394 int flag; | |
6395 long n; | |
6396 int findc; | |
6397 int c; | |
6398 | |
6399 cap->oap->motion_type = MCHAR; | |
6400 cap->oap->inclusive = FALSE; | |
6401 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
|
6402 curwin->w_cursor.coladd = 0; // TODO: don't do this for an error. |
7 | 6403 |
6404 #ifdef FEAT_SEARCHPATH | |
6405 /* | |
6406 * "[f" or "]f" : Edit file under the cursor (same as "gf") | |
6407 */ | |
6408 if (cap->nchar == 'f') | |
6409 nv_gotofile(cap); | |
6410 else | |
6411 #endif | |
6412 | |
6413 #ifdef FEAT_FIND_ID | |
6414 /* | |
1188 | 6415 * Find the occurrence(s) of the identifier or define under cursor |
6416 * in current and included files or jump to the first occurrence. | |
7 | 6417 * |
6418 * search list jump | |
6419 * fwd bwd fwd bwd fwd bwd | |
6420 * identifier "]i" "[i" "]I" "[I" "]^I" "[^I" | |
6421 * define "]d" "[d" "]D" "[D" "]^D" "[^D" | |
6422 */ | |
6423 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
|
6424 # ifdef EBCDIC |
7 | 6425 "iI\005dD\067", |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6426 # else |
7 | 6427 "iI\011dD\004", |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6428 # endif |
7 | 6429 cap->nchar) != NULL) |
6430 { | |
6431 char_u *ptr; | |
6432 int len; | |
6433 | |
6434 if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) | |
6435 clearop(cap->oap); | |
6436 else | |
6437 { | |
6438 find_pattern_in_path(ptr, 0, len, TRUE, | |
6439 cap->count0 == 0 ? !isupper(cap->nchar) : FALSE, | |
6440 ((cap->nchar & 0xf) == ('d' & 0xf)) ? FIND_DEFINE : FIND_ANY, | |
6441 cap->count1, | |
6442 isupper(cap->nchar) ? ACTION_SHOW_ALL : | |
6443 islower(cap->nchar) ? ACTION_SHOW : ACTION_GOTO, | |
6444 cap->cmdchar == ']' ? curwin->w_cursor.lnum + 1 : (linenr_T)1, | |
6445 (linenr_T)MAXLNUM); | |
6446 curwin->w_set_curswant = TRUE; | |
6447 } | |
6448 } | |
6449 else | |
6450 #endif | |
6451 | |
6452 /* | |
6453 * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')' | |
6454 * "[#", "]#": go to start/end of Nth innermost #if..#endif construct. | |
6455 * "[/", "[*", "]/", "]*": go to Nth comment start/end. | |
6456 * "[m" or "]m" search for prev/next start of (Java) method. | |
6457 * "[M" or "]M" search for prev/next end of (Java) method. | |
6458 */ | |
6459 if ( (cap->cmdchar == '[' | |
6460 && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL) | |
6461 || (cap->cmdchar == ']' | |
6462 && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) | |
6463 { | |
6464 if (cap->nchar == '*') | |
6465 cap->nchar = '/'; | |
6466 prev_pos.lnum = 0; | |
6467 if (cap->nchar == 'm' || cap->nchar == 'M') | |
6468 { | |
6469 if (cap->cmdchar == '[') | |
6470 findc = '{'; | |
6471 else | |
6472 findc = '}'; | |
6473 n = 9999; | |
6474 } | |
6475 else | |
6476 { | |
6477 findc = cap->nchar; | |
6478 n = cap->count1; | |
6479 } | |
6480 for ( ; n > 0; --n) | |
6481 { | |
6482 if ((pos = findmatchlimit(cap->oap, findc, | |
6483 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) | |
6484 { | |
6485 if (new_pos.lnum == 0) /* nothing found */ | |
6486 { | |
6487 if (cap->nchar != 'm' && cap->nchar != 'M') | |
6488 clearopbeep(cap->oap); | |
6489 } | |
6490 else | |
6491 pos = &new_pos; /* use last one found */ | |
6492 break; | |
6493 } | |
6494 prev_pos = new_pos; | |
6495 curwin->w_cursor = *pos; | |
6496 new_pos = *pos; | |
6497 } | |
6498 curwin->w_cursor = old_pos; | |
6499 | |
6500 /* | |
6501 * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only | |
6502 * brought us to the match for "[m" and "]M" when inside a method. | |
6503 * Try finding the '{' or '}' we want to be at. | |
6504 * Also repeat for the given count. | |
6505 */ | |
6506 if (cap->nchar == 'm' || cap->nchar == 'M') | |
6507 { | |
6508 /* norm is TRUE for "]M" and "[m" */ | |
6509 int norm = ((findc == '{') == (cap->nchar == 'm')); | |
6510 | |
6511 n = cap->count1; | |
6512 /* found a match: we were inside a method */ | |
6513 if (prev_pos.lnum != 0) | |
6514 { | |
6515 pos = &prev_pos; | |
6516 curwin->w_cursor = prev_pos; | |
6517 if (norm) | |
6518 --n; | |
6519 } | |
6520 else | |
6521 pos = NULL; | |
6522 while (n > 0) | |
6523 { | |
6524 for (;;) | |
6525 { | |
6526 if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0) | |
6527 { | |
6528 /* if not found anything, that's an error */ | |
6529 if (pos == NULL) | |
6530 clearopbeep(cap->oap); | |
6531 n = 0; | |
6532 break; | |
6533 } | |
6534 c = gchar_cursor(); | |
6535 if (c == '{' || c == '}') | |
6536 { | |
6537 /* Must have found end/start of class: use it. | |
6538 * Or found the place to be at. */ | |
6539 if ((c == findc && norm) || (n == 1 && !norm)) | |
6540 { | |
6541 new_pos = curwin->w_cursor; | |
6542 pos = &new_pos; | |
6543 n = 0; | |
6544 } | |
6545 /* if no match found at all, we started outside of the | |
6546 * class and we're inside now. Just go on. */ | |
6547 else if (new_pos.lnum == 0) | |
6548 { | |
6549 new_pos = curwin->w_cursor; | |
6550 pos = &new_pos; | |
6551 } | |
6552 /* found start/end of other method: go to match */ | |
6553 else if ((pos = findmatchlimit(cap->oap, findc, | |
6554 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, | |
6555 0)) == NULL) | |
6556 n = 0; | |
6557 else | |
6558 curwin->w_cursor = *pos; | |
6559 break; | |
6560 } | |
6561 } | |
6562 --n; | |
6563 } | |
6564 curwin->w_cursor = old_pos; | |
6565 if (pos == NULL && new_pos.lnum != 0) | |
6566 clearopbeep(cap->oap); | |
6567 } | |
6568 if (pos != NULL) | |
6569 { | |
6570 setpcmark(); | |
6571 curwin->w_cursor = *pos; | |
6572 curwin->w_set_curswant = TRUE; | |
6573 #ifdef FEAT_FOLDING | |
6574 if ((fdo_flags & FDO_BLOCK) && KeyTyped | |
6575 && cap->oap->op_type == OP_NOP) | |
6576 foldOpenCursor(); | |
6577 #endif | |
6578 } | |
6579 } | |
6580 | |
6581 /* | |
6582 * "[[", "[]", "]]" and "][": move to start or end of function | |
6583 */ | |
6584 else if (cap->nchar == '[' || cap->nchar == ']') | |
6585 { | |
6586 if (cap->nchar == cap->cmdchar) /* "]]" or "[[" */ | |
6587 flag = '{'; | |
6588 else | |
6589 flag = '}'; /* "][" or "[]" */ | |
6590 | |
6591 curwin->w_set_curswant = TRUE; | |
6592 /* | |
6593 * Imitate strange Vi behaviour: When using "]]" with an operator | |
6594 * we also stop at '}'. | |
6595 */ | |
503 | 6596 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, flag, |
7 | 6597 (cap->oap->op_type != OP_NOP |
6598 && cap->arg == FORWARD && flag == '{'))) | |
6599 clearopbeep(cap->oap); | |
6600 else | |
6601 { | |
6602 if (cap->oap->op_type == OP_NOP) | |
6603 beginline(BL_WHITE | BL_FIX); | |
6604 #ifdef FEAT_FOLDING | |
6605 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6606 foldOpenCursor(); | |
6607 #endif | |
6608 } | |
6609 } | |
6610 | |
6611 /* | |
6612 * "[p", "[P", "]P" and "]p": put with indent adjustment | |
6613 */ | |
6614 else if (cap->nchar == 'p' || cap->nchar == 'P') | |
6615 { | |
16742
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
6616 nv_put_opt(cap, TRUE); |
7 | 6617 } |
6618 | |
6619 /* | |
6620 * "['", "[`", "]'" and "]`": jump to next mark | |
6621 */ | |
6622 else if (cap->nchar == '\'' || cap->nchar == '`') | |
6623 { | |
6624 pos = &curwin->w_cursor; | |
6625 for (n = cap->count1; n > 0; --n) | |
6626 { | |
6627 prev_pos = *pos; | |
6628 pos = getnextmark(pos, cap->cmdchar == '[' ? BACKWARD : FORWARD, | |
6629 cap->nchar == '\''); | |
6630 if (pos == NULL) | |
6631 break; | |
6632 } | |
6633 if (pos == NULL) | |
6634 pos = &prev_pos; | |
6635 nv_cursormark(cap, cap->nchar == '\'', pos); | |
6636 } | |
6637 | |
6638 #ifdef FEAT_MOUSE | |
6639 /* | |
6640 * [ or ] followed by a middle mouse click: put selected text with | |
6641 * indent adjustment. Any other button just does as usual. | |
6642 */ | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
6643 else if (cap->nchar >= K_RIGHTRELEASE && cap->nchar <= K_LEFTMOUSE) |
7 | 6644 { |
6645 (void)do_mouse(cap->oap, cap->nchar, | |
6646 (cap->cmdchar == ']') ? FORWARD : BACKWARD, | |
6647 cap->count1, PUT_FIXINDENT); | |
6648 } | |
6649 #endif /* FEAT_MOUSE */ | |
6650 | |
6651 #ifdef FEAT_FOLDING | |
6652 /* | |
6653 * "[z" and "]z": move to start or end of open fold. | |
6654 */ | |
6655 else if (cap->nchar == 'z') | |
6656 { | |
6657 if (foldMoveTo(FALSE, cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
6658 cap->count1) == FAIL) | |
6659 clearopbeep(cap->oap); | |
6660 } | |
6661 #endif | |
6662 | |
6663 #ifdef FEAT_DIFF | |
6664 /* | |
6665 * "[c" and "]c": move to next or previous diff-change. | |
6666 */ | |
6667 else if (cap->nchar == 'c') | |
6668 { | |
6669 if (diff_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
6670 cap->count1) == FAIL) | |
6671 clearopbeep(cap->oap); | |
6672 } | |
6673 #endif | |
6674 | |
737 | 6675 #ifdef FEAT_SPELL |
236 | 6676 /* |
6677 * "[s", "[S", "]s" and "]S": move to next spell error. | |
6678 */ | |
6679 else if (cap->nchar == 's' || cap->nchar == 'S') | |
6680 { | |
249 | 6681 setpcmark(); |
6682 for (n = 0; n < cap->count1; ++n) | |
498 | 6683 if (spell_move_to(curwin, cap->cmdchar == ']' ? FORWARD : BACKWARD, |
6684 cap->nchar == 's' ? TRUE : FALSE, FALSE, NULL) == 0) | |
249 | 6685 { |
6686 clearopbeep(cap->oap); | |
6687 break; | |
6688 } | |
13088
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
6689 else |
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
6690 curwin->w_set_curswant = TRUE; |
819 | 6691 # ifdef FEAT_FOLDING |
6692 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
6693 foldOpenCursor(); | |
6694 # endif | |
236 | 6695 } |
6696 #endif | |
6697 | |
7 | 6698 /* Not a valid cap->nchar. */ |
6699 else | |
6700 clearopbeep(cap->oap); | |
6701 } | |
6702 | |
6703 /* | |
6704 * Handle Normal mode "%" command. | |
6705 */ | |
6706 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6707 nv_percent(cmdarg_T *cap) |
7 | 6708 { |
6709 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
|
6710 #if defined(FEAT_FOLDING) |
7 | 6711 linenr_T lnum = curwin->w_cursor.lnum; |
6712 #endif | |
6713 | |
6714 cap->oap->inclusive = TRUE; | |
6715 if (cap->count0) /* {cnt}% : goto {cnt} percentage in file */ | |
6716 { | |
6717 if (cap->count0 > 100) | |
6718 clearopbeep(cap->oap); | |
6719 else | |
6720 { | |
6721 cap->oap->motion_type = MLINE; | |
6722 setpcmark(); | |
6723 /* Round up, so CTRL-G will give same value. Watch out for a | |
6724 * large line count, the line number must not go negative! */ | |
6725 if (curbuf->b_ml.ml_line_count > 1000000) | |
6726 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) | |
6727 / 100L * cap->count0; | |
6728 else | |
6729 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count * | |
6730 cap->count0 + 99L) / 100L; | |
6731 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
6732 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
6733 beginline(BL_SOL | BL_FIX); | |
6734 } | |
6735 } | |
6736 else /* "%" : go to matching paren */ | |
6737 { | |
6738 cap->oap->motion_type = MCHAR; | |
6739 cap->oap->use_reg_one = TRUE; | |
6740 if ((pos = findmatch(cap->oap, NUL)) == NULL) | |
6741 clearopbeep(cap->oap); | |
6742 else | |
6743 { | |
6744 setpcmark(); | |
6745 curwin->w_cursor = *pos; | |
6746 curwin->w_set_curswant = TRUE; | |
6747 curwin->w_cursor.coladd = 0; | |
6748 adjust_for_sel(cap); | |
6749 } | |
6750 } | |
6751 #ifdef FEAT_FOLDING | |
6752 if (cap->oap->op_type == OP_NOP | |
6753 && lnum != curwin->w_cursor.lnum | |
6754 && (fdo_flags & FDO_PERCENT) | |
6755 && KeyTyped) | |
6756 foldOpenCursor(); | |
6757 #endif | |
6758 } | |
6759 | |
6760 /* | |
6761 * Handle "(" and ")" commands. | |
6762 * cap->arg is BACKWARD for "(" and FORWARD for ")". | |
6763 */ | |
6764 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6765 nv_brace(cmdarg_T *cap) |
7 | 6766 { |
6767 cap->oap->motion_type = MCHAR; | |
6768 cap->oap->use_reg_one = TRUE; | |
620 | 6769 /* The motion used to be inclusive for "(", but that is not what Vi does. */ |
6770 cap->oap->inclusive = FALSE; | |
7 | 6771 curwin->w_set_curswant = TRUE; |
6772 | |
6773 if (findsent(cap->arg, cap->count1) == FAIL) | |
6774 clearopbeep(cap->oap); | |
6775 else | |
6776 { | |
1505 | 6777 /* Don't leave the cursor on the NUL past end of line. */ |
6778 adjust_cursor(cap->oap); | |
7 | 6779 curwin->w_cursor.coladd = 0; |
6780 #ifdef FEAT_FOLDING | |
6781 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6782 foldOpenCursor(); | |
6783 #endif | |
6784 } | |
6785 } | |
6786 | |
6787 /* | |
6788 * "m" command: Mark a position. | |
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_mark(cmdarg_T *cap) |
7 | 6792 { |
6793 if (!checkclearop(cap->oap)) | |
6794 { | |
6795 if (setmark(cap->nchar) == FAIL) | |
6796 clearopbeep(cap->oap); | |
6797 } | |
6798 } | |
6799 | |
6800 /* | |
6801 * "{" and "}" commands. | |
6802 * cmd->arg is BACKWARD for "{" and FORWARD for "}". | |
6803 */ | |
6804 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6805 nv_findpar(cmdarg_T *cap) |
7 | 6806 { |
6807 cap->oap->motion_type = MCHAR; | |
6808 cap->oap->inclusive = FALSE; | |
6809 cap->oap->use_reg_one = TRUE; | |
6810 curwin->w_set_curswant = TRUE; | |
503 | 6811 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, FALSE)) |
7 | 6812 clearopbeep(cap->oap); |
6813 else | |
6814 { | |
6815 curwin->w_cursor.coladd = 0; | |
6816 #ifdef FEAT_FOLDING | |
6817 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6818 foldOpenCursor(); | |
6819 #endif | |
6820 } | |
6821 } | |
6822 | |
6823 /* | |
6824 * "u" command: Undo or make lower case. | |
6825 */ | |
6826 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6827 nv_undo(cmdarg_T *cap) |
7 | 6828 { |
5735 | 6829 if (cap->oap->op_type == OP_LOWER || VIsual_active) |
7 | 6830 { |
6831 /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */ | |
6832 cap->cmdchar = 'g'; | |
6833 cap->nchar = 'u'; | |
6834 nv_operator(cap); | |
6835 } | |
6836 else | |
6837 nv_kundo(cap); | |
6838 } | |
6839 | |
6840 /* | |
6841 * <Undo> command. | |
6842 */ | |
6843 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6844 nv_kundo(cmdarg_T *cap) |
7 | 6845 { |
6846 if (!checkclearopq(cap->oap)) | |
6847 { | |
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
|
6848 #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
|
6849 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
|
6850 { |
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
|
6851 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
|
6852 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
|
6853 } |
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
|
6854 #endif |
7 | 6855 u_undo((int)cap->count1); |
6856 curwin->w_set_curswant = TRUE; | |
6857 } | |
6858 } | |
6859 | |
6860 /* | |
6861 * Handle the "r" command. | |
6862 */ | |
6863 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6864 nv_replace(cmdarg_T *cap) |
7 | 6865 { |
6866 char_u *ptr; | |
6867 int had_ctrl_v; | |
6868 long n; | |
6869 | |
6870 if (checkclearop(cap->oap)) | |
6871 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
|
6872 #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
|
6873 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
|
6874 { |
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 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
|
6876 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
|
6877 } |
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 #endif |
7 | 6879 |
6880 /* get another character */ | |
6881 if (cap->nchar == Ctrl_V) | |
6882 { | |
6883 had_ctrl_v = Ctrl_V; | |
6884 cap->nchar = get_literal(); | |
6885 /* Don't redo a multibyte character with CTRL-V. */ | |
6886 if (cap->nchar > DEL) | |
6887 had_ctrl_v = NUL; | |
6888 } | |
6889 else | |
6890 had_ctrl_v = NUL; | |
6891 | |
1343 | 6892 /* Abort if the character is a special key. */ |
6893 if (IS_SPECIAL(cap->nchar)) | |
6894 { | |
6895 clearopbeep(cap->oap); | |
6896 return; | |
6897 } | |
6898 | |
7 | 6899 /* Visual mode "r" */ |
6900 if (VIsual_active) | |
6901 { | |
1797 | 6902 if (got_int) |
6903 reset_VIsual(); | |
5428 | 6904 if (had_ctrl_v) |
6905 { | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
6906 /* 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
|
6907 * 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
|
6908 if (cap->nchar == CAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
6909 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
|
6910 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
|
6911 cap->nchar = REPLACE_NL_NCHAR; |
5428 | 6912 } |
7 | 6913 nv_operator(cap); |
6914 return; | |
6915 } | |
6916 | |
6917 /* Break tabs, etc. */ | |
6918 if (virtual_active()) | |
6919 { | |
6920 if (u_save_cursor() == FAIL) | |
6921 return; | |
6922 if (gchar_cursor() == NUL) | |
6923 { | |
6924 /* Add extra space and put the cursor on the first one. */ | |
6925 coladvance_force((colnr_T)(getviscol() + cap->count1)); | |
6926 curwin->w_cursor.col -= cap->count1; | |
6927 } | |
6928 else if (gchar_cursor() == TAB) | |
6929 coladvance_force(getviscol()); | |
6930 } | |
6931 | |
1343 | 6932 /* Abort if not enough characters to replace. */ |
7 | 6933 ptr = ml_get_cursor(); |
1343 | 6934 if (STRLEN(ptr) < (unsigned)cap->count1 |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
6935 || (has_mbyte && mb_charlen(ptr) < cap->count1)) |
7 | 6936 { |
6937 clearopbeep(cap->oap); | |
6938 return; | |
6939 } | |
6940 | |
6941 /* | |
6942 * Replacing with a TAB is done by edit() when it is complicated because | |
6943 * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB. | |
6944 * Other characters are done below to avoid problems with things like | |
6945 * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC). | |
6946 */ | |
6947 if (had_ctrl_v != Ctrl_V && cap->nchar == '\t' && (curbuf->b_p_et || p_sta)) | |
6948 { | |
6949 stuffnumReadbuff(cap->count1); | |
6950 stuffcharReadbuff('R'); | |
6951 stuffcharReadbuff('\t'); | |
6952 stuffcharReadbuff(ESC); | |
6953 return; | |
6954 } | |
6955 | |
6956 /* save line for undo */ | |
6957 if (u_save_cursor() == FAIL) | |
6958 return; | |
6959 | |
6960 if (had_ctrl_v != Ctrl_V && (cap->nchar == '\r' || cap->nchar == '\n')) | |
6961 { | |
6962 /* | |
6963 * Replace character(s) by a single newline. | |
6964 * Strange vi behaviour: Only one newline is inserted. | |
6965 * Delete the characters here. | |
6966 * Insert the newline with an insert command, takes care of | |
6967 * autoindent. The insert command depends on being on the last | |
6968 * character of a line or not. | |
6969 */ | |
6970 (void)del_chars(cap->count1, FALSE); /* delete the characters */ | |
6971 stuffcharReadbuff('\r'); | |
6972 stuffcharReadbuff(ESC); | |
6973 | |
6974 /* Give 'r' to edit(), to get the redo command right. */ | |
6975 invoke_edit(cap, TRUE, 'r', FALSE); | |
6976 } | |
6977 else | |
6978 { | |
6979 prep_redo(cap->oap->regname, cap->count1, | |
6980 NUL, 'r', NUL, had_ctrl_v, cap->nchar); | |
6981 | |
6982 curbuf->b_op_start = curwin->w_cursor; | |
6983 if (has_mbyte) | |
6984 { | |
6985 int old_State = State; | |
6986 | |
6987 if (cap->ncharC1 != 0) | |
6988 AppendCharToRedobuff(cap->ncharC1); | |
6989 if (cap->ncharC2 != 0) | |
6990 AppendCharToRedobuff(cap->ncharC2); | |
6991 | |
6992 /* This is slow, but it handles replacing a single-byte with a | |
6993 * multi-byte and the other way around. Also handles adding | |
6994 * composing characters for utf-8. */ | |
6995 for (n = cap->count1; n > 0; --n) | |
6996 { | |
6997 State = REPLACE; | |
3501 | 6998 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
6999 { | |
7000 int c = ins_copychar(curwin->w_cursor.lnum | |
7001 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7002 if (c != NUL) | |
7003 ins_char(c); | |
7004 else | |
7005 /* will be decremented further down */ | |
7006 ++curwin->w_cursor.col; | |
7007 } | |
7008 else | |
7009 ins_char(cap->nchar); | |
7 | 7010 State = old_State; |
7011 if (cap->ncharC1 != 0) | |
7012 ins_char(cap->ncharC1); | |
7013 if (cap->ncharC2 != 0) | |
7014 ins_char(cap->ncharC2); | |
7015 } | |
7016 } | |
7017 else | |
7018 { | |
7019 /* | |
7020 * Replace the characters within one line. | |
7021 */ | |
7022 for (n = cap->count1; n > 0; --n) | |
7023 { | |
7024 /* | |
7025 * Get ptr again, because u_save and/or showmatch() will have | |
7026 * released the line. At the same time we let know that the | |
7027 * line will be changed. | |
7028 */ | |
7029 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); | |
3501 | 7030 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7031 { | |
7032 int c = ins_copychar(curwin->w_cursor.lnum | |
7033 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7034 if (c != NUL) | |
7035 ptr[curwin->w_cursor.col] = c; | |
7036 } | |
7037 else | |
7038 ptr[curwin->w_cursor.col] = cap->nchar; | |
7 | 7039 if (p_sm && msg_silent == 0) |
7040 showmatch(cap->nchar); | |
7041 ++curwin->w_cursor.col; | |
7042 } | |
7043 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7044 if (netbeans_active()) |
7 | 7045 { |
2210 | 7046 colnr_T start = (colnr_T)(curwin->w_cursor.col - cap->count1); |
7 | 7047 |
33 | 7048 netbeans_removed(curbuf, curwin->w_cursor.lnum, start, |
2210 | 7049 (long)cap->count1); |
7 | 7050 netbeans_inserted(curbuf, curwin->w_cursor.lnum, start, |
33 | 7051 &ptr[start], (int)cap->count1); |
7 | 7052 } |
7053 #endif | |
7054 | |
7055 /* mark the buffer as changed and prepare for displaying */ | |
7056 changed_bytes(curwin->w_cursor.lnum, | |
7057 (colnr_T)(curwin->w_cursor.col - cap->count1)); | |
7058 } | |
7059 --curwin->w_cursor.col; /* cursor on the last replaced char */ | |
7060 /* if the character on the left of the current cursor is a multi-byte | |
7061 * character, move two characters left */ | |
7062 if (has_mbyte) | |
7063 mb_adjust_cursor(); | |
7064 curbuf->b_op_end = curwin->w_cursor; | |
7065 curwin->w_set_curswant = TRUE; | |
7066 set_last_insert(cap->nchar); | |
7067 } | |
7068 } | |
7069 | |
7070 /* | |
7071 * 'o': Exchange start and end of Visual area. | |
7072 * 'O': same, but in block mode exchange left and right corners. | |
7073 */ | |
7074 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7075 v_swap_corners(int cmdchar) |
7 | 7076 { |
7077 pos_T old_cursor; | |
7078 colnr_T left, right; | |
7079 | |
7080 if (cmdchar == 'O' && VIsual_mode == Ctrl_V) | |
7081 { | |
7082 old_cursor = curwin->w_cursor; | |
7083 getvcols(curwin, &old_cursor, &VIsual, &left, &right); | |
7084 curwin->w_cursor.lnum = VIsual.lnum; | |
7085 coladvance(left); | |
7086 VIsual = curwin->w_cursor; | |
7087 | |
7088 curwin->w_cursor.lnum = old_cursor.lnum; | |
7089 curwin->w_curswant = right; | |
7090 /* 'selection "exclusive" and cursor at right-bottom corner: move it | |
7091 * right one column */ | |
7092 if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') | |
7093 ++curwin->w_curswant; | |
7094 coladvance(curwin->w_curswant); | |
7095 if (curwin->w_cursor.col == old_cursor.col | |
7096 && (!virtual_active() | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
7097 || curwin->w_cursor.coladd == old_cursor.coladd)) |
7 | 7098 { |
7099 curwin->w_cursor.lnum = VIsual.lnum; | |
7100 if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') | |
7101 ++right; | |
7102 coladvance(right); | |
7103 VIsual = curwin->w_cursor; | |
7104 | |
7105 curwin->w_cursor.lnum = old_cursor.lnum; | |
7106 coladvance(left); | |
7107 curwin->w_curswant = left; | |
7108 } | |
7109 } | |
7110 else | |
7111 { | |
7112 old_cursor = curwin->w_cursor; | |
7113 curwin->w_cursor = VIsual; | |
7114 VIsual = old_cursor; | |
7115 curwin->w_set_curswant = TRUE; | |
7116 } | |
7117 } | |
7118 | |
7119 /* | |
7120 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE). | |
7121 */ | |
7122 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7123 nv_Replace(cmdarg_T *cap) |
7 | 7124 { |
7125 if (VIsual_active) /* "R" is replace lines */ | |
7126 { | |
7127 cap->cmdchar = 'c'; | |
7128 cap->nchar = NUL; | |
4213 | 7129 VIsual_mode_orig = VIsual_mode; /* remember original area for gv */ |
7 | 7130 VIsual_mode = 'V'; |
7131 nv_operator(cap); | |
7132 } | |
5735 | 7133 else if (!checkclearopq(cap->oap)) |
7 | 7134 { |
7135 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
|
7136 emsg(_(e_modifiable)); |
7 | 7137 else |
7138 { | |
7139 if (virtual_active()) | |
7140 coladvance(getviscol()); | |
7141 invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE); | |
7142 } | |
7143 } | |
7144 } | |
7145 | |
7146 /* | |
7147 * "gr". | |
7148 */ | |
7149 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7150 nv_vreplace(cmdarg_T *cap) |
7 | 7151 { |
7152 if (VIsual_active) | |
7153 { | |
7154 cap->cmdchar = 'r'; | |
7155 cap->nchar = cap->extra_char; | |
7156 nv_replace(cap); /* Do same as "r" in Visual mode for now */ | |
7157 } | |
5735 | 7158 else if (!checkclearopq(cap->oap)) |
7 | 7159 { |
7160 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
|
7161 emsg(_(e_modifiable)); |
7 | 7162 else |
7163 { | |
7164 if (cap->extra_char == Ctrl_V) /* get another character */ | |
7165 cap->extra_char = get_literal(); | |
7166 stuffcharReadbuff(cap->extra_char); | |
7167 stuffcharReadbuff(ESC); | |
7168 if (virtual_active()) | |
7169 coladvance(getviscol()); | |
7170 invoke_edit(cap, TRUE, 'v', FALSE); | |
7171 } | |
7172 } | |
7173 } | |
7174 | |
7175 /* | |
7176 * Swap case for "~" command, when it does not work like an operator. | |
7177 */ | |
7178 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7179 n_swapchar(cmdarg_T *cap) |
7 | 7180 { |
7181 long n; | |
7182 pos_T startpos; | |
7183 int did_change = 0; | |
7184 #ifdef FEAT_NETBEANS_INTG | |
7185 pos_T pos; | |
7186 char_u *ptr; | |
7187 int count; | |
7188 #endif | |
7189 | |
7190 if (checkclearopq(cap->oap)) | |
7191 return; | |
7192 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7193 if (LINEEMPTY(curwin->w_cursor.lnum) && vim_strchr(p_ww, '~') == NULL) |
7 | 7194 { |
7195 clearopbeep(cap->oap); | |
7196 return; | |
7197 } | |
7198 | |
7199 prep_redo_cmd(cap); | |
7200 | |
7201 if (u_save_cursor() == FAIL) | |
7202 return; | |
7203 | |
7204 startpos = curwin->w_cursor; | |
7205 #ifdef FEAT_NETBEANS_INTG | |
7206 pos = startpos; | |
7207 #endif | |
7208 for (n = cap->count1; n > 0; --n) | |
7209 { | |
7210 did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor); | |
7211 inc_cursor(); | |
7212 if (gchar_cursor() == NUL) | |
7213 { | |
7214 if (vim_strchr(p_ww, '~') != NULL | |
7215 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
7216 { | |
7217 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7218 if (netbeans_active()) |
7 | 7219 { |
7220 if (did_change) | |
7221 { | |
7222 ptr = ml_get(pos.lnum); | |
835 | 7223 count = (int)STRLEN(ptr) - pos.col; |
33 | 7224 netbeans_removed(curbuf, pos.lnum, pos.col, |
7225 (long)count); | |
7 | 7226 netbeans_inserted(curbuf, pos.lnum, pos.col, |
33 | 7227 &ptr[pos.col], count); |
7 | 7228 } |
7229 pos.col = 0; | |
7230 pos.lnum++; | |
7231 } | |
7232 #endif | |
7233 ++curwin->w_cursor.lnum; | |
7234 curwin->w_cursor.col = 0; | |
7235 if (n > 1) | |
7236 { | |
7237 if (u_savesub(curwin->w_cursor.lnum) == FAIL) | |
7238 break; | |
7239 u_clearline(); | |
7240 } | |
7241 } | |
7242 else | |
7243 break; | |
7244 } | |
7245 } | |
7246 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7247 if (did_change && netbeans_active()) |
7 | 7248 { |
7249 ptr = ml_get(pos.lnum); | |
7250 count = curwin->w_cursor.col - pos.col; | |
33 | 7251 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7252 netbeans_inserted(curbuf, pos.lnum, pos.col, &ptr[pos.col], count); | |
7 | 7253 } |
7254 #endif | |
7255 | |
7256 | |
7257 check_cursor(); | |
7258 curwin->w_set_curswant = TRUE; | |
7259 if (did_change) | |
7260 { | |
7261 changed_lines(startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1, | |
7262 0L); | |
7263 curbuf->b_op_start = startpos; | |
7264 curbuf->b_op_end = curwin->w_cursor; | |
7265 if (curbuf->b_op_end.col > 0) | |
7266 --curbuf->b_op_end.col; | |
7267 } | |
7268 } | |
7269 | |
7270 /* | |
7271 * Move cursor to mark. | |
7272 */ | |
7273 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7274 nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos) |
7 | 7275 { |
7276 if (check_mark(pos) == FAIL) | |
7277 clearop(cap->oap); | |
7278 else | |
7279 { | |
7280 if (cap->cmdchar == '\'' | |
7281 || cap->cmdchar == '`' | |
7282 || cap->cmdchar == '[' | |
7283 || cap->cmdchar == ']') | |
7284 setpcmark(); | |
7285 curwin->w_cursor = *pos; | |
7286 if (flag) | |
7287 beginline(BL_WHITE | BL_FIX); | |
7288 else | |
7289 check_cursor(); | |
7290 } | |
7291 cap->oap->motion_type = flag ? MLINE : MCHAR; | |
7292 if (cap->cmdchar == '`') | |
7293 cap->oap->use_reg_one = TRUE; | |
7294 cap->oap->inclusive = FALSE; /* ignored if not MCHAR */ | |
7295 curwin->w_set_curswant = TRUE; | |
7296 } | |
7297 | |
7298 /* | |
7299 * Handle commands that are operators in Visual mode. | |
7300 */ | |
7301 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7302 v_visop(cmdarg_T *cap) |
7 | 7303 { |
7304 static char_u trans[] = "YyDdCcxdXdAAIIrr"; | |
7305 | |
7306 /* Uppercase means linewise, except in block mode, then "D" deletes till | |
4352 | 7307 * the end of the line, and "C" replaces till EOL */ |
7 | 7308 if (isupper(cap->cmdchar)) |
7309 { | |
7310 if (VIsual_mode != Ctrl_V) | |
4213 | 7311 { |
7312 VIsual_mode_orig = VIsual_mode; | |
7 | 7313 VIsual_mode = 'V'; |
4213 | 7314 } |
7 | 7315 else if (cap->cmdchar == 'C' || cap->cmdchar == 'D') |
7316 curwin->w_curswant = MAXCOL; | |
7317 } | |
7318 cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1); | |
7319 nv_operator(cap); | |
7320 } | |
7321 | |
7322 /* | |
7323 * "s" and "S" commands. | |
7324 */ | |
7325 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7326 nv_subst(cmdarg_T *cap) |
7 | 7327 { |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7328 #ifdef FEAT_TERMINAL |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7329 /* 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
|
7330 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
|
7331 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7332 #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
|
7333 #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
|
7334 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
|
7335 { |
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
|
7336 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
|
7337 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
|
7338 } |
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
|
7339 #endif |
7 | 7340 if (VIsual_active) /* "vs" and "vS" are the same as "vc" */ |
7341 { | |
7342 if (cap->cmdchar == 'S') | |
4213 | 7343 { |
7344 VIsual_mode_orig = VIsual_mode; | |
7 | 7345 VIsual_mode = 'V'; |
4213 | 7346 } |
7 | 7347 cap->cmdchar = 'c'; |
7348 nv_operator(cap); | |
7349 } | |
7350 else | |
7351 nv_optrans(cap); | |
7352 } | |
7353 | |
7354 /* | |
7355 * Abbreviated commands. | |
7356 */ | |
7357 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7358 nv_abbrev(cmdarg_T *cap) |
7 | 7359 { |
7360 if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) | |
7361 cap->cmdchar = 'x'; /* DEL key behaves like 'x' */ | |
7362 | |
7363 /* in Visual mode these commands are operators */ | |
7364 if (VIsual_active) | |
7365 v_visop(cap); | |
7366 else | |
7367 nv_optrans(cap); | |
7368 } | |
7369 | |
7370 /* | |
7371 * Translate a command into another command. | |
7372 */ | |
7373 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7374 nv_optrans(cmdarg_T *cap) |
7 | 7375 { |
7376 static char_u *(ar[8]) = {(char_u *)"dl", (char_u *)"dh", | |
7377 (char_u *)"d$", (char_u *)"c$", | |
7378 (char_u *)"cl", (char_u *)"cc", | |
7379 (char_u *)"yy", (char_u *)":s\r"}; | |
7380 static char_u *str = (char_u *)"xXDCsSY&"; | |
7381 | |
7382 if (!checkclearopq(cap->oap)) | |
7383 { | |
18114
90b0af9ba4ff
patch 8.1.2052: using "x" before a closed fold may delete that fold
Bram Moolenaar <Bram@vim.org>
parents:
18045
diff
changeset
|
7384 // In Vi "2D" doesn't delete the next line. Can't translate it |
90b0af9ba4ff
patch 8.1.2052: using "x" before a closed fold may delete that fold
Bram Moolenaar <Bram@vim.org>
parents:
18045
diff
changeset
|
7385 // either, because "2." should also not use the count. |
164 | 7386 if (cap->cmdchar == 'D' && vim_strchr(p_cpo, CPO_HASH) != NULL) |
7387 { | |
7388 cap->oap->start = curwin->w_cursor; | |
7389 cap->oap->op_type = OP_DELETE; | |
1490 | 7390 #ifdef FEAT_EVAL |
7391 set_op_var(OP_DELETE); | |
7392 #endif | |
164 | 7393 cap->count1 = 1; |
7394 nv_dollar(cap); | |
7395 finish_op = TRUE; | |
7396 ResetRedobuff(); | |
7397 AppendCharToRedobuff('D'); | |
7398 } | |
7399 else | |
7400 { | |
7401 if (cap->count0) | |
7402 stuffnumReadbuff(cap->count0); | |
18128
aeabc666a119
patch 8.1.2059: fix for "x" deleting a fold has side effects
Bram Moolenaar <Bram@vim.org>
parents:
18114
diff
changeset
|
7403 stuffReadbuff(ar[(int)(vim_strchr(str, cap->cmdchar) - str)]); |
164 | 7404 } |
7 | 7405 } |
7406 cap->opcount = 0; | |
7407 } | |
7408 | |
7409 /* | |
7410 * "'" and "`" commands. Also for "g'" and "g`". | |
7411 * cap->arg is TRUE for "'" and "g'". | |
7412 */ | |
7413 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7414 nv_gomark(cmdarg_T *cap) |
7 | 7415 { |
7416 pos_T *pos; | |
7417 int c; | |
7418 #ifdef FEAT_FOLDING | |
4017 | 7419 pos_T old_cursor = curwin->w_cursor; |
7 | 7420 int old_KeyTyped = KeyTyped; /* getting file may reset it */ |
7421 #endif | |
7422 | |
7423 if (cap->cmdchar == 'g') | |
7424 c = cap->extra_char; | |
7425 else | |
7426 c = cap->nchar; | |
7427 pos = getmark(c, (cap->oap->op_type == OP_NOP)); | |
7428 if (pos == (pos_T *)-1) /* jumped to other file */ | |
7429 { | |
7430 if (cap->arg) | |
7431 { | |
7432 check_cursor_lnum(); | |
7433 beginline(BL_WHITE | BL_FIX); | |
7434 } | |
7435 else | |
7436 check_cursor(); | |
7437 } | |
7438 else | |
7439 nv_cursormark(cap, cap->arg, pos); | |
7440 | |
7441 /* May need to clear the coladd that a mark includes. */ | |
7442 if (!virtual_active()) | |
7443 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
|
7444 check_cursor_col(); |
7 | 7445 #ifdef FEAT_FOLDING |
7446 if (cap->oap->op_type == OP_NOP | |
4057 | 7447 && pos != NULL |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7448 && (pos == (pos_T *)-1 || !EQUAL_POS(old_cursor, *pos)) |
7 | 7449 && (fdo_flags & FDO_MARK) |
7450 && old_KeyTyped) | |
7451 foldOpenCursor(); | |
7452 #endif | |
7453 } | |
7454 | |
7455 /* | |
7456 * Handle CTRL-O, CTRL-I, "g;" and "g," commands. | |
7457 */ | |
7458 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7459 nv_pcmark(cmdarg_T *cap) |
7 | 7460 { |
7461 #ifdef FEAT_JUMPLIST | |
7462 pos_T *pos; | |
7463 # ifdef FEAT_FOLDING | |
7464 linenr_T lnum = curwin->w_cursor.lnum; | |
7465 int old_KeyTyped = KeyTyped; /* getting file may reset it */ | |
7466 # endif | |
7467 | |
7468 if (!checkclearopq(cap->oap)) | |
7469 { | |
7470 if (cap->cmdchar == 'g') | |
7471 pos = movechangelist((int)cap->count1); | |
7472 else | |
7473 pos = movemark((int)cap->count1); | |
7474 if (pos == (pos_T *)-1) /* jump to other file */ | |
7475 { | |
7476 curwin->w_set_curswant = TRUE; | |
7477 check_cursor(); | |
7478 } | |
7479 else if (pos != NULL) /* can jump */ | |
7480 nv_cursormark(cap, FALSE, pos); | |
7481 else if (cap->cmdchar == 'g') | |
7482 { | |
7483 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
|
7484 emsg(_("E664: changelist is empty")); |
7 | 7485 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
|
7486 emsg(_("E662: At start of changelist")); |
7 | 7487 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
7488 emsg(_("E663: At end of changelist")); |
7 | 7489 } |
7490 else | |
7491 clearopbeep(cap->oap); | |
7492 # ifdef FEAT_FOLDING | |
7493 if (cap->oap->op_type == OP_NOP | |
7494 && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum) | |
7495 && (fdo_flags & FDO_MARK) | |
7496 && old_KeyTyped) | |
7497 foldOpenCursor(); | |
7498 # endif | |
7499 } | |
7500 #else | |
7501 clearopbeep(cap->oap); | |
7502 #endif | |
7503 } | |
7504 | |
7505 /* | |
7506 * Handle '"' command. | |
7507 */ | |
7508 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7509 nv_regname(cmdarg_T *cap) |
7 | 7510 { |
7511 if (checkclearop(cap->oap)) | |
7512 return; | |
7513 #ifdef FEAT_EVAL | |
7514 if (cap->nchar == '=') | |
7515 cap->nchar = get_expr_register(); | |
7516 #endif | |
7517 if (cap->nchar != NUL && valid_yank_reg(cap->nchar, FALSE)) | |
7518 { | |
7519 cap->oap->regname = cap->nchar; | |
7520 cap->opcount = cap->count0; /* remember count before '"' */ | |
7521 #ifdef FEAT_EVAL | |
7522 set_reg_var(cap->oap->regname); | |
7523 #endif | |
7524 } | |
7525 else | |
7526 clearopbeep(cap->oap); | |
7527 } | |
7528 | |
7529 /* | |
7530 * Handle "v", "V" and "CTRL-V" commands. | |
7531 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg | |
7532 * is TRUE. | |
167 | 7533 * Handle CTRL-Q just like CTRL-V. |
7 | 7534 */ |
7535 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7536 nv_visual(cmdarg_T *cap) |
7 | 7537 { |
167 | 7538 if (cap->cmdchar == Ctrl_Q) |
7539 cap->cmdchar = Ctrl_V; | |
7540 | |
7 | 7541 /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it |
7542 * characterwise, linewise, or blockwise. */ | |
7543 if (cap->oap->op_type != OP_NOP) | |
7544 { | |
15279
54457fc4af0b
patch 8.1.0648: custom operators can't act upon a forced motion
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
7545 motion_force = cap->oap->motion_force = cap->cmdchar; |
7 | 7546 finish_op = FALSE; /* operator doesn't finish now but later */ |
7547 return; | |
7548 } | |
7549 | |
7550 VIsual_select = cap->arg; | |
7551 if (VIsual_active) /* change Visual mode */ | |
7552 { | |
7553 if (VIsual_mode == cap->cmdchar) /* stop visual mode */ | |
7554 end_visual_mode(); | |
7555 else /* toggle char/block mode */ | |
7556 { /* or char/line mode */ | |
7557 VIsual_mode = cap->cmdchar; | |
7558 showmode(); | |
7559 } | |
7560 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
7561 } | |
7562 else /* start Visual mode */ | |
7563 { | |
7564 check_visual_highlight(); | |
3537 | 7565 if (cap->count0 > 0 && resel_VIsual_mode != NUL) |
7566 { | |
7567 /* use previously selected part */ | |
7 | 7568 VIsual = curwin->w_cursor; |
7569 | |
7570 VIsual_active = TRUE; | |
7571 VIsual_reselect = TRUE; | |
7572 if (!cap->arg) | |
7573 /* start Select mode when 'selectmode' contains "cmd" */ | |
7574 may_start_select('c'); | |
7575 #ifdef FEAT_MOUSE | |
7576 setmouse(); | |
7577 #endif | |
641 | 7578 if (p_smd && msg_silent == 0) |
7 | 7579 redraw_cmdline = TRUE; /* show visual mode later */ |
7580 /* | |
7581 * For V and ^V, we multiply the number of lines even if there | |
7582 * was only one -- webb | |
7583 */ | |
7584 if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) | |
7585 { | |
7586 curwin->w_cursor.lnum += | |
7587 resel_VIsual_line_count * cap->count0 - 1; | |
7588 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
7589 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7590 } | |
7591 VIsual_mode = resel_VIsual_mode; | |
7592 if (VIsual_mode == 'v') | |
7593 { | |
7594 if (resel_VIsual_line_count <= 1) | |
3125 | 7595 { |
7596 validate_virtcol(); | |
7597 curwin->w_curswant = curwin->w_virtcol | |
7598 + resel_VIsual_vcol * cap->count0 - 1; | |
7599 } | |
7 | 7600 else |
3125 | 7601 curwin->w_curswant = resel_VIsual_vcol; |
7602 coladvance(curwin->w_curswant); | |
7 | 7603 } |
3125 | 7604 if (resel_VIsual_vcol == MAXCOL) |
7 | 7605 { |
7606 curwin->w_curswant = MAXCOL; | |
7607 coladvance((colnr_T)MAXCOL); | |
7608 } | |
7609 else if (VIsual_mode == Ctrl_V) | |
7610 { | |
7611 validate_virtcol(); | |
7612 curwin->w_curswant = curwin->w_virtcol | |
3125 | 7613 + resel_VIsual_vcol * cap->count0 - 1; |
7 | 7614 coladvance(curwin->w_curswant); |
7615 } | |
7616 else | |
7617 curwin->w_set_curswant = TRUE; | |
7618 redraw_curbuf_later(INVERTED); /* show the inversion */ | |
7619 } | |
7620 else | |
7621 { | |
7622 if (!cap->arg) | |
7623 /* start Select mode when 'selectmode' contains "cmd" */ | |
7624 may_start_select('c'); | |
7625 n_start_visual_mode(cap->cmdchar); | |
3537 | 7626 if (VIsual_mode != 'V' && *p_sel == 'e') |
7627 ++cap->count1; /* include one more char */ | |
7628 if (cap->count0 > 0 && --cap->count1 > 0) | |
7629 { | |
7630 /* With a count select that many characters or lines. */ | |
7631 if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) | |
7632 nv_right(cap); | |
7633 else if (VIsual_mode == 'V') | |
7634 nv_down(cap); | |
7635 } | |
7 | 7636 } |
7637 } | |
7638 } | |
7639 | |
7640 /* | |
7641 * Start selection for Shift-movement keys. | |
7642 */ | |
7643 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7644 start_selection(void) |
7 | 7645 { |
7646 /* if 'selectmode' contains "key", start Select mode */ | |
7647 may_start_select('k'); | |
7648 n_start_visual_mode('v'); | |
7649 } | |
7650 | |
7651 /* | |
7652 * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu. | |
7653 */ | |
7654 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7655 may_start_select(int c) |
7 | 7656 { |
7657 VIsual_select = (stuff_empty() && typebuf_typed() | |
7658 && (vim_strchr(p_slm, c) != NULL)); | |
7659 } | |
7660 | |
7661 /* | |
7662 * Start Visual mode "c". | |
7663 * Should set VIsual_select before calling this. | |
7664 */ | |
7665 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7666 n_start_visual_mode(int c) |
7 | 7667 { |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7668 #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
|
7669 /* Check for redraw before changing the state. */ |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13772
diff
changeset
|
7670 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
|
7671 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7672 |
7 | 7673 VIsual_mode = c; |
7674 VIsual_active = TRUE; | |
7675 VIsual_reselect = TRUE; | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
7676 |
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
7677 // 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
|
7678 // virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting. |
7 | 7679 if (c == Ctrl_V && (ve_flags & VE_BLOCK) && gchar_cursor() == TAB) |
3742 | 7680 { |
7681 validate_virtcol(); | |
7 | 7682 coladvance(curwin->w_virtcol); |
3742 | 7683 } |
7 | 7684 VIsual = curwin->w_cursor; |
7685 | |
7686 #ifdef FEAT_FOLDING | |
7687 foldAdjustVisual(); | |
7688 #endif | |
7689 | |
7690 #ifdef FEAT_MOUSE | |
7691 setmouse(); | |
7692 #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
|
7693 #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
|
7694 /* Check for redraw after changing the state. */ |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13772
diff
changeset
|
7695 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
|
7696 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7697 |
641 | 7698 if (p_smd && msg_silent == 0) |
7 | 7699 redraw_cmdline = TRUE; /* show visual mode later */ |
7700 #ifdef FEAT_CLIPBOARD | |
7701 /* Make sure the clipboard gets updated. Needed because start and | |
7702 * end may still be the same, and the selection needs to be owned */ | |
7703 clip_star.vmode = NUL; | |
7704 #endif | |
7705 | |
7706 /* Only need to redraw this line, unless still need to redraw an old | |
7707 * Visual area (when 'lazyredraw' is set). */ | |
7708 if (curwin->w_redr_type < INVERTED) | |
7709 { | |
7710 curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
7711 curwin->w_old_visual_lnum = curwin->w_cursor.lnum; | |
7712 } | |
7713 } | |
7714 | |
7715 | |
7716 /* | |
7717 * CTRL-W: Window commands | |
7718 */ | |
7719 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7720 nv_window(cmdarg_T *cap) |
7 | 7721 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7722 if (cap->nchar == ':') |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7723 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7724 /* "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
|
7725 cap->cmdchar = ':'; |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7726 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
|
7727 nv_colon(cap); |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7728 } |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7729 else if (!checkclearop(cap->oap)) |
7 | 7730 do_window(cap->nchar, cap->count0, NUL); /* everything is in window.c */ |
7731 } | |
7732 | |
7733 /* | |
7734 * CTRL-Z: Suspend | |
7735 */ | |
7736 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7737 nv_suspend(cmdarg_T *cap) |
7 | 7738 { |
7739 clearop(cap->oap); | |
7740 if (VIsual_active) | |
7741 end_visual_mode(); /* stop Visual mode */ | |
7742 do_cmdline_cmd((char_u *)"st"); | |
7743 } | |
7744 | |
7745 /* | |
7746 * Commands starting with "g". | |
7747 */ | |
7748 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7749 nv_g_cmd(cmdarg_T *cap) |
7 | 7750 { |
7751 oparg_T *oap = cap->oap; | |
7752 pos_T tpos; | |
7753 int i; | |
7754 int flag = FALSE; | |
7755 | |
7756 switch (cap->nchar) | |
7757 { | |
6868 | 7758 case Ctrl_A: |
7759 case Ctrl_X: | |
7 | 7760 #ifdef MEM_PROFILE |
7761 /* | |
7762 * "g^A": dump log of used memory. | |
7763 */ | |
6868 | 7764 if (!VIsual_active && cap->nchar == Ctrl_A) |
7765 vim_mem_profile_dump(); | |
7766 else | |
7767 #endif | |
7768 /* | |
7769 * "g^A/g^X": sequentially increment visually selected region | |
7770 */ | |
7771 if (VIsual_active) | |
7772 { | |
7773 cap->arg = TRUE; | |
7774 cap->cmdchar = cap->nchar; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
7775 cap->nchar = NUL; |
6868 | 7776 nv_addsub(cap); |
7777 } | |
7778 else | |
7779 clearopbeep(oap); | |
7 | 7780 break; |
7781 | |
7782 /* | |
7783 * "gR": Enter virtual replace mode. | |
7784 */ | |
7785 case 'R': | |
7786 cap->arg = TRUE; | |
7787 nv_Replace(cap); | |
7788 break; | |
7789 | |
7790 case 'r': | |
7791 nv_vreplace(cap); | |
7792 break; | |
7793 | |
7794 case '&': | |
7795 do_cmdline_cmd((char_u *)"%s//~/&"); | |
7796 break; | |
7797 | |
7798 /* | |
7799 * "gv": Reselect the previous Visual area. If Visual already active, | |
7800 * exchange previous and current Visual area. | |
7801 */ | |
7802 case 'v': | |
7803 if (checkclearop(oap)) | |
7804 break; | |
7805 | |
690 | 7806 if ( curbuf->b_visual.vi_start.lnum == 0 |
7807 || curbuf->b_visual.vi_start.lnum > curbuf->b_ml.ml_line_count | |
7808 || curbuf->b_visual.vi_end.lnum == 0) | |
7 | 7809 beep_flush(); |
7810 else | |
7811 { | |
7812 /* set w_cursor to the start of the Visual area, tpos to the end */ | |
7813 if (VIsual_active) | |
7814 { | |
7815 i = VIsual_mode; | |
690 | 7816 VIsual_mode = curbuf->b_visual.vi_mode; |
7817 curbuf->b_visual.vi_mode = i; | |
7 | 7818 # ifdef FEAT_EVAL |
7819 curbuf->b_visual_mode_eval = i; | |
7820 # endif | |
7821 i = curwin->w_curswant; | |
690 | 7822 curwin->w_curswant = curbuf->b_visual.vi_curswant; |
7823 curbuf->b_visual.vi_curswant = i; | |
7824 | |
7825 tpos = curbuf->b_visual.vi_end; | |
7826 curbuf->b_visual.vi_end = curwin->w_cursor; | |
7827 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7828 curbuf->b_visual.vi_start = VIsual; | |
7 | 7829 } |
7830 else | |
7831 { | |
690 | 7832 VIsual_mode = curbuf->b_visual.vi_mode; |
7833 curwin->w_curswant = curbuf->b_visual.vi_curswant; | |
7834 tpos = curbuf->b_visual.vi_end; | |
7835 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7 | 7836 } |
7837 | |
7838 VIsual_active = TRUE; | |
7839 VIsual_reselect = TRUE; | |
7840 | |
7841 /* Set Visual to the start and w_cursor to the end of the Visual | |
7842 * area. Make sure they are on an existing character. */ | |
7843 check_cursor(); | |
7844 VIsual = curwin->w_cursor; | |
7845 curwin->w_cursor = tpos; | |
7846 check_cursor(); | |
7847 update_topline(); | |
7848 /* | |
7849 * When called from normal "g" command: start Select mode when | |
7850 * 'selectmode' contains "cmd". When called for K_SELECT, always | |
7851 * start Select mode. | |
7852 */ | |
7853 if (cap->arg) | |
7854 VIsual_select = TRUE; | |
7855 else | |
7856 may_start_select('c'); | |
7857 #ifdef FEAT_MOUSE | |
7858 setmouse(); | |
7859 #endif | |
7860 #ifdef FEAT_CLIPBOARD | |
7861 /* Make sure the clipboard gets updated. Needed because start and | |
7862 * end are still the same, and the selection needs to be owned */ | |
7863 clip_star.vmode = NUL; | |
7864 #endif | |
7865 redraw_curbuf_later(INVERTED); | |
7866 showmode(); | |
7867 } | |
7868 break; | |
7869 /* | |
7870 * "gV": Don't reselect the previous Visual area after a Select mode | |
7871 * mapping of menu. | |
7872 */ | |
7873 case 'V': | |
7874 VIsual_reselect = FALSE; | |
7875 break; | |
7876 | |
7877 /* | |
7878 * "gh": start Select mode. | |
7879 * "gH": start Select line mode. | |
7880 * "g^H": start Select block mode. | |
7881 */ | |
7882 case K_BS: | |
7883 cap->nchar = Ctrl_H; | |
7884 /* FALLTHROUGH */ | |
7885 case 'h': | |
7886 case 'H': | |
7887 case Ctrl_H: | |
7888 # ifdef EBCDIC | |
7889 /* EBCDIC: 'v'-'h' != '^v'-'^h' */ | |
7890 if (cap->nchar == Ctrl_H) | |
7891 cap->cmdchar = Ctrl_V; | |
7892 else | |
7893 # endif | |
7894 cap->cmdchar = cap->nchar + ('v' - 'h'); | |
7895 cap->arg = TRUE; | |
7896 nv_visual(cap); | |
7897 break; | |
3701 | 7898 |
7899 /* "gn", "gN" visually select next/previous search match | |
7900 * "gn" selects next match | |
7901 * "gN" selects previous match | |
7902 */ | |
7903 case 'N': | |
7904 case 'n': | |
7905 if (!current_search(cap->count1, cap->nchar == 'n')) | |
3896 | 7906 clearopbeep(oap); |
3701 | 7907 break; |
7 | 7908 |
7909 /* | |
7910 * "gj" and "gk" two new funny movement keys -- up and down | |
7911 * movement based on *screen* line rather than *file* line. | |
7912 */ | |
7913 case 'j': | |
7914 case K_DOWN: | |
7915 /* with 'nowrap' it works just like the normal "j" command; also when | |
7916 * in a closed fold */ | |
7917 if (!curwin->w_p_wrap | |
7918 #ifdef FEAT_FOLDING | |
7919 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
7920 #endif | |
7921 ) | |
7922 { | |
7923 oap->motion_type = MLINE; | |
7924 i = cursor_down(cap->count1, oap->op_type == OP_NOP); | |
7925 } | |
7926 else | |
7927 i = nv_screengo(oap, FORWARD, cap->count1); | |
7928 if (i == FAIL) | |
7929 clearopbeep(oap); | |
7930 break; | |
7931 | |
7932 case 'k': | |
7933 case K_UP: | |
7934 /* with 'nowrap' it works just like the normal "k" command; also when | |
7935 * in a closed fold */ | |
7936 if (!curwin->w_p_wrap | |
7937 #ifdef FEAT_FOLDING | |
7938 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
7939 #endif | |
7940 ) | |
7941 { | |
7942 oap->motion_type = MLINE; | |
7943 i = cursor_up(cap->count1, oap->op_type == OP_NOP); | |
7944 } | |
7945 else | |
7946 i = nv_screengo(oap, BACKWARD, cap->count1); | |
7947 if (i == FAIL) | |
7948 clearopbeep(oap); | |
7949 break; | |
7950 | |
7951 /* | |
7952 * "gJ": join two lines without inserting a space. | |
7953 */ | |
7954 case 'J': | |
7955 nv_join(cap); | |
7956 break; | |
7957 | |
7958 /* | |
7959 * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines. | |
7960 * "gm": middle of "g0" and "g$". | |
7961 */ | |
7962 case '^': | |
7963 flag = TRUE; | |
7964 /* FALLTHROUGH */ | |
7965 | |
7966 case '0': | |
7967 case 'm': | |
7968 case K_HOME: | |
7969 case K_KHOME: | |
7970 oap->motion_type = MCHAR; | |
7971 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
|
7972 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 7973 { |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
7974 int width1 = curwin->w_width - curwin_col_off(); |
7 | 7975 int width2 = width1 + curwin_col_off2(); |
7976 | |
7977 validate_virtcol(); | |
7978 i = 0; | |
7979 if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0) | |
7980 i = (curwin->w_virtcol - width1) / width2 * width2 + width1; | |
7981 } | |
7982 else | |
7983 i = curwin->w_leftcol; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2139
diff
changeset
|
7984 /* 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
|
7985 * '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
|
7986 * to the left. */ |
7 | 7987 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
|
7988 i += (curwin->w_width - curwin_col_off() |
7 | 7989 + ((curwin->w_p_wrap && i > 0) |
7990 ? curwin_col_off2() : 0)) / 2; | |
7991 coladvance((colnr_T)i); | |
7992 if (flag) | |
7993 { | |
7994 do | |
7995 i = gchar_cursor(); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
7996 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
|
7997 curwin->w_valid &= ~VALID_WCOL; |
7 | 7998 } |
7999 curwin->w_set_curswant = TRUE; | |
8000 break; | |
8001 | |
8002 case '_': | |
8003 /* "g_": to the last non-blank character in the line or <count> lines | |
8004 * downward. */ | |
8005 cap->oap->motion_type = MCHAR; | |
8006 cap->oap->inclusive = TRUE; | |
8007 curwin->w_curswant = MAXCOL; | |
8008 if (cursor_down((long)(cap->count1 - 1), | |
8009 cap->oap->op_type == OP_NOP) == FAIL) | |
8010 clearopbeep(cap->oap); | |
8011 else | |
8012 { | |
8013 char_u *ptr = ml_get_curline(); | |
8014 | |
8015 /* In Visual mode we may end up after the line. */ | |
8016 if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) | |
8017 --curwin->w_cursor.col; | |
8018 | |
8019 /* Decrease the cursor column until it's on a non-blank. */ | |
8020 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
|
8021 && VIM_ISWHITE(ptr[curwin->w_cursor.col])) |
7 | 8022 --curwin->w_cursor.col; |
8023 curwin->w_set_curswant = TRUE; | |
2040
70c67b1bb1f1
updated for version 7.2.329
Bram Moolenaar <bram@zimbu.org>
parents:
2024
diff
changeset
|
8024 adjust_for_sel(cap); |
7 | 8025 } |
8026 break; | |
8027 | |
8028 case '$': | |
8029 case K_END: | |
8030 case K_KEND: | |
8031 { | |
8032 int col_off = curwin_col_off(); | |
8033 | |
8034 oap->motion_type = MCHAR; | |
8035 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
|
8036 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 8037 { |
8038 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
8039 if (cap->count1 == 1) | |
8040 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8041 int width1 = curwin->w_width - col_off; |
7 | 8042 int width2 = width1 + curwin_col_off2(); |
8043 | |
8044 validate_virtcol(); | |
8045 i = width1 - 1; | |
8046 if (curwin->w_virtcol >= (colnr_T)width1) | |
8047 i += ((curwin->w_virtcol - width1) / width2 + 1) | |
8048 * width2; | |
8049 coladvance((colnr_T)i); | |
5162
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8050 |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8051 /* Make sure we stick in this column. */ |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8052 validate_virtcol(); |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8053 curwin->w_curswant = curwin->w_virtcol; |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8054 curwin->w_set_curswant = FALSE; |
7 | 8055 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) |
8056 { | |
8057 /* | |
8058 * Check for landing on a character that got split at | |
8059 * the end of the line. We do not want to advance to | |
8060 * the next screen line. | |
8061 */ | |
8062 if (curwin->w_virtcol > (colnr_T)i) | |
8063 --curwin->w_cursor.col; | |
8064 } | |
8065 } | |
8066 else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == FAIL) | |
8067 clearopbeep(oap); | |
8068 } | |
8069 else | |
8070 { | |
17520
827d29c8f7e8
patch 8.1.1758: count of g$ not used correctly when text is not wrapped
Bram Moolenaar <Bram@vim.org>
parents:
17318
diff
changeset
|
8071 if (cap->count1 > 1) |
827d29c8f7e8
patch 8.1.1758: count of g$ not used correctly when text is not wrapped
Bram Moolenaar <Bram@vim.org>
parents:
17318
diff
changeset
|
8072 // if it fails, let the cursor still move to the last char |
17730
2fe133c7e972
patch 8.1.1862: Coverity warns for not using return value
Bram Moolenaar <Bram@vim.org>
parents:
17682
diff
changeset
|
8073 (void)cursor_down(cap->count1 - 1, FALSE); |
17520
827d29c8f7e8
patch 8.1.1758: count of g$ not used correctly when text is not wrapped
Bram Moolenaar <Bram@vim.org>
parents:
17318
diff
changeset
|
8074 |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8075 i = curwin->w_leftcol + curwin->w_width - col_off - 1; |
7 | 8076 coladvance((colnr_T)i); |
40 | 8077 |
17520
827d29c8f7e8
patch 8.1.1758: count of g$ not used correctly when text is not wrapped
Bram Moolenaar <Bram@vim.org>
parents:
17318
diff
changeset
|
8078 // Make sure we stick in this column. |
40 | 8079 validate_virtcol(); |
8080 curwin->w_curswant = curwin->w_virtcol; | |
8081 curwin->w_set_curswant = FALSE; | |
7 | 8082 } |
8083 } | |
8084 break; | |
8085 | |
8086 /* | |
8087 * "g*" and "g#", like "*" and "#" but without using "\<" and "\>" | |
8088 */ | |
8089 case '*': | |
8090 case '#': | |
8091 #if POUND != '#' | |
8092 case POUND: /* pound sign (sometimes equal to '#') */ | |
8093 #endif | |
8094 case Ctrl_RSB: /* :tag or :tselect for current identifier */ | |
8095 case ']': /* :tselect for current identifier */ | |
8096 nv_ident(cap); | |
8097 break; | |
8098 | |
8099 /* | |
8100 * ge and gE: go back to end of word | |
8101 */ | |
8102 case 'e': | |
8103 case 'E': | |
8104 oap->motion_type = MCHAR; | |
8105 curwin->w_set_curswant = TRUE; | |
8106 oap->inclusive = TRUE; | |
8107 if (bckend_word(cap->count1, cap->nchar == 'E', FALSE) == FAIL) | |
8108 clearopbeep(oap); | |
8109 break; | |
8110 | |
8111 /* | |
8112 * "g CTRL-G": display info about cursor position | |
8113 */ | |
8114 case Ctrl_G: | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7311
diff
changeset
|
8115 cursor_pos_info(NULL); |
7 | 8116 break; |
8117 | |
8118 /* | |
8119 * "gi": start Insert at the last position. | |
8120 */ | |
8121 case 'i': | |
8122 if (curbuf->b_last_insert.lnum != 0) | |
8123 { | |
8124 curwin->w_cursor = curbuf->b_last_insert; | |
8125 check_cursor_lnum(); | |
8126 i = (int)STRLEN(ml_get_curline()); | |
8127 if (curwin->w_cursor.col > (colnr_T)i) | |
8128 { | |
8129 if (virtual_active()) | |
8130 curwin->w_cursor.coladd += curwin->w_cursor.col - i; | |
8131 curwin->w_cursor.col = i; | |
8132 } | |
8133 } | |
8134 cap->cmdchar = 'i'; | |
8135 nv_edit(cap); | |
8136 break; | |
8137 | |
8138 /* | |
8139 * "gI": Start insert in column 1. | |
8140 */ | |
8141 case 'I': | |
8142 beginline(0); | |
8143 if (!checkclearopq(oap)) | |
8144 invoke_edit(cap, FALSE, 'g', FALSE); | |
8145 break; | |
8146 | |
8147 #ifdef FEAT_SEARCHPATH | |
8148 /* | |
8149 * "gf": goto file, edit file under cursor | |
8150 * "]f" and "[f": can also be used. | |
8151 */ | |
8152 case 'f': | |
681 | 8153 case 'F': |
7 | 8154 nv_gotofile(cap); |
8155 break; | |
8156 #endif | |
8157 | |
8158 /* "g'm" and "g`m": jump to mark without setting pcmark */ | |
8159 case '\'': | |
8160 cap->arg = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
8161 /* FALLTHROUGH */ |
7 | 8162 case '`': |
8163 nv_gomark(cap); | |
8164 break; | |
8165 | |
8166 /* | |
8167 * "gs": Goto sleep. | |
8168 */ | |
8169 case 's': | |
8170 do_sleep(cap->count1 * 1000L); | |
8171 break; | |
8172 | |
8173 /* | |
8174 * "ga": Display the ascii value of the character under the | |
8175 * cursor. It is displayed in decimal, hex, and octal. -- webb | |
8176 */ | |
8177 case 'a': | |
8178 do_ascii(NULL); | |
8179 break; | |
8180 | |
8181 /* | |
8182 * "g8": Display the bytes used for the UTF-8 character under the | |
8183 * cursor. It is displayed in hex. | |
775 | 8184 * "8g8" finds illegal byte sequence. |
7 | 8185 */ |
8186 case '8': | |
775 | 8187 if (cap->count0 == 8) |
8188 utf_find_illegal(); | |
8189 else | |
8190 show_utf8(); | |
7 | 8191 break; |
8192 | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
8193 /* "g<": show scrollback text */ |
447 | 8194 case '<': |
8195 show_sb_text(); | |
8196 break; | |
8197 | |
7 | 8198 /* |
8199 * "gg": Goto the first line in file. With a count it goes to | |
8200 * that line number like for "G". -- webb | |
8201 */ | |
8202 case 'g': | |
8203 cap->arg = FALSE; | |
8204 nv_goto(cap); | |
8205 break; | |
8206 | |
8207 /* | |
8208 * Two-character operators: | |
8209 * "gq" Format text | |
8210 * "gw" Format text and keep cursor position | |
8211 * "g~" Toggle the case of the text. | |
8212 * "gu" Change text to lower case. | |
8213 * "gU" Change text to upper case. | |
8214 * "g?" rot13 encoding | |
602 | 8215 * "g@" call 'operatorfunc' |
7 | 8216 */ |
8217 case 'q': | |
8218 case 'w': | |
8219 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
|
8220 /* FALLTHROUGH */ |
7 | 8221 case '~': |
8222 case 'u': | |
8223 case 'U': | |
8224 case '?': | |
602 | 8225 case '@': |
7 | 8226 nv_operator(cap); |
8227 break; | |
8228 | |
8229 /* | |
1188 | 8230 * "gd": Find first occurrence of pattern under the cursor in the |
7 | 8231 * current function |
8232 * "gD": idem, but in the current file. | |
8233 */ | |
8234 case 'd': | |
8235 case 'D': | |
523 | 8236 nv_gd(oap, cap->nchar, (int)cap->count0); |
7 | 8237 break; |
8238 | |
8239 #ifdef FEAT_MOUSE | |
8240 /* | |
8241 * g<*Mouse> : <C-*mouse> | |
8242 */ | |
8243 case K_MIDDLEMOUSE: | |
8244 case K_MIDDLEDRAG: | |
8245 case K_MIDDLERELEASE: | |
8246 case K_LEFTMOUSE: | |
8247 case K_LEFTDRAG: | |
8248 case K_LEFTRELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
8249 case K_MOUSEMOVE: |
7 | 8250 case K_RIGHTMOUSE: |
8251 case K_RIGHTDRAG: | |
8252 case K_RIGHTRELEASE: | |
8253 case K_X1MOUSE: | |
8254 case K_X1DRAG: | |
8255 case K_X1RELEASE: | |
8256 case K_X2MOUSE: | |
8257 case K_X2DRAG: | |
8258 case K_X2RELEASE: | |
8259 mod_mask = MOD_MASK_CTRL; | |
8260 (void)do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0); | |
8261 break; | |
8262 #endif | |
8263 | |
8264 case K_IGNORE: | |
8265 break; | |
8266 | |
8267 /* | |
8268 * "gP" and "gp": same as "P" and "p" but leave cursor just after new text | |
8269 */ | |
8270 case 'p': | |
8271 case 'P': | |
8272 nv_put(cap); | |
8273 break; | |
8274 | |
8275 #ifdef FEAT_BYTEOFF | |
8276 /* "go": goto byte count from start of buffer */ | |
8277 case 'o': | |
8278 goto_byte(cap->count0); | |
8279 break; | |
8280 #endif | |
8281 | |
8282 /* "gQ": improved Ex mode */ | |
8283 case 'Q': | |
633 | 8284 if (text_locked()) |
7 | 8285 { |
8286 clearopbeep(cap->oap); | |
633 | 8287 text_locked_msg(); |
7 | 8288 break; |
8289 } | |
631 | 8290 |
7 | 8291 if (!checkclearopq(oap)) |
8292 do_exmode(TRUE); | |
8293 break; | |
8294 | |
8295 #ifdef FEAT_JUMPLIST | |
8296 case ',': | |
8297 nv_pcmark(cap); | |
8298 break; | |
8299 | |
8300 case ';': | |
8301 cap->count1 = -cap->count1; | |
8302 nv_pcmark(cap); | |
8303 break; | |
8304 #endif | |
8305 | |
667 | 8306 case 't': |
3630 | 8307 if (!checkclearop(oap)) |
8308 goto_tabpage((int)cap->count0); | |
667 | 8309 break; |
682 | 8310 case 'T': |
3630 | 8311 if (!checkclearop(oap)) |
8312 goto_tabpage(-(int)cap->count1); | |
682 | 8313 break; |
667 | 8314 |
750 | 8315 case '+': |
8316 case '-': /* "g+" and "g-": undo or redo along the timeline */ | |
8317 if (!checkclearopq(oap)) | |
771 | 8318 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
|
8319 FALSE, FALSE, FALSE); |
750 | 8320 break; |
8321 | |
7 | 8322 default: |
8323 clearopbeep(oap); | |
8324 break; | |
8325 } | |
8326 } | |
8327 | |
8328 /* | |
8329 * Handle "o" and "O" commands. | |
8330 */ | |
8331 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8332 n_opencmd(cmdarg_T *cap) |
7 | 8333 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8334 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8335 linenr_T oldline = curwin->w_cursor.lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8336 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8337 |
7 | 8338 if (!checkclearopq(cap->oap)) |
8339 { | |
8340 #ifdef FEAT_FOLDING | |
8341 if (cap->cmdchar == 'O') | |
8342 /* Open above the first line of a folded sequence of lines */ | |
8343 (void)hasFolding(curwin->w_cursor.lnum, | |
8344 &curwin->w_cursor.lnum, NULL); | |
8345 else | |
8346 /* Open below the last line of a folded sequence of lines */ | |
8347 (void)hasFolding(curwin->w_cursor.lnum, | |
8348 NULL, &curwin->w_cursor.lnum); | |
8349 #endif | |
8350 if (u_save((linenr_T)(curwin->w_cursor.lnum - | |
8351 (cap->cmdchar == 'O' ? 1 : 0)), | |
8352 (linenr_T)(curwin->w_cursor.lnum + | |
8353 (cap->cmdchar == 'o' ? 1 : 0)) | |
8354 ) == OK | |
8355 && open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD, | |
8356 #ifdef FEAT_COMMENTS | |
8357 has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM : | |
8358 #endif | |
13772
cc21507ee4b1
patch 8.0.1758: open_line() returns TRUE/FALSE for success/failure
Christian Brabandt <cb@256bit.org>
parents:
13762
diff
changeset
|
8359 0, 0) == OK) |
7 | 8360 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8361 #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
|
8362 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
|
8363 redrawWinline(curwin, oldline); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8364 #endif |
6834 | 8365 #ifdef FEAT_SYN_HL |
6821 | 8366 if (curwin->w_p_cul) |
8367 /* force redraw of cursorline */ | |
8368 curwin->w_valid &= ~VALID_CROW; | |
6834 | 8369 #endif |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
8370 /* 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
|
8371 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
|
8372 cap->count1 = 1; |
7 | 8373 invoke_edit(cap, FALSE, cap->cmdchar, TRUE); |
8374 } | |
8375 } | |
8376 } | |
8377 | |
8378 /* | |
8379 * "." command: redo last change. | |
8380 */ | |
8381 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8382 nv_dot(cmdarg_T *cap) |
7 | 8383 { |
8384 if (!checkclearopq(cap->oap)) | |
8385 { | |
8386 /* | |
8387 * If "restart_edit" is TRUE, the last but one command is repeated | |
8388 * instead of the last command (inserting text). This is used for | |
8389 * CTRL-O <.> in insert mode. | |
8390 */ | |
8391 if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == FAIL) | |
8392 clearopbeep(cap->oap); | |
8393 } | |
8394 } | |
8395 | |
8396 /* | |
8397 * CTRL-R: undo undo | |
8398 */ | |
8399 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8400 nv_redo(cmdarg_T *cap) |
7 | 8401 { |
8402 if (!checkclearopq(cap->oap)) | |
8403 { | |
8404 u_redo((int)cap->count1); | |
8405 curwin->w_set_curswant = TRUE; | |
8406 } | |
8407 } | |
8408 | |
8409 /* | |
8410 * Handle "U" command. | |
8411 */ | |
8412 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8413 nv_Undo(cmdarg_T *cap) |
7 | 8414 { |
8415 /* In Visual mode and typing "gUU" triggers an operator */ | |
5735 | 8416 if (cap->oap->op_type == OP_UPPER || VIsual_active) |
7 | 8417 { |
8418 /* translate "gUU" to "gUgU" */ | |
8419 cap->cmdchar = 'g'; | |
8420 cap->nchar = 'U'; | |
8421 nv_operator(cap); | |
8422 } | |
8423 else if (!checkclearopq(cap->oap)) | |
8424 { | |
8425 u_undoline(); | |
8426 curwin->w_set_curswant = TRUE; | |
8427 } | |
8428 } | |
8429 | |
8430 /* | |
8431 * '~' command: If tilde is not an operator and Visual is off: swap case of a | |
8432 * single character. | |
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_tilde(cmdarg_T *cap) |
7 | 8436 { |
5735 | 8437 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
|
8438 { |
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
|
8439 #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
|
8440 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
|
8441 { |
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
|
8442 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
|
8443 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
|
8444 } |
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
|
8445 #endif |
7 | 8446 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
|
8447 } |
7 | 8448 else |
8449 nv_operator(cap); | |
8450 } | |
8451 | |
8452 /* | |
8453 * Handle an operator command. | |
8454 * The actual work is done by do_pending_operator(). | |
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_operator(cmdarg_T *cap) |
7 | 8458 { |
8459 int op_type; | |
8460 | |
8461 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
|
8462 #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
|
8463 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
|
8464 { |
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 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
|
8466 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
|
8467 } |
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
|
8468 #endif |
7 | 8469 |
8470 if (op_type == cap->oap->op_type) /* double operator works on lines */ | |
8471 nv_lineop(cap); | |
8472 else if (!checkclearop(cap->oap)) | |
8473 { | |
8474 cap->oap->start = curwin->w_cursor; | |
8475 cap->oap->op_type = op_type; | |
1490 | 8476 #ifdef FEAT_EVAL |
8477 set_op_var(op_type); | |
8478 #endif | |
8479 } | |
8480 } | |
8481 | |
8482 #ifdef FEAT_EVAL | |
8483 /* | |
8484 * Set v:operator to the characters for "optype". | |
8485 */ | |
8486 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8487 set_op_var(int optype) |
1490 | 8488 { |
8489 char_u opchars[3]; | |
8490 | |
8491 if (optype == OP_NOP) | |
8492 set_vim_var_string(VV_OP, NULL, 0); | |
8493 else | |
8494 { | |
8495 opchars[0] = get_op_char(optype); | |
8496 opchars[1] = get_extra_op_char(optype); | |
8497 opchars[2] = NUL; | |
8498 set_vim_var_string(VV_OP, opchars, -1); | |
8499 } | |
8500 } | |
8501 #endif | |
7 | 8502 |
8503 /* | |
8504 * Handle linewise operator "dd", "yy", etc. | |
8505 * | |
8506 * "_" is is a strange motion command that helps make operators more logical. | |
8507 * It is actually implemented, but not documented in the real Vi. This motion | |
8508 * command actually refers to "the current line". Commands like "dd" and "yy" | |
8509 * are really an alternate form of "d_" and "y_". It does accept a count, so | |
8510 * "d3_" works to delete 3 lines. | |
8511 */ | |
8512 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8513 nv_lineop(cmdarg_T *cap) |
7 | 8514 { |
8515 cap->oap->motion_type = MLINE; | |
8516 if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL) | |
8517 clearopbeep(cap->oap); | |
4011 | 8518 else if ( (cap->oap->op_type == OP_DELETE /* only with linewise motions */ |
8519 && cap->oap->motion_force != 'v' | |
8520 && cap->oap->motion_force != Ctrl_V) | |
7 | 8521 || cap->oap->op_type == OP_LSHIFT |
8522 || cap->oap->op_type == OP_RSHIFT) | |
8523 beginline(BL_SOL | BL_FIX); | |
8524 else if (cap->oap->op_type != OP_YANK) /* 'Y' does not move cursor */ | |
8525 beginline(BL_WHITE | BL_FIX); | |
8526 } | |
8527 | |
8528 /* | |
8529 * <Home> command. | |
8530 */ | |
8531 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8532 nv_home(cmdarg_T *cap) |
7 | 8533 { |
180 | 8534 /* CTRL-HOME is like "gg" */ |
8535 if (mod_mask & MOD_MASK_CTRL) | |
8536 nv_goto(cap); | |
8537 else | |
8538 { | |
8539 cap->count0 = 1; | |
8540 nv_pipe(cap); | |
8541 } | |
229 | 8542 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8543 one-character line). */ | |
7 | 8544 } |
8545 | |
8546 /* | |
8547 * "|" command. | |
8548 */ | |
8549 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8550 nv_pipe(cmdarg_T *cap) |
7 | 8551 { |
8552 cap->oap->motion_type = MCHAR; | |
8553 cap->oap->inclusive = FALSE; | |
8554 beginline(0); | |
8555 if (cap->count0 > 0) | |
8556 { | |
8557 coladvance((colnr_T)(cap->count0 - 1)); | |
8558 curwin->w_curswant = (colnr_T)(cap->count0 - 1); | |
8559 } | |
8560 else | |
8561 curwin->w_curswant = 0; | |
8562 /* keep curswant at the column where we wanted to go, not where | |
2667 | 8563 * we ended; differs if line is too short */ |
7 | 8564 curwin->w_set_curswant = FALSE; |
8565 } | |
8566 | |
8567 /* | |
8568 * Handle back-word command "b" and "B". | |
8569 * cap->arg is 1 for "B" | |
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_bck_word(cmdarg_T *cap) |
7 | 8573 { |
8574 cap->oap->motion_type = MCHAR; | |
8575 cap->oap->inclusive = FALSE; | |
8576 curwin->w_set_curswant = TRUE; | |
8577 if (bck_word(cap->count1, cap->arg, FALSE) == FAIL) | |
8578 clearopbeep(cap->oap); | |
8579 #ifdef FEAT_FOLDING | |
8580 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8581 foldOpenCursor(); | |
8582 #endif | |
8583 } | |
8584 | |
8585 /* | |
8586 * Handle word motion commands "e", "E", "w" and "W". | |
8587 * cap->arg is TRUE for "E" and "W". | |
8588 */ | |
8589 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8590 nv_wordcmd(cmdarg_T *cap) |
7 | 8591 { |
8592 int n; | |
8593 int word_end; | |
8594 int flag = FALSE; | |
1573 | 8595 pos_T startpos = curwin->w_cursor; |
7 | 8596 |
8597 /* | |
8598 * Set inclusive for the "E" and "e" command. | |
8599 */ | |
8600 if (cap->cmdchar == 'e' || cap->cmdchar == 'E') | |
8601 word_end = TRUE; | |
8602 else | |
8603 word_end = FALSE; | |
8604 cap->oap->inclusive = word_end; | |
8605 | |
8606 /* | |
8607 * "cw" and "cW" are a special case. | |
8608 */ | |
8609 if (!word_end && cap->oap->op_type == OP_CHANGE) | |
8610 { | |
8611 n = gchar_cursor(); | |
8612 if (n != NUL) /* not an empty line */ | |
8613 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
8614 if (VIM_ISWHITE(n)) |
7 | 8615 { |
8616 /* | |
8617 * Reproduce a funny Vi behaviour: "cw" on a blank only | |
8618 * changes one character, not all blanks until the start of | |
8619 * the next word. Only do this when the 'w' flag is included | |
8620 * in 'cpoptions'. | |
8621 */ | |
8622 if (cap->count1 == 1 && vim_strchr(p_cpo, CPO_CW) != NULL) | |
8623 { | |
8624 cap->oap->inclusive = TRUE; | |
8625 cap->oap->motion_type = MCHAR; | |
8626 return; | |
8627 } | |
8628 } | |
8629 else | |
8630 { | |
8631 /* | |
8632 * This is a little strange. To match what the real Vi does, | |
8633 * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided | |
8634 * that we are not on a space or a TAB. This seems impolite | |
8635 * at first, but it's really more what we mean when we say | |
8636 * 'cw'. | |
8637 * Another strangeness: When standing on the end of a word | |
4352 | 8638 * "ce" will change until the end of the next word, but "cw" |
7 | 8639 * will change only one character! This is done by setting |
8640 * flag. | |
8641 */ | |
8642 cap->oap->inclusive = TRUE; | |
8643 word_end = TRUE; | |
8644 flag = TRUE; | |
8645 } | |
8646 } | |
8647 } | |
8648 | |
8649 cap->oap->motion_type = MCHAR; | |
8650 curwin->w_set_curswant = TRUE; | |
8651 if (word_end) | |
8652 n = end_word(cap->count1, cap->arg, flag, FALSE); | |
8653 else | |
8654 n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP); | |
8655 | |
1573 | 8656 /* Don't leave the cursor on the NUL past the end of line. Unless we |
8657 * 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
|
8658 if (LT_POS(startpos, curwin->w_cursor)) |
1505 | 8659 adjust_cursor(cap->oap); |
7 | 8660 |
8661 if (n == FAIL && cap->oap->op_type == OP_NOP) | |
8662 clearopbeep(cap->oap); | |
8663 else | |
8664 { | |
8665 adjust_for_sel(cap); | |
8666 #ifdef FEAT_FOLDING | |
8667 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8668 foldOpenCursor(); | |
8669 #endif | |
8670 } | |
8671 } | |
8672 | |
8673 /* | |
1505 | 8674 * Used after a movement command: If the cursor ends up on the NUL after the |
8675 * end of the line, may move it back to the last character and make the motion | |
8676 * inclusive. | |
8677 */ | |
8678 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8679 adjust_cursor(oparg_T *oap) |
1505 | 8680 { |
8681 /* The cursor cannot remain on the NUL when: | |
8682 * - the column is > 0 | |
8683 * - not in Visual mode or 'selection' is "o" | |
8684 * - 'virtualedit' is not "all" and not "onemore". | |
8685 */ | |
8686 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL | |
8687 && (!VIsual_active || *p_sel == 'o') | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
8688 && !virtual_active() && (ve_flags & VE_ONEMORE) == 0) |
1505 | 8689 { |
8690 --curwin->w_cursor.col; | |
8691 /* prevent cursor from moving on the trail byte */ | |
8692 if (has_mbyte) | |
8693 mb_adjust_cursor(); | |
8694 oap->inclusive = TRUE; | |
8695 } | |
8696 } | |
8697 | |
8698 /* | |
7 | 8699 * "0" and "^" commands. |
8700 * cap->arg is the argument for beginline(). | |
8701 */ | |
8702 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8703 nv_beginline(cmdarg_T *cap) |
7 | 8704 { |
8705 cap->oap->motion_type = MCHAR; | |
8706 cap->oap->inclusive = FALSE; | |
8707 beginline(cap->arg); | |
8708 #ifdef FEAT_FOLDING | |
8709 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8710 foldOpenCursor(); | |
8711 #endif | |
557 | 8712 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8713 one-character line). */ | |
7 | 8714 } |
8715 | |
8716 /* | |
8717 * In exclusive Visual mode, may include the last character. | |
8718 */ | |
8719 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8720 adjust_for_sel(cmdarg_T *cap) |
7 | 8721 { |
8722 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
|
8723 && gchar_cursor() != NUL && LT_POS(VIsual, curwin->w_cursor)) |
7 | 8724 { |
8725 if (has_mbyte) | |
8726 inc_cursor(); | |
8727 else | |
8728 ++curwin->w_cursor.col; | |
8729 cap->oap->inclusive = FALSE; | |
8730 } | |
8731 } | |
8732 | |
8733 /* | |
8734 * Exclude last character at end of Visual area for 'selection' == "exclusive". | |
8735 * Should check VIsual_mode before calling this. | |
8736 * Returns TRUE when backed up to the previous line. | |
8737 */ | |
8738 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8739 unadjust_for_sel(void) |
7 | 8740 { |
8741 pos_T *pp; | |
8742 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8743 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
|
8744 { |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8745 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 8746 pp = &curwin->w_cursor; |
8747 else | |
8748 pp = &VIsual; | |
8749 if (pp->coladd > 0) | |
8750 --pp->coladd; | |
8751 else | |
8752 if (pp->col > 0) | |
8753 { | |
8754 --pp->col; | |
2933 | 8755 mb_adjustpos(curbuf, pp); |
7 | 8756 } |
8757 else if (pp->lnum > 1) | |
8758 { | |
8759 --pp->lnum; | |
8760 pp->col = (colnr_T)STRLEN(ml_get(pp->lnum)); | |
8761 return TRUE; | |
8762 } | |
8763 } | |
8764 return FALSE; | |
8765 } | |
8766 | |
8767 /* | |
8768 * SELECT key in Normal or Visual mode: end of Select mode mapping. | |
8769 */ | |
8770 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8771 nv_select(cmdarg_T *cap) |
7 | 8772 { |
8773 if (VIsual_active) | |
8774 VIsual_select = TRUE; | |
8775 else if (VIsual_reselect) | |
8776 { | |
8777 cap->nchar = 'v'; /* fake "gv" command */ | |
8778 cap->arg = TRUE; | |
8779 nv_g_cmd(cap); | |
8780 } | |
8781 } | |
8782 | |
8783 | |
8784 /* | |
8785 * "G", "gg", CTRL-END, CTRL-HOME. | |
8786 * cap->arg is TRUE for "G". | |
8787 */ | |
8788 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8789 nv_goto(cmdarg_T *cap) |
7 | 8790 { |
8791 linenr_T lnum; | |
8792 | |
8793 if (cap->arg) | |
8794 lnum = curbuf->b_ml.ml_line_count; | |
8795 else | |
8796 lnum = 1L; | |
8797 cap->oap->motion_type = MLINE; | |
8798 setpcmark(); | |
8799 | |
8800 /* When a count is given, use it instead of the default lnum */ | |
8801 if (cap->count0 != 0) | |
8802 lnum = cap->count0; | |
8803 if (lnum < 1L) | |
8804 lnum = 1L; | |
8805 else if (lnum > curbuf->b_ml.ml_line_count) | |
8806 lnum = curbuf->b_ml.ml_line_count; | |
8807 curwin->w_cursor.lnum = lnum; | |
8808 beginline(BL_SOL | BL_FIX); | |
8809 #ifdef FEAT_FOLDING | |
8810 if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8811 foldOpenCursor(); | |
8812 #endif | |
8813 } | |
8814 | |
8815 /* | |
8816 * CTRL-\ in Normal mode. | |
8817 */ | |
8818 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8819 nv_normal(cmdarg_T *cap) |
7 | 8820 { |
8821 if (cap->nchar == Ctrl_N || cap->nchar == Ctrl_G) | |
8822 { | |
8823 clearop(cap->oap); | |
643 | 8824 if (restart_edit != 0 && mode_displayed) |
7 | 8825 clear_cmdline = TRUE; /* unshow mode later */ |
8826 restart_edit = 0; | |
8827 #ifdef FEAT_CMDWIN | |
8828 if (cmdwin_type != 0) | |
8829 cmdwin_result = Ctrl_C; | |
8830 #endif | |
8831 if (VIsual_active) | |
8832 { | |
8833 end_visual_mode(); /* stop Visual */ | |
8834 redraw_curbuf_later(INVERTED); | |
8835 } | |
8836 /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */ | |
8837 if (cap->nchar == Ctrl_G && p_im) | |
8838 restart_edit = 'a'; | |
8839 } | |
8840 else | |
8841 clearopbeep(cap->oap); | |
8842 } | |
8843 | |
8844 /* | |
8845 * ESC in Normal mode: beep, but don't flush buffers. | |
8846 * Don't even beep if we are canceling a command. | |
8847 */ | |
8848 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8849 nv_esc(cmdarg_T *cap) |
7 | 8850 { |
8851 int no_reason; | |
8852 | |
8853 no_reason = (cap->oap->op_type == OP_NOP | |
8854 && cap->opcount == 0 | |
8855 && cap->count0 == 0 | |
8856 && cap->oap->regname == 0 | |
8857 && !p_im); | |
8858 | |
8859 if (cap->arg) /* TRUE for CTRL-C */ | |
8860 { | |
8861 if (restart_edit == 0 | |
8862 #ifdef FEAT_CMDWIN | |
8863 && cmdwin_type == 0 | |
8864 #endif | |
8865 && !VIsual_active | |
8866 && 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
|
8867 { |
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
|
8868 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
|
8869 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
|
8870 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
|
8871 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
|
8872 } |
7 | 8873 |
8874 /* Don't reset "restart_edit" when 'insertmode' is set, it won't be | |
8875 * set again below when halfway a mapping. */ | |
8876 if (!p_im) | |
8877 restart_edit = 0; | |
8878 #ifdef FEAT_CMDWIN | |
8879 if (cmdwin_type != 0) | |
8880 { | |
8881 cmdwin_result = K_IGNORE; | |
8882 got_int = FALSE; /* don't stop executing autocommands et al. */ | |
8883 return; | |
8884 } | |
8885 #endif | |
8886 } | |
8887 | |
8888 if (VIsual_active) | |
8889 { | |
8890 end_visual_mode(); /* stop Visual */ | |
8891 check_cursor_col(); /* make sure cursor is not beyond EOL */ | |
8892 curwin->w_set_curswant = TRUE; | |
8893 redraw_curbuf_later(INVERTED); | |
8894 } | |
5735 | 8895 else if (no_reason) |
6949 | 8896 vim_beep(BO_ESC); |
7 | 8897 clearop(cap->oap); |
8898 | |
8899 /* A CTRL-C is often used at the start of a menu. When 'insertmode' is | |
8900 * 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
|
8901 if (restart_edit == 0 && goto_im() && ex_normal_busy == 0) |
7 | 8902 restart_edit = 'a'; |
8903 } | |
8904 | |
8905 /* | |
17984
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8906 * Move the cursor for the "A" command. |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8907 */ |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8908 void |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8909 set_cursor_for_append_to_line(void) |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8910 { |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8911 curwin->w_set_curswant = TRUE; |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8912 if (ve_flags == VE_ALL) |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8913 { |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8914 int save_State = State; |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8915 |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8916 /* Pretend Insert mode here to allow the cursor on the |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8917 * character past the end of the line */ |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8918 State = INSERT; |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8919 coladvance((colnr_T)MAXCOL); |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8920 State = save_State; |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8921 } |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8922 else |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8923 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor()); |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8924 } |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8925 |
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
8926 /* |
7 | 8927 * 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
|
8928 * Also handle K_PS, start bracketed paste. |
7 | 8929 */ |
8930 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8931 nv_edit(cmdarg_T *cap) |
7 | 8932 { |
8933 /* <Insert> is equal to "i" */ | |
8934 if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) | |
8935 cap->cmdchar = 'i'; | |
8936 | |
8937 /* in Visual mode "A" and "I" are an operator */ | |
8938 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
|
8939 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
8940 #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
|
8941 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
|
8942 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
8943 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
|
8944 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
|
8945 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
|
8946 return; |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
8947 } |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
8948 #endif |
7 | 8949 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
|
8950 } |
7 | 8951 |
8952 /* in Visual mode and after an operator "a" and "i" are for text objects */ | |
5735 | 8953 else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') |
8954 && (cap->oap->op_type != OP_NOP || VIsual_active)) | |
7 | 8955 { |
8956 #ifdef FEAT_TEXTOBJ | |
8957 nv_object(cap); | |
8958 #else | |
8959 clearopbeep(cap->oap); | |
8960 #endif | |
8961 } | |
11892
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
8962 #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
|
8963 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
|
8964 { |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
8965 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
|
8966 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
|
8967 return; |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
8968 } |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
8969 #endif |
7 | 8970 else if (!curbuf->b_p_ma && !p_im) |
8971 { | |
8972 /* 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
|
8973 emsg(_(e_modifiable)); |
7 | 8974 clearop(cap->oap); |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
8975 if (cap->cmdchar == K_PS) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
8976 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
8977 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 8978 } |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
8979 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
|
8980 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
8981 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
|
8982 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
|
8983 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
8984 /* 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
|
8985 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
|
8986 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
8987 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
|
8988 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
|
8989 } |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
8990 else |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
8991 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
|
8992 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
|
8993 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
|
8994 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
|
8995 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
|
8996 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
|
8997 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
8998 /* 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
|
8999 * 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
|
9000 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
|
9001 && 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
|
9002 inc_cursor(); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9003 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9004 /* 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
|
9005 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
|
9006 } |
7 | 9007 else if (!checkclearopq(cap->oap)) |
9008 { | |
9009 switch (cap->cmdchar) | |
9010 { | |
9011 case 'A': /* "A"ppend after the line */ | |
17984
2ea47dee7ddd
patch 8.1.1988: :startinsert! does not work the same way as "A"
Bram Moolenaar <Bram@vim.org>
parents:
17787
diff
changeset
|
9012 set_cursor_for_append_to_line(); |
7 | 9013 break; |
9014 | |
9015 case 'I': /* "I"nsert before the first non-blank */ | |
164 | 9016 if (vim_strchr(p_cpo, CPO_INSEND) == NULL) |
9017 beginline(BL_WHITE); | |
9018 else | |
9019 beginline(BL_WHITE|BL_FIX); | |
7 | 9020 break; |
9021 | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9022 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
|
9023 /* 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
|
9024 * 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
|
9025 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
|
9026 break; |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
9027 /* FALLTHROUGH */ |
10813
09eb5fd275e0
patch 8.0.0296: bracketed paste can only append, not insert
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
9028 |
7 | 9029 case 'a': /* "a"ppend is like "i"nsert on the next character. */ |
9030 /* increment coladd when in virtual space, increment the | |
9031 * column otherwise, also to append after an unprintable char */ | |
9032 if (virtual_active() | |
9033 && (curwin->w_cursor.coladd > 0 | |
9034 || *ml_get_cursor() == NUL | |
9035 || *ml_get_cursor() == TAB)) | |
9036 curwin->w_cursor.coladd++; | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
9037 else if (*ml_get_cursor() != NUL) |
7 | 9038 inc_cursor(); |
9039 break; | |
9040 } | |
9041 | |
9042 if (curwin->w_cursor.coladd && cap->cmdchar != 'A') | |
9043 { | |
9044 int save_State = State; | |
9045 | |
4352 | 9046 /* Pretend Insert mode here to allow the cursor on the |
7 | 9047 * character past the end of the line */ |
9048 State = INSERT; | |
9049 coladvance(getviscol()); | |
9050 State = save_State; | |
9051 } | |
9052 | |
9053 invoke_edit(cap, FALSE, cap->cmdchar, FALSE); | |
9054 } | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9055 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
|
9056 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9057 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 9058 } |
9059 | |
9060 /* | |
9061 * Invoke edit() and take care of "restart_edit" and the return value. | |
9062 */ | |
9063 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9064 invoke_edit( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9065 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9066 int repl, /* "r" or "gr" command */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9067 int cmd, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9068 int startln) |
7 | 9069 { |
9070 int restart_edit_save = 0; | |
9071 | |
9072 /* Complicated: When the user types "a<C-O>a" we don't want to do Insert | |
9073 * mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow | |
9074 * it. */ | |
9075 if (repl || !stuff_empty()) | |
9076 restart_edit_save = restart_edit; | |
9077 else | |
9078 restart_edit_save = 0; | |
9079 | |
9080 /* Always reset "restart_edit", this is not a restarted edit. */ | |
9081 restart_edit = 0; | |
9082 | |
9083 if (edit(cmd, startln, cap->count1)) | |
9084 cap->retval |= CA_COMMAND_BUSY; | |
9085 | |
9086 if (restart_edit == 0) | |
9087 restart_edit = restart_edit_save; | |
9088 } | |
9089 | |
9090 #ifdef FEAT_TEXTOBJ | |
9091 /* | |
9092 * "a" or "i" while an operator is pending or in Visual mode: object motion. | |
9093 */ | |
9094 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9095 nv_object( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9096 cmdarg_T *cap) |
7 | 9097 { |
9098 int flag; | |
9099 int include; | |
9100 char_u *mps_save; | |
9101 | |
9102 if (cap->cmdchar == 'i') | |
9103 include = FALSE; /* "ix" = inner object: exclude white space */ | |
9104 else | |
9105 include = TRUE; /* "ax" = an object: include white space */ | |
9106 | |
9107 /* Make sure (), [], {} and <> are in 'matchpairs' */ | |
9108 mps_save = curbuf->b_p_mps; | |
9109 curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>"; | |
9110 | |
9111 switch (cap->nchar) | |
9112 { | |
9113 case 'w': /* "aw" = a word */ | |
9114 flag = current_word(cap->oap, cap->count1, include, FALSE); | |
9115 break; | |
9116 case 'W': /* "aW" = a WORD */ | |
9117 flag = current_word(cap->oap, cap->count1, include, TRUE); | |
9118 break; | |
9119 case 'b': /* "ab" = a braces block */ | |
9120 case '(': | |
9121 case ')': | |
9122 flag = current_block(cap->oap, cap->count1, include, '(', ')'); | |
9123 break; | |
9124 case 'B': /* "aB" = a Brackets block */ | |
9125 case '{': | |
9126 case '}': | |
9127 flag = current_block(cap->oap, cap->count1, include, '{', '}'); | |
9128 break; | |
9129 case '[': /* "a[" = a [] block */ | |
9130 case ']': | |
9131 flag = current_block(cap->oap, cap->count1, include, '[', ']'); | |
9132 break; | |
9133 case '<': /* "a<" = a <> block */ | |
9134 case '>': | |
9135 flag = current_block(cap->oap, cap->count1, include, '<', '>'); | |
9136 break; | |
420 | 9137 case 't': /* "at" = a tag block (xml and html) */ |
6661 | 9138 /* Do not adjust oap->end in do_pending_operator() |
9139 * otherwise there are different results for 'dit' | |
9140 * (note leading whitespace in last line): | |
9141 * 1) <b> 2) <b> | |
9142 * foobar foobar | |
9143 * </b> </b> | |
9144 */ | |
9145 cap->retval |= CA_NO_ADJ_OP_END; | |
420 | 9146 flag = current_tagblock(cap->oap, cap->count1, include); |
9147 break; | |
7 | 9148 case 'p': /* "ap" = a paragraph */ |
9149 flag = current_par(cap->oap, cap->count1, include, 'p'); | |
9150 break; | |
9151 case 's': /* "as" = a sentence */ | |
9152 flag = current_sent(cap->oap, cap->count1, include); | |
9153 break; | |
12 | 9154 case '"': /* "a"" = a double quoted string */ |
9155 case '\'': /* "a'" = a single quoted string */ | |
9156 case '`': /* "a`" = a backtick quoted string */ | |
9157 flag = current_quote(cap->oap, cap->count1, include, | |
9158 cap->nchar); | |
9159 break; | |
7 | 9160 #if 0 /* TODO */ |
9161 case 'S': /* "aS" = a section */ | |
9162 case 'f': /* "af" = a filename */ | |
9163 case 'u': /* "au" = a URL */ | |
9164 #endif | |
9165 default: | |
9166 flag = FAIL; | |
9167 break; | |
9168 } | |
9169 | |
9170 curbuf->b_p_mps = mps_save; | |
9171 if (flag == FAIL) | |
9172 clearopbeep(cap->oap); | |
9173 adjust_cursor_col(); | |
9174 curwin->w_set_curswant = TRUE; | |
9175 } | |
9176 #endif | |
9177 | |
9178 /* | |
9179 * "q" command: Start/stop recording. | |
9180 * "q:", "q/", "q?": edit command-line in command-line window. | |
9181 */ | |
9182 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9183 nv_record(cmdarg_T *cap) |
7 | 9184 { |
9185 if (cap->oap->op_type == OP_FORMAT) | |
9186 { | |
9187 /* "gqq" is the same as "gqgq": format line */ | |
9188 cap->cmdchar = 'g'; | |
9189 cap->nchar = 'q'; | |
9190 nv_operator(cap); | |
9191 } | |
9192 else if (!checkclearop(cap->oap)) | |
9193 { | |
9194 #ifdef FEAT_CMDWIN | |
9195 if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?') | |
9196 { | |
9197 stuffcharReadbuff(cap->nchar); | |
9198 stuffcharReadbuff(K_CMDWIN); | |
9199 } | |
9200 else | |
9201 #endif | |
9202 /* (stop) recording into a named register, unless executing a | |
9203 * 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
|
9204 if (reg_executing == 0 && do_record(cap->nchar) == FAIL) |
7 | 9205 clearopbeep(cap->oap); |
9206 } | |
9207 } | |
9208 | |
9209 /* | |
9210 * Handle the "@r" command. | |
9211 */ | |
9212 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9213 nv_at(cmdarg_T *cap) |
7 | 9214 { |
9215 if (checkclearop(cap->oap)) | |
9216 return; | |
9217 #ifdef FEAT_EVAL | |
9218 if (cap->nchar == '=') | |
9219 { | |
9220 if (get_expr_register() == NUL) | |
9221 return; | |
9222 } | |
9223 #endif | |
9224 while (cap->count1-- && !got_int) | |
9225 { | |
1034 | 9226 if (do_execreg(cap->nchar, FALSE, FALSE, FALSE) == FAIL) |
7 | 9227 { |
9228 clearopbeep(cap->oap); | |
9229 break; | |
9230 } | |
9231 line_breakcheck(); | |
9232 } | |
9233 } | |
9234 | |
9235 /* | |
9236 * Handle the CTRL-U and CTRL-D commands. | |
9237 */ | |
9238 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9239 nv_halfpage(cmdarg_T *cap) |
7 | 9240 { |
9241 if ((cap->cmdchar == Ctrl_U && curwin->w_cursor.lnum == 1) | |
9242 || (cap->cmdchar == Ctrl_D | |
9243 && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)) | |
9244 clearopbeep(cap->oap); | |
9245 else if (!checkclearop(cap->oap)) | |
9246 halfpage(cap->cmdchar == Ctrl_D, cap->count0); | |
9247 } | |
9248 | |
9249 /* | |
9250 * Handle "J" or "gJ" command. | |
9251 */ | |
9252 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9253 nv_join(cmdarg_T *cap) |
7 | 9254 { |
9255 if (VIsual_active) /* join the visual lines */ | |
9256 nv_operator(cap); | |
5735 | 9257 else if (!checkclearop(cap->oap)) |
7 | 9258 { |
9259 if (cap->count0 <= 1) | |
9260 cap->count0 = 2; /* default for join is two lines! */ | |
9261 if (curwin->w_cursor.lnum + cap->count0 - 1 > | |
9262 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
|
9263 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9264 /* 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
|
9265 if (cap->count0 <= 2) |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9266 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9267 clearopbeep(cap->oap); |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9268 return; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9269 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9270 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
|
9271 - curwin->w_cursor.lnum + 1; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9272 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9273 |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9274 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
|
9275 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
|
9276 (void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE, TRUE); |
7 | 9277 } |
9278 } | |
9279 | |
9280 /* | |
9281 * "P", "gP", "p" and "gp" commands. | |
9282 */ | |
9283 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9284 nv_put(cmdarg_T *cap) |
7 | 9285 { |
16742
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9286 nv_put_opt(cap, FALSE); |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9287 } |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9288 |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9289 /* |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9290 * "P", "gP", "p" and "gp" commands. |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9291 * "fix_indent" is TRUE for "[p", "[P", "]p" and "]P". |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9292 */ |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9293 static void |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9294 nv_put_opt(cmdarg_T *cap, int fix_indent) |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9295 { |
7 | 9296 int regname = 0; |
9297 void *reg1 = NULL, *reg2 = NULL; | |
84 | 9298 int empty = FALSE; |
236 | 9299 int was_visual = FALSE; |
7 | 9300 int dir; |
9301 int flags = 0; | |
9302 | |
9303 if (cap->oap->op_type != OP_NOP) | |
9304 { | |
9305 #ifdef FEAT_DIFF | |
9306 /* "dp" is ":diffput" */ | |
9307 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') | |
9308 { | |
9309 clearop(cap->oap); | |
6314 | 9310 nv_diffgetput(TRUE, cap->opcount); |
7 | 9311 } |
9312 else | |
9313 #endif | |
9314 clearopbeep(cap->oap); | |
9315 } | |
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
|
9316 #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
|
9317 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
|
9318 { |
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 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
|
9320 } |
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 #endif |
7 | 9322 else |
9323 { | |
16742
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9324 if (fix_indent) |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9325 { |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9326 dir = (cap->cmdchar == ']' && cap->nchar == 'p') |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9327 ? FORWARD : BACKWARD; |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9328 flags |= PUT_FIXINDENT; |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9329 } |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9330 else |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9331 dir = (cap->cmdchar == 'P' |
75b5d77bbbab
patch 8.1.1373: "[p" in Visual mode puts in wrong line
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
9332 || (cap->cmdchar == 'g' && cap->nchar == 'P')) |
7 | 9333 ? BACKWARD : FORWARD; |
9334 prep_redo_cmd(cap); | |
9335 if (cap->cmdchar == 'g') | |
9336 flags |= PUT_CURSEND; | |
9337 | |
9338 if (VIsual_active) | |
9339 { | |
9340 /* Putting in Visual mode: The put text replaces the selected | |
9341 * text. First delete the selected text, then put the new text. | |
9342 * Need to save and restore the registers that the delete | |
9343 * overwrites if the old contents is being put. | |
9344 */ | |
236 | 9345 was_visual = TRUE; |
7 | 9346 regname = cap->oap->regname; |
5735 | 9347 #ifdef FEAT_CLIPBOARD |
7 | 9348 adjust_clip_reg(®name); |
5735 | 9349 #endif |
5682 | 9350 if (regname == 0 || regname == '"' |
4013 | 9351 || VIM_ISDIGIT(regname) || regname == '-' |
5735 | 9352 #ifdef FEAT_CLIPBOARD |
7 | 9353 || (clip_unnamed && (regname == '*' || regname == '+')) |
5735 | 9354 #endif |
7 | 9355 |
9356 ) | |
9357 { | |
4013 | 9358 /* The delete is going to overwrite the register we want to |
7 | 9359 * put, save it first. */ |
9360 reg1 = get_register(regname, TRUE); | |
9361 } | |
9362 | |
17787
92e0996e1cb8
patch 8.1.1890: ml_get error when deleting fold marker
Bram Moolenaar <Bram@vim.org>
parents:
17730
diff
changeset
|
9363 // Now delete the selected text. Avoid messages here. |
7 | 9364 cap->cmdchar = 'd'; |
9365 cap->nchar = NUL; | |
9366 cap->oap->regname = NUL; | |
17787
92e0996e1cb8
patch 8.1.1890: ml_get error when deleting fold marker
Bram Moolenaar <Bram@vim.org>
parents:
17730
diff
changeset
|
9367 ++msg_silent; |
7 | 9368 nv_operator(cap); |
9369 do_pending_operator(cap, 0, FALSE); | |
84 | 9370 empty = (curbuf->b_ml.ml_flags & ML_EMPTY); |
17787
92e0996e1cb8
patch 8.1.1890: ml_get error when deleting fold marker
Bram Moolenaar <Bram@vim.org>
parents:
17730
diff
changeset
|
9371 --msg_silent; |
7 | 9372 |
9373 /* delete PUT_LINE_BACKWARD; */ | |
9374 cap->oap->regname = regname; | |
9375 | |
9376 if (reg1 != NULL) | |
9377 { | |
9378 /* Delete probably changed the register we want to put, save | |
9379 * it first. Then put back what was there before the delete. */ | |
9380 reg2 = get_register(regname, FALSE); | |
9381 put_register(regname, reg1); | |
9382 } | |
9383 | |
9384 /* When deleted a linewise Visual area, put the register as | |
9385 * lines to avoid it joined with the next line. When deletion was | |
9386 * characterwise, split a line when putting lines. */ | |
9387 if (VIsual_mode == 'V') | |
9388 flags |= PUT_LINE; | |
9389 else if (VIsual_mode == 'v') | |
9390 flags |= PUT_LINE_SPLIT; | |
9391 if (VIsual_mode == Ctrl_V && dir == FORWARD) | |
9392 flags |= PUT_LINE_FORWARD; | |
9393 dir = BACKWARD; | |
9394 if ((VIsual_mode != 'V' | |
9395 && curwin->w_cursor.col < curbuf->b_op_start.col) | |
9396 || (VIsual_mode == 'V' | |
9397 && curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) | |
9398 /* cursor is at the end of the line or end of file, put | |
9399 * forward. */ | |
9400 dir = FORWARD; | |
5365 | 9401 /* May have been reset in do_put(). */ |
9402 VIsual_active = TRUE; | |
7 | 9403 } |
9404 do_put(cap->oap->regname, dir, cap->count1, flags); | |
9405 | |
9406 /* If a register was saved, put it back now. */ | |
9407 if (reg2 != NULL) | |
9408 put_register(regname, reg2); | |
236 | 9409 |
9410 /* What to reselect with "gv"? Selecting the just put text seems to | |
9411 * be the most useful, since the original text was removed. */ | |
9412 if (was_visual) | |
9413 { | |
690 | 9414 curbuf->b_visual.vi_start = curbuf->b_op_start; |
9415 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
|
9416 /* need to adjust cursor position */ |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
9417 if (*p_sel == 'e') |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
9418 inc(&curbuf->b_visual.vi_end); |
236 | 9419 } |
9420 | |
84 | 9421 /* When all lines were selected and deleted do_put() leaves an empty |
236 | 9422 * line that needs to be deleted now. */ |
84 | 9423 if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) |
817 | 9424 { |
84 | 9425 ml_delete(curbuf->b_ml.ml_line_count, TRUE); |
17787
92e0996e1cb8
patch 8.1.1890: ml_get error when deleting fold marker
Bram Moolenaar <Bram@vim.org>
parents:
17730
diff
changeset
|
9426 deleted_lines(curbuf->b_ml.ml_line_count + 1, 1); |
817 | 9427 |
9428 /* If the cursor was in that line, move it to the end of the last | |
9429 * line. */ | |
9430 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
9431 { | |
9432 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
9433 coladvance((colnr_T)MAXCOL); | |
9434 } | |
9435 } | |
7 | 9436 auto_format(FALSE, TRUE); |
9437 } | |
9438 } | |
9439 | |
9440 /* | |
9441 * "o" and "O" commands. | |
9442 */ | |
9443 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9444 nv_open(cmdarg_T *cap) |
7 | 9445 { |
9446 #ifdef FEAT_DIFF | |
9447 /* "do" is ":diffget" */ | |
9448 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') | |
9449 { | |
9450 clearop(cap->oap); | |
6314 | 9451 nv_diffgetput(FALSE, cap->opcount); |
7 | 9452 } |
9453 else | |
9454 #endif | |
9455 if (VIsual_active) /* switch start and end of visual */ | |
9456 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
|
9457 #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
|
9458 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
|
9459 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
|
9460 #endif |
7 | 9461 else |
9462 n_opencmd(cap); | |
9463 } | |
9464 | |
9465 #ifdef FEAT_NETBEANS_INTG | |
9466 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9467 nv_nbcmd(cmdarg_T *cap) |
7 | 9468 { |
9469 netbeans_keycommand(cap->nchar); | |
9470 } | |
9471 #endif | |
9472 | |
9473 #ifdef FEAT_DND | |
9474 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9475 nv_drop(cmdarg_T *cap UNUSED) |
7 | 9476 { |
9477 do_put('~', BACKWARD, 1L, PUT_CURSEND); | |
9478 } | |
9479 #endif | |
203 | 9480 |
9481 /* | |
9482 * Trigger CursorHold event. | |
9483 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the | |
9484 * input buffer. "did_cursorhold" is set to avoid retriggering. | |
9485 */ | |
9486 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9487 nv_cursorhold(cmdarg_T *cap) |
203 | 9488 { |
9489 apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); | |
9490 did_cursorhold = TRUE; | |
226 | 9491 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
9492 } | |
6866 | 9493 |
9494 /* | |
7001 | 9495 * Calculate start/end virtual columns for operating in block mode. |
6866 | 9496 */ |
9497 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9498 get_op_vcol( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9499 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9500 colnr_T redo_VIsual_vcol, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9501 int initial) /* when TRUE adjust position for 'selectmode' */ |
6866 | 9502 { |
9503 colnr_T start, end; | |
9504 | |
7001 | 9505 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
|
9506 || (!initial && oap->end.col < curwin->w_width)) |
6866 | 9507 return; |
9508 | |
7143
fe6d525d12f4
commit https://github.com/vim/vim/commit/10ad1d90da8c464e1bf08bf23d92d4888378a8a1
Christian Brabandt <cb@256bit.org>
parents:
7090
diff
changeset
|
9509 oap->block_mode = TRUE; |
6866 | 9510 |
9511 /* prevent from moving onto a trail byte */ | |
9512 if (has_mbyte) | |
9513 mb_adjustpos(curwin->w_buffer, &oap->end); | |
9514 | |
9515 getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol); | |
6961 | 9516 |
9517 if (!redo_VIsual_busy) | |
9518 { | |
9519 getvvcol(curwin, &(oap->end), &start, NULL, &end); | |
9520 | |
9521 if (start < oap->start_vcol) | |
9522 oap->start_vcol = start; | |
9523 if (end > oap->end_vcol) | |
9524 { | |
9525 if (initial && *p_sel == 'e' && start >= 1 | |
9526 && start - 1 >= oap->end_vcol) | |
9527 oap->end_vcol = start - 1; | |
9528 else | |
9529 oap->end_vcol = end; | |
9530 } | |
9531 } | |
9532 | |
6866 | 9533 /* if '$' was used, get oap->end_vcol from longest line */ |
9534 if (curwin->w_curswant == MAXCOL) | |
9535 { | |
9536 curwin->w_cursor.col = MAXCOL; | |
9537 oap->end_vcol = 0; | |
9538 for (curwin->w_cursor.lnum = oap->start.lnum; | |
9539 curwin->w_cursor.lnum <= oap->end.lnum; | |
9540 ++curwin->w_cursor.lnum) | |
9541 { | |
9542 getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end); | |
9543 if (end > oap->end_vcol) | |
9544 oap->end_vcol = end; | |
9545 } | |
9546 } | |
9547 else if (redo_VIsual_busy) | |
9548 oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1; | |
9549 /* | |
9550 * Correct oap->end.col and oap->start.col to be the | |
9551 * upper-left and lower-right corner of the block area. | |
9552 * | |
9553 * (Actually, this does convert column positions into character | |
9554 * positions) | |
9555 */ | |
9556 curwin->w_cursor.lnum = oap->end.lnum; | |
9557 coladvance(oap->end_vcol); | |
9558 oap->end = curwin->w_cursor; | |
9559 | |
9560 curwin->w_cursor = oap->start; | |
9561 coladvance(oap->start_vcol); | |
9562 oap->start = curwin->w_cursor; | |
9563 } |