Mercurial > vim
annotate src/normal.c @ 13202:2941a86f8aaa v8.0.1475
patch 8.0.1475: invalid memory access in read_redo()
commit https://github.com/vim/vim/commit/f12519dec88251305793f1651f558d16506b4be2
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Feb 6 22:52:49 2018 +0100
patch 8.0.1475: invalid memory access in read_redo()
Problem: Invalid memory access in read_redo(). (gy741)
Solution: Convert the replacement character back from a negative number to
CR or NL. (hint by Dominique Pelle, closes #2616)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 06 Feb 2018 23:00:07 +0100 |
parents | 3dd37eec73f0 |
children | ac42c4b11dbc |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 /* | |
10 * normal.c: Contains the main routine for processing characters in command | |
11 * mode. Communicates closely with the code in ops.c to handle | |
12 * the operators. | |
13 */ | |
14 | |
15 #include "vim.h" | |
16 | |
17 /* | |
18 * The Visual area is remembered for reselection. | |
19 */ | |
20 static int resel_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ | |
21 static linenr_T resel_VIsual_line_count; /* number of lines */ | |
3125 | 22 static colnr_T resel_VIsual_vcol; /* nr of cols or end col */ |
5682 | 23 static int VIsual_mode_orig = NUL; /* saved Visual mode */ |
7 | 24 |
25 static int restart_VIsual_select = 0; | |
26 | |
2667 | 27 #ifdef FEAT_EVAL |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
28 static void set_vcount_ca(cmdarg_T *cap, int *set_prevcount); |
2667 | 29 #endif |
7 | 30 static int |
3531 | 31 #ifdef __BORLANDC__ |
32 _RTLENTRYF | |
33 #endif | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
34 nv_compare(const void *s1, const void *s2); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
35 static int find_command(int cmdchar); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
36 static void op_colon(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
37 static void op_function(oparg_T *oap); |
5735 | 38 #if defined(FEAT_MOUSE) |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
39 static void find_start_of_word(pos_T *); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
40 static void find_end_of_word(pos_T *); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
41 static int get_mouse_class(char_u *p); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
42 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
43 static void prep_redo_cmd(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
44 static void prep_redo(int regname, long, int, int, int, int, int); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
45 static int checkclearop(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
46 static int checkclearopq(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
47 static void clearop(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
48 static void clearopbeep(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
49 static void unshift_special(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
50 static void may_clear_cmdline(void); |
7 | 51 #ifdef FEAT_CMDL_INFO |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
52 static void del_from_showcmd(int); |
7 | 53 #endif |
54 | |
55 /* | |
56 * nv_*(): functions called to handle Normal and Visual mode commands. | |
57 * n_*(): functions called to handle Normal mode commands. | |
58 * v_*(): functions called to handle Visual mode commands. | |
59 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
60 static void nv_ignore(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
61 static void nv_nop(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
62 static void nv_error(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
63 static void nv_help(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
64 static void nv_addsub(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
65 static void nv_page(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
66 static void nv_gd(oparg_T *oap, int nchar, int thisblock); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
67 static int nv_screengo(oparg_T *oap, int dir, long dist); |
7 | 68 #ifdef FEAT_MOUSE |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
69 static void nv_mousescroll(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
70 static void nv_mouse(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
71 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
72 static void nv_scroll_line(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
73 static void nv_zet(cmdarg_T *cap); |
7 | 74 #ifdef FEAT_GUI |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
75 static void nv_ver_scrollbar(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
76 static void nv_hor_scrollbar(cmdarg_T *cap); |
7 | 77 #endif |
685 | 78 #ifdef FEAT_GUI_TABLINE |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
79 static void nv_tabline(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
80 static void nv_tabmenu(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
81 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
82 static void nv_exmode(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
83 static void nv_colon(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
84 static void nv_ctrlg(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
85 static void nv_ctrlh(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
86 static void nv_clear(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
87 static void nv_ctrlo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
88 static void nv_hat(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
89 static void nv_Zet(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
90 static void nv_ident(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
91 static void nv_tagpop(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
92 static void nv_scroll(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
93 static void nv_right(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
94 static void nv_left(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
95 static void nv_up(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
96 static void nv_down(cmdarg_T *cap); |
7 | 97 #ifdef FEAT_SEARCHPATH |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
98 static void nv_gotofile(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
99 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
100 static void nv_end(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
101 static void nv_dollar(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
102 static void nv_search(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
103 static void nv_next(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
104 static int normal_search(cmdarg_T *cap, int dir, char_u *pat, int opt); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
105 static void nv_csearch(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
106 static void nv_brackets(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
107 static void nv_percent(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
108 static void nv_brace(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
109 static void nv_mark(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
110 static void nv_findpar(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
111 static void nv_undo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
112 static void nv_kundo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
113 static void nv_Replace(cmdarg_T *cap); |
7 | 114 #ifdef FEAT_VREPLACE |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
115 static void nv_vreplace(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
116 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
117 static void v_swap_corners(int cmdchar); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
118 static void nv_replace(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
119 static void n_swapchar(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
120 static void nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
121 static void v_visop(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
122 static void nv_subst(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
123 static void nv_abbrev(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
124 static void nv_optrans(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
125 static void nv_gomark(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
126 static void nv_pcmark(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
127 static void nv_regname(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
128 static void nv_visual(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
129 static void n_start_visual_mode(int c); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
130 static void nv_window(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
131 static void nv_suspend(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
132 static void nv_g_cmd(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
133 static void n_opencmd(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
134 static void nv_dot(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
135 static void nv_redo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
136 static void nv_Undo(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
137 static void nv_tilde(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
138 static void nv_operator(cmdarg_T *cap); |
1490 | 139 #ifdef FEAT_EVAL |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
140 static void set_op_var(int optype); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
141 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
142 static void nv_lineop(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
143 static void nv_home(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
144 static void nv_pipe(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
145 static void nv_bck_word(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
146 static void nv_wordcmd(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
147 static void nv_beginline(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
148 static void adjust_cursor(oparg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
149 static void adjust_for_sel(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
150 static int unadjust_for_sel(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
151 static void nv_select(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
152 static void nv_goto(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
153 static void nv_normal(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
154 static void nv_esc(cmdarg_T *oap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
155 static void nv_edit(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
156 static void invoke_edit(cmdarg_T *cap, int repl, int cmd, int startln); |
7 | 157 #ifdef FEAT_TEXTOBJ |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
158 static void nv_object(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
159 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
160 static void nv_record(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
161 static void nv_at(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
162 static void nv_halfpage(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
163 static void nv_join(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
164 static void nv_put(cmdarg_T *cap); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
165 static void nv_open(cmdarg_T *cap); |
7 | 166 #ifdef FEAT_NETBEANS_INTG |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
167 static void nv_nbcmd(cmdarg_T *cap); |
7 | 168 #endif |
169 #ifdef FEAT_DND | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
170 static void nv_drop(cmdarg_T *cap); |
7 | 171 #endif |
203 | 172 #ifdef FEAT_AUTOCMD |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
173 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
|
174 #endif |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
175 static void get_op_vcol(oparg_T *oap, colnr_T col, int initial); |
7 | 176 |
1728 | 177 static char *e_noident = N_("E349: No identifier under cursor"); |
178 | |
7 | 179 /* |
180 * Function to be called for a Normal or Visual mode command. | |
181 * The argument is a cmdarg_T. | |
182 */ | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
183 typedef void (*nv_func_T)(cmdarg_T *cap); |
7 | 184 |
185 /* Values for cmd_flags. */ | |
186 #define NV_NCH 0x01 /* may need to get a second char */ | |
187 #define NV_NCH_NOP (0x02|NV_NCH) /* get second char when no operator pending */ | |
188 #define NV_NCH_ALW (0x04|NV_NCH) /* always get a second char */ | |
189 #define NV_LANG 0x08 /* second char needs language adjustment */ | |
190 | |
191 #define NV_SS 0x10 /* may start selection */ | |
192 #define NV_SSS 0x20 /* may start selection with shift modifier */ | |
193 #define NV_STS 0x40 /* may stop selection without shift modif. */ | |
194 #define NV_RL 0x80 /* 'rightleft' modifies command */ | |
195 #define NV_KEEPREG 0x100 /* don't clear regname */ | |
196 #define NV_NCW 0x200 /* not allowed in command-line window */ | |
197 | |
198 /* | |
199 * Generally speaking, every Normal mode command should either clear any | |
200 * pending operator (with *clearop*()), or set the motion type variable | |
201 * oap->motion_type. | |
202 * | |
203 * When a cursor motion command is made, it is marked as being a character or | |
204 * line oriented motion. Then, if an operator is in effect, the operation | |
205 * becomes character or line oriented accordingly. | |
206 */ | |
207 | |
208 /* | |
209 * This table contains one entry for every Normal or Visual mode command. | |
210 * The order doesn't matter, init_normal_cmds() will create a sorted index. | |
211 * It is faster when all keys from zero to '~' are present. | |
212 */ | |
213 static const struct nv_cmd | |
214 { | |
215 int cmd_char; /* (first) command character */ | |
216 nv_func_T cmd_func; /* function for this command */ | |
217 short_u cmd_flags; /* NV_ flags */ | |
218 short cmd_arg; /* value for ca.arg */ | |
219 } nv_cmds[] = | |
220 { | |
221 {NUL, nv_error, 0, 0}, | |
222 {Ctrl_A, nv_addsub, 0, 0}, | |
223 {Ctrl_B, nv_page, NV_STS, BACKWARD}, | |
224 {Ctrl_C, nv_esc, 0, TRUE}, | |
225 {Ctrl_D, nv_halfpage, 0, 0}, | |
226 {Ctrl_E, nv_scroll_line, 0, TRUE}, | |
227 {Ctrl_F, nv_page, NV_STS, FORWARD}, | |
228 {Ctrl_G, nv_ctrlg, 0, 0}, | |
229 {Ctrl_H, nv_ctrlh, 0, 0}, | |
230 {Ctrl_I, nv_pcmark, 0, 0}, | |
231 {NL, nv_down, 0, FALSE}, | |
232 {Ctrl_K, nv_error, 0, 0}, | |
233 {Ctrl_L, nv_clear, 0, 0}, | |
376 | 234 {Ctrl_M, nv_down, 0, TRUE}, |
7 | 235 {Ctrl_N, nv_down, NV_STS, FALSE}, |
236 {Ctrl_O, nv_ctrlo, 0, 0}, | |
237 {Ctrl_P, nv_up, NV_STS, FALSE}, | |
167 | 238 {Ctrl_Q, nv_visual, 0, FALSE}, |
7 | 239 {Ctrl_R, nv_redo, 0, 0}, |
240 {Ctrl_S, nv_ignore, 0, 0}, | |
241 {Ctrl_T, nv_tagpop, NV_NCW, 0}, | |
242 {Ctrl_U, nv_halfpage, 0, 0}, | |
243 {Ctrl_V, nv_visual, 0, FALSE}, | |
244 {'V', nv_visual, 0, FALSE}, | |
245 {'v', nv_visual, 0, FALSE}, | |
246 {Ctrl_W, nv_window, 0, 0}, | |
247 {Ctrl_X, nv_addsub, 0, 0}, | |
248 {Ctrl_Y, nv_scroll_line, 0, FALSE}, | |
249 {Ctrl_Z, nv_suspend, 0, 0}, | |
250 {ESC, nv_esc, 0, FALSE}, | |
251 {Ctrl_BSL, nv_normal, NV_NCH_ALW, 0}, | |
252 {Ctrl_RSB, nv_ident, NV_NCW, 0}, | |
253 {Ctrl_HAT, nv_hat, NV_NCW, 0}, | |
254 {Ctrl__, nv_error, 0, 0}, | |
255 {' ', nv_right, 0, 0}, | |
256 {'!', nv_operator, 0, 0}, | |
257 {'"', nv_regname, NV_NCH_NOP|NV_KEEPREG, 0}, | |
258 {'#', nv_ident, 0, 0}, | |
259 {'$', nv_dollar, 0, 0}, | |
260 {'%', nv_percent, 0, 0}, | |
261 {'&', nv_optrans, 0, 0}, | |
262 {'\'', nv_gomark, NV_NCH_ALW, TRUE}, | |
263 {'(', nv_brace, 0, BACKWARD}, | |
264 {')', nv_brace, 0, FORWARD}, | |
265 {'*', nv_ident, 0, 0}, | |
266 {'+', nv_down, 0, TRUE}, | |
267 {',', nv_csearch, 0, TRUE}, | |
268 {'-', nv_up, 0, TRUE}, | |
269 {'.', nv_dot, NV_KEEPREG, 0}, | |
270 {'/', nv_search, 0, FALSE}, | |
271 {'0', nv_beginline, 0, 0}, | |
272 {'1', nv_ignore, 0, 0}, | |
273 {'2', nv_ignore, 0, 0}, | |
274 {'3', nv_ignore, 0, 0}, | |
275 {'4', nv_ignore, 0, 0}, | |
276 {'5', nv_ignore, 0, 0}, | |
277 {'6', nv_ignore, 0, 0}, | |
278 {'7', nv_ignore, 0, 0}, | |
279 {'8', nv_ignore, 0, 0}, | |
280 {'9', nv_ignore, 0, 0}, | |
281 {':', nv_colon, 0, 0}, | |
282 {';', nv_csearch, 0, FALSE}, | |
283 {'<', nv_operator, NV_RL, 0}, | |
284 {'=', nv_operator, 0, 0}, | |
285 {'>', nv_operator, NV_RL, 0}, | |
286 {'?', nv_search, 0, FALSE}, | |
287 {'@', nv_at, NV_NCH_NOP, FALSE}, | |
288 {'A', nv_edit, 0, 0}, | |
289 {'B', nv_bck_word, 0, 1}, | |
290 {'C', nv_abbrev, NV_KEEPREG, 0}, | |
291 {'D', nv_abbrev, NV_KEEPREG, 0}, | |
292 {'E', nv_wordcmd, 0, TRUE}, | |
293 {'F', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
294 {'G', nv_goto, 0, TRUE}, | |
295 {'H', nv_scroll, 0, 0}, | |
296 {'I', nv_edit, 0, 0}, | |
297 {'J', nv_join, 0, 0}, | |
298 {'K', nv_ident, 0, 0}, | |
299 {'L', nv_scroll, 0, 0}, | |
300 {'M', nv_scroll, 0, 0}, | |
301 {'N', nv_next, 0, SEARCH_REV}, | |
302 {'O', nv_open, 0, 0}, | |
303 {'P', nv_put, 0, 0}, | |
304 {'Q', nv_exmode, NV_NCW, 0}, | |
305 {'R', nv_Replace, 0, FALSE}, | |
306 {'S', nv_subst, NV_KEEPREG, 0}, | |
307 {'T', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD}, | |
308 {'U', nv_Undo, 0, 0}, | |
309 {'W', nv_wordcmd, 0, TRUE}, | |
310 {'X', nv_abbrev, NV_KEEPREG, 0}, | |
311 {'Y', nv_abbrev, NV_KEEPREG, 0}, | |
312 {'Z', nv_Zet, NV_NCH_NOP|NV_NCW, 0}, | |
313 {'[', nv_brackets, NV_NCH_ALW, BACKWARD}, | |
314 {'\\', nv_error, 0, 0}, | |
315 {']', nv_brackets, NV_NCH_ALW, FORWARD}, | |
316 {'^', nv_beginline, 0, BL_WHITE | BL_FIX}, | |
317 {'_', nv_lineop, 0, 0}, | |
318 {'`', nv_gomark, NV_NCH_ALW, FALSE}, | |
319 {'a', nv_edit, NV_NCH, 0}, | |
320 {'b', nv_bck_word, 0, 0}, | |
321 {'c', nv_operator, 0, 0}, | |
322 {'d', nv_operator, 0, 0}, | |
323 {'e', nv_wordcmd, 0, FALSE}, | |
324 {'f', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
325 {'g', nv_g_cmd, NV_NCH_ALW, FALSE}, | |
326 {'h', nv_left, NV_RL, 0}, | |
327 {'i', nv_edit, NV_NCH, 0}, | |
328 {'j', nv_down, 0, FALSE}, | |
329 {'k', nv_up, 0, FALSE}, | |
330 {'l', nv_right, NV_RL, 0}, | |
331 {'m', nv_mark, NV_NCH_NOP, 0}, | |
332 {'n', nv_next, 0, 0}, | |
333 {'o', nv_open, 0, 0}, | |
334 {'p', nv_put, 0, 0}, | |
335 {'q', nv_record, NV_NCH, 0}, | |
336 {'r', nv_replace, NV_NCH_NOP|NV_LANG, 0}, | |
337 {'s', nv_subst, NV_KEEPREG, 0}, | |
338 {'t', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD}, | |
339 {'u', nv_undo, 0, 0}, | |
340 {'w', nv_wordcmd, 0, FALSE}, | |
341 {'x', nv_abbrev, NV_KEEPREG, 0}, | |
342 {'y', nv_operator, 0, 0}, | |
343 {'z', nv_zet, NV_NCH_ALW, 0}, | |
344 {'{', nv_findpar, 0, BACKWARD}, | |
345 {'|', nv_pipe, 0, 0}, | |
346 {'}', nv_findpar, 0, FORWARD}, | |
347 {'~', nv_tilde, 0, 0}, | |
348 | |
349 /* pound sign */ | |
350 {POUND, nv_ident, 0, 0}, | |
351 #ifdef FEAT_MOUSE | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
352 {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
|
353 {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
|
354 {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
|
355 {K_MOUSERIGHT, nv_mousescroll, 0, MSCR_RIGHT}, |
7 | 356 {K_LEFTMOUSE, nv_mouse, 0, 0}, |
357 {K_LEFTMOUSE_NM, nv_mouse, 0, 0}, | |
358 {K_LEFTDRAG, nv_mouse, 0, 0}, | |
359 {K_LEFTRELEASE, nv_mouse, 0, 0}, | |
360 {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
|
361 {K_MOUSEMOVE, nv_mouse, 0, 0}, |
7 | 362 {K_MIDDLEMOUSE, nv_mouse, 0, 0}, |
363 {K_MIDDLEDRAG, nv_mouse, 0, 0}, | |
364 {K_MIDDLERELEASE, nv_mouse, 0, 0}, | |
365 {K_RIGHTMOUSE, nv_mouse, 0, 0}, | |
366 {K_RIGHTDRAG, nv_mouse, 0, 0}, | |
367 {K_RIGHTRELEASE, nv_mouse, 0, 0}, | |
368 {K_X1MOUSE, nv_mouse, 0, 0}, | |
369 {K_X1DRAG, nv_mouse, 0, 0}, | |
370 {K_X1RELEASE, nv_mouse, 0, 0}, | |
371 {K_X2MOUSE, nv_mouse, 0, 0}, | |
372 {K_X2DRAG, nv_mouse, 0, 0}, | |
373 {K_X2RELEASE, nv_mouse, 0, 0}, | |
374 #endif | |
819 | 375 {K_IGNORE, nv_ignore, NV_KEEPREG, 0}, |
620 | 376 {K_NOP, nv_nop, 0, 0}, |
7 | 377 {K_INS, nv_edit, 0, 0}, |
378 {K_KINS, nv_edit, 0, 0}, | |
379 {K_BS, nv_ctrlh, 0, 0}, | |
380 {K_UP, nv_up, NV_SSS|NV_STS, FALSE}, | |
381 {K_S_UP, nv_page, NV_SS, BACKWARD}, | |
382 {K_DOWN, nv_down, NV_SSS|NV_STS, FALSE}, | |
383 {K_S_DOWN, nv_page, NV_SS, FORWARD}, | |
384 {K_LEFT, nv_left, NV_SSS|NV_STS|NV_RL, 0}, | |
385 {K_S_LEFT, nv_bck_word, NV_SS|NV_RL, 0}, | |
386 {K_C_LEFT, nv_bck_word, NV_SSS|NV_RL|NV_STS, 1}, | |
387 {K_RIGHT, nv_right, NV_SSS|NV_STS|NV_RL, 0}, | |
388 {K_S_RIGHT, nv_wordcmd, NV_SS|NV_RL, FALSE}, | |
389 {K_C_RIGHT, nv_wordcmd, NV_SSS|NV_RL|NV_STS, TRUE}, | |
390 {K_PAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
391 {K_KPAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD}, | |
392 {K_PAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
393 {K_KPAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD}, | |
394 {K_END, nv_end, NV_SSS|NV_STS, FALSE}, | |
395 {K_KEND, nv_end, NV_SSS|NV_STS, FALSE}, | |
396 {K_S_END, nv_end, NV_SS, FALSE}, | |
397 {K_C_END, nv_end, NV_SSS|NV_STS, TRUE}, | |
398 {K_HOME, nv_home, NV_SSS|NV_STS, 0}, | |
399 {K_KHOME, nv_home, NV_SSS|NV_STS, 0}, | |
400 {K_S_HOME, nv_home, NV_SS, 0}, | |
401 {K_C_HOME, nv_goto, NV_SSS|NV_STS, FALSE}, | |
402 {K_DEL, nv_abbrev, 0, 0}, | |
403 {K_KDEL, nv_abbrev, 0, 0}, | |
404 {K_UNDO, nv_kundo, 0, 0}, | |
405 {K_HELP, nv_help, NV_NCW, 0}, | |
406 {K_F1, nv_help, NV_NCW, 0}, | |
407 {K_XF1, nv_help, NV_NCW, 0}, | |
408 {K_SELECT, nv_select, 0, 0}, | |
409 #ifdef FEAT_GUI | |
410 {K_VER_SCROLLBAR, nv_ver_scrollbar, 0, 0}, | |
411 {K_HOR_SCROLLBAR, nv_hor_scrollbar, 0, 0}, | |
412 #endif | |
685 | 413 #ifdef FEAT_GUI_TABLINE |
414 {K_TABLINE, nv_tabline, 0, 0}, | |
686 | 415 {K_TABMENU, nv_tabmenu, 0, 0}, |
685 | 416 #endif |
7 | 417 #ifdef FEAT_FKMAP |
9399
43b8570abbec
commit https://github.com/vim/vim/commit/ee2615af64fdcee87d8e4b13b65356e77fbd969b
Christian Brabandt <cb@256bit.org>
parents:
9315
diff
changeset
|
418 {K_F8, farsi_f8, 0, 0}, |
43b8570abbec
commit https://github.com/vim/vim/commit/ee2615af64fdcee87d8e4b13b65356e77fbd969b
Christian Brabandt <cb@256bit.org>
parents:
9315
diff
changeset
|
419 {K_F9, farsi_f9, 0, 0}, |
7 | 420 #endif |
421 #ifdef FEAT_NETBEANS_INTG | |
422 {K_F21, nv_nbcmd, NV_NCH_ALW, 0}, | |
423 #endif | |
424 #ifdef FEAT_DND | |
425 {K_DROP, nv_drop, NV_STS, 0}, | |
426 #endif | |
203 | 427 #ifdef FEAT_AUTOCMD |
819 | 428 {K_CURSORHOLD, nv_cursorhold, NV_KEEPREG, 0}, |
203 | 429 #endif |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
430 {K_PS, nv_edit, 0, 0}, |
7 | 431 }; |
432 | |
433 /* Number of commands in nv_cmds[]. */ | |
434 #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd)) | |
435 | |
436 /* Sorted index of commands in nv_cmds[]. */ | |
437 static short nv_cmd_idx[NV_CMDS_SIZE]; | |
438 | |
439 /* The highest index for which | |
440 * nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] */ | |
441 static int nv_max_linear; | |
442 | |
443 /* | |
444 * Compare functions for qsort() below, that checks the command character | |
445 * through the index in nv_cmd_idx[]. | |
446 */ | |
447 static int | |
448 #ifdef __BORLANDC__ | |
449 _RTLENTRYF | |
450 #endif | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
451 nv_compare(const void *s1, const void *s2) |
7 | 452 { |
453 int c1, c2; | |
454 | |
455 /* The commands are sorted on absolute value. */ | |
456 c1 = nv_cmds[*(const short *)s1].cmd_char; | |
457 c2 = nv_cmds[*(const short *)s2].cmd_char; | |
458 if (c1 < 0) | |
459 c1 = -c1; | |
460 if (c2 < 0) | |
461 c2 = -c2; | |
462 return c1 - c2; | |
463 } | |
464 | |
465 /* | |
466 * Initialize the nv_cmd_idx[] table. | |
467 */ | |
468 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
469 init_normal_cmds(void) |
7 | 470 { |
471 int i; | |
472 | |
473 /* Fill the index table with a one to one relation. */ | |
1877 | 474 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 475 nv_cmd_idx[i] = i; |
476 | |
477 /* Sort the commands by the command character. */ | |
478 qsort((void *)&nv_cmd_idx, (size_t)NV_CMDS_SIZE, sizeof(short), nv_compare); | |
479 | |
480 /* Find the first entry that can't be indexed by the command character. */ | |
1877 | 481 for (i = 0; i < (int)NV_CMDS_SIZE; ++i) |
7 | 482 if (i != nv_cmds[nv_cmd_idx[i]].cmd_char) |
483 break; | |
484 nv_max_linear = i - 1; | |
485 } | |
486 | |
487 /* | |
488 * Search for a command in the commands table. | |
489 * Returns -1 for invalid command. | |
490 */ | |
491 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
492 find_command(int cmdchar) |
7 | 493 { |
494 int i; | |
495 int idx; | |
496 int top, bot; | |
497 int c; | |
498 | |
499 #ifdef FEAT_MBYTE | |
500 /* A multi-byte character is never a command. */ | |
501 if (cmdchar >= 0x100) | |
502 return -1; | |
503 #endif | |
504 | |
505 /* We use the absolute value of the character. Special keys have a | |
506 * negative value, but are sorted on their absolute value. */ | |
507 if (cmdchar < 0) | |
508 cmdchar = -cmdchar; | |
509 | |
510 /* If the character is in the first part: The character is the index into | |
511 * nv_cmd_idx[]. */ | |
512 if (cmdchar <= nv_max_linear) | |
513 return nv_cmd_idx[cmdchar]; | |
514 | |
515 /* Perform a binary search. */ | |
516 bot = nv_max_linear + 1; | |
517 top = NV_CMDS_SIZE - 1; | |
518 idx = -1; | |
519 while (bot <= top) | |
520 { | |
521 i = (top + bot) / 2; | |
522 c = nv_cmds[nv_cmd_idx[i]].cmd_char; | |
523 if (c < 0) | |
524 c = -c; | |
525 if (cmdchar == c) | |
526 { | |
527 idx = nv_cmd_idx[i]; | |
528 break; | |
529 } | |
530 if (cmdchar > c) | |
531 bot = i + 1; | |
532 else | |
533 top = i - 1; | |
534 } | |
535 return idx; | |
536 } | |
537 | |
538 /* | |
539 * Execute a command in Normal mode. | |
540 */ | |
541 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
542 normal_cmd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
543 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
544 int toplevel UNUSED) /* TRUE when called from main() */ |
7 | 545 { |
546 cmdarg_T ca; /* command arguments */ | |
547 int c; | |
548 int ctrl_w = FALSE; /* got CTRL-W command */ | |
549 int old_col = curwin->w_curswant; | |
550 #ifdef FEAT_CMDL_INFO | |
551 int need_flushbuf; /* need to call out_flush() */ | |
552 #endif | |
553 pos_T old_pos; /* cursor position before command */ | |
554 int mapped_len; | |
555 static int old_mapped_len = 0; | |
556 int idx; | |
1751 | 557 #ifdef FEAT_EVAL |
558 int set_prevcount = FALSE; | |
559 #endif | |
7 | 560 |
561 vim_memset(&ca, 0, sizeof(ca)); /* also resets ca.retval */ | |
562 ca.oap = oap; | |
1692 | 563 |
564 /* Use a count remembered from before entering an operator. After typing | |
565 * "3d" we return from normal_cmd() and come back here, the "3" is | |
566 * remembered in "opcount". */ | |
7 | 567 ca.opcount = opcount; |
568 | |
569 /* | |
570 * If there is an operator pending, then the command we take this time | |
571 * will terminate it. Finish_op tells us to finish the operation before | |
572 * returning this time (unless the operation was cancelled). | |
573 */ | |
574 #ifdef CURSOR_SHAPE | |
575 c = finish_op; | |
576 #endif | |
577 finish_op = (oap->op_type != OP_NOP); | |
578 #ifdef CURSOR_SHAPE | |
579 if (finish_op != c) | |
580 { | |
581 ui_cursor_shape(); /* may show different cursor shape */ | |
582 # ifdef FEAT_MOUSESHAPE | |
583 update_mouseshape(-1); | |
584 # endif | |
585 } | |
586 #endif | |
587 | |
1692 | 588 /* When not finishing an operator and no register name typed, reset the |
589 * count. */ | |
7 | 590 if (!finish_op && !oap->regname) |
1751 | 591 { |
7 | 592 ca.opcount = 0; |
1751 | 593 #ifdef FEAT_EVAL |
594 set_prevcount = TRUE; | |
595 #endif | |
596 } | |
7 | 597 |
1692 | 598 #ifdef FEAT_AUTOCMD |
599 /* Restore counts from before receiving K_CURSORHOLD. This means after | |
600 * typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not | |
601 * "3 * 2". */ | |
602 if (oap->prev_opcount > 0 || oap->prev_count0 > 0) | |
603 { | |
604 ca.opcount = oap->prev_opcount; | |
605 ca.count0 = oap->prev_count0; | |
606 oap->prev_opcount = 0; | |
607 oap->prev_count0 = 0; | |
608 } | |
609 #endif | |
610 | |
7 | 611 mapped_len = typebuf_maplen(); |
612 | |
613 State = NORMAL_BUSY; | |
614 #ifdef USE_ON_FLY_SCROLL | |
615 dont_scroll = FALSE; /* allow scrolling here */ | |
616 #endif | |
617 | |
2667 | 618 #ifdef FEAT_EVAL |
619 /* Set v:count here, when called from main() and not a stuffed | |
620 * command, so that v:count can be used in an expression mapping | |
5649 | 621 * when there is no count. Do set it for redo. */ |
622 if (toplevel && readbuf1_empty()) | |
2667 | 623 set_vcount_ca(&ca, &set_prevcount); |
624 #endif | |
625 | |
7 | 626 /* |
627 * Get the command character from the user. | |
628 */ | |
629 c = safe_vgetc(); | |
7703
39251e981d1f
commit https://github.com/vim/vim/commit/25281634cda03ce302aaf9f906a9520b5f81f91e
Christian Brabandt <cb@256bit.org>
parents:
7578
diff
changeset
|
630 LANGMAP_ADJUST(c, get_real_state() != SELECTMODE); |
7 | 631 |
632 /* | |
633 * If a mapping was started in Visual or Select mode, remember the length | |
634 * of the mapping. This is used below to not return to Insert mode for as | |
635 * long as the mapping is being executed. | |
636 */ | |
637 if (restart_edit == 0) | |
638 old_mapped_len = 0; | |
639 else if (old_mapped_len | |
819 | 640 || (VIsual_active && mapped_len == 0 && typebuf_maplen() > 0)) |
7 | 641 old_mapped_len = typebuf_maplen(); |
642 | |
643 if (c == NUL) | |
644 c = K_ZERO; | |
645 | |
646 /* | |
647 * In Select mode, typed text replaces the selection. | |
648 */ | |
649 if (VIsual_active | |
650 && VIsual_select | |
651 && (vim_isprintc(c) || c == NL || c == CAR || c == K_KENTER)) | |
652 { | |
275 | 653 /* Fake a "c"hange command. When "restart_edit" is set (e.g., because |
654 * 'insertmode' is set) fake a "d"elete command, Insert mode will | |
655 * restart automatically. | |
1051 | 656 * Insert the typed character in the typeahead buffer, so that it can |
657 * be mapped in Insert mode. Required for ":lmap" to work. */ | |
852 | 658 ins_char_typebuf(c); |
275 | 659 if (restart_edit != 0) |
660 c = 'd'; | |
661 else | |
662 c = 'c'; | |
695 | 663 msg_nowait = TRUE; /* don't delay going to insert mode */ |
4472 | 664 old_mapped_len = 0; /* do go to Insert mode */ |
7 | 665 } |
666 | |
667 #ifdef FEAT_CMDL_INFO | |
668 need_flushbuf = add_to_showcmd(c); | |
669 #endif | |
670 | |
671 getcount: | |
672 if (!(VIsual_active && VIsual_select)) | |
673 { | |
674 /* | |
675 * Handle a count before a command and compute ca.count0. | |
676 * Note that '0' is a command and not the start of a count, but it's | |
677 * part of a count after other digits. | |
678 */ | |
679 while ( (c >= '1' && c <= '9') | |
680 || (ca.count0 != 0 && (c == K_DEL || c == K_KDEL || c == '0'))) | |
681 { | |
682 if (c == K_DEL || c == K_KDEL) | |
683 { | |
684 ca.count0 /= 10; | |
685 #ifdef FEAT_CMDL_INFO | |
686 del_from_showcmd(4); /* delete the digit and ~@% */ | |
687 #endif | |
688 } | |
689 else | |
690 ca.count0 = ca.count0 * 10 + (c - '0'); | |
691 if (ca.count0 < 0) /* got too large! */ | |
692 ca.count0 = 999999999L; | |
1425 | 693 #ifdef FEAT_EVAL |
694 /* Set v:count here, when called from main() and not a stuffed | |
695 * command, so that v:count can be used in an expression mapping | |
5649 | 696 * right after the count. Do set it for redo. */ |
697 if (toplevel && readbuf1_empty()) | |
2667 | 698 set_vcount_ca(&ca, &set_prevcount); |
1425 | 699 #endif |
7 | 700 if (ctrl_w) |
701 { | |
702 ++no_mapping; | |
703 ++allow_keys; /* no mapping for nchar, but keys */ | |
704 } | |
705 ++no_zero_mapping; /* don't map zero here */ | |
1389 | 706 c = plain_vgetc(); |
7 | 707 LANGMAP_ADJUST(c, TRUE); |
708 --no_zero_mapping; | |
709 if (ctrl_w) | |
710 { | |
711 --no_mapping; | |
712 --allow_keys; | |
713 } | |
714 #ifdef FEAT_CMDL_INFO | |
715 need_flushbuf |= add_to_showcmd(c); | |
716 #endif | |
717 } | |
718 | |
719 /* | |
720 * If we got CTRL-W there may be a/another count | |
721 */ | |
722 if (c == Ctrl_W && !ctrl_w && oap->op_type == OP_NOP) | |
723 { | |
724 ctrl_w = TRUE; | |
725 ca.opcount = ca.count0; /* remember first count */ | |
726 ca.count0 = 0; | |
727 ++no_mapping; | |
728 ++allow_keys; /* no mapping for nchar, but keys */ | |
1389 | 729 c = plain_vgetc(); /* get next character */ |
7 | 730 LANGMAP_ADJUST(c, TRUE); |
731 --no_mapping; | |
732 --allow_keys; | |
733 #ifdef FEAT_CMDL_INFO | |
734 need_flushbuf |= add_to_showcmd(c); | |
735 #endif | |
736 goto getcount; /* jump back */ | |
737 } | |
738 } | |
739 | |
1692 | 740 #ifdef FEAT_AUTOCMD |
741 if (c == K_CURSORHOLD) | |
742 { | |
743 /* Save the count values so that ca.opcount and ca.count0 are exactly | |
744 * the same when coming back here after handling K_CURSORHOLD. */ | |
745 oap->prev_opcount = ca.opcount; | |
746 oap->prev_count0 = ca.count0; | |
747 } | |
748 else | |
749 #endif | |
750 if (ca.opcount != 0) | |
751 { | |
752 /* | |
753 * If we're in the middle of an operator (including after entering a | |
754 * yank buffer with '"') AND we had a count before the operator, then | |
755 * that count overrides the current value of ca.count0. | |
756 * What this means effectively, is that commands like "3dw" get turned | |
757 * into "d3w" which makes things fall into place pretty neatly. | |
758 * If you give a count before AND after the operator, they are | |
759 * multiplied. | |
760 */ | |
7 | 761 if (ca.count0) |
762 ca.count0 *= ca.opcount; | |
763 else | |
764 ca.count0 = ca.opcount; | |
765 } | |
766 | |
767 /* | |
768 * Always remember the count. It will be set to zero (on the next call, | |
769 * above) when there is no pending operator. | |
770 * When called from main(), save the count for use by the "count" built-in | |
771 * variable. | |
772 */ | |
773 ca.opcount = ca.count0; | |
774 ca.count1 = (ca.count0 == 0 ? 1 : ca.count0); | |
775 | |
776 #ifdef FEAT_EVAL | |
777 /* | |
778 * Only set v:count when called from main() and not a stuffed command. | |
5649 | 779 * Do set it for redo. |
7 | 780 */ |
5649 | 781 if (toplevel && readbuf1_empty()) |
1751 | 782 set_vcount(ca.count0, ca.count1, set_prevcount); |
7 | 783 #endif |
784 | |
785 /* | |
786 * Find the command character in the table of commands. | |
787 * For CTRL-W we already got nchar when looking for a count. | |
788 */ | |
789 if (ctrl_w) | |
790 { | |
791 ca.nchar = c; | |
792 ca.cmdchar = Ctrl_W; | |
793 } | |
794 else | |
795 ca.cmdchar = c; | |
796 idx = find_command(ca.cmdchar); | |
797 if (idx < 0) | |
798 { | |
799 /* Not a known command: beep. */ | |
800 clearopbeep(oap); | |
801 goto normal_end; | |
802 } | |
631 | 803 |
633 | 804 if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW)) |
631 | 805 { |
5848 | 806 /* This command is not allowed while editing a cmdline: beep. */ |
7 | 807 clearopbeep(oap); |
633 | 808 text_locked_msg(); |
7 | 809 goto normal_end; |
810 } | |
819 | 811 #ifdef FEAT_AUTOCMD |
812 if ((nv_cmds[idx].cmd_flags & NV_NCW) && curbuf_locked()) | |
813 goto normal_end; | |
814 #endif | |
7 | 815 |
816 /* | |
817 * In Visual/Select mode, a few keys are handled in a special way. | |
818 */ | |
819 if (VIsual_active) | |
820 { | |
821 /* when 'keymodel' contains "stopsel" may stop Select/Visual mode */ | |
822 if (km_stopsel | |
823 && (nv_cmds[idx].cmd_flags & NV_STS) | |
824 && !(mod_mask & MOD_MASK_SHIFT)) | |
825 { | |
826 end_visual_mode(); | |
827 redraw_curbuf_later(INVERTED); | |
828 } | |
829 | |
830 /* Keys that work different when 'keymodel' contains "startsel" */ | |
831 if (km_startsel) | |
832 { | |
833 if (nv_cmds[idx].cmd_flags & NV_SS) | |
834 { | |
835 unshift_special(&ca); | |
836 idx = find_command(ca.cmdchar); | |
840 | 837 if (idx < 0) |
838 { | |
839 /* Just in case */ | |
840 clearopbeep(oap); | |
841 goto normal_end; | |
842 } | |
7 | 843 } |
844 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
845 && (mod_mask & MOD_MASK_SHIFT)) | |
846 { | |
847 mod_mask &= ~MOD_MASK_SHIFT; | |
848 } | |
849 } | |
850 } | |
851 | |
852 #ifdef FEAT_RIGHTLEFT | |
853 if (curwin->w_p_rl && KeyTyped && !KeyStuffed | |
854 && (nv_cmds[idx].cmd_flags & NV_RL)) | |
855 { | |
856 /* Invert horizontal movements and operations. Only when typed by the | |
857 * user directly, not when the result of a mapping or "x" translated | |
858 * to "dl". */ | |
859 switch (ca.cmdchar) | |
860 { | |
861 case 'l': ca.cmdchar = 'h'; break; | |
862 case K_RIGHT: ca.cmdchar = K_LEFT; break; | |
863 case K_S_RIGHT: ca.cmdchar = K_S_LEFT; break; | |
864 case K_C_RIGHT: ca.cmdchar = K_C_LEFT; break; | |
865 case 'h': ca.cmdchar = 'l'; break; | |
866 case K_LEFT: ca.cmdchar = K_RIGHT; break; | |
867 case K_S_LEFT: ca.cmdchar = K_S_RIGHT; break; | |
868 case K_C_LEFT: ca.cmdchar = K_C_RIGHT; break; | |
869 case '>': ca.cmdchar = '<'; break; | |
870 case '<': ca.cmdchar = '>'; break; | |
871 } | |
872 idx = find_command(ca.cmdchar); | |
873 } | |
874 #endif | |
875 | |
876 /* | |
877 * Get an additional character if we need one. | |
878 */ | |
879 if ((nv_cmds[idx].cmd_flags & NV_NCH) | |
880 && (((nv_cmds[idx].cmd_flags & NV_NCH_NOP) == NV_NCH_NOP | |
881 && oap->op_type == OP_NOP) | |
882 || (nv_cmds[idx].cmd_flags & NV_NCH_ALW) == NV_NCH_ALW | |
883 || (ca.cmdchar == 'q' | |
884 && oap->op_type == OP_NOP | |
885 && !Recording | |
886 && !Exec_reg) | |
887 || ((ca.cmdchar == 'a' || ca.cmdchar == 'i') | |
5735 | 888 && (oap->op_type != OP_NOP || VIsual_active)))) |
7 | 889 { |
890 int *cp; | |
891 int repl = FALSE; /* get character for replace mode */ | |
892 int lit = FALSE; /* get extra character literally */ | |
893 int langmap_active = FALSE; /* using :lmap mappings */ | |
894 int lang; /* getting a text character */ | |
12924
85a601f985ab
patch 8.0.1338: USE_IM_CONTROL is confusing and incomplete
Christian Brabandt <cb@256bit.org>
parents:
12893
diff
changeset
|
895 #ifdef FEAT_MBYTE |
7 | 896 int save_smd; /* saved value of p_smd */ |
897 #endif | |
898 | |
899 ++no_mapping; | |
900 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1343 | 901 #ifdef FEAT_AUTOCMD |
902 /* Don't generate a CursorHold event here, most commands can't handle | |
903 * it, e.g., nv_replace(), nv_csearch(). */ | |
904 did_cursorhold = TRUE; | |
905 #endif | |
7 | 906 if (ca.cmdchar == 'g') |
907 { | |
908 /* | |
909 * For 'g' get the next character now, so that we can check for | |
910 * "gr", "g'" and "g`". | |
911 */ | |
1389 | 912 ca.nchar = plain_vgetc(); |
7 | 913 LANGMAP_ADJUST(ca.nchar, TRUE); |
914 #ifdef FEAT_CMDL_INFO | |
915 need_flushbuf |= add_to_showcmd(ca.nchar); | |
916 #endif | |
917 if (ca.nchar == 'r' || ca.nchar == '\'' || ca.nchar == '`' | |
5523 | 918 || ca.nchar == Ctrl_BSL) |
7 | 919 { |
920 cp = &ca.extra_char; /* need to get a third character */ | |
921 if (ca.nchar != 'r') | |
922 lit = TRUE; /* get it literally */ | |
923 else | |
924 repl = TRUE; /* get it in replace mode */ | |
925 } | |
926 else | |
927 cp = NULL; /* no third character needed */ | |
928 } | |
929 else | |
930 { | |
931 if (ca.cmdchar == 'r') /* get it in replace mode */ | |
932 repl = TRUE; | |
933 cp = &ca.nchar; | |
934 } | |
935 lang = (repl || (nv_cmds[idx].cmd_flags & NV_LANG)); | |
936 | |
937 /* | |
938 * Get a second or third character. | |
939 */ | |
940 if (cp != NULL) | |
941 { | |
942 #ifdef CURSOR_SHAPE | |
943 if (repl) | |
944 { | |
945 State = REPLACE; /* pretend Replace mode */ | |
946 ui_cursor_shape(); /* show different cursor shape */ | |
947 } | |
948 #endif | |
949 if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP) | |
950 { | |
951 /* Allow mappings defined with ":lmap". */ | |
952 --no_mapping; | |
953 --allow_keys; | |
954 if (repl) | |
955 State = LREPLACE; | |
956 else | |
957 State = LANGMAP; | |
958 langmap_active = TRUE; | |
959 } | |
12924
85a601f985ab
patch 8.0.1338: USE_IM_CONTROL is confusing and incomplete
Christian Brabandt <cb@256bit.org>
parents:
12893
diff
changeset
|
960 #ifdef FEAT_MBYTE |
7 | 961 save_smd = p_smd; |
962 p_smd = FALSE; /* Don't let the IM code show the mode here */ | |
963 if (lang && curbuf->b_p_iminsert == B_IMODE_IM) | |
964 im_set_active(TRUE); | |
965 #endif | |
966 | |
1389 | 967 *cp = plain_vgetc(); |
7 | 968 |
969 if (langmap_active) | |
970 { | |
971 /* Undo the decrement done above */ | |
972 ++no_mapping; | |
973 ++allow_keys; | |
974 State = NORMAL_BUSY; | |
975 } | |
12924
85a601f985ab
patch 8.0.1338: USE_IM_CONTROL is confusing and incomplete
Christian Brabandt <cb@256bit.org>
parents:
12893
diff
changeset
|
976 #ifdef FEAT_MBYTE |
7 | 977 if (lang) |
978 { | |
979 if (curbuf->b_p_iminsert != B_IMODE_LMAP) | |
980 im_save_status(&curbuf->b_p_iminsert); | |
981 im_set_active(FALSE); | |
982 } | |
983 p_smd = save_smd; | |
984 #endif | |
985 #ifdef CURSOR_SHAPE | |
986 State = NORMAL_BUSY; | |
987 #endif | |
988 #ifdef FEAT_CMDL_INFO | |
989 need_flushbuf |= add_to_showcmd(*cp); | |
990 #endif | |
991 | |
992 if (!lit) | |
993 { | |
994 #ifdef FEAT_DIGRAPHS | |
995 /* Typing CTRL-K gets a digraph. */ | |
996 if (*cp == Ctrl_K | |
997 && ((nv_cmds[idx].cmd_flags & NV_LANG) | |
998 || cp == &ca.extra_char) | |
999 && vim_strchr(p_cpo, CPO_DIGRAPH) == NULL) | |
1000 { | |
1001 c = get_digraph(FALSE); | |
1002 if (c > 0) | |
1003 { | |
1004 *cp = c; | |
1005 # ifdef FEAT_CMDL_INFO | |
1006 /* Guessing how to update showcmd here... */ | |
1007 del_from_showcmd(3); | |
1008 need_flushbuf |= add_to_showcmd(*cp); | |
1009 # endif | |
1010 } | |
1011 } | |
1012 #endif | |
1013 | |
1014 /* adjust chars > 127, except after "tTfFr" commands */ | |
1015 LANGMAP_ADJUST(*cp, !lang); | |
1016 #ifdef FEAT_RIGHTLEFT | |
1017 /* adjust Hebrew mapped char */ | |
1018 if (p_hkmap && lang && KeyTyped) | |
1019 *cp = hkmap(*cp); | |
1020 # ifdef FEAT_FKMAP | |
1021 /* adjust Farsi mapped char */ | |
1022 if (p_fkmap && lang && KeyTyped) | |
1023 *cp = fkmap(*cp); | |
1024 # endif | |
1025 #endif | |
1026 } | |
1027 | |
1028 /* | |
1029 * When the next character is CTRL-\ a following CTRL-N means the | |
1030 * command is aborted and we go to Normal mode. | |
1031 */ | |
1032 if (cp == &ca.extra_char | |
1033 && ca.nchar == Ctrl_BSL | |
1034 && (ca.extra_char == Ctrl_N || ca.extra_char == Ctrl_G)) | |
1035 { | |
1036 ca.cmdchar = Ctrl_BSL; | |
1037 ca.nchar = ca.extra_char; | |
1038 idx = find_command(ca.cmdchar); | |
1039 } | |
3908 | 1040 else if ((ca.nchar == 'n' || ca.nchar == 'N') && ca.cmdchar == 'g') |
3896 | 1041 ca.oap->op_type = get_op_type(*cp, NUL); |
7 | 1042 else if (*cp == Ctrl_BSL) |
1043 { | |
1044 long towait = (p_ttm >= 0 ? p_ttm : p_tm); | |
1045 | |
1046 /* There is a busy wait here when typing "f<C-\>" and then | |
1047 * something different from CTRL-N. Can't be avoided. */ | |
1048 while ((c = vpeekc()) <= 0 && towait > 0L) | |
1049 { | |
1050 do_sleep(towait > 50L ? 50L : towait); | |
1051 towait -= 50L; | |
1052 } | |
1053 if (c > 0) | |
1054 { | |
1389 | 1055 c = plain_vgetc(); |
7 | 1056 if (c != Ctrl_N && c != Ctrl_G) |
1057 vungetc(c); | |
1058 else | |
1059 { | |
1060 ca.cmdchar = Ctrl_BSL; | |
1061 ca.nchar = c; | |
1062 idx = find_command(ca.cmdchar); | |
1063 } | |
1064 } | |
1065 } | |
1066 | |
1067 #ifdef FEAT_MBYTE | |
1068 /* When getting a text character and the next character is a | |
1069 * multi-byte character, it could be a composing character. | |
6071 | 1070 * However, don't wait for it to arrive. Also, do enable mapping, |
1071 * because if it's put back with vungetc() it's too late to apply | |
1072 * mapping. */ | |
1073 --no_mapping; | |
7 | 1074 while (enc_utf8 && lang && (c = vpeekc()) > 0 |
1075 && (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1)) | |
1076 { | |
1389 | 1077 c = plain_vgetc(); |
7 | 1078 if (!utf_iscomposing(c)) |
1079 { | |
1080 vungetc(c); /* it wasn't, put it back */ | |
1081 break; | |
1082 } | |
1083 else if (ca.ncharC1 == 0) | |
1084 ca.ncharC1 = c; | |
1085 else | |
1086 ca.ncharC2 = c; | |
1087 } | |
6071 | 1088 ++no_mapping; |
7 | 1089 #endif |
1090 } | |
1091 --no_mapping; | |
1092 --allow_keys; | |
1093 } | |
1094 | |
1095 #ifdef FEAT_CMDL_INFO | |
1096 /* | |
1097 * Flush the showcmd characters onto the screen so we can see them while | |
1098 * the command is being executed. Only do this when the shown command was | |
1099 * actually displayed, otherwise this will slow down a lot when executing | |
1100 * mappings. | |
1101 */ | |
1102 if (need_flushbuf) | |
1103 out_flush(); | |
1104 #endif | |
203 | 1105 #ifdef FEAT_AUTOCMD |
1727 | 1106 if (ca.cmdchar != K_IGNORE) |
1107 did_cursorhold = FALSE; | |
203 | 1108 #endif |
7 | 1109 |
1110 State = NORMAL; | |
1111 | |
1112 if (ca.nchar == ESC) | |
1113 { | |
1114 clearop(oap); | |
1115 if (restart_edit == 0 && goto_im()) | |
1116 restart_edit = 'a'; | |
1117 goto normal_end; | |
1118 } | |
1119 | |
24 | 1120 if (ca.cmdchar != K_IGNORE) |
1121 { | |
1122 msg_didout = FALSE; /* don't scroll screen up for normal command */ | |
1123 msg_col = 0; | |
1124 } | |
7 | 1125 |
1126 old_pos = curwin->w_cursor; /* remember where cursor was */ | |
1127 | |
1128 /* When 'keymodel' contains "startsel" some keys start Select/Visual | |
1129 * mode. */ | |
1130 if (!VIsual_active && km_startsel) | |
1131 { | |
1132 if (nv_cmds[idx].cmd_flags & NV_SS) | |
1133 { | |
1134 start_selection(); | |
1135 unshift_special(&ca); | |
1136 idx = find_command(ca.cmdchar); | |
1137 } | |
1138 else if ((nv_cmds[idx].cmd_flags & NV_SSS) | |
1139 && (mod_mask & MOD_MASK_SHIFT)) | |
1140 { | |
1141 start_selection(); | |
1142 mod_mask &= ~MOD_MASK_SHIFT; | |
1143 } | |
1144 } | |
1145 | |
1146 /* | |
1147 * Execute the command! | |
1148 * Call the command function found in the commands table. | |
1149 */ | |
1150 ca.arg = nv_cmds[idx].cmd_arg; | |
1151 (nv_cmds[idx].cmd_func)(&ca); | |
1152 | |
1153 /* | |
1154 * If we didn't start or finish an operator, reset oap->regname, unless we | |
1155 * need it later. | |
1156 */ | |
1157 if (!finish_op | |
1158 && !oap->op_type | |
1159 && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) | |
1160 { | |
1161 clearop(oap); | |
1162 #ifdef FEAT_EVAL | |
2821 | 1163 { |
1164 int regname = 0; | |
2829 | 1165 |
2821 | 1166 /* Adjust the register according to 'clipboard', so that when |
1167 * "unnamed" is present it becomes '*' or '+' instead of '"'. */ | |
2829 | 1168 # ifdef FEAT_CLIPBOARD |
2821 | 1169 adjust_clip_reg(®name); |
2829 | 1170 # endif |
2821 | 1171 set_reg_var(regname); |
1172 } | |
7 | 1173 #endif |
1174 } | |
1175 | |
570 | 1176 /* Get the length of mapped chars again after typing a count, second |
36 | 1177 * character or "z333<cr>". */ |
1178 if (old_mapped_len > 0) | |
1179 old_mapped_len = typebuf_maplen(); | |
1180 | |
7 | 1181 /* |
1182 * If an operation is pending, handle it... | |
1183 */ | |
1184 do_pending_operator(&ca, old_col, FALSE); | |
1185 | |
1186 /* | |
1187 * Wait for a moment when a message is displayed that will be overwritten | |
1188 * by the mode message. | |
1189 * In Visual mode and with "^O" in Insert mode, a short message will be | |
1190 * overwritten by the mode message. Wait a bit, until a key is hit. | |
1191 * In Visual mode, it's more important to keep the Visual area updated | |
1192 * than keeping a message (e.g. from a /pat search). | |
1193 * Only do this if the command was typed, not from a mapping. | |
1194 * Don't wait when emsg_silent is non-zero. | |
1195 * Also wait a bit after an error message, e.g. for "^O:". | |
1196 * Don't redraw the screen, it would remove the message. | |
1197 */ | |
1198 if ( ((p_smd | |
641 | 1199 && msg_silent == 0 |
7 | 1200 && (restart_edit != 0 |
1201 || (VIsual_active | |
1202 && old_pos.lnum == curwin->w_cursor.lnum | |
1203 && old_pos.col == curwin->w_cursor.col) | |
1204 ) | |
1205 && (clear_cmdline | |
1206 || redraw_cmdline) | |
1207 && (msg_didout || (msg_didany && msg_scroll)) | |
1208 && !msg_nowait | |
1209 && KeyTyped) | |
1210 || (restart_edit != 0 | |
1211 && !VIsual_active | |
1212 && (msg_scroll | |
1213 || emsg_on_display))) | |
1214 && oap->regname == 0 | |
1215 && !(ca.retval & CA_COMMAND_BUSY) | |
1216 && stuff_empty() | |
1217 && typebuf_typed() | |
1218 && emsg_silent == 0 | |
1219 && !did_wait_return | |
1220 && oap->op_type == OP_NOP) | |
1221 { | |
1222 int save_State = State; | |
1223 | |
1224 /* Draw the cursor with the right shape here */ | |
1225 if (restart_edit != 0) | |
1226 State = INSERT; | |
1227 | |
1228 /* If need to redraw, and there is a "keep_msg", redraw before the | |
1229 * delay */ | |
1230 if (must_redraw && keep_msg != NULL && !emsg_on_display) | |
1231 { | |
1232 char_u *kmsg; | |
1233 | |
1234 kmsg = keep_msg; | |
1235 keep_msg = NULL; | |
1236 /* showmode() will clear keep_msg, but we want to use it anyway */ | |
1237 update_screen(0); | |
1238 /* now reset it, otherwise it's put in the history again */ | |
1239 keep_msg = kmsg; | |
1240 msg_attr(kmsg, keep_msg_attr); | |
1241 vim_free(kmsg); | |
1242 } | |
1243 setcursor(); | |
1244 cursor_on(); | |
1245 out_flush(); | |
1246 if (msg_scroll || emsg_on_display) | |
1247 ui_delay(1000L, TRUE); /* wait at least one second */ | |
1248 ui_delay(3000L, FALSE); /* wait up to three seconds */ | |
1249 State = save_State; | |
1250 | |
1251 msg_scroll = FALSE; | |
1252 emsg_on_display = FALSE; | |
1253 } | |
1254 | |
1255 /* | |
1256 * Finish up after executing a Normal mode command. | |
1257 */ | |
1258 normal_end: | |
1259 | |
1260 msg_nowait = FALSE; | |
1261 | |
1262 /* Reset finish_op, in case it was set */ | |
1263 #ifdef CURSOR_SHAPE | |
1264 c = finish_op; | |
1265 #endif | |
1266 finish_op = FALSE; | |
1267 #ifdef CURSOR_SHAPE | |
1268 /* Redraw the cursor with another shape, if we were in Operator-pending | |
1269 * mode or did a replace command. */ | |
1270 if (c || ca.cmdchar == 'r') | |
1271 { | |
1272 ui_cursor_shape(); /* may show different cursor shape */ | |
1273 # ifdef FEAT_MOUSESHAPE | |
1274 update_mouseshape(-1); | |
1275 # endif | |
1276 } | |
1277 #endif | |
1278 | |
1279 #ifdef FEAT_CMDL_INFO | |
1692 | 1280 if (oap->op_type == OP_NOP && oap->regname == 0 |
1281 # ifdef FEAT_AUTOCMD | |
1282 && ca.cmdchar != K_CURSORHOLD | |
1283 # endif | |
1284 ) | |
7 | 1285 clear_showcmd(); |
1286 #endif | |
1287 | |
1288 checkpcmark(); /* check if we moved since setting pcmark */ | |
1289 vim_free(ca.searchbuf); | |
1290 | |
1291 #ifdef FEAT_MBYTE | |
1292 if (has_mbyte) | |
1293 mb_adjust_cursor(); | |
1294 #endif | |
1295 | |
1296 #ifdef FEAT_SCROLLBIND | |
1297 if (curwin->w_p_scb && toplevel) | |
1298 { | |
1299 validate_cursor(); /* may need to update w_leftcol */ | |
1300 do_check_scrollbind(TRUE); | |
1301 } | |
1302 #endif | |
1303 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1304 #ifdef FEAT_CURSORBIND |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1305 if (curwin->w_p_crb && toplevel) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1306 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1307 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
|
1308 do_check_cursorbind(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1309 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1310 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
1311 |
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
|
1312 #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
|
1313 /* 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
|
1314 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
|
1315 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
|
1316 #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
|
1317 |
7 | 1318 /* |
1319 * May restart edit(), if we got here with CTRL-O in Insert mode (but not | |
1320 * if still inside a mapping that started in Visual mode). | |
1321 * May switch from Visual to Select mode after CTRL-O command. | |
1322 */ | |
1323 if ( oap->op_type == OP_NOP | |
1324 && ((restart_edit != 0 && !VIsual_active && old_mapped_len == 0) | |
1325 || restart_VIsual_select == 1) | |
1326 && !(ca.retval & CA_COMMAND_BUSY) | |
1327 && stuff_empty() | |
1328 && oap->regname == 0) | |
1329 { | |
1330 if (restart_VIsual_select == 1) | |
1331 { | |
1332 VIsual_select = TRUE; | |
1333 showmode(); | |
1334 restart_VIsual_select = 0; | |
1335 } | |
5735 | 1336 if (restart_edit != 0 && !VIsual_active && old_mapped_len == 0) |
7 | 1337 (void)edit(restart_edit, FALSE, 1L); |
1338 } | |
1339 | |
1340 if (restart_VIsual_select == 2) | |
1341 restart_VIsual_select = 1; | |
1342 | |
1343 /* Save count before an operator for next time. */ | |
1344 opcount = ca.opcount; | |
1345 } | |
1346 | |
2667 | 1347 #ifdef FEAT_EVAL |
1348 /* | |
1349 * Set v:count and v:count1 according to "cap". | |
1350 * Set v:prevcount only when "set_prevcount" is TRUE. | |
1351 */ | |
1352 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1353 set_vcount_ca(cmdarg_T *cap, int *set_prevcount) |
2667 | 1354 { |
1355 long count = cap->count0; | |
1356 | |
1357 /* multiply with cap->opcount the same way as above */ | |
1358 if (cap->opcount != 0) | |
1359 count = cap->opcount * (count == 0 ? 1 : count); | |
1360 set_vcount(count, count == 0 ? 1 : count, *set_prevcount); | |
1361 *set_prevcount = FALSE; /* only set v:prevcount once */ | |
1362 } | |
1363 #endif | |
1364 | |
7 | 1365 /* |
1366 * Handle an operator after visual mode or when the movement is finished | |
1367 */ | |
1368 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1369 do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank) |
7 | 1370 { |
1371 oparg_T *oap = cap->oap; | |
1372 pos_T old_cursor; | |
1373 int empty_region_error; | |
1374 int restart_edit_save; | |
6266 | 1375 #ifdef FEAT_LINEBREAK |
1376 int lbr_saved = curwin->w_p_lbr; | |
1377 #endif | |
7 | 1378 |
1379 /* The visual area is remembered for redo */ | |
1380 static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */ | |
1381 static linenr_T redo_VIsual_line_count; /* number of lines */ | |
3125 | 1382 static colnr_T redo_VIsual_vcol; /* number of cols or end column */ |
7 | 1383 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
|
1384 static int redo_VIsual_arg; /* extra argument */ |
5735 | 1385 #ifdef FEAT_VIRTUALEDIT |
7 | 1386 int include_line_break = FALSE; |
1387 #endif | |
1388 | |
1389 #if defined(FEAT_CLIPBOARD) | |
1390 /* | |
1391 * Yank the visual area into the GUI selection register before we operate | |
1392 * on it and lose it forever. | |
1393 * Don't do it if a specific register was specified, so that ""x"*P works. | |
1394 * This could call do_pending_operator() recursively, but that's OK | |
1395 * because gui_yank will be TRUE for the nested call. | |
1396 */ | |
3674 | 1397 if ((clip_star.available || clip_plus.available) |
7 | 1398 && oap->op_type != OP_NOP |
1399 && !gui_yank | |
1400 && VIsual_active | |
1401 && !redo_VIsual_busy | |
1402 && oap->regname == 0) | |
1403 clip_auto_select(); | |
1404 #endif | |
1405 old_cursor = curwin->w_cursor; | |
1406 | |
1407 /* | |
1408 * If an operation is pending, handle it... | |
1409 */ | |
5735 | 1410 if ((finish_op || VIsual_active) && oap->op_type != OP_NOP) |
1411 { | |
6497 | 1412 #ifdef FEAT_LINEBREAK |
1413 /* Avoid a problem with unwanted linebreaks in block mode. */ | |
6866 | 1414 if (curwin->w_p_lbr) |
1415 curwin->w_valid &= ~VALID_VIRTCOL; | |
6497 | 1416 curwin->w_p_lbr = FALSE; |
1417 #endif | |
7 | 1418 oap->is_VIsual = VIsual_active; |
1419 if (oap->motion_force == 'V') | |
1420 oap->motion_type = MLINE; | |
1421 else if (oap->motion_force == 'v') | |
1422 { | |
1423 /* If the motion was linewise, "inclusive" will not have been set. | |
1424 * Use "exclusive" to be consistent. Makes "dvj" work nice. */ | |
1425 if (oap->motion_type == MLINE) | |
1426 oap->inclusive = FALSE; | |
1427 /* If the motion already was characterwise, toggle "inclusive" */ | |
1428 else if (oap->motion_type == MCHAR) | |
1429 oap->inclusive = !oap->inclusive; | |
1430 oap->motion_type = MCHAR; | |
1431 } | |
1432 else if (oap->motion_force == Ctrl_V) | |
1433 { | |
1434 /* Change line- or characterwise motion into Visual block mode. */ | |
1435 VIsual_active = TRUE; | |
1436 VIsual = oap->start; | |
1437 VIsual_mode = Ctrl_V; | |
1438 VIsual_select = FALSE; | |
1439 VIsual_reselect = FALSE; | |
1440 } | |
1441 | |
4337 | 1442 /* Only redo yank when 'y' flag is in 'cpoptions'. */ |
1443 /* Never redo "zf" (define fold). */ | |
7 | 1444 if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) |
4337 | 1445 && ((!VIsual_active || oap->motion_force) |
1446 /* Also redo Operator-pending Visual mode mappings */ | |
1447 || (VIsual_active && cap->cmdchar == ':' | |
1448 && oap->op_type != OP_COLON)) | |
164 | 1449 && cap->cmdchar != 'D' |
7 | 1450 #ifdef FEAT_FOLDING |
1451 && oap->op_type != OP_FOLD | |
1452 && oap->op_type != OP_FOLDOPEN | |
1453 && oap->op_type != OP_FOLDOPENREC | |
1454 && oap->op_type != OP_FOLDCLOSE | |
1455 && oap->op_type != OP_FOLDCLOSEREC | |
1456 && oap->op_type != OP_FOLDDEL | |
1457 && oap->op_type != OP_FOLDDELREC | |
1458 #endif | |
1459 ) | |
1460 { | |
1461 prep_redo(oap->regname, cap->count0, | |
1462 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1463 oap->motion_force, cap->cmdchar, cap->nchar); | |
1464 if (cap->cmdchar == '/' || cap->cmdchar == '?') /* was a search */ | |
1465 { | |
1466 /* | |
1467 * If 'cpoptions' does not contain 'r', insert the search | |
1468 * pattern to really repeat the same command. | |
1469 */ | |
1470 if (vim_strchr(p_cpo, CPO_REDO) == NULL) | |
620 | 1471 AppendToRedobuffLit(cap->searchbuf, -1); |
7 | 1472 AppendToRedobuff(NL_STR); |
1473 } | |
1474 else if (cap->cmdchar == ':') | |
1475 { | |
1476 /* do_cmdline() has stored the first typed line in | |
1477 * "repeat_cmdline". When several lines are typed repeating | |
1478 * won't be possible. */ | |
1479 if (repeat_cmdline == NULL) | |
1480 ResetRedobuff(); | |
1481 else | |
1482 { | |
620 | 1483 AppendToRedobuffLit(repeat_cmdline, -1); |
7 | 1484 AppendToRedobuff(NL_STR); |
1485 vim_free(repeat_cmdline); | |
1486 repeat_cmdline = NULL; | |
1487 } | |
1488 } | |
1489 } | |
1490 | |
1491 if (redo_VIsual_busy) | |
1492 { | |
3125 | 1493 /* Redo of an operation on a Visual area. Use the same size from |
1494 * redo_VIsual_line_count and redo_VIsual_vcol. */ | |
7 | 1495 oap->start = curwin->w_cursor; |
1496 curwin->w_cursor.lnum += redo_VIsual_line_count - 1; | |
1497 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
1498 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
1499 VIsual_mode = redo_VIsual_mode; | |
3125 | 1500 if (redo_VIsual_vcol == MAXCOL || VIsual_mode == 'v') |
7 | 1501 { |
3125 | 1502 if (VIsual_mode == 'v') |
1503 { | |
1504 if (redo_VIsual_line_count <= 1) | |
1505 { | |
1506 validate_virtcol(); | |
1507 curwin->w_curswant = | |
1508 curwin->w_virtcol + redo_VIsual_vcol - 1; | |
1509 } | |
1510 else | |
1511 curwin->w_curswant = redo_VIsual_vcol; | |
1512 } | |
7 | 1513 else |
3125 | 1514 { |
1515 curwin->w_curswant = MAXCOL; | |
1516 } | |
1517 coladvance(curwin->w_curswant); | |
7 | 1518 } |
1519 cap->count0 = redo_VIsual_count; | |
1520 if (redo_VIsual_count != 0) | |
1521 cap->count1 = redo_VIsual_count; | |
1522 else | |
1523 cap->count1 = 1; | |
1524 } | |
1525 else if (VIsual_active) | |
1526 { | |
999 | 1527 if (!gui_yank) |
1528 { | |
1529 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
1530 curbuf->b_visual.vi_start = VIsual; | |
1531 curbuf->b_visual.vi_end = curwin->w_cursor; | |
1532 curbuf->b_visual.vi_mode = VIsual_mode; | |
4213 | 1533 if (VIsual_mode_orig != NUL) |
1534 { | |
1535 curbuf->b_visual.vi_mode = VIsual_mode_orig; | |
1536 VIsual_mode_orig = NUL; | |
1537 } | |
999 | 1538 curbuf->b_visual.vi_curswant = curwin->w_curswant; |
7 | 1539 # ifdef FEAT_EVAL |
999 | 1540 curbuf->b_visual_mode_eval = VIsual_mode; |
7 | 1541 # endif |
999 | 1542 } |
7 | 1543 |
1544 /* In Select mode, a linewise selection is operated upon like a | |
6826 | 1545 * characterwise selection. |
1546 * Special case: gH<Del> deletes the last line. */ | |
1547 if (VIsual_select && VIsual_mode == 'V' | |
1548 && cap->oap->op_type != OP_DELETE) | |
7 | 1549 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1550 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 1551 { |
1552 VIsual.col = 0; | |
1553 curwin->w_cursor.col = | |
1554 (colnr_T)STRLEN(ml_get(curwin->w_cursor.lnum)); | |
1555 } | |
1556 else | |
1557 { | |
1558 curwin->w_cursor.col = 0; | |
1559 VIsual.col = (colnr_T)STRLEN(ml_get(VIsual.lnum)); | |
1560 } | |
1561 VIsual_mode = 'v'; | |
1562 } | |
1563 /* If 'selection' is "exclusive", backup one character for | |
1564 * charwise selections. */ | |
1565 else if (VIsual_mode == 'v') | |
1566 { | |
1567 # ifdef FEAT_VIRTUALEDIT | |
1568 include_line_break = | |
1569 # endif | |
1570 unadjust_for_sel(); | |
1571 } | |
1572 | |
1573 oap->start = VIsual; | |
1574 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
|
1575 { |
7 | 1576 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
|
1577 # ifdef FEAT_VIRTUALEDIT |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1578 oap->start.coladd = 0; |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1579 # endif |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1580 } |
7 | 1581 } |
1582 | |
1583 /* | |
1584 * Set oap->start to the first position of the operated text, oap->end | |
1585 * to the end of the operated text. w_cursor is equal to oap->start. | |
1586 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1587 if (LT_POS(oap->start, curwin->w_cursor)) |
7 | 1588 { |
1589 #ifdef FEAT_FOLDING | |
1590 /* Include folded lines completely. */ | |
1591 if (!VIsual_active) | |
1592 { | |
1593 if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL)) | |
1594 oap->start.col = 0; | |
1595 if (hasFolding(curwin->w_cursor.lnum, NULL, | |
1596 &curwin->w_cursor.lnum)) | |
1597 curwin->w_cursor.col = (colnr_T)STRLEN(ml_get_curline()); | |
1598 } | |
1599 #endif | |
1600 oap->end = curwin->w_cursor; | |
1601 curwin->w_cursor = oap->start; | |
1602 | |
1603 /* w_virtcol may have been updated; if the cursor goes back to its | |
1604 * previous position w_virtcol becomes invalid and isn't updated | |
1605 * automatically. */ | |
1606 curwin->w_valid &= ~VALID_VIRTCOL; | |
1607 } | |
1608 else | |
1609 { | |
1610 #ifdef FEAT_FOLDING | |
1611 /* Include folded lines completely. */ | |
1612 if (!VIsual_active && oap->motion_type == MLINE) | |
1613 { | |
1614 if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, | |
1615 NULL)) | |
1616 curwin->w_cursor.col = 0; | |
1617 if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) | |
1618 oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum)); | |
1619 } | |
1620 #endif | |
1621 oap->end = oap->start; | |
1622 oap->start = curwin->w_cursor; | |
1623 } | |
1624 | |
10154
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10110
diff
changeset
|
1625 /* 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
|
1626 check_pos(curwin->w_buffer, &oap->end); |
7 | 1627 oap->line_count = oap->end.lnum - oap->start.lnum + 1; |
1628 | |
1629 #ifdef FEAT_VIRTUALEDIT | |
1630 /* Set "virtual_op" before resetting VIsual_active. */ | |
1631 virtual_op = virtual_active(); | |
1632 #endif | |
1633 | |
1634 if (VIsual_active || redo_VIsual_busy) | |
1635 { | |
6866 | 1636 get_op_vcol(oap, redo_VIsual_vcol, TRUE); |
7 | 1637 |
1638 if (!redo_VIsual_busy && !gui_yank) | |
1639 { | |
1640 /* | |
1641 * Prepare to reselect and redo Visual: this is based on the | |
1642 * size of the Visual text | |
1643 */ | |
1644 resel_VIsual_mode = VIsual_mode; | |
1645 if (curwin->w_curswant == MAXCOL) | |
3125 | 1646 resel_VIsual_vcol = MAXCOL; |
7 | 1647 else |
3125 | 1648 { |
1649 if (VIsual_mode != Ctrl_V) | |
1650 getvvcol(curwin, &(oap->end), | |
1651 NULL, NULL, &oap->end_vcol); | |
1652 if (VIsual_mode == Ctrl_V || oap->line_count <= 1) | |
1653 { | |
1654 if (VIsual_mode != Ctrl_V) | |
1655 getvvcol(curwin, &(oap->start), | |
1656 &oap->start_vcol, NULL, NULL); | |
1657 resel_VIsual_vcol = oap->end_vcol - oap->start_vcol + 1; | |
1658 } | |
1659 else | |
1660 resel_VIsual_vcol = oap->end_vcol; | |
1661 } | |
7 | 1662 resel_VIsual_line_count = oap->line_count; |
1663 } | |
1664 | |
1665 /* can't redo yank (unless 'y' is in 'cpoptions') and ":" */ | |
1666 if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) | |
1667 && oap->op_type != OP_COLON | |
1668 #ifdef FEAT_FOLDING | |
1669 && oap->op_type != OP_FOLD | |
1670 && oap->op_type != OP_FOLDOPEN | |
1671 && oap->op_type != OP_FOLDOPENREC | |
1672 && oap->op_type != OP_FOLDCLOSE | |
1673 && oap->op_type != OP_FOLDCLOSEREC | |
1674 && oap->op_type != OP_FOLDDEL | |
1675 && oap->op_type != OP_FOLDDELREC | |
1676 #endif | |
1677 && oap->motion_force == NUL | |
1678 ) | |
1679 { | |
1680 /* Prepare for redoing. Only use the nchar field for "r", | |
1681 * otherwise it might be the second char of the operator. */ | |
3701 | 1682 if (cap->cmdchar == 'g' && (cap->nchar == 'n' |
1683 || cap->nchar == 'N')) | |
5523 | 1684 prep_redo(oap->regname, cap->count0, |
1685 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1686 oap->motion_force, cap->cmdchar, cap->nchar); | |
4337 | 1687 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
|
1688 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1689 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
|
1690 |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1691 /* 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
|
1692 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
|
1693 nchar = CAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1694 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
|
1695 nchar = NL; |
3701 | 1696 prep_redo(oap->regname, 0L, NUL, 'v', |
1697 get_op_char(oap->op_type), | |
1698 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
|
1699 nchar); |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1700 } |
7 | 1701 if (!redo_VIsual_busy) |
1702 { | |
1703 redo_VIsual_mode = resel_VIsual_mode; | |
3125 | 1704 redo_VIsual_vcol = resel_VIsual_vcol; |
7 | 1705 redo_VIsual_line_count = resel_VIsual_line_count; |
1706 redo_VIsual_count = cap->count0; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
1707 redo_VIsual_arg = cap->arg; |
7 | 1708 } |
1709 } | |
1710 | |
1711 /* | |
1712 * oap->inclusive defaults to TRUE. | |
1713 * If oap->end is on a NUL (empty line) oap->inclusive becomes | |
1714 * FALSE. This makes "d}P" and "v}dP" work the same. | |
1715 */ | |
1716 if (oap->motion_force == NUL || oap->motion_type == MLINE) | |
1717 oap->inclusive = TRUE; | |
1718 if (VIsual_mode == 'V') | |
1719 oap->motion_type = MLINE; | |
1720 else | |
1721 { | |
1722 oap->motion_type = MCHAR; | |
1723 if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL | |
5735 | 1724 #ifdef FEAT_VIRTUALEDIT |
7 | 1725 && (include_line_break || !virtual_op) |
5735 | 1726 #endif |
7 | 1727 ) |
1728 { | |
1729 oap->inclusive = FALSE; | |
1730 /* Try to include the newline, unless it's an operator | |
2957 | 1731 * that works on lines only. */ |
6826 | 1732 if (*p_sel != 'o' |
1733 && !op_on_lines(oap->op_type) | |
1734 && oap->end.lnum < curbuf->b_ml.ml_line_count) | |
7 | 1735 { |
6826 | 1736 ++oap->end.lnum; |
1737 oap->end.col = 0; | |
5735 | 1738 #ifdef FEAT_VIRTUALEDIT |
6826 | 1739 oap->end.coladd = 0; |
1740 #endif | |
1741 ++oap->line_count; | |
7 | 1742 } |
1743 } | |
1744 } | |
1745 | |
1746 redo_VIsual_busy = FALSE; | |
592 | 1747 |
7 | 1748 /* |
1749 * Switch Visual off now, so screen updating does | |
1750 * not show inverted text when the screen is redrawn. | |
1751 * With OP_YANK and sometimes with OP_COLON and OP_FILTER there is | |
1752 * no screen redraw, so it is done here to remove the inverted | |
1753 * part. | |
1754 */ | |
1755 if (!gui_yank) | |
1756 { | |
1757 VIsual_active = FALSE; | |
5735 | 1758 #ifdef FEAT_MOUSE |
7 | 1759 setmouse(); |
1760 mouse_dragging = 0; | |
5735 | 1761 #endif |
6979 | 1762 may_clear_cmdline(); |
7 | 1763 if ((oap->op_type == OP_YANK |
1764 || oap->op_type == OP_COLON | |
592 | 1765 || oap->op_type == OP_FUNCTION |
7 | 1766 || oap->op_type == OP_FILTER) |
1767 && oap->motion_force == NUL) | |
6497 | 1768 { |
1769 #ifdef FEAT_LINEBREAK | |
1770 /* make sure redrawing is correct */ | |
1771 curwin->w_p_lbr = lbr_saved; | |
1772 #endif | |
7 | 1773 redraw_curbuf_later(INVERTED); |
6497 | 1774 } |
7 | 1775 } |
1776 } | |
1777 | |
1778 #ifdef FEAT_MBYTE | |
1779 /* Include the trailing byte of a multi-byte char. */ | |
1780 if (has_mbyte && oap->inclusive) | |
1781 { | |
1782 int l; | |
1783 | |
474 | 1784 l = (*mb_ptr2len)(ml_get_pos(&oap->end)); |
7 | 1785 if (l > 1) |
1786 oap->end.col += l - 1; | |
1787 } | |
1788 #endif | |
1789 curwin->w_set_curswant = TRUE; | |
1790 | |
1791 /* | |
1792 * oap->empty is set when start and end are the same. The inclusive | |
1793 * flag affects this too, unless yanking and the end is on a NUL. | |
1794 */ | |
1795 oap->empty = (oap->motion_type == MCHAR | |
1796 && (!oap->inclusive | |
1797 || (oap->op_type == OP_YANK | |
1798 && 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
|
1799 && EQUAL_POS(oap->start, oap->end) |
7 | 1800 #ifdef FEAT_VIRTUALEDIT |
1801 && !(virtual_op && oap->start.coladd != oap->end.coladd) | |
1802 #endif | |
1803 ); | |
1804 /* | |
1805 * For delete, change and yank, it's an error to operate on an | |
1806 * empty region, when 'E' included in 'cpoptions' (Vi compatible). | |
1807 */ | |
1808 empty_region_error = (oap->empty | |
1809 && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL); | |
1810 | |
1811 /* Force a redraw when operating on an empty Visual region, when | |
1812 * 'modifiable is off or creating a fold. */ | |
1813 if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma | |
5735 | 1814 #ifdef FEAT_FOLDING |
7 | 1815 || oap->op_type == OP_FOLD |
5735 | 1816 #endif |
7 | 1817 )) |
6497 | 1818 { |
1819 #ifdef FEAT_LINEBREAK | |
1820 curwin->w_p_lbr = lbr_saved; | |
1821 #endif | |
7 | 1822 redraw_curbuf_later(INVERTED); |
6497 | 1823 } |
7 | 1824 |
1825 /* | |
1826 * If the end of an operator is in column one while oap->motion_type | |
1827 * is MCHAR and oap->inclusive is FALSE, we put op_end after the last | |
1828 * character in the previous line. If op_start is on or before the | |
1829 * first non-blank in the line, the operator becomes linewise | |
1830 * (strange, but that's the way vi does it). | |
1831 */ | |
1832 if ( oap->motion_type == MCHAR | |
1833 && oap->inclusive == FALSE | |
1834 && !(cap->retval & CA_NO_ADJ_OP_END) | |
1835 && oap->end.col == 0 | |
1836 && (!oap->is_VIsual || *p_sel == 'o') | |
47 | 1837 && !oap->block_mode |
7 | 1838 && oap->line_count > 1) |
1839 { | |
1840 oap->end_adjusted = TRUE; /* remember that we did this */ | |
1841 --oap->line_count; | |
1842 --oap->end.lnum; | |
1843 if (inindent(0)) | |
1844 oap->motion_type = MLINE; | |
1845 else | |
1846 { | |
1847 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
1848 if (oap->end.col) | |
1849 { | |
1850 --oap->end.col; | |
1851 oap->inclusive = TRUE; | |
1852 } | |
1853 } | |
1854 } | |
1855 else | |
1856 oap->end_adjusted = FALSE; | |
1857 | |
1858 switch (oap->op_type) | |
1859 { | |
1860 case OP_LSHIFT: | |
1861 case OP_RSHIFT: | |
5735 | 1862 op_shift(oap, TRUE, oap->is_VIsual ? (int)cap->count1 : 1); |
7 | 1863 auto_format(FALSE, TRUE); |
1864 break; | |
1865 | |
1866 case OP_JOIN_NS: | |
1867 case OP_JOIN: | |
1868 if (oap->line_count < 2) | |
1869 oap->line_count = 2; | |
1870 if (curwin->w_cursor.lnum + oap->line_count - 1 > | |
1871 curbuf->b_ml.ml_line_count) | |
1872 beep_flush(); | |
1873 else | |
1874 { | |
5735 | 1875 (void)do_join(oap->line_count, oap->op_type == OP_JOIN, |
5848 | 1876 TRUE, TRUE, TRUE); |
7 | 1877 auto_format(FALSE, TRUE); |
1878 } | |
1879 break; | |
1880 | |
1881 case OP_DELETE: | |
1882 VIsual_reselect = FALSE; /* don't reselect now */ | |
1883 if (empty_region_error) | |
3324 | 1884 { |
6949 | 1885 vim_beep(BO_OPER); |
3324 | 1886 CancelRedo(); |
1887 } | |
7 | 1888 else |
1889 { | |
1890 (void)op_delete(oap); | |
1891 if (oap->motion_type == MLINE && has_format_option(FO_AUTO)) | |
1892 u_save_cursor(); /* cursor line wasn't saved yet */ | |
1893 auto_format(FALSE, TRUE); | |
1894 } | |
1895 break; | |
1896 | |
1897 case OP_YANK: | |
1898 if (empty_region_error) | |
1899 { | |
1900 if (!gui_yank) | |
3324 | 1901 { |
6949 | 1902 vim_beep(BO_OPER); |
3324 | 1903 CancelRedo(); |
1904 } | |
7 | 1905 } |
1906 else | |
6497 | 1907 { |
1908 #ifdef FEAT_LINEBREAK | |
1909 curwin->w_p_lbr = lbr_saved; | |
1910 #endif | |
7 | 1911 (void)op_yank(oap, FALSE, !gui_yank); |
6497 | 1912 } |
7 | 1913 check_cursor_col(); |
1914 break; | |
1915 | |
1916 case OP_CHANGE: | |
1917 VIsual_reselect = FALSE; /* don't reselect now */ | |
1918 if (empty_region_error) | |
3324 | 1919 { |
6949 | 1920 vim_beep(BO_OPER); |
3324 | 1921 CancelRedo(); |
1922 } | |
7 | 1923 else |
1924 { | |
1925 /* This is a new edit command, not a restart. Need to | |
1926 * remember it to make 'insertmode' work with mappings for | |
1927 * Visual mode. But do this only once and not when typed and | |
1928 * 'insertmode' isn't set. */ | |
1929 if (p_im || !KeyTyped) | |
1930 restart_edit_save = restart_edit; | |
1931 else | |
1932 restart_edit_save = 0; | |
1933 restart_edit = 0; | |
6497 | 1934 #ifdef FEAT_LINEBREAK |
1935 /* Restore linebreak, so that when the user edits it looks as | |
1936 * before. */ | |
6866 | 1937 if (curwin->w_p_lbr != lbr_saved) |
1938 { | |
1939 curwin->w_p_lbr = lbr_saved; | |
1940 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
1941 } | |
6497 | 1942 #endif |
7 | 1943 /* Reset finish_op now, don't want it set inside edit(). */ |
1944 finish_op = FALSE; | |
1945 if (op_change(oap)) /* will call edit() */ | |
1946 cap->retval |= CA_COMMAND_BUSY; | |
1947 if (restart_edit == 0) | |
1948 restart_edit = restart_edit_save; | |
1949 } | |
1950 break; | |
1951 | |
1952 case OP_FILTER: | |
1953 if (vim_strchr(p_cpo, CPO_FILTER) != NULL) | |
1954 AppendToRedobuff((char_u *)"!\r"); /* use any last used !cmd */ | |
1955 else | |
1956 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
|
1957 /* FALLTHROUGH */ |
7 | 1958 |
1959 case OP_INDENT: | |
1960 case OP_COLON: | |
1961 | |
1962 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
1963 /* | |
1964 * If 'equalprg' is empty, do the indenting internally. | |
1965 */ | |
1966 if (oap->op_type == OP_INDENT && *get_equalprg() == NUL) | |
1967 { | |
1968 # ifdef FEAT_LISP | |
1969 if (curbuf->b_p_lisp) | |
1970 { | |
1971 op_reindent(oap, get_lisp_indent); | |
1972 break; | |
1973 } | |
1974 # endif | |
1975 # ifdef FEAT_CINDENT | |
1976 op_reindent(oap, | |
1977 # ifdef FEAT_EVAL | |
1978 *curbuf->b_p_inde != NUL ? get_expr_indent : | |
1979 # endif | |
1980 get_c_indent); | |
1981 break; | |
1982 # endif | |
1983 } | |
1984 #endif | |
1985 | |
1986 op_colon(oap); | |
1987 break; | |
1988 | |
1989 case OP_TILDE: | |
1990 case OP_UPPER: | |
1991 case OP_LOWER: | |
1992 case OP_ROT13: | |
1993 if (empty_region_error) | |
3324 | 1994 { |
6949 | 1995 vim_beep(BO_OPER); |
3324 | 1996 CancelRedo(); |
1997 } | |
7 | 1998 else |
1999 op_tilde(oap); | |
2000 check_cursor_col(); | |
2001 break; | |
2002 | |
2003 case OP_FORMAT: | |
667 | 2004 #if defined(FEAT_EVAL) |
2005 if (*curbuf->b_p_fex != NUL) | |
2006 op_formatexpr(oap); /* use expression */ | |
2007 else | |
2008 #endif | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2009 if (*p_fp != NUL || *curbuf->b_p_fp != NUL) |
7 | 2010 op_colon(oap); /* use external command */ |
2011 else | |
2012 op_format(oap, FALSE); /* use internal function */ | |
2013 break; | |
2014 | |
2015 case OP_FORMAT2: | |
2016 op_format(oap, TRUE); /* use internal function */ | |
2017 break; | |
2018 | |
592 | 2019 case OP_FUNCTION: |
10342
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2020 #ifdef FEAT_LINEBREAK |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2021 /* 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
|
2022 * before. */ |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2023 curwin->w_p_lbr = lbr_saved; |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2024 #endif |
592 | 2025 op_function(oap); /* call 'operatorfunc' */ |
2026 break; | |
2027 | |
7 | 2028 case OP_INSERT: |
2029 case OP_APPEND: | |
2030 VIsual_reselect = FALSE; /* don't reselect now */ | |
2031 #ifdef FEAT_VISUALEXTRA | |
2032 if (empty_region_error) | |
3324 | 2033 { |
6949 | 2034 vim_beep(BO_OPER); |
3324 | 2035 CancelRedo(); |
2036 } | |
7 | 2037 else |
2038 { | |
2039 /* This is a new edit command, not a restart. Need to | |
2040 * remember it to make 'insertmode' work with mappings for | |
2041 * Visual mode. But do this only once. */ | |
2042 restart_edit_save = restart_edit; | |
2043 restart_edit = 0; | |
6497 | 2044 #ifdef FEAT_LINEBREAK |
2045 /* Restore linebreak, so that when the user edits it looks as | |
2046 * before. */ | |
6866 | 2047 if (curwin->w_p_lbr != lbr_saved) |
2048 { | |
2049 curwin->w_p_lbr = lbr_saved; | |
2050 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
2051 } | |
6497 | 2052 #endif |
7 | 2053 op_insert(oap, cap->count1); |
6497 | 2054 #ifdef FEAT_LINEBREAK |
2055 /* Reset linebreak, so that formatting works correctly. */ | |
2056 curwin->w_p_lbr = FALSE; | |
2057 #endif | |
7 | 2058 |
2059 /* TODO: when inserting in several lines, should format all | |
2060 * the lines. */ | |
2061 auto_format(FALSE, TRUE); | |
2062 | |
2063 if (restart_edit == 0) | |
2064 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
|
2065 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
|
2066 cap->retval |= CA_COMMAND_BUSY; |
7 | 2067 } |
2068 #else | |
6949 | 2069 vim_beep(BO_OPER); |
7 | 2070 #endif |
2071 break; | |
2072 | |
2073 case OP_REPLACE: | |
2074 VIsual_reselect = FALSE; /* don't reselect now */ | |
2075 #ifdef FEAT_VISUALEXTRA | |
2076 if (empty_region_error) | |
2077 #endif | |
3324 | 2078 { |
6949 | 2079 vim_beep(BO_OPER); |
3324 | 2080 CancelRedo(); |
2081 } | |
7 | 2082 #ifdef FEAT_VISUALEXTRA |
2083 else | |
6497 | 2084 { |
6866 | 2085 # ifdef FEAT_LINEBREAK |
6497 | 2086 /* Restore linebreak, so that when the user edits it looks as |
2087 * before. */ | |
6866 | 2088 if (curwin->w_p_lbr != lbr_saved) |
2089 { | |
2090 curwin->w_p_lbr = lbr_saved; | |
2091 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
2092 } | |
2093 # endif | |
7 | 2094 op_replace(oap, cap->nchar); |
6497 | 2095 } |
7 | 2096 #endif |
2097 break; | |
2098 | |
2099 #ifdef FEAT_FOLDING | |
2100 case OP_FOLD: | |
2101 VIsual_reselect = FALSE; /* don't reselect now */ | |
2102 foldCreate(oap->start.lnum, oap->end.lnum); | |
2103 break; | |
2104 | |
2105 case OP_FOLDOPEN: | |
2106 case OP_FOLDOPENREC: | |
2107 case OP_FOLDCLOSE: | |
2108 case OP_FOLDCLOSEREC: | |
2109 VIsual_reselect = FALSE; /* don't reselect now */ | |
2110 opFoldRange(oap->start.lnum, oap->end.lnum, | |
2111 oap->op_type == OP_FOLDOPEN | |
2112 || oap->op_type == OP_FOLDOPENREC, | |
2113 oap->op_type == OP_FOLDOPENREC | |
2114 || oap->op_type == OP_FOLDCLOSEREC, | |
2115 oap->is_VIsual); | |
2116 break; | |
2117 | |
2118 case OP_FOLDDEL: | |
2119 case OP_FOLDDELREC: | |
2120 VIsual_reselect = FALSE; /* don't reselect now */ | |
2121 deleteFold(oap->start.lnum, oap->end.lnum, | |
2122 oap->op_type == OP_FOLDDELREC, oap->is_VIsual); | |
2123 break; | |
2124 #endif | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2125 case OP_NR_ADD: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2126 case OP_NR_SUB: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2127 if (empty_region_error) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2128 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2129 vim_beep(BO_OPER); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2130 CancelRedo(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2131 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2132 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2133 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2134 VIsual_active = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2135 #ifdef FEAT_LINEBREAK |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2136 curwin->w_p_lbr = lbr_saved; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2137 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2138 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
|
2139 VIsual_active = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2140 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2141 check_cursor_col(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2142 break; |
7 | 2143 default: |
2144 clearopbeep(oap); | |
2145 } | |
2146 #ifdef FEAT_VIRTUALEDIT | |
2147 virtual_op = MAYBE; | |
2148 #endif | |
2149 if (!gui_yank) | |
2150 { | |
2151 /* | |
2152 * if 'sol' not set, go back to old column for some commands | |
2153 */ | |
2154 if (!p_sol && oap->motion_type == MLINE && !oap->end_adjusted | |
2155 && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT | |
2156 || oap->op_type == OP_DELETE)) | |
6497 | 2157 { |
2158 #ifdef FEAT_LINEBREAK | |
2159 curwin->w_p_lbr = FALSE; | |
2160 #endif | |
7 | 2161 coladvance(curwin->w_curswant = old_col); |
6497 | 2162 } |
7 | 2163 } |
2164 else | |
2165 { | |
2166 curwin->w_cursor = old_cursor; | |
2167 } | |
2168 oap->block_mode = FALSE; | |
2169 clearop(oap); | |
2170 } | |
6266 | 2171 #ifdef FEAT_LINEBREAK |
2172 curwin->w_p_lbr = lbr_saved; | |
2173 #endif | |
7 | 2174 } |
2175 | |
2176 /* | |
2177 * Handle indent and format operators and visual mode ":". | |
2178 */ | |
2179 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2180 op_colon(oparg_T *oap) |
7 | 2181 { |
2182 stuffcharReadbuff(':'); | |
2183 if (oap->is_VIsual) | |
2184 stuffReadbuff((char_u *)"'<,'>"); | |
2185 else | |
2186 { | |
2187 /* | |
2188 * Make the range look nice, so it can be repeated. | |
2189 */ | |
2190 if (oap->start.lnum == curwin->w_cursor.lnum) | |
2191 stuffcharReadbuff('.'); | |
2192 else | |
2193 stuffnumReadbuff((long)oap->start.lnum); | |
2194 if (oap->end.lnum != oap->start.lnum) | |
2195 { | |
2196 stuffcharReadbuff(','); | |
2197 if (oap->end.lnum == curwin->w_cursor.lnum) | |
2198 stuffcharReadbuff('.'); | |
2199 else if (oap->end.lnum == curbuf->b_ml.ml_line_count) | |
2200 stuffcharReadbuff('$'); | |
2201 else if (oap->start.lnum == curwin->w_cursor.lnum) | |
2202 { | |
2203 stuffReadbuff((char_u *)".+"); | |
2204 stuffnumReadbuff((long)oap->line_count - 1); | |
2205 } | |
2206 else | |
2207 stuffnumReadbuff((long)oap->end.lnum); | |
2208 } | |
2209 } | |
2210 if (oap->op_type != OP_COLON) | |
2211 stuffReadbuff((char_u *)"!"); | |
2212 if (oap->op_type == OP_INDENT) | |
2213 { | |
2214 #ifndef FEAT_CINDENT | |
2215 if (*get_equalprg() == NUL) | |
2216 stuffReadbuff((char_u *)"indent"); | |
2217 else | |
2218 #endif | |
2219 stuffReadbuff(get_equalprg()); | |
2220 stuffReadbuff((char_u *)"\n"); | |
2221 } | |
2222 else if (oap->op_type == OP_FORMAT) | |
2223 { | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2224 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
|
2225 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
|
2226 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
|
2227 stuffReadbuff(p_fp); |
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2228 else |
7 | 2229 stuffReadbuff((char_u *)"fmt"); |
216 | 2230 stuffReadbuff((char_u *)"\n']"); |
7 | 2231 } |
2232 | |
2233 /* | |
2234 * do_cmdline() does the rest | |
2235 */ | |
2236 } | |
2237 | |
592 | 2238 /* |
602 | 2239 * Handle the "g@" operator: call 'operatorfunc'. |
592 | 2240 */ |
690 | 2241 static void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2242 op_function(oparg_T *oap UNUSED) |
592 | 2243 { |
2244 #ifdef FEAT_EVAL | |
2245 char_u *(argv[1]); | |
4133 | 2246 # ifdef FEAT_VIRTUALEDIT |
3431 | 2247 int save_virtual_op = virtual_op; |
4133 | 2248 # endif |
592 | 2249 |
2250 if (*p_opfunc == NUL) | |
2251 EMSG(_("E774: 'operatorfunc' is empty")); | |
2252 else | |
2253 { | |
2254 /* Set '[ and '] marks to text to be operated on. */ | |
2255 curbuf->b_op_start = oap->start; | |
2256 curbuf->b_op_end = oap->end; | |
2257 if (oap->motion_type != MLINE && !oap->inclusive) | |
2258 /* Exclude the end position. */ | |
2259 decl(&curbuf->b_op_end); | |
2260 | |
2261 if (oap->block_mode) | |
2262 argv[0] = (char_u *)"block"; | |
2263 else if (oap->motion_type == MLINE) | |
2264 argv[0] = (char_u *)"line"; | |
2265 else | |
2266 argv[0] = (char_u *)"char"; | |
3431 | 2267 |
4133 | 2268 # ifdef FEAT_VIRTUALEDIT |
3431 | 2269 /* Reset virtual_op so that 'virtualedit' can be changed in the |
2270 * function. */ | |
2271 virtual_op = MAYBE; | |
4133 | 2272 # endif |
3431 | 2273 |
592 | 2274 (void)call_func_retnr(p_opfunc, 1, argv, FALSE); |
3431 | 2275 |
4133 | 2276 # ifdef FEAT_VIRTUALEDIT |
3431 | 2277 virtual_op = save_virtual_op; |
4133 | 2278 # endif |
592 | 2279 } |
2280 #else | |
2281 EMSG(_("E775: Eval feature not available")); | |
2282 #endif | |
2283 } | |
2284 | |
7 | 2285 #if defined(FEAT_MOUSE) || defined(PROTO) |
2286 /* | |
2287 * Do the appropriate action for the current mouse click in the current mode. | |
2288 * Not used for Command-line mode. | |
2289 * | |
2290 * Normal Mode: | |
2291 * event modi- position visual change action | |
2292 * fier cursor window | |
2293 * left press - yes end yes | |
2294 * left press C yes end yes "^]" (2) | |
2295 * left press S yes end yes "*" (2) | |
2296 * left drag - yes start if moved no | |
2297 * left relse - yes start if moved no | |
2298 * middle press - yes if not active no put register | |
2299 * middle press - yes if active no yank and put | |
2300 * right press - yes start or extend yes | |
2301 * right press S yes no change yes "#" (2) | |
2302 * right drag - yes extend no | |
2303 * right relse - yes extend no | |
2304 * | |
2305 * Insert or Replace Mode: | |
2306 * event modi- position visual change action | |
2307 * fier cursor window | |
2308 * left press - yes (cannot be active) yes | |
2309 * left press C yes (cannot be active) yes "CTRL-O^]" (2) | |
2310 * left press S yes (cannot be active) yes "CTRL-O*" (2) | |
2311 * left drag - yes start or extend (1) no CTRL-O (1) | |
2312 * left relse - yes start or extend (1) no CTRL-O (1) | |
2313 * middle press - no (cannot be active) no put register | |
2314 * right press - yes start or extend yes CTRL-O | |
2315 * right press S yes (cannot be active) yes "CTRL-O#" (2) | |
2316 * | |
2317 * (1) only if mouse pointer moved since press | |
2318 * (2) only if click is in same buffer | |
2319 * | |
2320 * Return TRUE if start_arrow() should be called for edit mode. | |
2321 */ | |
2322 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2323 do_mouse( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2324 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
|
2325 int c, /* K_LEFTMOUSE, etc */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2326 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
|
2327 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2328 int fixindent) /* PUT_FIXINDENT if fixing indent necessary */ |
7 | 2329 { |
2330 static int do_always = FALSE; /* ignore 'mouse' setting next time */ | |
2331 static int got_click = FALSE; /* got a click some time back */ | |
2332 | |
2333 int which_button; /* MOUSE_LEFT, _MIDDLE or _RIGHT */ | |
2334 int is_click; /* If FALSE it's a drag or release event */ | |
2335 int is_drag; /* If TRUE it's a drag event */ | |
2336 int jump_flags = 0; /* flags for jump_to_mouse() */ | |
2337 pos_T start_visual; | |
2338 int moved; /* Has cursor moved? */ | |
2339 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
|
2340 static int in_tab_line = FALSE; /* mouse clicked in tab line */ |
7 | 2341 int in_sep_line; /* mouse in vertical separator line */ |
2342 int c1, c2; | |
2343 #if defined(FEAT_FOLDING) | |
2344 pos_T save_cursor; | |
2345 #endif | |
2346 win_T *old_curwin = curwin; | |
2347 static pos_T orig_cursor; | |
2348 colnr_T leftcol, rightcol; | |
2349 pos_T end_visual; | |
2350 int diff; | |
2351 int old_active = VIsual_active; | |
2352 int old_mode = VIsual_mode; | |
2353 int regname; | |
2354 | |
2355 #if defined(FEAT_FOLDING) | |
2356 save_cursor = curwin->w_cursor; | |
2357 #endif | |
2358 | |
2359 /* | |
2360 * When GUI is active, always recognize mouse events, otherwise: | |
2361 * - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'. | |
2362 * - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'. | |
2363 * - For command line and insert mode 'mouse' is checked before calling | |
2364 * do_mouse(). | |
2365 */ | |
2366 if (do_always) | |
2367 do_always = FALSE; | |
2368 else | |
2369 #ifdef FEAT_GUI | |
2370 if (!gui.in_use) | |
2371 #endif | |
2372 { | |
2373 if (VIsual_active) | |
2374 { | |
2375 if (!mouse_has(MOUSE_VISUAL)) | |
2376 return FALSE; | |
2377 } | |
5735 | 2378 else if (State == NORMAL && !mouse_has(MOUSE_NORMAL)) |
7 | 2379 return FALSE; |
2380 } | |
2381 | |
4221 | 2382 for (;;) |
2383 { | |
2384 which_button = get_mouse_button(KEY2TERMCAP1(c), &is_click, &is_drag); | |
2385 if (is_drag) | |
2386 { | |
2387 /* If the next character is the same mouse event then use that | |
2388 * one. Speeds up dragging the status line. */ | |
2389 if (vpeekc() != NUL) | |
2390 { | |
2391 int nc; | |
2392 int save_mouse_row = mouse_row; | |
2393 int save_mouse_col = mouse_col; | |
2394 | |
2395 /* Need to get the character, peeking doesn't get the actual | |
2396 * one. */ | |
2397 nc = safe_vgetc(); | |
2398 if (c == nc) | |
2399 continue; | |
2400 vungetc(nc); | |
2401 mouse_row = save_mouse_row; | |
2402 mouse_col = save_mouse_col; | |
2403 } | |
2404 } | |
2405 break; | |
2406 } | |
7 | 2407 |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2408 if (c == K_MOUSEMOVE) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2409 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2410 /* 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
|
2411 #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
|
2412 ui_may_remove_balloon(); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2413 if (p_bevalterm && !VIsual_active) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2414 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2415 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
|
2416 bevalexpr_due_set = TRUE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2417 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2418 #endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2419 return FALSE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2420 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2421 |
7 | 2422 #ifdef FEAT_MOUSESHAPE |
2423 /* May have stopped dragging the status or separator line. The pointer is | |
2424 * most likely still on the status or separator line. */ | |
2425 if (!is_drag && drag_status_line) | |
2426 { | |
2427 drag_status_line = FALSE; | |
2428 update_mouseshape(SHAPE_IDX_STATUS); | |
2429 } | |
2430 if (!is_drag && drag_sep_line) | |
2431 { | |
2432 drag_sep_line = FALSE; | |
2433 update_mouseshape(SHAPE_IDX_VSEP); | |
2434 } | |
2435 #endif | |
2436 | |
2437 /* | |
2438 * Ignore drag and release events if we didn't get a click. | |
2439 */ | |
2440 if (is_click) | |
2441 got_click = TRUE; | |
2442 else | |
2443 { | |
2444 if (!got_click) /* didn't get click, ignore */ | |
2445 return FALSE; | |
2446 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
|
2447 { |
7 | 2448 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
|
2449 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
|
2450 { |
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
|
2451 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
|
2452 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
|
2453 } |
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
|
2454 } |
7 | 2455 } |
2456 | |
2457 /* | |
2458 * CTRL right mouse button does CTRL-T | |
2459 */ | |
2460 if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) | |
2461 { | |
2462 if (State & INSERT) | |
2463 stuffcharReadbuff(Ctrl_O); | |
2464 if (count > 1) | |
2465 stuffnumReadbuff(count); | |
2466 stuffcharReadbuff(Ctrl_T); | |
2467 got_click = FALSE; /* ignore drag&release now */ | |
2468 return FALSE; | |
2469 } | |
2470 | |
2471 /* | |
2472 * CTRL only works with left mouse button | |
2473 */ | |
2474 if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT) | |
2475 return FALSE; | |
2476 | |
2477 /* | |
2478 * When a modifier is down, ignore drag and release events, as well as | |
2479 * multiple clicks and the middle mouse button. | |
2480 * Accept shift-leftmouse drags when 'mousemodel' is "popup.*". | |
2481 */ | |
179 | 2482 if ((mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT |
2483 | MOD_MASK_META)) | |
7 | 2484 && (!is_click |
2485 || (mod_mask & MOD_MASK_MULTI_CLICK) | |
2486 || which_button == MOUSE_MIDDLE) | |
598 | 2487 && !((mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT)) |
7 | 2488 && mouse_model_popup() |
2489 && which_button == MOUSE_LEFT) | |
598 | 2490 && !((mod_mask & MOD_MASK_ALT) |
2491 && !mouse_model_popup() | |
2492 && which_button == MOUSE_RIGHT) | |
7 | 2493 ) |
2494 return FALSE; | |
2495 | |
2496 /* | |
2497 * If the button press was used as the movement command for an operator | |
2498 * (eg "d<MOUSE>"), or it is the middle button that is held down, ignore | |
2499 * drag/release events. | |
2500 */ | |
2501 if (!is_click && which_button == MOUSE_MIDDLE) | |
2502 return FALSE; | |
2503 | |
2504 if (oap != NULL) | |
2505 regname = oap->regname; | |
2506 else | |
2507 regname = 0; | |
2508 | |
2509 /* | |
2510 * Middle mouse button does a 'put' of the selected text | |
2511 */ | |
2512 if (which_button == MOUSE_MIDDLE) | |
2513 { | |
2514 if (State == NORMAL) | |
2515 { | |
2516 /* | |
2517 * If an operator was pending, we don't know what the user wanted | |
2518 * to do. Go back to normal mode: Clear the operator and beep(). | |
2519 */ | |
2520 if (oap != NULL && oap->op_type != OP_NOP) | |
2521 { | |
2522 clearopbeep(oap); | |
2523 return FALSE; | |
2524 } | |
2525 | |
2526 /* | |
2527 * If visual was active, yank the highlighted text and put it | |
2528 * before the mouse pointer position. | |
1016 | 2529 * In Select mode replace the highlighted text with the clipboard. |
7 | 2530 */ |
2531 if (VIsual_active) | |
2532 { | |
1016 | 2533 if (VIsual_select) |
2534 { | |
2535 stuffcharReadbuff(Ctrl_G); | |
1019 | 2536 stuffReadbuff((char_u *)"\"+p"); |
1016 | 2537 } |
2538 else | |
2539 { | |
2540 stuffcharReadbuff('y'); | |
2541 stuffcharReadbuff(K_MIDDLEMOUSE); | |
2542 } | |
7 | 2543 do_always = TRUE; /* ignore 'mouse' setting next time */ |
2544 return FALSE; | |
2545 } | |
2546 /* | |
2547 * The rest is below jump_to_mouse() | |
2548 */ | |
2549 } | |
2550 | |
2551 else if ((State & INSERT) == 0) | |
2552 return FALSE; | |
2553 | |
2554 /* | |
2555 * Middle click in insert mode doesn't move the mouse, just insert the | |
2556 * contents of a register. '.' register is special, can't insert that | |
2557 * with do_put(). | |
2558 * Also paste at the cursor if the current mode isn't in 'mouse' (only | |
2559 * happens for the GUI). | |
2560 */ | |
2561 if ((State & INSERT) || !mouse_has(MOUSE_NORMAL)) | |
2562 { | |
2563 if (regname == '.') | |
2564 insert_reg(regname, TRUE); | |
2565 else | |
2566 { | |
2567 #ifdef FEAT_CLIPBOARD | |
2568 if (clip_star.available && regname == 0) | |
2569 regname = '*'; | |
2570 #endif | |
2571 if ((State & REPLACE_FLAG) && !yank_register_mline(regname)) | |
2572 insert_reg(regname, TRUE); | |
2573 else | |
2574 { | |
2575 do_put(regname, BACKWARD, 1L, fixindent | PUT_CURSEND); | |
2576 | |
2577 /* Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r */ | |
2578 AppendCharToRedobuff(Ctrl_R); | |
2579 AppendCharToRedobuff(fixindent ? Ctrl_P : Ctrl_O); | |
2580 AppendCharToRedobuff(regname == 0 ? '"' : regname); | |
2581 } | |
2582 } | |
2583 return FALSE; | |
2584 } | |
2585 } | |
2586 | |
2587 /* When dragging or button-up stay in the same window. */ | |
2588 if (!is_click) | |
2589 jump_flags |= MOUSE_FOCUS | MOUSE_DID_MOVE; | |
2590 | |
2591 start_visual.lnum = 0; | |
2592 | |
671 | 2593 /* Check for clicking in the tab page line. */ |
2594 if (mouse_row == 0 && firstwin->w_winrow > 0) | |
2595 { | |
1619 | 2596 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
|
2597 { |
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
|
2598 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
|
2599 { |
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
|
2600 c1 = TabPageIdxs[mouse_col]; |
7090
052043fc57ab
commit https://github.com/vim/vim/commit/4a4b821085847651b71d8ad9fab9f180635cb453
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2601 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
|
2602 ? 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
|
2603 } |
1619 | 2604 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
|
2605 } |
671 | 2606 |
2607 /* click in a tab selects that tab page */ | |
2608 if (is_click | |
2609 # ifdef FEAT_CMDWIN | |
2610 && cmdwin_type == 0 | |
2611 # endif | |
681 | 2612 && mouse_col < Columns) |
2613 { | |
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
|
2614 in_tab_line = TRUE; |
681 | 2615 c1 = TabPageIdxs[mouse_col]; |
2616 if (c1 >= 0) | |
2617 { | |
682 | 2618 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) |
2619 { | |
2620 /* double click opens new page */ | |
681 | 2621 end_visual_mode(); |
682 | 2622 tabpage_new(); |
2623 tabpage_move(c1 == 0 ? 9999 : c1 - 1); | |
2624 } | |
2625 else | |
2626 { | |
2627 /* Go to specified tab page, or next one if not clicking | |
2628 * on a label. */ | |
2629 goto_tabpage(c1); | |
2630 | |
2631 /* It's like clicking on the status line of a window. */ | |
2632 if (curwin != old_curwin) | |
2633 end_visual_mode(); | |
2634 } | |
681 | 2635 } |
2636 else if (c1 < 0) | |
2637 { | |
2638 tabpage_T *tp; | |
2639 | |
2640 /* Close the current or specified tab page. */ | |
2641 if (c1 == -999) | |
2642 tp = curtab; | |
2643 else | |
2644 tp = find_tabpage(-c1); | |
2645 if (tp == curtab) | |
2646 { | |
2647 if (first_tabpage->tp_next != NULL) | |
2648 tabpage_close(FALSE); | |
2649 } | |
2650 else if (tp != NULL) | |
2651 tabpage_close_other(tp, FALSE); | |
2652 } | |
2653 } | |
2654 return TRUE; | |
671 | 2655 } |
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
|
2656 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
|
2657 { |
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
|
2658 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
|
2659 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
|
2660 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
|
2661 } |
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
|
2662 |
7 | 2663 /* |
2664 * When 'mousemodel' is "popup" or "popup_setpos", translate mouse events: | |
2665 * right button up -> pop-up menu | |
2666 * shift-left button -> right button | |
598 | 2667 * alt-left button -> alt-right button |
7 | 2668 */ |
2669 if (mouse_model_popup()) | |
2670 { | |
2671 if (which_button == MOUSE_RIGHT | |
2672 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | |
2673 { | |
2674 /* | |
2675 * NOTE: Ignore right button down and drag mouse events. | |
2676 * Windows only shows the popup menu on the button up event. | |
2677 */ | |
936 | 2678 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \ |
2679 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) | |
7 | 2680 if (!is_click) |
2681 return FALSE; | |
2682 #endif | |
2683 #if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) | |
2684 if (is_click || is_drag) | |
2685 return FALSE; | |
2686 #endif | |
573 | 2687 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \ |
7 | 2688 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \ |
2689 || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_PHOTON) | |
2690 if (gui.in_use) | |
2691 { | |
2692 jump_flags = 0; | |
2693 if (STRCMP(p_mousem, "popup_setpos") == 0) | |
2694 { | |
2695 /* First set the cursor position before showing the popup | |
2696 * menu. */ | |
2697 if (VIsual_active) | |
2698 { | |
2699 pos_T m_pos; | |
2700 | |
2701 /* | |
2702 * set MOUSE_MAY_STOP_VIS if we are outside the | |
2703 * selection or the current window (might have false | |
2704 * negative here) | |
2705 */ | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2706 if (mouse_row < curwin->w_winrow |
7 | 2707 || mouse_row |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2708 > (curwin->w_winrow + curwin->w_height)) |
7 | 2709 jump_flags = MOUSE_MAY_STOP_VIS; |
2710 else if (get_fpos_of_mouse(&m_pos) != IN_BUFFER) | |
2711 jump_flags = MOUSE_MAY_STOP_VIS; | |
2712 else | |
2713 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2714 if ((LT_POS(curwin->w_cursor, VIsual) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2715 && (LT_POS(m_pos, curwin->w_cursor) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2716 || LT_POS(VIsual, m_pos))) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2717 || (LT_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
|
2718 && (LT_POS(m_pos, VIsual) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2719 || LT_POS(curwin->w_cursor, m_pos)))) |
7 | 2720 { |
2721 jump_flags = MOUSE_MAY_STOP_VIS; | |
2722 } | |
2723 else if (VIsual_mode == Ctrl_V) | |
2724 { | |
2725 getvcols(curwin, &curwin->w_cursor, &VIsual, | |
2726 &leftcol, &rightcol); | |
2727 getvcol(curwin, &m_pos, NULL, &m_pos.col, NULL); | |
2728 if (m_pos.col < leftcol || m_pos.col > rightcol) | |
2729 jump_flags = MOUSE_MAY_STOP_VIS; | |
2730 } | |
2731 } | |
2732 } | |
2733 else | |
2734 jump_flags = MOUSE_MAY_STOP_VIS; | |
2735 } | |
2736 if (jump_flags) | |
2737 { | |
2738 jump_flags = jump_to_mouse(jump_flags, NULL, which_button); | |
5735 | 2739 update_curbuf(VIsual_active ? INVERTED : VALID); |
7 | 2740 setcursor(); |
2741 out_flush(); /* Update before showing popup menu */ | |
2742 } | |
2743 # ifdef FEAT_MENU | |
2744 gui_show_popupmenu(); | |
2745 # endif | |
2746 return (jump_flags & CURSOR_MOVED) != 0; | |
2747 } | |
2748 else | |
2749 return FALSE; | |
2750 #else | |
2751 return FALSE; | |
2752 #endif | |
2753 } | |
598 | 2754 if (which_button == MOUSE_LEFT |
2755 && (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT))) | |
7 | 2756 { |
2757 which_button = MOUSE_RIGHT; | |
2758 mod_mask &= ~MOD_MASK_SHIFT; | |
2759 } | |
2760 } | |
2761 | |
2762 if ((State & (NORMAL | INSERT)) | |
2763 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | |
2764 { | |
2765 if (which_button == MOUSE_LEFT) | |
2766 { | |
2767 if (is_click) | |
2768 { | |
2769 /* stop Visual mode for a left click in a window, but not when | |
2770 * on a status line */ | |
2771 if (VIsual_active) | |
2772 jump_flags |= MOUSE_MAY_STOP_VIS; | |
2773 } | |
2774 else if (mouse_has(MOUSE_VISUAL)) | |
2775 jump_flags |= MOUSE_MAY_VIS; | |
2776 } | |
2777 else if (which_button == MOUSE_RIGHT) | |
2778 { | |
2779 if (is_click && VIsual_active) | |
2780 { | |
2781 /* | |
2782 * Remember the start and end of visual before moving the | |
2783 * cursor. | |
2784 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2785 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 2786 { |
2787 start_visual = curwin->w_cursor; | |
2788 end_visual = VIsual; | |
2789 } | |
2790 else | |
2791 { | |
2792 start_visual = VIsual; | |
2793 end_visual = curwin->w_cursor; | |
2794 } | |
2795 } | |
2796 jump_flags |= MOUSE_FOCUS; | |
2797 if (mouse_has(MOUSE_VISUAL)) | |
2798 jump_flags |= MOUSE_MAY_VIS; | |
2799 } | |
2800 } | |
2801 | |
2802 /* | |
2803 * If an operator is pending, ignore all drags and releases until the | |
2804 * next mouse click. | |
2805 */ | |
2806 if (!is_drag && oap != NULL && oap->op_type != OP_NOP) | |
2807 { | |
2808 got_click = FALSE; | |
2809 oap->motion_type = MCHAR; | |
2810 } | |
2811 | |
2812 /* When releasing the button let jump_to_mouse() know. */ | |
2813 if (!is_click && !is_drag) | |
2814 jump_flags |= MOUSE_RELEASED; | |
2815 | |
2816 /* | |
2817 * JUMP! | |
2818 */ | |
2819 jump_flags = jump_to_mouse(jump_flags, | |
2820 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
|
2821 |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2822 #ifdef FEAT_MENU |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2823 /* 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
|
2824 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
|
2825 return FALSE; |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2826 #endif |
7 | 2827 moved = (jump_flags & CURSOR_MOVED); |
2828 in_status_line = (jump_flags & IN_STATUS_LINE); | |
2829 in_sep_line = (jump_flags & IN_SEP_LINE); | |
2830 | |
2831 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2832 if (isNetbeansBuffer(curbuf) |
7 | 2833 && !(jump_flags & (IN_STATUS_LINE | IN_SEP_LINE))) |
2834 { | |
2835 int key = KEY2TERMCAP1(c); | |
2836 | |
2837 if (key == (int)KE_LEFTRELEASE || key == (int)KE_MIDDLERELEASE | |
2838 || key == (int)KE_RIGHTRELEASE) | |
2839 netbeans_button_release(which_button); | |
2840 } | |
2841 #endif | |
2842 | |
2843 /* When jumping to another window, clear a pending operator. That's a bit | |
2844 * friendlier than beeping and not jumping to that window. */ | |
2845 if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP) | |
2846 clearop(oap); | |
2847 | |
2848 #ifdef FEAT_FOLDING | |
2849 if (mod_mask == 0 | |
2850 && !is_drag | |
2851 && (jump_flags & (MOUSE_FOLD_CLOSE | MOUSE_FOLD_OPEN)) | |
2852 && which_button == MOUSE_LEFT) | |
2853 { | |
2854 /* open or close a fold at this line */ | |
2855 if (jump_flags & MOUSE_FOLD_OPEN) | |
2856 openFold(curwin->w_cursor.lnum, 1L); | |
2857 else | |
2858 closeFold(curwin->w_cursor.lnum, 1L); | |
2859 /* don't move the cursor if still in the same window */ | |
2860 if (curwin == old_curwin) | |
2861 curwin->w_cursor = save_cursor; | |
2862 } | |
2863 #endif | |
2864 | |
2865 #if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN) | |
2866 if ((jump_flags & IN_OTHER_WIN) && !VIsual_active && clip_star.available) | |
2867 { | |
2868 clip_modeless(which_button, is_click, is_drag); | |
2869 return FALSE; | |
2870 } | |
2871 #endif | |
2872 | |
2873 /* Set global flag that we are extending the Visual area with mouse | |
1188 | 2874 * dragging; temporarily minimize 'scrolloff'. */ |
7 | 2875 if (VIsual_active && is_drag && p_so) |
2876 { | |
2877 /* In the very first line, allow scrolling one line */ | |
2878 if (mouse_row == 0) | |
2879 mouse_dragging = 2; | |
2880 else | |
2881 mouse_dragging = 1; | |
2882 } | |
2883 | |
2884 /* When dragging the mouse above the window, scroll down. */ | |
2885 if (is_drag && mouse_row < 0 && !in_status_line) | |
2886 { | |
2887 scroll_redraw(FALSE, 1L); | |
2888 mouse_row = 0; | |
2889 } | |
2890 | |
2891 if (start_visual.lnum) /* right click in visual mode */ | |
2892 { | |
598 | 2893 /* When ALT is pressed make Visual mode blockwise. */ |
2894 if (mod_mask & MOD_MASK_ALT) | |
2895 VIsual_mode = Ctrl_V; | |
2896 | |
7 | 2897 /* |
2898 * In Visual-block mode, divide the area in four, pick up the corner | |
2899 * that is in the quarter that the cursor is in. | |
2900 */ | |
2901 if (VIsual_mode == Ctrl_V) | |
2902 { | |
2903 getvcols(curwin, &start_visual, &end_visual, &leftcol, &rightcol); | |
2904 if (curwin->w_curswant > (leftcol + rightcol) / 2) | |
2905 end_visual.col = leftcol; | |
2906 else | |
2907 end_visual.col = rightcol; | |
7009 | 2908 if (curwin->w_cursor.lnum >= |
7 | 2909 (start_visual.lnum + end_visual.lnum) / 2) |
2910 end_visual.lnum = start_visual.lnum; | |
2911 | |
2912 /* move VIsual to the right column */ | |
2913 start_visual = curwin->w_cursor; /* save the cursor pos */ | |
2914 curwin->w_cursor = end_visual; | |
2915 coladvance(end_visual.col); | |
2916 VIsual = curwin->w_cursor; | |
2917 curwin->w_cursor = start_visual; /* restore the cursor */ | |
2918 } | |
2919 else | |
2920 { | |
2921 /* | |
2922 * If the click is before the start of visual, change the start. | |
2923 * If the click is after the end of visual, change the end. If | |
2924 * the click is inside the visual, change the closest side. | |
2925 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2926 if (LT_POS(curwin->w_cursor, start_visual)) |
7 | 2927 VIsual = end_visual; |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2928 else if (LT_POS(end_visual, curwin->w_cursor)) |
7 | 2929 VIsual = start_visual; |
2930 else | |
2931 { | |
2932 /* In the same line, compare column number */ | |
2933 if (end_visual.lnum == start_visual.lnum) | |
2934 { | |
2935 if (curwin->w_cursor.col - start_visual.col > | |
2936 end_visual.col - curwin->w_cursor.col) | |
2937 VIsual = start_visual; | |
2938 else | |
2939 VIsual = end_visual; | |
2940 } | |
2941 | |
2942 /* In different lines, compare line number */ | |
2943 else | |
2944 { | |
2945 diff = (curwin->w_cursor.lnum - start_visual.lnum) - | |
2946 (end_visual.lnum - curwin->w_cursor.lnum); | |
2947 | |
2948 if (diff > 0) /* closest to end */ | |
2949 VIsual = start_visual; | |
2950 else if (diff < 0) /* closest to start */ | |
2951 VIsual = end_visual; | |
2952 else /* in the middle line */ | |
2953 { | |
2954 if (curwin->w_cursor.col < | |
2955 (start_visual.col + end_visual.col) / 2) | |
2956 VIsual = end_visual; | |
2957 else | |
2958 VIsual = start_visual; | |
2959 } | |
2960 } | |
2961 } | |
2962 } | |
2963 } | |
2964 /* | |
2965 * If Visual mode started in insert mode, execute "CTRL-O" | |
2966 */ | |
2967 else if ((State & INSERT) && VIsual_active) | |
2968 stuffcharReadbuff(Ctrl_O); | |
2969 | |
2970 /* | |
2971 * Middle mouse click: Put text before cursor. | |
2972 */ | |
2973 if (which_button == MOUSE_MIDDLE) | |
2974 { | |
2975 #ifdef FEAT_CLIPBOARD | |
2976 if (clip_star.available && regname == 0) | |
2977 regname = '*'; | |
2978 #endif | |
2979 if (yank_register_mline(regname)) | |
2980 { | |
2981 if (mouse_past_bottom) | |
2982 dir = FORWARD; | |
2983 } | |
2984 else if (mouse_past_eol) | |
2985 dir = FORWARD; | |
2986 | |
2987 if (fixindent) | |
2988 { | |
2989 c1 = (dir == BACKWARD) ? '[' : ']'; | |
2990 c2 = 'p'; | |
2991 } | |
2992 else | |
2993 { | |
2994 c1 = (dir == FORWARD) ? 'p' : 'P'; | |
2995 c2 = NUL; | |
2996 } | |
2997 prep_redo(regname, count, NUL, c1, NUL, c2, NUL); | |
2998 | |
2999 /* | |
3000 * Remember where the paste started, so in edit() Insstart can be set | |
3001 * to this position | |
3002 */ | |
3003 if (restart_edit != 0) | |
3004 where_paste_started = curwin->w_cursor; | |
3005 do_put(regname, dir, count, fixindent | PUT_CURSEND); | |
3006 } | |
3007 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3008 #if defined(FEAT_QUICKFIX) |
7 | 3009 /* |
3010 * Ctrl-Mouse click or double click in a quickfix window jumps to the | |
3011 * error under the mouse pointer. | |
3012 */ | |
3013 else if (((mod_mask & MOD_MASK_CTRL) | |
3014 || (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
3015 && bt_quickfix(curbuf)) | |
3016 { | |
643 | 3017 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
|
3018 do_cmdline_cmd((char_u *)".cc"); |
643 | 3019 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
|
3020 do_cmdline_cmd((char_u *)".ll"); |
7 | 3021 got_click = FALSE; /* ignore drag&release now */ |
3022 } | |
3023 #endif | |
3024 | |
3025 /* | |
3026 * Ctrl-Mouse click (or double click in a help window) jumps to the tag | |
3027 * under the mouse pointer. | |
3028 */ | |
3029 else if ((mod_mask & MOD_MASK_CTRL) || (curbuf->b_help | |
3030 && (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)) | |
3031 { | |
3032 if (State & INSERT) | |
3033 stuffcharReadbuff(Ctrl_O); | |
3034 stuffcharReadbuff(Ctrl_RSB); | |
3035 got_click = FALSE; /* ignore drag&release now */ | |
3036 } | |
3037 | |
3038 /* | |
3039 * Shift-Mouse click searches for the next occurrence of the word under | |
3040 * the mouse pointer | |
3041 */ | |
3042 else if ((mod_mask & MOD_MASK_SHIFT)) | |
3043 { | |
5735 | 3044 if ((State & INSERT) || (VIsual_active && VIsual_select)) |
7 | 3045 stuffcharReadbuff(Ctrl_O); |
3046 if (which_button == MOUSE_LEFT) | |
3047 stuffcharReadbuff('*'); | |
3048 else /* MOUSE_RIGHT */ | |
3049 stuffcharReadbuff('#'); | |
3050 } | |
3051 | |
3052 /* Handle double clicks, unless on status line */ | |
3053 else if (in_status_line) | |
3054 { | |
3055 #ifdef FEAT_MOUSESHAPE | |
3056 if ((is_drag || is_click) && !drag_status_line) | |
3057 { | |
3058 drag_status_line = TRUE; | |
3059 update_mouseshape(-1); | |
3060 } | |
3061 #endif | |
3062 } | |
3063 else if (in_sep_line) | |
3064 { | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3065 #ifdef FEAT_MOUSESHAPE |
7 | 3066 if ((is_drag || is_click) && !drag_sep_line) |
3067 { | |
3068 drag_sep_line = TRUE; | |
3069 update_mouseshape(-1); | |
3070 } | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3071 #endif |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3072 } |
7 | 3073 else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT)) |
3074 && mouse_has(MOUSE_VISUAL)) | |
3075 { | |
3076 if (is_click || !VIsual_active) | |
3077 { | |
3078 if (VIsual_active) | |
3079 orig_cursor = VIsual; | |
3080 else | |
3081 { | |
3082 check_visual_highlight(); | |
3083 VIsual = curwin->w_cursor; | |
3084 orig_cursor = VIsual; | |
3085 VIsual_active = TRUE; | |
3086 VIsual_reselect = TRUE; | |
3087 /* start Select mode if 'selectmode' contains "mouse" */ | |
3088 may_start_select('o'); | |
3089 setmouse(); | |
3090 } | |
3091 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
598 | 3092 { |
3093 /* Double click with ALT pressed makes it blockwise. */ | |
3094 if (mod_mask & MOD_MASK_ALT) | |
3095 VIsual_mode = Ctrl_V; | |
3096 else | |
3097 VIsual_mode = 'v'; | |
3098 } | |
7 | 3099 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK) |
3100 VIsual_mode = 'V'; | |
3101 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK) | |
3102 VIsual_mode = Ctrl_V; | |
3103 #ifdef FEAT_CLIPBOARD | |
3104 /* Make sure the clipboard gets updated. Needed because start and | |
3105 * end may still be the same, and the selection needs to be owned */ | |
3106 clip_star.vmode = NUL; | |
3107 #endif | |
3108 } | |
3109 /* | |
3110 * A double click selects a word or a block. | |
3111 */ | |
3112 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
3113 { | |
3114 pos_T *pos = NULL; | |
300 | 3115 int gc; |
7 | 3116 |
3117 if (is_click) | |
3118 { | |
3119 /* If the character under the cursor (skipping white space) is | |
3120 * not a word character, try finding a match and select a (), | |
3121 * {}, [], #if/#endif, etc. block. */ | |
3122 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
|
3123 while (gc = gchar_pos(&end_visual), VIM_ISWHITE(gc)) |
7 | 3124 inc(&end_visual); |
3125 if (oap != NULL) | |
3126 oap->motion_type = MCHAR; | |
3127 if (oap != NULL | |
3128 && VIsual_mode == 'v' | |
3129 && !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
|
3130 && EQUAL_POS(curwin->w_cursor, VIsual) |
7 | 3131 && (pos = findmatch(oap, NUL)) != NULL) |
3132 { | |
3133 curwin->w_cursor = *pos; | |
3134 if (oap->motion_type == MLINE) | |
3135 VIsual_mode = 'V'; | |
3136 else if (*p_sel == 'e') | |
3137 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3138 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 3139 ++VIsual.col; |
3140 else | |
3141 ++curwin->w_cursor.col; | |
3142 } | |
3143 } | |
3144 } | |
3145 | |
3146 if (pos == NULL && (is_click || is_drag)) | |
3147 { | |
3148 /* When not found a match or when dragging: extend to include | |
3149 * a word. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3150 if (LT_POS(curwin->w_cursor, orig_cursor)) |
7 | 3151 { |
3152 find_start_of_word(&curwin->w_cursor); | |
3153 find_end_of_word(&VIsual); | |
3154 } | |
3155 else | |
3156 { | |
3157 find_start_of_word(&VIsual); | |
3158 if (*p_sel == 'e' && *ml_get_cursor() != NUL) | |
3159 #ifdef FEAT_MBYTE | |
3160 curwin->w_cursor.col += | |
474 | 3161 (*mb_ptr2len)(ml_get_cursor()); |
7 | 3162 #else |
3163 ++curwin->w_cursor.col; | |
3164 #endif | |
3165 find_end_of_word(&curwin->w_cursor); | |
3166 } | |
3167 } | |
3168 curwin->w_set_curswant = TRUE; | |
3169 } | |
3170 if (is_click) | |
3171 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
3172 } | |
3173 else if (VIsual_active && !old_active) | |
598 | 3174 { |
3175 if (mod_mask & MOD_MASK_ALT) | |
3176 VIsual_mode = Ctrl_V; | |
3177 else | |
3178 VIsual_mode = 'v'; | |
3179 } | |
7 | 3180 |
3181 /* If Visual mode changed show it later. */ | |
643 | 3182 if ((!VIsual_active && old_active && mode_displayed) |
3183 || (VIsual_active && p_smd && msg_silent == 0 | |
3184 && (!old_active || VIsual_mode != old_mode))) | |
7 | 3185 redraw_cmdline = TRUE; |
3186 | |
3187 return moved; | |
3188 } | |
3189 | |
3190 /* | |
3191 * Move "pos" back to the start of the word it's in. | |
3192 */ | |
3193 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3194 find_start_of_word(pos_T *pos) |
7 | 3195 { |
3196 char_u *line; | |
3197 int cclass; | |
3198 int col; | |
3199 | |
3200 line = ml_get(pos->lnum); | |
3201 cclass = get_mouse_class(line + pos->col); | |
3202 | |
3203 while (pos->col > 0) | |
3204 { | |
3205 col = pos->col - 1; | |
3206 #ifdef FEAT_MBYTE | |
3207 col -= (*mb_head_off)(line, line + col); | |
3208 #endif | |
3209 if (get_mouse_class(line + col) != cclass) | |
3210 break; | |
3211 pos->col = col; | |
3212 } | |
3213 } | |
3214 | |
3215 /* | |
3216 * Move "pos" forward to the end of the word it's in. | |
3217 * When 'selection' is "exclusive", the position is just after the word. | |
3218 */ | |
3219 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3220 find_end_of_word(pos_T *pos) |
7 | 3221 { |
3222 char_u *line; | |
3223 int cclass; | |
3224 int col; | |
3225 | |
3226 line = ml_get(pos->lnum); | |
3227 if (*p_sel == 'e' && pos->col > 0) | |
3228 { | |
3229 --pos->col; | |
3230 #ifdef FEAT_MBYTE | |
3231 pos->col -= (*mb_head_off)(line, line + pos->col); | |
3232 #endif | |
3233 } | |
3234 cclass = get_mouse_class(line + pos->col); | |
3235 while (line[pos->col] != NUL) | |
3236 { | |
3237 #ifdef FEAT_MBYTE | |
474 | 3238 col = pos->col + (*mb_ptr2len)(line + pos->col); |
7 | 3239 #else |
3240 col = pos->col + 1; | |
3241 #endif | |
3242 if (get_mouse_class(line + col) != cclass) | |
3243 { | |
3244 if (*p_sel == 'e') | |
3245 pos->col = col; | |
3246 break; | |
3247 } | |
3248 pos->col = col; | |
3249 } | |
3250 } | |
3251 | |
3252 /* | |
3253 * Get class of a character for selection: same class means same word. | |
3254 * 0: blank | |
3255 * 1: punctuation groups | |
3256 * 2: normal word character | |
3257 * >2: multi-byte word character. | |
3258 */ | |
3259 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3260 get_mouse_class(char_u *p) |
7 | 3261 { |
3262 int c; | |
3263 | |
3264 #ifdef FEAT_MBYTE | |
3265 if (has_mbyte && MB_BYTE2LEN(p[0]) > 1) | |
3266 return mb_get_class(p); | |
3267 #endif | |
3268 | |
3269 c = *p; | |
3270 if (c == ' ' || c == '\t') | |
3271 return 0; | |
3272 | |
3273 if (vim_iswordc(c)) | |
3274 return 2; | |
3275 | |
3276 /* | |
3277 * There are a few special cases where we want certain combinations of | |
3278 * characters to be considered as a single word. These are things like | |
3279 * "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
3280 * character is in its own class. |
7 | 3281 */ |
3282 if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL) | |
3283 return 1; | |
3284 return c; | |
3285 } | |
3286 #endif /* FEAT_MOUSE */ | |
3287 | |
3288 /* | |
3289 * Check if highlighting for visual mode is possible, give a warning message | |
3290 * if not. | |
3291 */ | |
3292 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3293 check_visual_highlight(void) |
7 | 3294 { |
3295 static int did_check = FALSE; | |
3296 | |
3297 if (full_screen) | |
3298 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3299 if (!did_check && HL_ATTR(HLF_V) == 0) |
7 | 3300 MSG(_("Warning: terminal cannot highlight")); |
3301 did_check = TRUE; | |
3302 } | |
3303 } | |
3304 | |
3305 /* | |
638 | 3306 * End Visual mode. |
7 | 3307 * This function should ALWAYS be called to end Visual mode, except from |
3308 * do_pending_operator(). | |
3309 */ | |
3310 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3311 end_visual_mode(void) |
7 | 3312 { |
3313 #ifdef FEAT_CLIPBOARD | |
3314 /* | |
3315 * If we are using the clipboard, then remember what was selected in case | |
3316 * we need to paste it somewhere while we still own the selection. | |
3317 * Only do this when the clipboard is already owned. Don't want to grab | |
3318 * the selection when hitting ESC. | |
3319 */ | |
3320 if (clip_star.available && clip_star.owned) | |
3321 clip_auto_select(); | |
3322 #endif | |
3323 | |
3324 VIsual_active = FALSE; | |
3325 #ifdef FEAT_MOUSE | |
3326 setmouse(); | |
3327 mouse_dragging = 0; | |
3328 #endif | |
3329 | |
3330 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
690 | 3331 curbuf->b_visual.vi_mode = VIsual_mode; |
3332 curbuf->b_visual.vi_start = VIsual; | |
3333 curbuf->b_visual.vi_end = curwin->w_cursor; | |
3334 curbuf->b_visual.vi_curswant = curwin->w_curswant; | |
7 | 3335 #ifdef FEAT_EVAL |
3336 curbuf->b_visual_mode_eval = VIsual_mode; | |
3337 #endif | |
3338 #ifdef FEAT_VIRTUALEDIT | |
3339 if (!virtual_active()) | |
3340 curwin->w_cursor.coladd = 0; | |
3341 #endif | |
6979 | 3342 may_clear_cmdline(); |
7 | 3343 |
844 | 3344 adjust_cursor_eol(); |
7 | 3345 } |
3346 | |
3347 /* | |
3348 * Reset VIsual_active and VIsual_reselect. | |
3349 */ | |
3350 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3351 reset_VIsual_and_resel(void) |
7 | 3352 { |
3353 if (VIsual_active) | |
3354 { | |
3355 end_visual_mode(); | |
3356 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
3357 } | |
3358 VIsual_reselect = FALSE; | |
3359 } | |
3360 | |
3361 /* | |
3362 * Reset VIsual_active and VIsual_reselect if it's set. | |
3363 */ | |
3364 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3365 reset_VIsual(void) |
7 | 3366 { |
3367 if (VIsual_active) | |
3368 { | |
3369 end_visual_mode(); | |
3370 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
3371 VIsual_reselect = FALSE; | |
3372 } | |
3373 } | |
3374 | |
3375 /* | |
3376 * Check for a balloon-eval special item to include when searching for an | |
3377 * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid! | |
3378 * Returns TRUE if the character at "*ptr" should be included. | |
3379 * "dir" is FORWARD or BACKWARD, the direction of searching. | |
3380 * "*colp" is in/decremented if "ptr[-dir]" should also be included. | |
3381 * "bnp" points to a counter for square brackets. | |
3382 */ | |
3383 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3384 find_is_eval_item( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3385 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3386 int *colp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3387 int *bnp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3388 int dir) |
7 | 3389 { |
3390 /* Accept everything inside []. */ | |
3391 if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) | |
3392 ++*bnp; | |
3393 if (*bnp > 0) | |
3394 { | |
3395 if ((*ptr == '[' && dir == BACKWARD) || (*ptr == ']' && dir == FORWARD)) | |
3396 --*bnp; | |
3397 return TRUE; | |
3398 } | |
3399 | |
3400 /* skip over "s.var" */ | |
3401 if (*ptr == '.') | |
3402 return TRUE; | |
3403 | |
3404 /* two-character item: s->var */ | |
3405 if (ptr[dir == BACKWARD ? 0 : 1] == '>' | |
3406 && ptr[dir == BACKWARD ? -1 : 0] == '-') | |
3407 { | |
3408 *colp += dir; | |
3409 return TRUE; | |
3410 } | |
3411 return FALSE; | |
3412 } | |
3413 | |
3414 /* | |
3415 * Find the identifier under or to the right of the cursor. | |
3416 * "find_type" can have one of three values: | |
3417 * FIND_IDENT: find an identifier (keyword) | |
3418 * FIND_STRING: find any non-white string | |
3419 * FIND_IDENT + FIND_STRING: find any non-white string, identifier preferred. | |
184 | 3420 * FIND_EVAL: find text useful for C program debugging |
7 | 3421 * |
3422 * There are three steps: | |
3423 * 1. Search forward for the start of an identifier/string. Doesn't move if | |
3424 * already on one. | |
3425 * 2. Search backward for the start of this identifier/string. | |
3426 * This doesn't match the real Vi but I like it a little better and it | |
3427 * shouldn't bother anyone. | |
3428 * 3. Search forward to the end of this identifier/string. | |
3429 * When FIND_IDENT isn't defined, we backup until a blank. | |
3430 * | |
3431 * Returns the length of the string, or zero if no string is found. | |
3432 * If a string is found, a pointer to the string is put in "*string". This | |
3433 * string is not always NUL terminated. | |
3434 */ | |
3435 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3436 find_ident_under_cursor(char_u **string, int find_type) |
7 | 3437 { |
3438 return find_ident_at_pos(curwin, curwin->w_cursor.lnum, | |
3439 curwin->w_cursor.col, string, find_type); | |
3440 } | |
3441 | |
3442 /* | |
3443 * Like find_ident_under_cursor(), but for any window and any position. | |
3444 * However: Uses 'iskeyword' from the current window!. | |
3445 */ | |
3446 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3447 find_ident_at_pos( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3448 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3449 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3450 colnr_T startcol, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3451 char_u **string, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3452 int find_type) |
7 | 3453 { |
3454 char_u *ptr; | |
3455 int col = 0; /* init to shut up GCC */ | |
3456 int i; | |
3457 #ifdef FEAT_MBYTE | |
3458 int this_class = 0; | |
3459 int prev_class; | |
3460 int prevcol; | |
3461 #endif | |
3462 int bn = 0; /* bracket nesting */ | |
3463 | |
3464 /* | |
3465 * if i == 0: try to find an identifier | |
3466 * if i == 1: try to find any non-white string | |
3467 */ | |
3468 ptr = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3469 for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; ++i) | |
3470 { | |
3471 /* | |
3472 * 1. skip to start of identifier/string | |
3473 */ | |
3474 col = startcol; | |
3475 #ifdef FEAT_MBYTE | |
3476 if (has_mbyte) | |
3477 { | |
3478 while (ptr[col] != NUL) | |
3479 { | |
3480 /* Stop at a ']' to evaluate "a[x]". */ | |
3481 if ((find_type & FIND_EVAL) && ptr[col] == ']') | |
3482 break; | |
3483 this_class = mb_get_class(ptr + col); | |
3484 if (this_class != 0 && (i == 1 || this_class != 1)) | |
3485 break; | |
474 | 3486 col += (*mb_ptr2len)(ptr + col); |
7 | 3487 } |
3488 } | |
3489 else | |
3490 #endif | |
3491 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
|
3492 && (i == 0 ? !vim_iswordc(ptr[col]) : VIM_ISWHITE(ptr[col])) |
7 | 3493 && (!(find_type & FIND_EVAL) || ptr[col] != ']') |
3494 ) | |
3495 ++col; | |
3496 | |
3497 /* When starting on a ']' count it, so that we include the '['. */ | |
3498 bn = ptr[col] == ']'; | |
3499 | |
3500 /* | |
3501 * 2. Back up to start of identifier/string. | |
3502 */ | |
3503 #ifdef FEAT_MBYTE | |
3504 if (has_mbyte) | |
3505 { | |
3506 /* Remember class of character under cursor. */ | |
3507 if ((find_type & FIND_EVAL) && ptr[col] == ']') | |
3508 this_class = mb_get_class((char_u *)"a"); | |
3509 else | |
3510 this_class = mb_get_class(ptr + col); | |
835 | 3511 while (col > 0 && this_class != 0) |
7 | 3512 { |
3513 prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1); | |
3514 prev_class = mb_get_class(ptr + prevcol); | |
3515 if (this_class != prev_class | |
3516 && (i == 0 | |
3517 || prev_class == 0 | |
3518 || (find_type & FIND_IDENT)) | |
3519 && (!(find_type & FIND_EVAL) | |
3520 || prevcol == 0 | |
3521 || !find_is_eval_item(ptr + prevcol, &prevcol, | |
3522 &bn, BACKWARD)) | |
3523 ) | |
3524 break; | |
3525 col = prevcol; | |
3526 } | |
3527 | |
3528 /* If we don't want just any old string, or we've found an | |
3529 * identifier, stop searching. */ | |
3530 if (this_class > 2) | |
3531 this_class = 2; | |
3532 if (!(find_type & FIND_STRING) || this_class == 2) | |
3533 break; | |
3534 } | |
3535 else | |
3536 #endif | |
3537 { | |
3538 while (col > 0 | |
3539 && ((i == 0 | |
3540 ? 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
|
3541 : (!VIM_ISWHITE(ptr[col - 1]) |
7 | 3542 && (!(find_type & FIND_IDENT) |
3543 || !vim_iswordc(ptr[col - 1])))) | |
3544 || ((find_type & FIND_EVAL) | |
3545 && col > 1 | |
3546 && find_is_eval_item(ptr + col - 1, &col, | |
3547 &bn, BACKWARD)) | |
3548 )) | |
3549 --col; | |
3550 | |
3551 /* If we don't want just any old string, or we've found an | |
3552 * identifier, stop searching. */ | |
3553 if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col])) | |
3554 break; | |
3555 } | |
3556 } | |
3557 | |
3558 if (ptr[col] == NUL || (i == 0 && ( | |
3559 #ifdef FEAT_MBYTE | |
3560 has_mbyte ? this_class != 2 : | |
3561 #endif | |
3562 !vim_iswordc(ptr[col])))) | |
3563 { | |
3564 /* | |
3565 * didn't find an identifier or string | |
3566 */ | |
3567 if (find_type & FIND_STRING) | |
3568 EMSG(_("E348: No string under cursor")); | |
3569 else | |
1728 | 3570 EMSG(_(e_noident)); |
7 | 3571 return 0; |
3572 } | |
3573 ptr += col; | |
3574 *string = ptr; | |
3575 | |
3576 /* | |
3577 * 3. Find the end if the identifier/string. | |
3578 */ | |
3579 bn = 0; | |
3580 startcol -= col; | |
3581 col = 0; | |
3582 #ifdef FEAT_MBYTE | |
3583 if (has_mbyte) | |
3584 { | |
3585 /* Search for point of changing multibyte character class. */ | |
3586 this_class = mb_get_class(ptr); | |
3587 while (ptr[col] != NUL | |
3588 && ((i == 0 ? mb_get_class(ptr + col) == this_class | |
3589 : mb_get_class(ptr + col) != 0) | |
3590 || ((find_type & FIND_EVAL) | |
3591 && col <= (int)startcol | |
3592 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
3593 )) | |
474 | 3594 col += (*mb_ptr2len)(ptr + col); |
7 | 3595 } |
3596 else | |
3597 #endif | |
3598 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
|
3599 : (ptr[col] != NUL && !VIM_ISWHITE(ptr[col]))) |
7 | 3600 || ((find_type & FIND_EVAL) |
3601 && col <= (int)startcol | |
3602 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
3603 ) | |
3604 { | |
3605 ++col; | |
3606 } | |
3607 | |
3608 return col; | |
3609 } | |
3610 | |
3611 /* | |
3612 * Prepare for redo of a normal command. | |
3613 */ | |
3614 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3615 prep_redo_cmd(cmdarg_T *cap) |
7 | 3616 { |
3617 prep_redo(cap->oap->regname, cap->count0, | |
3618 NUL, cap->cmdchar, NUL, NUL, cap->nchar); | |
3619 } | |
3620 | |
3621 /* | |
3622 * Prepare for redo of any command. | |
3623 * Note that only the last argument can be a multi-byte char. | |
3624 */ | |
3625 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3626 prep_redo( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3627 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3628 long num, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3629 int cmd1, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3630 int cmd2, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3631 int cmd3, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3632 int cmd4, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3633 int cmd5) |
7 | 3634 { |
3635 ResetRedobuff(); | |
3636 if (regname != 0) /* yank from specified buffer */ | |
3637 { | |
3638 AppendCharToRedobuff('"'); | |
3639 AppendCharToRedobuff(regname); | |
3640 } | |
3641 if (num) | |
3642 AppendNumberToRedobuff(num); | |
3643 | |
3644 if (cmd1 != NUL) | |
3645 AppendCharToRedobuff(cmd1); | |
3646 if (cmd2 != NUL) | |
3647 AppendCharToRedobuff(cmd2); | |
3648 if (cmd3 != NUL) | |
3649 AppendCharToRedobuff(cmd3); | |
3650 if (cmd4 != NUL) | |
3651 AppendCharToRedobuff(cmd4); | |
3652 if (cmd5 != NUL) | |
3653 AppendCharToRedobuff(cmd5); | |
3654 } | |
3655 | |
3656 /* | |
3657 * check for operator active and clear it | |
3658 * | |
3659 * return TRUE if operator was active | |
3660 */ | |
3661 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3662 checkclearop(oparg_T *oap) |
7 | 3663 { |
3664 if (oap->op_type == OP_NOP) | |
3665 return FALSE; | |
3666 clearopbeep(oap); | |
3667 return TRUE; | |
3668 } | |
3669 | |
3670 /* | |
1131 | 3671 * Check for operator or Visual active. Clear active operator. |
7 | 3672 * |
1131 | 3673 * Return TRUE if operator or Visual was active. |
7 | 3674 */ |
3675 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3676 checkclearopq(oparg_T *oap) |
7 | 3677 { |
5735 | 3678 if (oap->op_type == OP_NOP && !VIsual_active) |
7 | 3679 return FALSE; |
3680 clearopbeep(oap); | |
3681 return TRUE; | |
3682 } | |
3683 | |
3684 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3685 clearop(oparg_T *oap) |
7 | 3686 { |
3687 oap->op_type = OP_NOP; | |
3688 oap->regname = 0; | |
3689 oap->motion_force = NUL; | |
3690 oap->use_reg_one = FALSE; | |
3691 } | |
3692 | |
3693 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3694 clearopbeep(oparg_T *oap) |
7 | 3695 { |
3696 clearop(oap); | |
3697 beep_flush(); | |
3698 } | |
3699 | |
3700 /* | |
3701 * Remove the shift modifier from a special key. | |
3702 */ | |
3703 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3704 unshift_special(cmdarg_T *cap) |
7 | 3705 { |
3706 switch (cap->cmdchar) | |
3707 { | |
3708 case K_S_RIGHT: cap->cmdchar = K_RIGHT; break; | |
3709 case K_S_LEFT: cap->cmdchar = K_LEFT; break; | |
3710 case K_S_UP: cap->cmdchar = K_UP; break; | |
3711 case K_S_DOWN: cap->cmdchar = K_DOWN; break; | |
3712 case K_S_HOME: cap->cmdchar = K_HOME; break; | |
3713 case K_S_END: cap->cmdchar = K_END; break; | |
3714 } | |
3715 cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask); | |
3716 } | |
3717 | |
6979 | 3718 /* |
3719 * If the mode is currently displayed clear the command line or update the | |
3720 * command displayed. | |
3721 */ | |
3722 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3723 may_clear_cmdline(void) |
6979 | 3724 { |
3725 if (mode_displayed) | |
3726 clear_cmdline = TRUE; /* unshow visual mode later */ | |
3727 #ifdef FEAT_CMDL_INFO | |
3728 else | |
3729 clear_showcmd(); | |
3730 #endif | |
3731 } | |
3732 | |
7 | 3733 #if defined(FEAT_CMDL_INFO) || defined(PROTO) |
3734 /* | |
3735 * Routines for displaying a partly typed command | |
3736 */ | |
3737 | |
5735 | 3738 #define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 |
7 | 3739 static char_u showcmd_buf[SHOWCMD_BUFLEN]; |
3740 static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */ | |
3741 static int showcmd_is_clear = TRUE; | |
3742 static int showcmd_visual = FALSE; | |
3743 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
3744 static void display_showcmd(void); |
7 | 3745 |
3746 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3747 clear_showcmd(void) |
7 | 3748 { |
3749 if (!p_sc) | |
3750 return; | |
3751 | |
3752 if (VIsual_active && !char_avail()) | |
3753 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3754 int cursor_bot = LT_POS(VIsual, curwin->w_cursor); |
7 | 3755 long lines; |
3756 colnr_T leftcol, rightcol; | |
3757 linenr_T top, bot; | |
3758 | |
3759 /* Show the size of the Visual area. */ | |
1866 | 3760 if (cursor_bot) |
7 | 3761 { |
3762 top = VIsual.lnum; | |
3763 bot = curwin->w_cursor.lnum; | |
3764 } | |
3765 else | |
3766 { | |
3767 top = curwin->w_cursor.lnum; | |
3768 bot = VIsual.lnum; | |
3769 } | |
3770 # ifdef FEAT_FOLDING | |
3771 /* Include closed folds as a whole. */ | |
7009 | 3772 (void)hasFolding(top, &top, NULL); |
3773 (void)hasFolding(bot, NULL, &bot); | |
7 | 3774 # endif |
3775 lines = bot - top + 1; | |
3776 | |
3777 if (VIsual_mode == Ctrl_V) | |
3778 { | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3779 # ifdef FEAT_LINEBREAK |
1866 | 3780 char_u *saved_sbr = p_sbr; |
3781 | |
3782 /* Make 'sbr' empty for a moment to get the correct size. */ | |
3783 p_sbr = empty_option; | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3784 # endif |
7 | 3785 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
|
3786 # ifdef FEAT_LINEBREAK |
1866 | 3787 p_sbr = saved_sbr; |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3788 # endif |
7 | 3789 sprintf((char *)showcmd_buf, "%ldx%ld", lines, |
3790 (long)(rightcol - leftcol + 1)); | |
3791 } | |
3792 else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum) | |
3793 sprintf((char *)showcmd_buf, "%ld", lines); | |
3794 else | |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3795 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3796 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
|
3797 int l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3798 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
|
3799 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
|
3800 |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3801 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
|
3802 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3803 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
|
3804 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
|
3805 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3806 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3807 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3808 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
|
3809 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
|
3810 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3811 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
|
3812 { |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3813 # ifdef FEAT_MBYTE |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3814 l = (*mb_ptr2len)(s); |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3815 # else |
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3816 l = (*s == NUL) ? 0 : 1; |
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3817 # endif |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3818 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
|
3819 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3820 ++bytes; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3821 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3822 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
|
3823 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3824 bytes += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3825 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3826 s += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3827 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3828 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
|
3829 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
|
3830 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3831 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
|
3832 } |
7 | 3833 showcmd_buf[SHOWCMD_COLS] = NUL; /* truncate */ |
3834 showcmd_visual = TRUE; | |
3835 } | |
3836 else | |
3837 { | |
3838 showcmd_buf[0] = NUL; | |
3839 showcmd_visual = FALSE; | |
3840 | |
3841 /* Don't actually display something if there is nothing to clear. */ | |
3842 if (showcmd_is_clear) | |
3843 return; | |
3844 } | |
3845 | |
3846 display_showcmd(); | |
3847 } | |
3848 | |
3849 /* | |
3850 * Add 'c' to string of shown command chars. | |
3851 * Return TRUE if output has been written (and setcursor() has been called). | |
3852 */ | |
3853 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3854 add_to_showcmd(int c) |
7 | 3855 { |
3856 char_u *p; | |
3857 int old_len; | |
3858 int extra_len; | |
3859 int overflow; | |
3860 #if defined(FEAT_MOUSE) | |
3861 int i; | |
3862 static int ignore[] = | |
3863 { | |
660 | 3864 # ifdef FEAT_GUI |
7 | 3865 K_VER_SCROLLBAR, K_HOR_SCROLLBAR, |
3866 K_LEFTMOUSE_NM, K_LEFTRELEASE_NM, | |
660 | 3867 # endif |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
3868 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
|
3869 K_LEFTMOUSE, K_LEFTDRAG, K_LEFTRELEASE, K_MOUSEMOVE, |
7 | 3870 K_MIDDLEMOUSE, K_MIDDLEDRAG, K_MIDDLERELEASE, |
3871 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
|
3872 K_MOUSEDOWN, K_MOUSEUP, K_MOUSELEFT, K_MOUSERIGHT, |
7 | 3873 K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE, |
631 | 3874 K_CURSORHOLD, |
7 | 3875 0 |
3876 }; | |
3877 #endif | |
3878 | |
641 | 3879 if (!p_sc || msg_silent != 0) |
7 | 3880 return FALSE; |
3881 | |
3882 if (showcmd_visual) | |
3883 { | |
3884 showcmd_buf[0] = NUL; | |
3885 showcmd_visual = FALSE; | |
3886 } | |
3887 | |
3888 #if defined(FEAT_MOUSE) | |
3889 /* Ignore keys that are scrollbar updates and mouse clicks */ | |
3890 if (IS_SPECIAL(c)) | |
3891 for (i = 0; ignore[i] != 0; ++i) | |
3892 if (ignore[i] == c) | |
3893 return FALSE; | |
3894 #endif | |
3895 | |
3896 p = transchar(c); | |
5535 | 3897 if (*p == ' ') |
3898 STRCPY(p, "<20>"); | |
7 | 3899 old_len = (int)STRLEN(showcmd_buf); |
3900 extra_len = (int)STRLEN(p); | |
3901 overflow = old_len + extra_len - SHOWCMD_COLS; | |
3902 if (overflow > 0) | |
1362 | 3903 mch_memmove(showcmd_buf, showcmd_buf + overflow, |
3904 old_len - overflow + 1); | |
7 | 3905 STRCAT(showcmd_buf, p); |
3906 | |
3907 if (char_avail()) | |
3908 return FALSE; | |
3909 | |
3910 display_showcmd(); | |
3911 | |
3912 return TRUE; | |
3913 } | |
3914 | |
3915 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3916 add_to_showcmd_c(int c) |
7 | 3917 { |
3918 if (!add_to_showcmd(c)) | |
3919 setcursor(); | |
3920 } | |
3921 | |
3922 /* | |
3923 * Delete 'len' characters from the end of the shown command. | |
3924 */ | |
3925 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3926 del_from_showcmd(int len) |
7 | 3927 { |
3928 int old_len; | |
3929 | |
3930 if (!p_sc) | |
3931 return; | |
3932 | |
3933 old_len = (int)STRLEN(showcmd_buf); | |
3934 if (len > old_len) | |
3935 len = old_len; | |
3936 showcmd_buf[old_len - len] = NUL; | |
3937 | |
3938 if (!char_avail()) | |
3939 display_showcmd(); | |
3940 } | |
3941 | |
3942 /* | |
3943 * push_showcmd() and pop_showcmd() are used when waiting for the user to type | |
3944 * something and there is a partial mapping. | |
3945 */ | |
3946 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3947 push_showcmd(void) |
7 | 3948 { |
3949 if (p_sc) | |
3950 STRCPY(old_showcmd_buf, showcmd_buf); | |
3951 } | |
3952 | |
3953 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3954 pop_showcmd(void) |
7 | 3955 { |
3956 if (!p_sc) | |
3957 return; | |
3958 | |
3959 STRCPY(showcmd_buf, old_showcmd_buf); | |
3960 | |
3961 display_showcmd(); | |
3962 } | |
3963 | |
3964 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3965 display_showcmd(void) |
7 | 3966 { |
3967 int len; | |
3968 | |
3969 cursor_off(); | |
3970 | |
3971 len = (int)STRLEN(showcmd_buf); | |
3972 if (len == 0) | |
3973 showcmd_is_clear = TRUE; | |
3974 else | |
3975 { | |
3976 screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0); | |
3977 showcmd_is_clear = FALSE; | |
3978 } | |
3979 | |
3980 /* | |
1188 | 3981 * clear the rest of an old message by outputting up to SHOWCMD_COLS |
3982 * spaces | |
7 | 3983 */ |
3984 screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0); | |
3985 | |
3986 setcursor(); /* put cursor back where it belongs */ | |
3987 } | |
3988 #endif | |
3989 | |
3990 #ifdef FEAT_SCROLLBIND | |
3991 /* | |
3992 * When "check" is FALSE, prepare for commands that scroll the window. | |
3993 * When "check" is TRUE, take care of scroll-binding after the window has | |
3994 * scrolled. Called from normal_cmd() and edit(). | |
3995 */ | |
3996 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3997 do_check_scrollbind(int check) |
7 | 3998 { |
3999 static win_T *old_curwin = NULL; | |
4000 static linenr_T old_topline = 0; | |
4001 #ifdef FEAT_DIFF | |
4002 static int old_topfill = 0; | |
4003 #endif | |
4004 static buf_T *old_buf = NULL; | |
4005 static colnr_T old_leftcol = 0; | |
4006 | |
4007 if (check && curwin->w_p_scb) | |
4008 { | |
4009 /* If a ":syncbind" command was just used, don't scroll, only reset | |
4010 * the values. */ | |
4011 if (did_syncbind) | |
4012 did_syncbind = FALSE; | |
4013 else if (curwin == old_curwin) | |
4014 { | |
4015 /* | |
4016 * Synchronize other windows, as necessary according to | |
4017 * 'scrollbind'. Don't do this after an ":edit" command, except | |
4018 * when 'diff' is set. | |
4019 */ | |
4020 if ((curwin->w_buffer == old_buf | |
4021 #ifdef FEAT_DIFF | |
4022 || curwin->w_p_diff | |
4023 #endif | |
4024 ) | |
4025 && (curwin->w_topline != old_topline | |
4026 #ifdef FEAT_DIFF | |
4027 || curwin->w_topfill != old_topfill | |
4028 #endif | |
4029 || curwin->w_leftcol != old_leftcol)) | |
4030 { | |
4031 check_scrollbind(curwin->w_topline - old_topline, | |
4032 (long)(curwin->w_leftcol - old_leftcol)); | |
4033 } | |
4034 } | |
4035 else if (vim_strchr(p_sbo, 'j')) /* jump flag set in 'scrollopt' */ | |
4036 { | |
4037 /* | |
4038 * When switching between windows, make sure that the relative | |
4039 * vertical offset is valid for the new window. The relative | |
4040 * offset is invalid whenever another 'scrollbind' window has | |
4041 * scrolled to a point that would force the current window to | |
4042 * scroll past the beginning or end of its buffer. When the | |
4043 * resync is performed, some of the other 'scrollbind' windows may | |
4044 * need to jump so that the current window's relative position is | |
4045 * visible on-screen. | |
4046 */ | |
4047 check_scrollbind(curwin->w_topline - curwin->w_scbind_pos, 0L); | |
4048 } | |
4049 curwin->w_scbind_pos = curwin->w_topline; | |
4050 } | |
4051 | |
4052 old_curwin = curwin; | |
4053 old_topline = curwin->w_topline; | |
4054 #ifdef FEAT_DIFF | |
4055 old_topfill = curwin->w_topfill; | |
4056 #endif | |
4057 old_buf = curwin->w_buffer; | |
4058 old_leftcol = curwin->w_leftcol; | |
4059 } | |
4060 | |
4061 /* | |
4062 * Synchronize any windows that have "scrollbind" set, based on the | |
4063 * number of rows by which the current window has changed | |
4064 * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>) | |
4065 */ | |
4066 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4067 check_scrollbind(linenr_T topline_diff, long leftcol_diff) |
7 | 4068 { |
4069 int want_ver; | |
4070 int want_hor; | |
4071 win_T *old_curwin = curwin; | |
4072 buf_T *old_curbuf = curbuf; | |
4073 int old_VIsual_select = VIsual_select; | |
4074 int old_VIsual_active = VIsual_active; | |
4075 colnr_T tgt_leftcol = curwin->w_leftcol; | |
4076 long topline; | |
4077 long y; | |
4078 | |
4079 /* | |
4080 * check 'scrollopt' string for vertical and horizontal scroll options | |
4081 */ | |
4082 want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0); | |
4083 #ifdef FEAT_DIFF | |
4084 want_ver |= old_curwin->w_p_diff; | |
4085 #endif | |
4086 want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0)); | |
4087 | |
4088 /* | |
4089 * loop through the scrollbound windows and scroll accordingly | |
4090 */ | |
4091 VIsual_select = VIsual_active = 0; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9399
diff
changeset
|
4092 FOR_ALL_WINDOWS(curwin) |
7 | 4093 { |
4094 curbuf = curwin->w_buffer; | |
4095 /* skip original window and windows with 'noscrollbind' */ | |
4096 if (curwin != old_curwin && curwin->w_p_scb) | |
4097 { | |
4098 /* | |
4099 * do the vertical scroll | |
4100 */ | |
4101 if (want_ver) | |
4102 { | |
4103 #ifdef FEAT_DIFF | |
4104 if (old_curwin->w_p_diff && curwin->w_p_diff) | |
4105 { | |
4106 diff_set_topline(old_curwin, curwin); | |
4107 } | |
4108 else | |
4109 #endif | |
4110 { | |
4111 curwin->w_scbind_pos += topline_diff; | |
4112 topline = curwin->w_scbind_pos; | |
4113 if (topline > curbuf->b_ml.ml_line_count) | |
4114 topline = curbuf->b_ml.ml_line_count; | |
4115 if (topline < 1) | |
4116 topline = 1; | |
4117 | |
4118 y = topline - curwin->w_topline; | |
4119 if (y > 0) | |
4120 scrollup(y, FALSE); | |
4121 else | |
4122 scrolldown(-y, FALSE); | |
4123 } | |
4124 | |
4125 redraw_later(VALID); | |
4126 cursor_correct(); | |
4127 curwin->w_redr_status = TRUE; | |
4128 } | |
4129 | |
4130 /* | |
4131 * do the horizontal scroll | |
4132 */ | |
4133 if (want_hor && curwin->w_leftcol != tgt_leftcol) | |
4134 { | |
4135 curwin->w_leftcol = tgt_leftcol; | |
4136 leftcol_changed(); | |
4137 } | |
4138 } | |
4139 } | |
4140 | |
4141 /* | |
4142 * reset current-window | |
4143 */ | |
4144 VIsual_select = old_VIsual_select; | |
4145 VIsual_active = old_VIsual_active; | |
4146 curwin = old_curwin; | |
4147 curbuf = old_curbuf; | |
4148 } | |
4149 #endif /* #ifdef FEAT_SCROLLBIND */ | |
4150 | |
4151 /* | |
4152 * Command character that's ignored. | |
4153 * 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
|
4154 * xon/xoff. |
7 | 4155 */ |
4156 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4157 nv_ignore(cmdarg_T *cap) |
7 | 4158 { |
226 | 4159 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
7 | 4160 } |
4161 | |
4162 /* | |
620 | 4163 * Command character that doesn't do anything, but unlike nv_ignore() does |
4164 * start edit(). Used for "startinsert" executed while starting up. | |
4165 */ | |
4166 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4167 nv_nop(cmdarg_T *cap UNUSED) |
620 | 4168 { |
4169 } | |
4170 | |
4171 /* | |
7 | 4172 * Command character doesn't exist. |
4173 */ | |
4174 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4175 nv_error(cmdarg_T *cap) |
7 | 4176 { |
4177 clearopbeep(cap->oap); | |
4178 } | |
4179 | |
4180 /* | |
4181 * <Help> and <F1> commands. | |
4182 */ | |
4183 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4184 nv_help(cmdarg_T *cap) |
7 | 4185 { |
4186 if (!checkclearopq(cap->oap)) | |
4187 ex_help(NULL); | |
4188 } | |
4189 | |
4190 /* | |
4191 * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor. | |
4192 */ | |
4193 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4194 nv_addsub(cmdarg_T *cap) |
7 | 4195 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4196 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
|
4197 { |
7578
fdae4c496775
commit https://github.com/vim/vim/commit/ef2b5036b3005f1ce15d146dce72379a9834c56d
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
4198 prep_redo_cmd(cap); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4199 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
|
4200 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
|
4201 cap->oap->op_type = OP_NOP; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4202 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4203 else if (VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4204 nv_operator(cap); |
6868 | 4205 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4206 clearop(cap->oap); |
7 | 4207 } |
4208 | |
4209 /* | |
4210 * CTRL-F, CTRL-B, etc: Scroll page up or down. | |
4211 */ | |
4212 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4213 nv_page(cmdarg_T *cap) |
7 | 4214 { |
4215 if (!checkclearop(cap->oap)) | |
819 | 4216 { |
4217 if (mod_mask & MOD_MASK_CTRL) | |
4218 { | |
4219 /* <C-PageUp>: tab page back; <C-PageDown>: tab page forward */ | |
4220 if (cap->arg == BACKWARD) | |
4221 goto_tabpage(-(int)cap->count1); | |
4222 else | |
4223 goto_tabpage((int)cap->count0); | |
4224 } | |
4225 else | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
4226 (void)onepage(cap->arg, cap->count1); |
819 | 4227 } |
7 | 4228 } |
4229 | |
4230 /* | |
4231 * Implementation of "gd" and "gD" command. | |
4232 */ | |
4233 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4234 nv_gd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4235 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4236 int nchar, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4237 int thisblock) /* 1 for "1gd" and "1gD" */ |
7 | 4238 { |
4239 int len; | |
503 | 4240 char_u *ptr; |
4241 | |
4242 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
|
4243 || 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
|
4244 == FAIL) |
503 | 4245 clearopbeep(oap); |
4246 #ifdef FEAT_FOLDING | |
4247 else if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) | |
4248 foldOpenCursor(); | |
4249 #endif | |
4250 } | |
4251 | |
4252 /* | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4253 * 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
|
4254 * otherwise. |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4255 */ |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4256 static int |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4257 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
|
4258 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4259 int i; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4260 int incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4261 int instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4262 int prev = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4263 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4264 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
|
4265 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4266 if (instring != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4267 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4268 if (prev != '\\' && line[i] == instring) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4269 instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4270 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4271 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
|
4272 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4273 instring = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4274 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4275 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4276 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4277 if (incomment) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4278 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4279 if (prev == '*' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4280 incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4281 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4282 else if (prev == '/' && line[i] == '*') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4283 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4284 incomment = TRUE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4285 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4286 else if (prev == '/' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4287 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4288 return FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4289 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4290 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4291 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4292 prev = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4293 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4294 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4295 return incomment == FALSE && instring == 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4296 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4297 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4298 /* |
523 | 4299 * Search for variable declaration of "ptr[len]". |
4300 * When "locally" is TRUE in the current function ("gd"), otherwise in the | |
4301 * current file ("gD"). | |
4302 * When "thisblock" is TRUE check the {} block scope. | |
503 | 4303 * Return FAIL when not found. |
4304 */ | |
4305 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4306 find_decl( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4307 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4308 int len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4309 int locally, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4310 int thisblock, |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4311 int flags_arg) /* flags passed to searchit() */ |
503 | 4312 { |
7 | 4313 char_u *pat; |
4314 pos_T old_pos; | |
503 | 4315 pos_T par_pos; |
4316 pos_T found_pos; | |
7 | 4317 int t; |
4318 int save_p_ws; | |
4319 int save_p_scs; | |
503 | 4320 int retval = OK; |
944 | 4321 int incll; |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4322 int searchflags = flags_arg; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4323 int valid; |
503 | 4324 |
4325 if ((pat = alloc(len + 7)) == NULL) | |
4326 return FAIL; | |
268 | 4327 |
4328 /* Put "\V" before the pattern to avoid that the special meaning of "." | |
4329 * and "~" causes trouble. */ | |
4330 sprintf((char *)pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", | |
4331 len, ptr); | |
7 | 4332 old_pos = curwin->w_cursor; |
4333 save_p_ws = p_ws; | |
4334 save_p_scs = p_scs; | |
4335 p_ws = FALSE; /* don't wrap around end of file now */ | |
4336 p_scs = FALSE; /* don't switch ignorecase off now */ | |
4337 | |
4338 /* | |
4339 * With "gD" go to line 1. | |
4340 * With "gd" Search back for the start of the current function, then go | |
4341 * back until a blank line. If this fails go to line 1. | |
4342 */ | |
944 | 4343 if (!locally || !findpar(&incll, BACKWARD, 1L, '{', FALSE)) |
7 | 4344 { |
4345 setpcmark(); /* Set in findpar() otherwise */ | |
4346 curwin->w_cursor.lnum = 1; | |
539 | 4347 par_pos = curwin->w_cursor; |
7 | 4348 } |
4349 else | |
4350 { | |
539 | 4351 par_pos = curwin->w_cursor; |
7 | 4352 while (curwin->w_cursor.lnum > 1 && *skipwhite(ml_get_curline()) != NUL) |
4353 --curwin->w_cursor.lnum; | |
4354 } | |
4355 curwin->w_cursor.col = 0; | |
4356 | |
4357 /* 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
|
4358 CLEAR_POS(&found_pos); |
503 | 4359 for (;;) |
4360 { | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4361 valid = FALSE; |
503 | 4362 t = searchit(curwin, curbuf, &curwin->w_cursor, FORWARD, |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11451
diff
changeset
|
4363 pat, 1L, searchflags, RE_LAST, (linenr_T)0, NULL, NULL); |
503 | 4364 if (curwin->w_cursor.lnum >= old_pos.lnum) |
4365 t = FAIL; /* match after start is failure too */ | |
523 | 4366 |
718 | 4367 if (thisblock && t != FAIL) |
523 | 4368 { |
4369 pos_T *pos; | |
4370 | |
4371 /* Check that the block the match is in doesn't end before the | |
4372 * position where we started the search from. */ | |
4373 if ((pos = findmatchlimit(NULL, '}', FM_FORWARD, | |
4374 (int)(old_pos.lnum - curwin->w_cursor.lnum + 1))) != NULL | |
4375 && pos->lnum < old_pos.lnum) | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4376 { |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4377 /* 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
|
4378 * Skip to the end. */ |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4379 curwin->w_cursor = *pos; |
523 | 4380 continue; |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4381 } |
523 | 4382 } |
4383 | |
503 | 4384 if (t == FAIL) |
4385 { | |
4386 /* If we previously found a valid position, use it. */ | |
4387 if (found_pos.lnum != 0) | |
4388 { | |
4389 curwin->w_cursor = found_pos; | |
4390 t = OK; | |
4391 } | |
4392 break; | |
4393 } | |
7 | 4394 #ifdef FEAT_COMMENTS |
3562 | 4395 if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0) |
503 | 4396 { |
4397 /* Ignore this line, continue at start of next line. */ | |
4398 ++curwin->w_cursor.lnum; | |
4399 curwin->w_cursor.col = 0; | |
4400 continue; | |
4401 } | |
4402 #endif | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4403 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
|
4404 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4405 /* 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
|
4406 * 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
|
4407 if (!valid && found_pos.lnum != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4408 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4409 curwin->w_cursor = found_pos; |
503 | 4410 break; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4411 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4412 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4413 /* 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
|
4414 if (valid && !locally) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4415 break; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4416 if (valid && curwin->w_cursor.lnum >= par_pos.lnum) |
503 | 4417 { |
4418 /* If we previously found a valid position, use it. */ | |
4419 if (found_pos.lnum != 0) | |
4420 curwin->w_cursor = found_pos; | |
4421 break; | |
4422 } | |
4423 | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4424 /* 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
|
4425 * 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
|
4426 * 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
|
4427 if (!valid) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4428 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4429 CLEAR_POS(&found_pos); |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4430 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4431 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4432 found_pos = curwin->w_cursor; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4433 /* 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
|
4434 * position. */ |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4435 searchflags &= ~SEARCH_START; |
503 | 4436 } |
4437 | |
4438 if (t == FAIL) | |
4439 { | |
4440 retval = FAIL; | |
7 | 4441 curwin->w_cursor = old_pos; |
4442 } | |
4443 else | |
4444 { | |
4445 curwin->w_set_curswant = TRUE; | |
4446 /* "n" searches forward now */ | |
4447 reset_search_dir(); | |
4448 } | |
4449 | |
4450 vim_free(pat); | |
4451 p_ws = save_p_ws; | |
4452 p_scs = save_p_scs; | |
503 | 4453 |
4454 return retval; | |
7 | 4455 } |
4456 | |
4457 /* | |
4458 * Move 'dist' lines in direction 'dir', counting lines by *screen* | |
4459 * lines rather than lines in the file. | |
4460 * 'dist' must be positive. | |
4461 * | |
4462 * Return OK if able to move cursor, FAIL otherwise. | |
4463 */ | |
4464 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4465 nv_screengo(oparg_T *oap, int dir, long dist) |
7 | 4466 { |
4467 int linelen = linetabsize(ml_get_curline()); | |
4468 int retval = OK; | |
4469 int atend = FALSE; | |
4470 int n; | |
4471 int col_off1; /* margin offset for first screen line */ | |
4472 int col_off2; /* margin offset for wrapped screen line */ | |
4473 int width1; /* text width for first screen line */ | |
4474 int width2; /* test width for wrapped screen line */ | |
4475 | |
4476 oap->motion_type = MCHAR; | |
5192
c28202427d71
updated for version 7.4a.022
Bram Moolenaar <bram@vim.org>
parents:
5162
diff
changeset
|
4477 oap->inclusive = (curwin->w_curswant == MAXCOL); |
7 | 4478 |
4479 col_off1 = curwin_col_off(); | |
4480 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
|
4481 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
|
4482 width2 = curwin->w_width - col_off2; |
6559 | 4483 if (width2 == 0) |
4484 width2 = 1; /* avoid divide by zero */ | |
7 | 4485 |
4486 if (curwin->w_width != 0) | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4487 { |
7 | 4488 /* |
4489 * Instead of sticking at the last character of the buffer line we | |
4490 * try to stick in the last column of the screen. | |
4491 */ | |
4492 if (curwin->w_curswant == MAXCOL) | |
4493 { | |
4494 atend = TRUE; | |
4495 validate_virtcol(); | |
4496 if (width1 <= 0) | |
4497 curwin->w_curswant = 0; | |
4498 else | |
4499 { | |
4500 curwin->w_curswant = width1 - 1; | |
4501 if (curwin->w_virtcol > curwin->w_curswant) | |
4502 curwin->w_curswant += ((curwin->w_virtcol | |
4503 - curwin->w_curswant - 1) / width2 + 1) * width2; | |
4504 } | |
4505 } | |
4506 else | |
4507 { | |
4508 if (linelen > width1) | |
4509 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
4510 else | |
4511 n = width1; | |
4512 if (curwin->w_curswant > (colnr_T)n + 1) | |
4513 curwin->w_curswant -= ((curwin->w_curswant - n) / width2 + 1) | |
4514 * width2; | |
4515 } | |
4516 | |
4517 while (dist--) | |
4518 { | |
4519 if (dir == BACKWARD) | |
4520 { | |
4521 if ((long)curwin->w_curswant >= width2) | |
4522 /* move back within line */ | |
4523 curwin->w_curswant -= width2; | |
4524 else | |
4525 { | |
4526 /* to previous line */ | |
4527 if (curwin->w_cursor.lnum == 1) | |
4528 { | |
4529 retval = FAIL; | |
4530 break; | |
4531 } | |
4532 --curwin->w_cursor.lnum; | |
4533 #ifdef FEAT_FOLDING | |
4534 /* Move to the start of a closed fold. Don't do that when | |
4535 * 'foldopen' contains "all": it will open in a moment. */ | |
4536 if (!(fdo_flags & FDO_ALL)) | |
4537 (void)hasFolding(curwin->w_cursor.lnum, | |
4538 &curwin->w_cursor.lnum, NULL); | |
4539 #endif | |
4540 linelen = linetabsize(ml_get_curline()); | |
4541 if (linelen > width1) | |
4542 curwin->w_curswant += (((linelen - width1 - 1) / width2) | |
4543 + 1) * width2; | |
4544 } | |
4545 } | |
4546 else /* dir == FORWARD */ | |
4547 { | |
4548 if (linelen > width1) | |
4549 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
4550 else | |
4551 n = width1; | |
4552 if (curwin->w_curswant + width2 < (colnr_T)n) | |
4553 /* move forward within line */ | |
4554 curwin->w_curswant += width2; | |
4555 else | |
4556 { | |
4557 /* to next line */ | |
4558 #ifdef FEAT_FOLDING | |
4559 /* Move to the end of a closed fold. */ | |
4560 (void)hasFolding(curwin->w_cursor.lnum, NULL, | |
4561 &curwin->w_cursor.lnum); | |
4562 #endif | |
4563 if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
4564 { | |
4565 retval = FAIL; | |
4566 break; | |
4567 } | |
4568 curwin->w_cursor.lnum++; | |
4569 curwin->w_curswant %= width2; | |
2911 | 4570 linelen = linetabsize(ml_get_curline()); |
7 | 4571 } |
4572 } | |
4573 } | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4574 } |
7 | 4575 |
5600 | 4576 if (virtual_active() && atend) |
4577 coladvance(MAXCOL); | |
4578 else | |
4579 coladvance(curwin->w_curswant); | |
7 | 4580 |
4581 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE) | |
4582 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
4583 { | |
6178 | 4584 colnr_T virtcol; |
4585 | |
7 | 4586 /* |
4587 * Check for landing on a character that got split at the end of the | |
4588 * last line. We want to advance a screenline, not end up in the same | |
4589 * screenline or move two screenlines. | |
4590 */ | |
4591 validate_virtcol(); | |
6178 | 4592 virtcol = curwin->w_virtcol; |
6187 | 4593 # if defined(FEAT_LINEBREAK) |
6178 | 4594 if (virtcol > (colnr_T)width1 && *p_sbr != NUL) |
4595 virtcol -= vim_strsize(p_sbr); | |
6187 | 4596 # endif |
6178 | 4597 |
4598 if (virtcol > curwin->w_curswant | |
7 | 4599 && (curwin->w_curswant < (colnr_T)width1 |
4600 ? (curwin->w_curswant > (colnr_T)width1 / 2) | |
4601 : ((curwin->w_curswant - width1) % width2 | |
4602 > (colnr_T)width2 / 2))) | |
4603 --curwin->w_cursor.col; | |
4604 } | |
4605 #endif | |
4606 | |
4607 if (atend) | |
4608 curwin->w_curswant = MAXCOL; /* stick in the last column */ | |
4609 | |
4610 return retval; | |
4611 } | |
4612 | |
4613 #ifdef FEAT_MOUSE | |
4614 /* | |
4615 * Mouse scroll wheel: Default action is to scroll three lines, or one page | |
4616 * 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
|
4617 * 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
|
4618 * K_MOUSELEFT (cap->arg == -1) or K_MOUSERIGHT (cap->arg == -2) |
7 | 4619 */ |
4620 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4621 nv_mousescroll(cmdarg_T *cap) |
7 | 4622 { |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4623 win_T *old_curwin = curwin, *wp; |
7 | 4624 |
4162 | 4625 if (mouse_row >= 0 && mouse_col >= 0) |
7 | 4626 { |
4627 int row, col; | |
4628 | |
4629 row = mouse_row; | |
4630 col = mouse_col; | |
4631 | |
4632 /* find the window at the pointer coordinates */ | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4633 wp = mouse_find_win(&row, &col); |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4634 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
|
4635 return; |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4636 curwin = wp; |
7 | 4637 curbuf = curwin->w_buffer; |
4638 } | |
4639 | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4640 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
|
4641 { |
11983
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4642 # 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
|
4643 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
|
4644 /* 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
|
4645 * 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
|
4646 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
|
4647 else |
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4648 # endif |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4649 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
|
4650 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4651 (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
|
4652 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4653 else |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4654 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4655 cap->count1 = 3; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4656 cap->count0 = 3; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4657 nv_scroll_line(cap); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4658 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4659 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4660 # ifdef FEAT_GUI |
7 | 4661 else |
4662 { | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4663 /* 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
|
4664 if (!curwin->w_p_wrap) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4665 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4666 int val, step = 6; |
2416
1a9c16dd76d4
Fix compiler warnings on 64 bit systems.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4667 |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4668 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
|
4669 step = curwin->w_width; |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4670 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
|
4671 if (val < 0) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4672 val = 0; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4673 |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4674 gui_do_horiz_scroll(val, TRUE); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4675 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4676 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4677 # endif |
7 | 4678 |
4679 curwin->w_redr_status = TRUE; | |
4680 | |
4681 curwin = old_curwin; | |
4682 curbuf = curwin->w_buffer; | |
4683 } | |
4684 | |
4685 /* | |
4686 * Mouse clicks and drags. | |
4687 */ | |
4688 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4689 nv_mouse(cmdarg_T *cap) |
7 | 4690 { |
4691 (void)do_mouse(cap->oap, cap->cmdchar, BACKWARD, cap->count1, 0); | |
4692 } | |
4693 #endif | |
4694 | |
4695 /* | |
4696 * Handle CTRL-E and CTRL-Y commands: scroll a line up or down. | |
4697 * cap->arg must be TRUE for CTRL-E. | |
4698 */ | |
4699 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4700 nv_scroll_line(cmdarg_T *cap) |
7 | 4701 { |
4702 if (!checkclearop(cap->oap)) | |
4703 scroll_redraw(cap->arg, cap->count1); | |
4704 } | |
4705 | |
4706 /* | |
4707 * Scroll "count" lines up or down, and redraw. | |
4708 */ | |
4709 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4710 scroll_redraw(int up, long count) |
7 | 4711 { |
4712 linenr_T prev_topline = curwin->w_topline; | |
4713 #ifdef FEAT_DIFF | |
4714 int prev_topfill = curwin->w_topfill; | |
4715 #endif | |
4716 linenr_T prev_lnum = curwin->w_cursor.lnum; | |
4717 | |
4718 if (up) | |
4719 scrollup(count, TRUE); | |
4720 else | |
4721 scrolldown(count, TRUE); | |
4722 if (p_so) | |
4723 { | |
4724 /* Adjust the cursor position for 'scrolloff'. Mark w_topline as | |
4725 * valid, otherwise the screen jumps back at the end of the file. */ | |
4726 cursor_correct(); | |
4727 check_cursor_moved(curwin); | |
4728 curwin->w_valid |= VALID_TOPLINE; | |
4729 | |
4730 /* If moved back to where we were, at least move the cursor, otherwise | |
4731 * we get stuck at one position. Don't move the cursor up if the | |
4732 * first line of the buffer is already on the screen */ | |
4733 while (curwin->w_topline == prev_topline | |
4734 #ifdef FEAT_DIFF | |
4735 && curwin->w_topfill == prev_topfill | |
4736 #endif | |
4737 ) | |
4738 { | |
4739 if (up) | |
4740 { | |
4741 if (curwin->w_cursor.lnum > prev_lnum | |
4742 || cursor_down(1L, FALSE) == FAIL) | |
4743 break; | |
4744 } | |
4745 else | |
4746 { | |
4747 if (curwin->w_cursor.lnum < prev_lnum | |
4748 || prev_topline == 1L | |
4749 || cursor_up(1L, FALSE) == FAIL) | |
4750 break; | |
4751 } | |
4752 /* Mark w_topline as valid, otherwise the screen jumps back at the | |
4753 * end of the file. */ | |
4754 check_cursor_moved(curwin); | |
4755 curwin->w_valid |= VALID_TOPLINE; | |
4756 } | |
4757 } | |
4758 if (curwin->w_cursor.lnum != prev_lnum) | |
4759 coladvance(curwin->w_curswant); | |
4760 redraw_later(VALID); | |
4761 } | |
4762 | |
4763 /* | |
4764 * Commands that start with "z". | |
4765 */ | |
4766 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4767 nv_zet(cmdarg_T *cap) |
7 | 4768 { |
4769 long n; | |
4770 colnr_T col; | |
4771 int nchar = cap->nchar; | |
4772 #ifdef FEAT_FOLDING | |
4773 long old_fdl = curwin->w_p_fdl; | |
4774 int old_fen = curwin->w_p_fen; | |
4775 #endif | |
737 | 4776 #ifdef FEAT_SPELL |
710 | 4777 int undo = FALSE; |
4778 #endif | |
7 | 4779 |
4780 if (VIM_ISDIGIT(nchar)) | |
4781 { | |
4782 /* | |
4783 * "z123{nchar}": edit the count before obtaining {nchar} | |
4784 */ | |
4785 if (checkclearop(cap->oap)) | |
4786 return; | |
4787 n = nchar - '0'; | |
4788 for (;;) | |
4789 { | |
4790 #ifdef USE_ON_FLY_SCROLL | |
4791 dont_scroll = TRUE; /* disallow scrolling here */ | |
4792 #endif | |
4793 ++no_mapping; | |
4794 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 4795 nchar = plain_vgetc(); |
7 | 4796 LANGMAP_ADJUST(nchar, TRUE); |
4797 --no_mapping; | |
4798 --allow_keys; | |
4799 #ifdef FEAT_CMDL_INFO | |
4800 (void)add_to_showcmd(nchar); | |
4801 #endif | |
4802 if (nchar == K_DEL || nchar == K_KDEL) | |
4803 n /= 10; | |
4804 else if (VIM_ISDIGIT(nchar)) | |
4805 n = n * 10 + (nchar - '0'); | |
4806 else if (nchar == CAR) | |
4807 { | |
4808 #ifdef FEAT_GUI | |
4809 need_mouse_correct = TRUE; | |
4810 #endif | |
4811 win_setheight((int)n); | |
4812 break; | |
4813 } | |
4814 else if (nchar == 'l' | |
4815 || nchar == 'h' | |
4816 || nchar == K_LEFT | |
229 | 4817 || nchar == K_RIGHT) |
7 | 4818 { |
4819 cap->count1 = n ? n * cap->count1 : cap->count1; | |
4820 goto dozet; | |
4821 } | |
4822 else | |
4823 { | |
4824 clearopbeep(cap->oap); | |
4825 break; | |
4826 } | |
4827 } | |
4828 cap->oap->op_type = OP_NOP; | |
4829 return; | |
4830 } | |
4831 | |
4832 dozet: | |
4833 if ( | |
4834 #ifdef FEAT_FOLDING | |
4835 /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" | |
4836 * and "zC" only in Visual mode. "zj" and "zk" are motion | |
4837 * commands. */ | |
4838 cap->nchar != 'f' && cap->nchar != 'F' | |
4839 && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) | |
4840 && cap->nchar != 'j' && cap->nchar != 'k' | |
4841 && | |
4842 #endif | |
4843 checkclearop(cap->oap)) | |
4844 return; | |
4845 | |
4846 /* | |
4847 * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb": | |
4848 * If line number given, set cursor. | |
4849 */ | |
4850 if ((vim_strchr((char_u *)"+\r\nt.z^-b", nchar) != NULL) | |
4851 && cap->count0 | |
4852 && cap->count0 != curwin->w_cursor.lnum) | |
4853 { | |
4854 setpcmark(); | |
4855 if (cap->count0 > curbuf->b_ml.ml_line_count) | |
4856 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4857 else | |
4858 curwin->w_cursor.lnum = cap->count0; | |
22 | 4859 check_cursor_col(); |
7 | 4860 } |
4861 | |
4862 switch (nchar) | |
4863 { | |
4864 /* "z+", "z<CR>" and "zt": put cursor at top of screen */ | |
4865 case '+': | |
4866 if (cap->count0 == 0) | |
4867 { | |
4868 /* No count given: put cursor at the line below screen */ | |
4869 validate_botline(); /* make sure w_botline is valid */ | |
4870 if (curwin->w_botline > curbuf->b_ml.ml_line_count) | |
4871 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4872 else | |
4873 curwin->w_cursor.lnum = curwin->w_botline; | |
4874 } | |
4875 /* FALLTHROUGH */ | |
4876 case NL: | |
4877 case CAR: | |
4878 case K_KENTER: | |
4879 beginline(BL_WHITE | BL_FIX); | |
4880 /* FALLTHROUGH */ | |
4881 | |
4882 case 't': scroll_cursor_top(0, TRUE); | |
4883 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4884 set_fraction(curwin); |
7 | 4885 break; |
4886 | |
4887 /* "z." and "zz": put cursor in middle of screen */ | |
4888 case '.': beginline(BL_WHITE | BL_FIX); | |
4889 /* FALLTHROUGH */ | |
4890 | |
4891 case 'z': scroll_cursor_halfway(TRUE); | |
4892 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4893 set_fraction(curwin); |
7 | 4894 break; |
4895 | |
4896 /* "z^", "z-" and "zb": put cursor at bottom of screen */ | |
4897 case '^': /* Strange Vi behavior: <count>z^ finds line at top of window | |
4898 * when <count> is at bottom of window, and puts that one at | |
4899 * bottom of window. */ | |
4900 if (cap->count0 != 0) | |
4901 { | |
4902 scroll_cursor_bot(0, TRUE); | |
4903 curwin->w_cursor.lnum = curwin->w_topline; | |
4904 } | |
4905 else if (curwin->w_topline == 1) | |
4906 curwin->w_cursor.lnum = 1; | |
4907 else | |
4908 curwin->w_cursor.lnum = curwin->w_topline - 1; | |
4909 /* FALLTHROUGH */ | |
4910 case '-': | |
4911 beginline(BL_WHITE | BL_FIX); | |
4912 /* FALLTHROUGH */ | |
4913 | |
4914 case 'b': scroll_cursor_bot(0, TRUE); | |
4915 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4916 set_fraction(curwin); |
7 | 4917 break; |
4918 | |
4919 /* "zH" - scroll screen right half-page */ | |
4920 case 'H': | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
4921 cap->count1 *= curwin->w_width / 2; |
7 | 4922 /* FALLTHROUGH */ |
4923 | |
4924 /* "zh" - scroll screen to the right */ | |
4925 case 'h': | |
4926 case K_LEFT: | |
4927 if (!curwin->w_p_wrap) | |
4928 { | |
4929 if ((colnr_T)cap->count1 > curwin->w_leftcol) | |
4930 curwin->w_leftcol = 0; | |
4931 else | |
4932 curwin->w_leftcol -= (colnr_T)cap->count1; | |
4933 leftcol_changed(); | |
4934 } | |
4935 break; | |
4936 | |
4937 /* "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
|
4938 case 'L': cap->count1 *= curwin->w_width / 2; |
7 | 4939 /* FALLTHROUGH */ |
4940 | |
4941 /* "zl" - scroll screen to the left */ | |
4942 case 'l': | |
4943 case K_RIGHT: | |
4944 if (!curwin->w_p_wrap) | |
4945 { | |
4946 /* scroll the window left */ | |
4947 curwin->w_leftcol += (colnr_T)cap->count1; | |
4948 leftcol_changed(); | |
4949 } | |
4950 break; | |
4951 | |
4952 /* "zs" - scroll screen, cursor at the start */ | |
4953 case 's': if (!curwin->w_p_wrap) | |
4954 { | |
4955 #ifdef FEAT_FOLDING | |
4956 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4957 col = 0; /* like the cursor is in col 0 */ | |
4958 else | |
4959 #endif | |
4960 getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL); | |
4961 if ((long)col > p_siso) | |
4962 col -= p_siso; | |
4963 else | |
4964 col = 0; | |
4965 if (curwin->w_leftcol != col) | |
4966 { | |
4967 curwin->w_leftcol = col; | |
4968 redraw_later(NOT_VALID); | |
4969 } | |
4970 } | |
4971 break; | |
4972 | |
4973 /* "ze" - scroll screen, cursor at the end */ | |
4974 case 'e': if (!curwin->w_p_wrap) | |
4975 { | |
4976 #ifdef FEAT_FOLDING | |
4977 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4978 col = 0; /* like the cursor is in col 0 */ | |
4979 else | |
4980 #endif | |
4981 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
|
4982 n = curwin->w_width - curwin_col_off(); |
7 | 4983 if ((long)col + p_siso < n) |
4984 col = 0; | |
4985 else | |
4986 col = col + p_siso - n + 1; | |
4987 if (curwin->w_leftcol != col) | |
4988 { | |
4989 curwin->w_leftcol = col; | |
4990 redraw_later(NOT_VALID); | |
4991 } | |
4992 } | |
4993 break; | |
4994 | |
4995 #ifdef FEAT_FOLDING | |
4996 /* "zF": create fold command */ | |
4997 /* "zf": create fold operator */ | |
4998 case 'F': | |
4999 case 'f': if (foldManualAllowed(TRUE)) | |
5000 { | |
5001 cap->nchar = 'f'; | |
5002 nv_operator(cap); | |
5003 curwin->w_p_fen = TRUE; | |
5004 | |
5005 /* "zF" is like "zfzf" */ | |
5006 if (nchar == 'F' && cap->oap->op_type == OP_FOLD) | |
5007 { | |
5008 nv_operator(cap); | |
5009 finish_op = TRUE; | |
5010 } | |
5011 } | |
5012 else | |
5013 clearopbeep(cap->oap); | |
5014 break; | |
5015 | |
5016 /* "zd": delete fold at cursor */ | |
5017 /* "zD": delete fold at cursor recursively */ | |
5018 case 'd': | |
5019 case 'D': if (foldManualAllowed(FALSE)) | |
5020 { | |
5021 if (VIsual_active) | |
5022 nv_operator(cap); | |
5023 else | |
5024 deleteFold(curwin->w_cursor.lnum, | |
5025 curwin->w_cursor.lnum, nchar == 'D', FALSE); | |
5026 } | |
5027 break; | |
5028 | |
4352 | 5029 /* "zE": erase all folds */ |
7 | 5030 case 'E': if (foldmethodIsManual(curwin)) |
5031 { | |
5032 clearFolding(curwin); | |
5033 changed_window_setting(); | |
5034 } | |
5035 else if (foldmethodIsMarker(curwin)) | |
5036 deleteFold((linenr_T)1, curbuf->b_ml.ml_line_count, | |
5037 TRUE, FALSE); | |
5038 else | |
5039 EMSG(_("E352: Cannot erase folds with current 'foldmethod'")); | |
5040 break; | |
5041 | |
5042 /* "zn": fold none: reset 'foldenable' */ | |
5043 case 'n': curwin->w_p_fen = FALSE; | |
5044 break; | |
5045 | |
5046 /* "zN": fold Normal: set 'foldenable' */ | |
5047 case 'N': curwin->w_p_fen = TRUE; | |
5048 break; | |
5049 | |
5050 /* "zi": invert folding: toggle 'foldenable' */ | |
5051 case 'i': curwin->w_p_fen = !curwin->w_p_fen; | |
5052 break; | |
5053 | |
5054 /* "za": open closed fold or close open fold at cursor */ | |
5055 case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
5056 openFold(curwin->w_cursor.lnum, cap->count1); | |
5057 else | |
5058 { | |
5059 closeFold(curwin->w_cursor.lnum, cap->count1); | |
5060 curwin->w_p_fen = TRUE; | |
5061 } | |
5062 break; | |
5063 | |
5064 /* "zA": open fold at cursor recursively */ | |
5065 case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
5066 openFoldRecurse(curwin->w_cursor.lnum); | |
5067 else | |
5068 { | |
5069 closeFoldRecurse(curwin->w_cursor.lnum); | |
5070 curwin->w_p_fen = TRUE; | |
5071 } | |
5072 break; | |
5073 | |
5074 /* "zo": open fold at cursor or Visual area */ | |
5075 case 'o': if (VIsual_active) | |
5076 nv_operator(cap); | |
5077 else | |
5078 openFold(curwin->w_cursor.lnum, cap->count1); | |
5079 break; | |
5080 | |
5081 /* "zO": open fold recursively */ | |
5082 case 'O': if (VIsual_active) | |
5083 nv_operator(cap); | |
5084 else | |
5085 openFoldRecurse(curwin->w_cursor.lnum); | |
5086 break; | |
5087 | |
5088 /* "zc": close fold at cursor or Visual area */ | |
5089 case 'c': if (VIsual_active) | |
5090 nv_operator(cap); | |
5091 else | |
5092 closeFold(curwin->w_cursor.lnum, cap->count1); | |
5093 curwin->w_p_fen = TRUE; | |
5094 break; | |
5095 | |
5096 /* "zC": close fold recursively */ | |
5097 case 'C': if (VIsual_active) | |
5098 nv_operator(cap); | |
5099 else | |
5100 closeFoldRecurse(curwin->w_cursor.lnum); | |
5101 curwin->w_p_fen = TRUE; | |
5102 break; | |
5103 | |
5104 /* "zv": open folds at the cursor */ | |
5105 case 'v': foldOpenCursor(); | |
5106 break; | |
5107 | |
5108 /* "zx": re-apply 'foldlevel' and open folds at the cursor */ | |
5109 case 'x': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5110 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5111 newFoldLevel(); /* update right now */ |
7 | 5112 foldOpenCursor(); |
5113 break; | |
5114 | |
5115 /* "zX": undo manual opens/closes, re-apply 'foldlevel' */ | |
5116 case 'X': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5117 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5118 old_fdl = -1; /* force an update */ |
7 | 5119 break; |
5120 | |
5121 /* "zm": fold more */ | |
5122 case 'm': if (curwin->w_p_fdl > 0) | |
6725 | 5123 { |
5124 curwin->w_p_fdl -= cap->count1; | |
5125 if (curwin->w_p_fdl < 0) | |
5126 curwin->w_p_fdl = 0; | |
5127 } | |
7 | 5128 old_fdl = -1; /* force an update */ |
5129 curwin->w_p_fen = TRUE; | |
5130 break; | |
5131 | |
5132 /* "zM": close all folds */ | |
5133 case 'M': curwin->w_p_fdl = 0; | |
5134 old_fdl = -1; /* force an update */ | |
5135 curwin->w_p_fen = TRUE; | |
5136 break; | |
5137 | |
5138 /* "zr": reduce folding */ | |
6725 | 5139 case 'r': curwin->w_p_fdl += cap->count1; |
5140 { | |
5141 int d = getDeepestNesting(); | |
5142 | |
5143 if (curwin->w_p_fdl >= d) | |
5144 curwin->w_p_fdl = d; | |
5145 } | |
7 | 5146 break; |
5147 | |
5148 /* "zR": open all folds */ | |
5149 case 'R': curwin->w_p_fdl = getDeepestNesting(); | |
5150 old_fdl = -1; /* force an update */ | |
5151 break; | |
5152 | |
5153 case 'j': /* "zj" move to next fold downwards */ | |
5154 case 'k': /* "zk" move to next fold upwards */ | |
5155 if (foldMoveTo(TRUE, nchar == 'j' ? FORWARD : BACKWARD, | |
5156 cap->count1) == FAIL) | |
5157 clearopbeep(cap->oap); | |
5158 break; | |
5159 | |
5160 #endif /* FEAT_FOLDING */ | |
5161 | |
737 | 5162 #ifdef FEAT_SPELL |
710 | 5163 case 'u': /* "zug" and "zuw": undo "zg" and "zw" */ |
5164 ++no_mapping; | |
5165 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 5166 nchar = plain_vgetc(); |
710 | 5167 LANGMAP_ADJUST(nchar, TRUE); |
5168 --no_mapping; | |
5169 --allow_keys; | |
5170 #ifdef FEAT_CMDL_INFO | |
5171 (void)add_to_showcmd(nchar); | |
5172 #endif | |
5173 if (vim_strchr((char_u *)"gGwW", nchar) == NULL) | |
5174 { | |
5175 clearopbeep(cap->oap); | |
5176 break; | |
5177 } | |
5178 undo = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
5179 /* FALLTHROUGH */ |
710 | 5180 |
310 | 5181 case 'g': /* "zg": add good word to word list */ |
5182 case 'w': /* "zw": add wrong word to word list */ | |
381 | 5183 case 'G': /* "zG": add good word to temp word list */ |
5184 case 'W': /* "zW": add wrong word to temp word list */ | |
310 | 5185 { |
5186 char_u *ptr = NULL; | |
5187 int len; | |
5188 | |
5189 if (checkclearop(cap->oap)) | |
5190 break; | |
5191 if (VIsual_active && get_visual_text(cap, &ptr, &len) | |
5192 == FAIL) | |
5193 return; | |
501 | 5194 if (ptr == NULL) |
5195 { | |
5196 pos_T pos = curwin->w_cursor; | |
5197 | |
5374 | 5198 /* Find bad word under the cursor. When 'spell' is |
5199 * off this fails and find_ident_under_cursor() is | |
5200 * used below. */ | |
5201 emsg_off++; | |
534 | 5202 len = spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL); |
5374 | 5203 emsg_off--; |
501 | 5204 if (len != 0 && curwin->w_cursor.col <= pos.col) |
5205 ptr = ml_get_pos(&curwin->w_cursor); | |
5206 curwin->w_cursor = pos; | |
5207 } | |
5208 | |
310 | 5209 if (ptr == NULL && (len = find_ident_under_cursor(&ptr, |
5210 FIND_IDENT)) == 0) | |
5211 return; | |
381 | 5212 spell_add_word(ptr, len, nchar == 'w' || nchar == 'W', |
710 | 5213 (nchar == 'G' || nchar == 'W') |
5214 ? 0 : (int)cap->count1, | |
5215 undo); | |
310 | 5216 } |
316 | 5217 break; |
323 | 5218 |
584 | 5219 case '=': /* "z=": suggestions for a badly spelled word */ |
638 | 5220 if (!checkclearop(cap->oap)) |
485 | 5221 spell_suggest((int)cap->count0); |
323 | 5222 break; |
310 | 5223 #endif |
5224 | |
7 | 5225 default: clearopbeep(cap->oap); |
5226 } | |
5227 | |
5228 #ifdef FEAT_FOLDING | |
5229 /* Redraw when 'foldenable' changed */ | |
5230 if (old_fen != curwin->w_p_fen) | |
5231 { | |
5232 # ifdef FEAT_DIFF | |
5233 win_T *wp; | |
5234 | |
5235 if (foldmethodIsDiff(curwin) && curwin->w_p_scb) | |
5236 { | |
5237 /* Adjust 'foldenable' in diff-synced windows. */ | |
5238 FOR_ALL_WINDOWS(wp) | |
5239 { | |
5240 if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) | |
5241 { | |
5242 wp->w_p_fen = curwin->w_p_fen; | |
5243 changed_window_setting_win(wp); | |
5244 } | |
5245 } | |
5246 } | |
5247 # endif | |
5248 changed_window_setting(); | |
5249 } | |
5250 | |
5251 /* Redraw when 'foldlevel' changed. */ | |
5252 if (old_fdl != curwin->w_p_fdl) | |
5253 newFoldLevel(); | |
5254 #endif | |
5255 } | |
5256 | |
5257 #ifdef FEAT_GUI | |
5258 /* | |
5259 * Vertical scrollbar movement. | |
5260 */ | |
5261 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5262 nv_ver_scrollbar(cmdarg_T *cap) |
7 | 5263 { |
5264 if (cap->oap->op_type != OP_NOP) | |
5265 clearopbeep(cap->oap); | |
5266 | |
5267 /* Even if an operator was pending, we still want to scroll */ | |
5268 gui_do_scroll(); | |
5269 } | |
5270 | |
5271 /* | |
5272 * Horizontal scrollbar movement. | |
5273 */ | |
5274 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5275 nv_hor_scrollbar(cmdarg_T *cap) |
7 | 5276 { |
5277 if (cap->oap->op_type != OP_NOP) | |
5278 clearopbeep(cap->oap); | |
5279 | |
5280 /* 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
|
5281 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 5282 } |
5283 #endif | |
5284 | |
690 | 5285 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
685 | 5286 /* |
5287 * Click in GUI tab. | |
5288 */ | |
5289 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5290 nv_tabline(cmdarg_T *cap) |
685 | 5291 { |
5292 if (cap->oap->op_type != OP_NOP) | |
5293 clearopbeep(cap->oap); | |
5294 | |
5295 /* Even if an operator was pending, we still want to jump tabs. */ | |
5296 goto_tabpage(current_tab); | |
5297 } | |
686 | 5298 |
5299 /* | |
5300 * Selected item in tab line menu. | |
5301 */ | |
5302 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5303 nv_tabmenu(cmdarg_T *cap) |
686 | 5304 { |
5305 if (cap->oap->op_type != OP_NOP) | |
5306 clearopbeep(cap->oap); | |
5307 | |
5308 /* Even if an operator was pending, we still want to jump tabs. */ | |
690 | 5309 handle_tabmenu(); |
5310 } | |
5311 | |
5312 /* | |
5313 * Handle selecting an item of the GUI tab line menu. | |
5314 * Used in Normal and Insert mode. | |
5315 */ | |
5316 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5317 handle_tabmenu(void) |
690 | 5318 { |
686 | 5319 switch (current_tabmenu) |
5320 { | |
5321 case TABLINE_MENU_CLOSE: | |
5322 if (current_tab == 0) | |
5323 do_cmdline_cmd((char_u *)"tabclose"); | |
5324 else | |
5325 { | |
5326 vim_snprintf((char *)IObuff, IOSIZE, "tabclose %d", | |
5327 current_tab); | |
5328 do_cmdline_cmd(IObuff); | |
5329 } | |
5330 break; | |
5331 | |
5332 case TABLINE_MENU_NEW: | |
6631 | 5333 if (current_tab == 0) |
5334 do_cmdline_cmd((char_u *)"$tabnew"); | |
5335 else | |
5336 { | |
5337 vim_snprintf((char *)IObuff, IOSIZE, "%dtabnew", | |
5338 current_tab - 1); | |
5339 do_cmdline_cmd(IObuff); | |
5340 } | |
686 | 5341 break; |
5342 | |
5343 case TABLINE_MENU_OPEN: | |
6631 | 5344 if (current_tab == 0) |
5345 do_cmdline_cmd((char_u *)"browse $tabnew"); | |
5346 else | |
5347 { | |
5348 vim_snprintf((char *)IObuff, IOSIZE, "browse %dtabnew", | |
5349 current_tab - 1); | |
5350 do_cmdline_cmd(IObuff); | |
5351 } | |
686 | 5352 break; |
5353 } | |
5354 } | |
685 | 5355 #endif |
5356 | |
7 | 5357 /* |
5358 * "Q" command. | |
5359 */ | |
5360 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5361 nv_exmode(cmdarg_T *cap) |
7 | 5362 { |
5363 /* | |
5364 * Ignore 'Q' in Visual mode, just give a beep. | |
5365 */ | |
5366 if (VIsual_active) | |
6949 | 5367 vim_beep(BO_EX); |
5735 | 5368 else if (!checkclearop(cap->oap)) |
7 | 5369 do_exmode(FALSE); |
5370 } | |
5371 | |
5372 /* | |
5373 * Handle a ":" command. | |
5374 */ | |
5375 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5376 nv_colon(cmdarg_T *cap) |
7 | 5377 { |
5378 int old_p_im; | |
4256 | 5379 int cmd_result; |
7 | 5380 |
5381 if (VIsual_active) | |
5382 nv_operator(cap); | |
5383 else | |
5384 { | |
5385 if (cap->oap->op_type != OP_NOP) | |
5386 { | |
5387 /* Using ":" as a movement is characterwise exclusive. */ | |
5388 cap->oap->motion_type = MCHAR; | |
5389 cap->oap->inclusive = FALSE; | |
5390 } | |
5391 else if (cap->count0) | |
5392 { | |
5393 /* translate "count:" into ":.,.+(count - 1)" */ | |
5394 stuffcharReadbuff('.'); | |
5395 if (cap->count0 > 1) | |
5396 { | |
5397 stuffReadbuff((char_u *)",.+"); | |
5398 stuffnumReadbuff((long)cap->count0 - 1L); | |
5399 } | |
5400 } | |
5401 | |
5402 /* When typing, don't type below an old message */ | |
5403 if (KeyTyped) | |
5404 compute_cmdrow(); | |
5405 | |
5406 old_p_im = p_im; | |
5407 | |
5408 /* get a command line and execute it */ | |
4256 | 5409 cmd_result = do_cmdline(NULL, getexline, NULL, |
7 | 5410 cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0); |
5411 | |
5412 /* If 'insertmode' changed, enter or exit Insert mode */ | |
5413 if (p_im != old_p_im) | |
5414 { | |
5415 if (p_im) | |
5416 restart_edit = 'i'; | |
5417 else | |
5418 restart_edit = 0; | |
5419 } | |
5420 | |
4256 | 5421 if (cmd_result == FAIL) |
5422 /* The Ex command failed, do not execute the operator. */ | |
5423 clearop(cap->oap); | |
5424 else if (cap->oap->op_type != OP_NOP | |
7 | 5425 && (cap->oap->start.lnum > curbuf->b_ml.ml_line_count |
5426 || cap->oap->start.col > | |
4256 | 5427 (colnr_T)STRLEN(ml_get(cap->oap->start.lnum)) |
5428 || did_emsg | |
5429 )) | |
5430 /* The start of the operator has become invalid by the Ex command. | |
5431 */ | |
7 | 5432 clearopbeep(cap->oap); |
5433 } | |
5434 } | |
5435 | |
5436 /* | |
5437 * Handle CTRL-G command. | |
5438 */ | |
5439 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5440 nv_ctrlg(cmdarg_T *cap) |
7 | 5441 { |
5442 if (VIsual_active) /* toggle Selection/Visual mode */ | |
5443 { | |
5444 VIsual_select = !VIsual_select; | |
5445 showmode(); | |
5446 } | |
5735 | 5447 else if (!checkclearop(cap->oap)) |
7 | 5448 /* print full name if count given or :cd used */ |
5449 fileinfo((int)cap->count0, FALSE, TRUE); | |
5450 } | |
5451 | |
5452 /* | |
5453 * Handle CTRL-H <Backspace> command. | |
5454 */ | |
5455 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5456 nv_ctrlh(cmdarg_T *cap) |
7 | 5457 { |
5458 if (VIsual_active && VIsual_select) | |
5459 { | |
5460 cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */ | |
5461 v_visop(cap); | |
5462 } | |
5463 else | |
5464 nv_left(cap); | |
5465 } | |
5466 | |
5467 /* | |
5468 * CTRL-L: clear screen and redraw. | |
5469 */ | |
5470 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5471 nv_clear(cmdarg_T *cap) |
7 | 5472 { |
5473 if (!checkclearop(cap->oap)) | |
5474 { | |
5475 #if defined(__BEOS__) && !USE_THREAD_FOR_INPUT_WITH_TIMEOUT | |
5476 /* | |
5477 * Right now, the BeBox doesn't seem to have an easy way to detect | |
5478 * window resizing, so we cheat and make the user detect it | |
5479 * manually with CTRL-L instead | |
5480 */ | |
5481 ui_get_shellsize(); | |
5482 #endif | |
5483 #ifdef FEAT_SYN_HL | |
5484 /* 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
|
5485 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
|
5486 # ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5487 { |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5488 win_T *wp; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5489 |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5490 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
|
5491 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
|
5492 } |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5493 # endif |
7 | 5494 #endif |
5495 redraw_later(CLEAR); | |
5496 } | |
5497 } | |
5498 | |
5499 /* | |
5500 * CTRL-O: In Select mode: switch to Visual mode for one command. | |
5501 * Otherwise: Go to older pcmark. | |
5502 */ | |
5503 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5504 nv_ctrlo(cmdarg_T *cap) |
7 | 5505 { |
5506 if (VIsual_active && VIsual_select) | |
5507 { | |
5508 VIsual_select = FALSE; | |
5509 showmode(); | |
5510 restart_VIsual_select = 2; /* restart Select mode later */ | |
5511 } | |
5512 else | |
5513 { | |
5514 cap->count1 = -cap->count1; | |
5515 nv_pcmark(cap); | |
5516 } | |
5517 } | |
5518 | |
5519 /* | |
5520 * CTRL-^ command, short for ":e #" | |
5521 */ | |
5522 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5523 nv_hat(cmdarg_T *cap) |
7 | 5524 { |
5525 if (!checkclearopq(cap->oap)) | |
5526 (void)buflist_getfile((int)cap->count0, (linenr_T)0, | |
5527 GETF_SETMARK|GETF_ALT, FALSE); | |
5528 } | |
5529 | |
5530 /* | |
5531 * "Z" commands. | |
5532 */ | |
5533 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5534 nv_Zet(cmdarg_T *cap) |
7 | 5535 { |
5536 if (!checkclearopq(cap->oap)) | |
5537 { | |
5538 switch (cap->nchar) | |
5539 { | |
5540 /* "ZZ": equivalent to ":x". */ | |
5541 case 'Z': do_cmdline_cmd((char_u *)"x"); | |
5542 break; | |
5543 | |
5544 /* "ZQ": equivalent to ":q!" (Elvis compatible). */ | |
5545 case 'Q': do_cmdline_cmd((char_u *)"q!"); | |
5546 break; | |
5547 | |
5548 default: clearopbeep(cap->oap); | |
5549 } | |
5550 } | |
5551 } | |
5552 | |
5553 /* | |
5554 * Call nv_ident() as if "c1" was used, with "c2" as next character. | |
5555 */ | |
5556 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5557 do_nv_ident(int c1, int c2) |
7 | 5558 { |
5559 oparg_T oa; | |
5560 cmdarg_T ca; | |
5561 | |
5562 clear_oparg(&oa); | |
5563 vim_memset(&ca, 0, sizeof(ca)); | |
5564 ca.oap = &oa; | |
5565 ca.cmdchar = c1; | |
5566 ca.nchar = c2; | |
5567 nv_ident(&ca); | |
5568 } | |
5569 | |
5570 /* | |
5571 * Handle the commands that use the word under the cursor. | |
5572 * [g] CTRL-] :ta to current identifier | |
5573 * [g] 'K' run program for current identifier | |
5574 * [g] '*' / to current identifier or string | |
5575 * [g] '#' ? to current identifier or string | |
5576 * g ']' :tselect for current identifier | |
5577 */ | |
5578 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5579 nv_ident(cmdarg_T *cap) |
7 | 5580 { |
5581 char_u *ptr = NULL; | |
5582 char_u *buf; | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5583 unsigned buflen; |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5584 char_u *newbuf; |
7 | 5585 char_u *p; |
5586 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
|
5587 int kp_help; /* 'keywordprg' is ":he" */ |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5588 int kp_ex; /* 'keywordprg' starts with ":" */ |
7 | 5589 int n = 0; /* init for GCC */ |
5590 int cmdchar; | |
5591 int g_cmd; /* "g" command */ | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5592 int tag_cmd = FALSE; |
7 | 5593 char_u *aux_ptr; |
5594 int isman; | |
5595 int isman_s; | |
5596 | |
5597 if (cap->cmdchar == 'g') /* "g*", "g#", "g]" and "gCTRL-]" */ | |
5598 { | |
5599 cmdchar = cap->nchar; | |
5600 g_cmd = TRUE; | |
5601 } | |
5602 else | |
5603 { | |
5604 cmdchar = cap->cmdchar; | |
5605 g_cmd = FALSE; | |
5606 } | |
5607 | |
5608 if (cmdchar == POUND) /* the pound sign, '#' for English keyboards */ | |
5609 cmdchar = '#'; | |
5610 | |
5611 /* | |
5612 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode. | |
5613 */ | |
5614 if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') | |
5615 { | |
5616 if (VIsual_active && get_visual_text(cap, &ptr, &n) == FAIL) | |
5617 return; | |
5618 if (checkclearopq(cap->oap)) | |
5619 return; | |
5620 } | |
5621 | |
5622 if (ptr == NULL && (n = find_ident_under_cursor(&ptr, | |
5623 (cmdchar == '*' || cmdchar == '#') | |
5624 ? FIND_IDENT|FIND_STRING : FIND_IDENT)) == 0) | |
5625 { | |
5626 clearop(cap->oap); | |
5627 return; | |
5628 } | |
5629 | |
5630 /* Allocate buffer to put the command in. Inserting backslashes can | |
5631 * double the length of the word. p_kp / curbuf->b_p_kp could be added | |
5632 * and some numbers. */ | |
5633 kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); | |
5634 kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 | |
5635 || 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
|
5636 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
|
5637 { |
55cf556d8ce1
patch 8.0.0998: strange error when using K while only spaces are selected
Christian Brabandt <cb@256bit.org>
parents:
12164
diff
changeset
|
5638 EMSG(_(e_noident)); /* found white space only */ |
55cf556d8ce1
patch 8.0.0998: strange error when using K while only spaces are selected
Christian Brabandt <cb@256bit.org>
parents:
12164
diff
changeset
|
5639 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
|
5640 } |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5641 kp_ex = (*kp == ':'); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5642 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
|
5643 buf = alloc(buflen); |
7 | 5644 if (buf == NULL) |
5645 return; | |
5646 buf[0] = NUL; | |
5647 | |
5648 switch (cmdchar) | |
5649 { | |
5650 case '*': | |
5651 case '#': | |
5652 /* | |
5653 * Put cursor at start of word, makes search skip the word | |
5654 * under the cursor. | |
5655 * Call setpcmark() first, so "*``" puts the cursor back where | |
5656 * it was. | |
5657 */ | |
5658 setpcmark(); | |
5659 curwin->w_cursor.col = (colnr_T) (ptr - ml_get_curline()); | |
5660 | |
5661 if (!g_cmd && vim_iswordp(ptr)) | |
5662 STRCPY(buf, "\\<"); | |
5663 no_smartcase = TRUE; /* don't use 'smartcase' now */ | |
5664 break; | |
5665 | |
5666 case 'K': | |
5667 if (kp_help) | |
5668 STRCPY(buf, "he! "); | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5669 else if (kp_ex) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5670 { |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5671 if (cap->count0 != 0) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5672 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
|
5673 kp, cap->count0); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5674 else |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5675 STRCPY(buf, kp); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5676 STRCAT(buf, " "); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5677 } |
7 | 5678 else |
5679 { | |
1712 | 5680 /* An external command will probably use an argument starting |
5681 * with "-" as an option. To avoid trouble we skip the "-". */ | |
1728 | 5682 while (*ptr == '-' && n > 0) |
5683 { | |
1712 | 5684 ++ptr; |
1728 | 5685 --n; |
5686 } | |
5687 if (n == 0) | |
5688 { | |
5689 EMSG(_(e_noident)); /* found dashes only */ | |
5690 vim_free(buf); | |
5691 return; | |
5692 } | |
1712 | 5693 |
7 | 5694 /* When a count is given, turn it into a range. Is this |
5695 * really what we want? */ | |
5696 isman = (STRCMP(kp, "man") == 0); | |
5697 isman_s = (STRCMP(kp, "man -s") == 0); | |
5698 if (cap->count0 != 0 && !(isman || isman_s)) | |
5699 sprintf((char *)buf, ".,.+%ld", cap->count0 - 1); | |
5700 | |
5701 STRCAT(buf, "! "); | |
5702 if (cap->count0 == 0 && isman_s) | |
5703 STRCAT(buf, "man"); | |
5704 else | |
5705 STRCAT(buf, kp); | |
5706 STRCAT(buf, " "); | |
5707 if (cap->count0 != 0 && (isman || isman_s)) | |
5708 { | |
5709 sprintf((char *)buf + STRLEN(buf), "%ld", cap->count0); | |
5710 STRCAT(buf, " "); | |
5711 } | |
5712 } | |
5713 break; | |
5714 | |
5715 case ']': | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5716 tag_cmd = TRUE; |
7 | 5717 #ifdef FEAT_CSCOPE |
5718 if (p_cst) | |
5719 STRCPY(buf, "cstag "); | |
5720 else | |
5721 #endif | |
5722 STRCPY(buf, "ts "); | |
5723 break; | |
5724 | |
5725 default: | |
2112
6b5d641bcdd4
updated for version 7.2.395
Bram Moolenaar <bram@zimbu.org>
parents:
2049
diff
changeset
|
5726 tag_cmd = TRUE; |
7 | 5727 if (curbuf->b_help) |
5728 STRCPY(buf, "he! "); | |
5729 else | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5730 { |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5731 if (g_cmd) |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5732 STRCPY(buf, "tj "); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5733 else |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5734 sprintf((char *)buf, "%ldta ", cap->count0); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5735 } |
7 | 5736 } |
5737 | |
5738 /* | |
5739 * Now grab the chars in the identifier | |
5740 */ | |
1712 | 5741 if (cmdchar == 'K' && !kp_help) |
5742 { | |
1728 | 5743 ptr = vim_strnsave(ptr, n); |
10330
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5744 if (kp_ex) |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5745 /* 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
|
5746 p = vim_strsave_fnameescape(ptr, FALSE); |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5747 else |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5748 /* 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
|
5749 p = vim_strsave_shellescape(ptr, TRUE, TRUE); |
1728 | 5750 vim_free(ptr); |
1712 | 5751 if (p == NULL) |
5752 { | |
5753 vim_free(buf); | |
5754 return; | |
5755 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5756 newbuf = (char_u *)vim_realloc(buf, STRLEN(buf) + STRLEN(p) + 1); |
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5757 if (newbuf == NULL) |
1712 | 5758 { |
5759 vim_free(buf); | |
5760 vim_free(p); | |
5761 return; | |
5762 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5763 buf = newbuf; |
1712 | 5764 STRCAT(buf, p); |
5765 vim_free(p); | |
5766 } | |
7 | 5767 else |
1712 | 5768 { |
5769 if (cmdchar == '*') | |
5770 aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\"); | |
5771 else if (cmdchar == '#') | |
5772 aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\"); | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5773 else if (tag_cmd) |
2603 | 5774 { |
5775 if (curbuf->b_help) | |
5776 /* ":help" handles unescaped argument */ | |
5777 aux_ptr = (char_u *)""; | |
5778 else | |
5779 aux_ptr = (char_u *)"\\|\"\n["; | |
5780 } | |
1712 | 5781 else |
5782 aux_ptr = (char_u *)"\\|\"\n*?["; | |
5783 | |
5784 p = buf + STRLEN(buf); | |
5785 while (n-- > 0) | |
5786 { | |
5787 /* put a backslash before \ and some others */ | |
5788 if (vim_strchr(aux_ptr, *ptr) != NULL) | |
5789 *p++ = '\\'; | |
7 | 5790 #ifdef FEAT_MBYTE |
1712 | 5791 /* When current byte is a part of multibyte character, copy all |
5792 * bytes of that character. */ | |
5793 if (has_mbyte) | |
5794 { | |
5795 int i; | |
5796 int len = (*mb_ptr2len)(ptr) - 1; | |
5797 | |
5798 for (i = 0; i < len && n >= 1; ++i, --n) | |
5799 *p++ = *ptr++; | |
5800 } | |
5801 #endif | |
5802 *p++ = *ptr++; | |
5803 } | |
5804 *p = NUL; | |
5805 } | |
7 | 5806 |
5807 /* | |
5808 * Execute the command. | |
5809 */ | |
5810 if (cmdchar == '*' || cmdchar == '#') | |
5811 { | |
5812 if (!g_cmd && ( | |
5813 #ifdef FEAT_MBYTE | |
5814 has_mbyte ? vim_iswordp(mb_prevptr(ml_get_curline(), ptr)) : | |
5815 #endif | |
5816 vim_iswordc(ptr[-1]))) | |
5817 STRCAT(buf, "\\>"); | |
5818 #ifdef FEAT_CMDHIST | |
5819 /* put pattern in search history */ | |
2024 | 5820 init_history(); |
7 | 5821 add_to_history(HIST_SEARCH, buf, TRUE, NUL); |
5822 #endif | |
6620 | 5823 (void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0); |
7 | 5824 } |
5825 else | |
5826 do_cmdline_cmd(buf); | |
5827 | |
5828 vim_free(buf); | |
5829 } | |
5830 | |
5831 /* | |
5832 * Get visually selected text, within one line only. | |
5833 * Returns FAIL if more than one line selected. | |
5834 */ | |
344 | 5835 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5836 get_visual_text( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5837 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5838 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
|
5839 int *lenp) /* return: length of selected text */ |
7 | 5840 { |
5841 if (VIsual_mode != 'V') | |
5842 unadjust_for_sel(); | |
5843 if (VIsual.lnum != curwin->w_cursor.lnum) | |
5844 { | |
344 | 5845 if (cap != NULL) |
5846 clearopbeep(cap->oap); | |
7 | 5847 return FAIL; |
5848 } | |
5849 if (VIsual_mode == 'V') | |
5850 { | |
5851 *pp = ml_get_curline(); | |
5852 *lenp = (int)STRLEN(*pp); | |
5853 } | |
5854 else | |
5855 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5856 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 5857 { |
5858 *pp = ml_get_pos(&curwin->w_cursor); | |
5859 *lenp = VIsual.col - curwin->w_cursor.col + 1; | |
5860 } | |
5861 else | |
5862 { | |
5863 *pp = ml_get_pos(&VIsual); | |
5864 *lenp = curwin->w_cursor.col - VIsual.col + 1; | |
5865 } | |
5866 #ifdef FEAT_MBYTE | |
5867 if (has_mbyte) | |
5868 /* Correct the length to include the whole last character. */ | |
474 | 5869 *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; |
7 | 5870 #endif |
5871 } | |
5872 reset_VIsual_and_resel(); | |
5873 return OK; | |
5874 } | |
5875 | |
5876 /* | |
5877 * CTRL-T: backwards in tag stack | |
5878 */ | |
5879 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5880 nv_tagpop(cmdarg_T *cap) |
7 | 5881 { |
5882 if (!checkclearopq(cap->oap)) | |
5883 do_tag((char_u *)"", DT_POP, (int)cap->count1, FALSE, TRUE); | |
5884 } | |
5885 | |
5886 /* | |
5887 * Handle scrolling command 'H', 'L' and 'M'. | |
5888 */ | |
5889 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5890 nv_scroll(cmdarg_T *cap) |
7 | 5891 { |
5892 int used = 0; | |
5893 long n; | |
5894 #ifdef FEAT_FOLDING | |
5895 linenr_T lnum; | |
5896 #endif | |
5897 int half; | |
5898 | |
5899 cap->oap->motion_type = MLINE; | |
5900 setpcmark(); | |
5901 | |
5902 if (cap->cmdchar == 'L') | |
5903 { | |
5904 validate_botline(); /* make sure curwin->w_botline is valid */ | |
5905 curwin->w_cursor.lnum = curwin->w_botline - 1; | |
5906 if (cap->count1 - 1 >= curwin->w_cursor.lnum) | |
5907 curwin->w_cursor.lnum = 1; | |
5908 else | |
9 | 5909 { |
5910 #ifdef FEAT_FOLDING | |
5911 if (hasAnyFolding(curwin)) | |
5912 { | |
5913 /* Count a fold for one screen line. */ | |
5914 for (n = cap->count1 - 1; n > 0 | |
5915 && curwin->w_cursor.lnum > curwin->w_topline; --n) | |
5916 { | |
5917 (void)hasFolding(curwin->w_cursor.lnum, | |
5918 &curwin->w_cursor.lnum, NULL); | |
5919 --curwin->w_cursor.lnum; | |
5920 } | |
5921 } | |
5922 else | |
5923 #endif | |
5924 curwin->w_cursor.lnum -= cap->count1 - 1; | |
5925 } | |
7 | 5926 } |
5927 else | |
5928 { | |
5929 if (cap->cmdchar == 'M') | |
5930 { | |
5931 #ifdef FEAT_DIFF | |
5932 /* Don't count filler lines above the window. */ | |
5933 used -= diff_check_fill(curwin, curwin->w_topline) | |
5934 - curwin->w_topfill; | |
5935 #endif | |
5936 validate_botline(); /* make sure w_empty_rows is valid */ | |
5937 half = (curwin->w_height - curwin->w_empty_rows + 1) / 2; | |
5938 for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) | |
5939 { | |
5940 #ifdef FEAT_DIFF | |
5941 /* Count half he number of filler lines to be "below this | |
5942 * line" and half to be "above the next line". */ | |
5943 if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline | |
5944 + n) / 2 >= half) | |
5945 { | |
5946 --n; | |
5947 break; | |
5948 } | |
5949 #endif | |
5950 used += plines(curwin->w_topline + n); | |
5951 if (used >= half) | |
5952 break; | |
5953 #ifdef FEAT_FOLDING | |
5954 if (hasFolding(curwin->w_topline + n, NULL, &lnum)) | |
5955 n = lnum - curwin->w_topline; | |
5956 #endif | |
5957 } | |
5958 if (n > 0 && used > curwin->w_height) | |
5959 --n; | |
5960 } | |
9 | 5961 else /* (cap->cmdchar == 'H') */ |
5962 { | |
7 | 5963 n = cap->count1 - 1; |
9 | 5964 #ifdef FEAT_FOLDING |
5965 if (hasAnyFolding(curwin)) | |
5966 { | |
5967 /* Count a fold for one screen line. */ | |
5968 lnum = curwin->w_topline; | |
5969 while (n-- > 0 && lnum < curwin->w_botline - 1) | |
5970 { | |
7009 | 5971 (void)hasFolding(lnum, NULL, &lnum); |
9 | 5972 ++lnum; |
5973 } | |
5974 n = lnum - curwin->w_topline; | |
5975 } | |
5976 #endif | |
5977 } | |
7 | 5978 curwin->w_cursor.lnum = curwin->w_topline + n; |
5979 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
5980 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
5981 } | |
5982 | |
12646
b908a3682f6e
patch 8.0.1201: "yL" is affected by 'scrolloff'
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
5983 /* 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
|
5984 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
|
5985 cursor_correct(); |
7 | 5986 beginline(BL_SOL | BL_FIX); |
5987 } | |
5988 | |
5989 /* | |
5990 * Cursor right commands. | |
5991 */ | |
5992 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5993 nv_right(cmdarg_T *cap) |
7 | 5994 { |
5995 long n; | |
5735 | 5996 int past_line; |
7 | 5997 |
180 | 5998 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
5999 { | |
6000 /* <C-Right> and <S-Right> move a word or WORD right */ | |
6001 if (mod_mask & MOD_MASK_CTRL) | |
6002 cap->arg = TRUE; | |
6003 nv_wordcmd(cap); | |
6004 return; | |
6005 } | |
6006 | |
7 | 6007 cap->oap->motion_type = MCHAR; |
6008 cap->oap->inclusive = FALSE; | |
5735 | 6009 past_line = (VIsual_active && *p_sel != 'o'); |
6010 | |
6011 #ifdef FEAT_VIRTUALEDIT | |
7 | 6012 /* |
5735 | 6013 * In virtual edit mode, there's no such thing as "past_line", as lines |
6014 * are (theoretically) infinitely long. | |
7 | 6015 */ |
6016 if (virtual_active()) | |
5735 | 6017 past_line = 0; |
7 | 6018 #endif |
6019 | |
6020 for (n = cap->count1; n > 0; --n) | |
6021 { | |
5735 | 6022 if ((!past_line && oneright() == FAIL) |
6023 || (past_line && *ml_get_cursor() == NUL) | |
1877 | 6024 ) |
7 | 6025 { |
6026 /* | |
714 | 6027 * <Space> wraps to next line if 'whichwrap' has 's'. |
6028 * 'l' wraps to next line if 'whichwrap' has 'l'. | |
6029 * CURS_RIGHT wraps to next line if 'whichwrap' has '>'. | |
7 | 6030 */ |
6031 if ( ((cap->cmdchar == ' ' | |
6032 && vim_strchr(p_ww, 's') != NULL) | |
6033 || (cap->cmdchar == 'l' | |
6034 && vim_strchr(p_ww, 'l') != NULL) | |
229 | 6035 || (cap->cmdchar == K_RIGHT |
7 | 6036 && vim_strchr(p_ww, '>') != NULL)) |
6037 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
6038 { | |
6039 /* When deleting we also count the NL as a character. | |
6040 * Set cap->oap->inclusive when last char in the line is | |
6041 * included, move to next line after that */ | |
714 | 6042 if ( cap->oap->op_type != OP_NOP |
7 | 6043 && !cap->oap->inclusive |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6044 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6045 cap->oap->inclusive = TRUE; |
6046 else | |
6047 { | |
6048 ++curwin->w_cursor.lnum; | |
6049 curwin->w_cursor.col = 0; | |
6050 #ifdef FEAT_VIRTUALEDIT | |
6051 curwin->w_cursor.coladd = 0; | |
6052 #endif | |
6053 curwin->w_set_curswant = TRUE; | |
6054 cap->oap->inclusive = FALSE; | |
6055 } | |
6056 continue; | |
6057 } | |
6058 if (cap->oap->op_type == OP_NOP) | |
6059 { | |
6060 /* Only beep and flush if not moved at all */ | |
6061 if (n == cap->count1) | |
6062 beep_flush(); | |
6063 } | |
6064 else | |
6065 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6066 if (!LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6067 cap->oap->inclusive = TRUE; |
6068 } | |
6069 break; | |
6070 } | |
5735 | 6071 else if (past_line) |
7 | 6072 { |
6073 curwin->w_set_curswant = TRUE; | |
5735 | 6074 #ifdef FEAT_VIRTUALEDIT |
7 | 6075 if (virtual_active()) |
6076 oneright(); | |
6077 else | |
5735 | 6078 #endif |
6079 { | |
6080 #ifdef FEAT_MBYTE | |
7 | 6081 if (has_mbyte) |
6082 curwin->w_cursor.col += | |
474 | 6083 (*mb_ptr2len)(ml_get_cursor()); |
7 | 6084 else |
5735 | 6085 #endif |
7 | 6086 ++curwin->w_cursor.col; |
6087 } | |
6088 } | |
6089 } | |
6090 #ifdef FEAT_FOLDING | |
6091 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
6092 && cap->oap->op_type == OP_NOP) | |
6093 foldOpenCursor(); | |
6094 #endif | |
6095 } | |
6096 | |
6097 /* | |
6098 * Cursor left commands. | |
6099 * | |
6100 * Returns TRUE when operator end should not be adjusted. | |
6101 */ | |
6102 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6103 nv_left(cmdarg_T *cap) |
7 | 6104 { |
6105 long n; | |
6106 | |
180 | 6107 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
6108 { | |
6109 /* <C-Left> and <S-Left> move a word or WORD left */ | |
6110 if (mod_mask & MOD_MASK_CTRL) | |
6111 cap->arg = 1; | |
6112 nv_bck_word(cap); | |
6113 return; | |
6114 } | |
6115 | |
7 | 6116 cap->oap->motion_type = MCHAR; |
6117 cap->oap->inclusive = FALSE; | |
6118 for (n = cap->count1; n > 0; --n) | |
6119 { | |
6120 if (oneleft() == FAIL) | |
6121 { | |
6122 /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'. | |
6123 * 'h' wraps to previous line if 'whichwrap' has 'h'. | |
6124 * CURS_LEFT wraps to previous line if 'whichwrap' has '<'. | |
6125 */ | |
6126 if ( (((cap->cmdchar == K_BS | |
6127 || cap->cmdchar == Ctrl_H) | |
6128 && vim_strchr(p_ww, 'b') != NULL) | |
6129 || (cap->cmdchar == 'h' | |
6130 && vim_strchr(p_ww, 'h') != NULL) | |
229 | 6131 || (cap->cmdchar == K_LEFT |
7 | 6132 && vim_strchr(p_ww, '<') != NULL)) |
6133 && curwin->w_cursor.lnum > 1) | |
6134 { | |
6135 --(curwin->w_cursor.lnum); | |
6136 coladvance((colnr_T)MAXCOL); | |
6137 curwin->w_set_curswant = TRUE; | |
6138 | |
6139 /* When the NL before the first char has to be deleted we | |
6140 * put the cursor on the NUL after the previous line. | |
6141 * This is a very special case, be careful! | |
1469 | 6142 * Don't adjust op_end now, otherwise it won't work. */ |
7 | 6143 if ( (cap->oap->op_type == OP_DELETE |
6144 || 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
|
6145 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6146 { |
5682 | 6147 char_u *cp = ml_get_cursor(); |
6148 | |
6149 if (*cp != NUL) | |
6150 { | |
6151 #ifdef FEAT_MBYTE | |
6152 if (has_mbyte) | |
6153 curwin->w_cursor.col += (*mb_ptr2len)(cp); | |
6154 else | |
6155 #endif | |
6156 ++curwin->w_cursor.col; | |
6157 } | |
7 | 6158 cap->retval |= CA_NO_ADJ_OP_END; |
6159 } | |
6160 continue; | |
6161 } | |
6162 /* Only beep and flush if not moved at all */ | |
6163 else if (cap->oap->op_type == OP_NOP && n == cap->count1) | |
6164 beep_flush(); | |
6165 break; | |
6166 } | |
6167 } | |
6168 #ifdef FEAT_FOLDING | |
6169 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
6170 && cap->oap->op_type == OP_NOP) | |
6171 foldOpenCursor(); | |
6172 #endif | |
6173 } | |
6174 | |
6175 /* | |
6176 * Cursor up commands. | |
6177 * cap->arg is TRUE for "-": Move cursor to first non-blank. | |
6178 */ | |
6179 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6180 nv_up(cmdarg_T *cap) |
7 | 6181 { |
180 | 6182 if (mod_mask & MOD_MASK_SHIFT) |
6183 { | |
6184 /* <S-Up> is page up */ | |
6185 cap->arg = BACKWARD; | |
6186 nv_page(cap); | |
6187 } | |
6188 else | |
6189 { | |
6190 cap->oap->motion_type = MLINE; | |
6191 if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
6192 clearopbeep(cap->oap); | |
6193 else if (cap->arg) | |
6194 beginline(BL_WHITE | BL_FIX); | |
6195 } | |
7 | 6196 } |
6197 | |
6198 /* | |
6199 * Cursor down commands. | |
6200 * cap->arg is TRUE for CR and "+": Move cursor to first non-blank. | |
6201 */ | |
6202 static void | |
10192
758f3d5a463d
commit https://github.com/vim/vim/commit/1b010058235fb803c1d4f42a02d2883921be8ef4
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
6203 nv_down(cmdarg_T *cap) |
7 | 6204 { |
180 | 6205 if (mod_mask & MOD_MASK_SHIFT) |
6206 { | |
6207 /* <S-Down> is page down */ | |
6208 cap->arg = FORWARD; | |
6209 nv_page(cap); | |
6210 } | |
6211 else | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
6212 #if defined(FEAT_QUICKFIX) |
7 | 6213 /* In a quickfix window a <CR> jumps to the error under the cursor. */ |
170 | 6214 if (bt_quickfix(curbuf) && cap->cmdchar == CAR) |
10980
5362b4b6042c
patch 8.0.0379: CTRL-Z and mouse click use CTRL-O unnecessary
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
6215 { |
643 | 6216 if (curwin->w_llist_ref == NULL) |
6217 do_cmdline_cmd((char_u *)".cc"); /* quickfix window */ | |
6218 else | |
6219 do_cmdline_cmd((char_u *)".ll"); /* location list window */ | |
10980
5362b4b6042c
patch 8.0.0379: CTRL-Z and mouse click use CTRL-O unnecessary
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
6220 } |
7 | 6221 else |
6222 #endif | |
6223 { | |
6224 #ifdef FEAT_CMDWIN | |
6225 /* In the cmdline window a <CR> executes the command. */ | |
170 | 6226 if (cmdwin_type != 0 && cap->cmdchar == CAR) |
7 | 6227 cmdwin_result = CAR; |
6228 else | |
6229 #endif | |
6230 { | |
6231 cap->oap->motion_type = MLINE; | |
6232 if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
6233 clearopbeep(cap->oap); | |
6234 else if (cap->arg) | |
6235 beginline(BL_WHITE | BL_FIX); | |
6236 } | |
6237 } | |
6238 } | |
6239 | |
6240 #ifdef FEAT_SEARCHPATH | |
6241 /* | |
6242 * Grab the file name under the cursor and edit it. | |
6243 */ | |
6244 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6245 nv_gotofile(cmdarg_T *cap) |
7 | 6246 { |
6247 char_u *ptr; | |
681 | 6248 linenr_T lnum = -1; |
7 | 6249 |
633 | 6250 if (text_locked()) |
7 | 6251 { |
6252 clearopbeep(cap->oap); | |
633 | 6253 text_locked_msg(); |
7 | 6254 return; |
6255 } | |
819 | 6256 #ifdef FEAT_AUTOCMD |
6257 if (curbuf_locked()) | |
6258 { | |
6259 clearop(cap->oap); | |
6260 return; | |
6261 } | |
6262 #endif | |
7 | 6263 |
681 | 6264 ptr = grab_file_name(cap->count1, &lnum); |
7 | 6265 |
6266 if (ptr != NULL) | |
6267 { | |
6268 /* 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
|
6269 if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !buf_hide(curbuf)) |
7009 | 6270 (void)autowrite(curbuf, FALSE); |
7 | 6271 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
|
6272 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
|
6273 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
|
6274 && cap->nchar == 'F' && lnum >= 0) |
681 | 6275 { |
6276 curwin->w_cursor.lnum = lnum; | |
6277 check_cursor_lnum(); | |
6278 beginline(BL_SOL | BL_FIX); | |
6279 } | |
7 | 6280 vim_free(ptr); |
6281 } | |
6282 else | |
6283 clearop(cap->oap); | |
6284 } | |
6285 #endif | |
6286 | |
6287 /* | |
6288 * <End> command: to end of current line or last line. | |
6289 */ | |
6290 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6291 nv_end(cmdarg_T *cap) |
7 | 6292 { |
180 | 6293 if (cap->arg || (mod_mask & MOD_MASK_CTRL)) /* CTRL-END = goto last line */ |
6294 { | |
6295 cap->arg = TRUE; | |
7 | 6296 nv_goto(cap); |
6297 cap->count1 = 1; /* to end of current line */ | |
6298 } | |
6299 nv_dollar(cap); | |
6300 } | |
6301 | |
6302 /* | |
6303 * Handle the "$" command. | |
6304 */ | |
6305 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6306 nv_dollar(cmdarg_T *cap) |
7 | 6307 { |
6308 cap->oap->motion_type = MCHAR; | |
6309 cap->oap->inclusive = TRUE; | |
6310 #ifdef FEAT_VIRTUALEDIT | |
6311 /* In virtual mode when off the edge of a line and an operator | |
6312 * is pending (whew!) keep the cursor where it is. | |
6313 * Otherwise, send it to the end of the line. */ | |
6314 if (!virtual_active() || gchar_cursor() != NUL | |
6315 || cap->oap->op_type == OP_NOP) | |
6316 #endif | |
6317 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
6318 if (cursor_down((long)(cap->count1 - 1), | |
6319 cap->oap->op_type == OP_NOP) == FAIL) | |
6320 clearopbeep(cap->oap); | |
6321 #ifdef FEAT_FOLDING | |
6322 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6323 foldOpenCursor(); | |
6324 #endif | |
6325 } | |
6326 | |
6327 /* | |
6328 * Implementation of '?' and '/' commands. | |
6329 * If cap->arg is TRUE don't set PC mark. | |
6330 */ | |
6331 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6332 nv_search(cmdarg_T *cap) |
7 | 6333 { |
6334 oparg_T *oap = cap->oap; | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6335 pos_T save_cursor = curwin->w_cursor; |
7 | 6336 |
6337 if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13) | |
6338 { | |
6339 /* Translate "g??" to "g?g?" */ | |
6340 cap->cmdchar = 'g'; | |
6341 cap->nchar = '?'; | |
6342 nv_operator(cap); | |
6343 return; | |
6344 } | |
6345 | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6346 /* 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
|
6347 * start position. */ |
7 | 6348 cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0); |
6349 | |
6350 if (cap->searchbuf == NULL) | |
6351 { | |
6352 clearop(oap); | |
6353 return; | |
6354 } | |
6355 | |
6620 | 6356 (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
|
6357 (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
|
6358 ? 0 : SEARCH_MARK); |
7 | 6359 } |
6360 | |
6361 /* | |
6362 * Handle "N" and "n" commands. | |
6363 * cap->arg is SEARCH_REV for "N", 0 for "n". | |
6364 */ | |
6365 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6366 nv_next(cmdarg_T *cap) |
7 | 6367 { |
6620 | 6368 pos_T old = curwin->w_cursor; |
6369 int i = normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
6370 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6371 if (i == 1 && EQUAL_POS(old, curwin->w_cursor)) |
6620 | 6372 { |
6373 /* Avoid getting stuck on the current cursor position, which can | |
6374 * happen when an offset is given and the cursor is on the last char | |
6375 * in the buffer: Repeat with count + 1. */ | |
6376 cap->count1 += 1; | |
6377 (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
6378 cap->count1 -= 1; | |
6379 } | |
7 | 6380 } |
6381 | |
6382 /* | |
6383 * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat). | |
6384 * Uses only cap->count1 and cap->oap from "cap". | |
6620 | 6385 * Return 0 for failure, 1 for found, 2 for found and line offset added. |
6386 */ | |
6387 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6388 normal_search( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6389 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6390 int dir, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6391 char_u *pat, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6392 int opt) /* extra flags for do_search() */ |
7 | 6393 { |
6394 int i; | |
6395 | |
6396 cap->oap->motion_type = MCHAR; | |
6397 cap->oap->inclusive = FALSE; | |
6398 cap->oap->use_reg_one = TRUE; | |
6399 curwin->w_set_curswant = TRUE; | |
6400 | |
6401 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
|
6402 opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL, NULL); |
7 | 6403 if (i == 0) |
6404 clearop(cap->oap); | |
6405 else | |
6406 { | |
6407 if (i == 2) | |
6408 cap->oap->motion_type = MLINE; | |
6409 #ifdef FEAT_VIRTUALEDIT | |
6410 curwin->w_cursor.coladd = 0; | |
6411 #endif | |
6412 #ifdef FEAT_FOLDING | |
6413 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
6414 foldOpenCursor(); | |
6415 #endif | |
6416 } | |
6417 | |
6418 /* "/$" will put the cursor after the end of the line, may need to | |
6419 * correct that here */ | |
6420 check_cursor(); | |
6620 | 6421 return i; |
7 | 6422 } |
6423 | |
6424 /* | |
6425 * Character search commands. | |
6426 * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for | |
6427 * ',' and FALSE for ';'. | |
6428 * cap->nchar is NUL for ',' and ';' (repeat the search) | |
6429 */ | |
6430 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6431 nv_csearch(cmdarg_T *cap) |
7 | 6432 { |
6433 int t_cmd; | |
6434 | |
6435 if (cap->cmdchar == 't' || cap->cmdchar == 'T') | |
6436 t_cmd = TRUE; | |
6437 else | |
6438 t_cmd = FALSE; | |
6439 | |
6440 cap->oap->motion_type = MCHAR; | |
6441 if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL) | |
6442 clearopbeep(cap->oap); | |
6443 else | |
6444 { | |
6445 curwin->w_set_curswant = TRUE; | |
6446 #ifdef FEAT_VIRTUALEDIT | |
6447 /* Include a Tab for "tx" and for "dfx". */ | |
6448 if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD | |
6449 && (t_cmd || cap->oap->op_type != OP_NOP)) | |
6450 { | |
6451 colnr_T scol, ecol; | |
6452 | |
6453 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
6454 curwin->w_cursor.coladd = ecol - scol; | |
6455 } | |
6456 else | |
6457 curwin->w_cursor.coladd = 0; | |
6458 #endif | |
6459 adjust_for_sel(cap); | |
6460 #ifdef FEAT_FOLDING | |
6461 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6462 foldOpenCursor(); | |
6463 #endif | |
6464 } | |
6465 } | |
6466 | |
6467 /* | |
6468 * "[" and "]" commands. | |
6469 * cap->arg is BACKWARD for "[" and FORWARD for "]". | |
6470 */ | |
6471 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6472 nv_brackets(cmdarg_T *cap) |
7 | 6473 { |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
6474 pos_T new_pos = INIT_POS_T(0, 0, 0); |
7 | 6475 pos_T prev_pos; |
6476 pos_T *pos = NULL; /* init for GCC */ | |
6477 pos_T old_pos; /* cursor position before command */ | |
6478 int flag; | |
6479 long n; | |
6480 int findc; | |
6481 int c; | |
6482 | |
6483 cap->oap->motion_type = MCHAR; | |
6484 cap->oap->inclusive = FALSE; | |
6485 old_pos = curwin->w_cursor; | |
6486 #ifdef FEAT_VIRTUALEDIT | |
6487 curwin->w_cursor.coladd = 0; /* TODO: don't do this for an error. */ | |
6488 #endif | |
6489 | |
6490 #ifdef FEAT_SEARCHPATH | |
6491 /* | |
6492 * "[f" or "]f" : Edit file under the cursor (same as "gf") | |
6493 */ | |
6494 if (cap->nchar == 'f') | |
6495 nv_gotofile(cap); | |
6496 else | |
6497 #endif | |
6498 | |
6499 #ifdef FEAT_FIND_ID | |
6500 /* | |
1188 | 6501 * Find the occurrence(s) of the identifier or define under cursor |
6502 * in current and included files or jump to the first occurrence. | |
7 | 6503 * |
6504 * search list jump | |
6505 * fwd bwd fwd bwd fwd bwd | |
6506 * identifier "]i" "[i" "]I" "[I" "]^I" "[^I" | |
6507 * define "]d" "[d" "]D" "[D" "]^D" "[^D" | |
6508 */ | |
6509 if (vim_strchr((char_u *) | |
6510 #ifdef EBCDIC | |
6511 "iI\005dD\067", | |
6512 #else | |
6513 "iI\011dD\004", | |
6514 #endif | |
6515 cap->nchar) != NULL) | |
6516 { | |
6517 char_u *ptr; | |
6518 int len; | |
6519 | |
6520 if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) | |
6521 clearop(cap->oap); | |
6522 else | |
6523 { | |
6524 find_pattern_in_path(ptr, 0, len, TRUE, | |
6525 cap->count0 == 0 ? !isupper(cap->nchar) : FALSE, | |
6526 ((cap->nchar & 0xf) == ('d' & 0xf)) ? FIND_DEFINE : FIND_ANY, | |
6527 cap->count1, | |
6528 isupper(cap->nchar) ? ACTION_SHOW_ALL : | |
6529 islower(cap->nchar) ? ACTION_SHOW : ACTION_GOTO, | |
6530 cap->cmdchar == ']' ? curwin->w_cursor.lnum + 1 : (linenr_T)1, | |
6531 (linenr_T)MAXLNUM); | |
6532 curwin->w_set_curswant = TRUE; | |
6533 } | |
6534 } | |
6535 else | |
6536 #endif | |
6537 | |
6538 /* | |
6539 * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')' | |
6540 * "[#", "]#": go to start/end of Nth innermost #if..#endif construct. | |
6541 * "[/", "[*", "]/", "]*": go to Nth comment start/end. | |
6542 * "[m" or "]m" search for prev/next start of (Java) method. | |
6543 * "[M" or "]M" search for prev/next end of (Java) method. | |
6544 */ | |
6545 if ( (cap->cmdchar == '[' | |
6546 && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL) | |
6547 || (cap->cmdchar == ']' | |
6548 && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) | |
6549 { | |
6550 if (cap->nchar == '*') | |
6551 cap->nchar = '/'; | |
6552 prev_pos.lnum = 0; | |
6553 if (cap->nchar == 'm' || cap->nchar == 'M') | |
6554 { | |
6555 if (cap->cmdchar == '[') | |
6556 findc = '{'; | |
6557 else | |
6558 findc = '}'; | |
6559 n = 9999; | |
6560 } | |
6561 else | |
6562 { | |
6563 findc = cap->nchar; | |
6564 n = cap->count1; | |
6565 } | |
6566 for ( ; n > 0; --n) | |
6567 { | |
6568 if ((pos = findmatchlimit(cap->oap, findc, | |
6569 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) | |
6570 { | |
6571 if (new_pos.lnum == 0) /* nothing found */ | |
6572 { | |
6573 if (cap->nchar != 'm' && cap->nchar != 'M') | |
6574 clearopbeep(cap->oap); | |
6575 } | |
6576 else | |
6577 pos = &new_pos; /* use last one found */ | |
6578 break; | |
6579 } | |
6580 prev_pos = new_pos; | |
6581 curwin->w_cursor = *pos; | |
6582 new_pos = *pos; | |
6583 } | |
6584 curwin->w_cursor = old_pos; | |
6585 | |
6586 /* | |
6587 * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only | |
6588 * brought us to the match for "[m" and "]M" when inside a method. | |
6589 * Try finding the '{' or '}' we want to be at. | |
6590 * Also repeat for the given count. | |
6591 */ | |
6592 if (cap->nchar == 'm' || cap->nchar == 'M') | |
6593 { | |
6594 /* norm is TRUE for "]M" and "[m" */ | |
6595 int norm = ((findc == '{') == (cap->nchar == 'm')); | |
6596 | |
6597 n = cap->count1; | |
6598 /* found a match: we were inside a method */ | |
6599 if (prev_pos.lnum != 0) | |
6600 { | |
6601 pos = &prev_pos; | |
6602 curwin->w_cursor = prev_pos; | |
6603 if (norm) | |
6604 --n; | |
6605 } | |
6606 else | |
6607 pos = NULL; | |
6608 while (n > 0) | |
6609 { | |
6610 for (;;) | |
6611 { | |
6612 if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0) | |
6613 { | |
6614 /* if not found anything, that's an error */ | |
6615 if (pos == NULL) | |
6616 clearopbeep(cap->oap); | |
6617 n = 0; | |
6618 break; | |
6619 } | |
6620 c = gchar_cursor(); | |
6621 if (c == '{' || c == '}') | |
6622 { | |
6623 /* Must have found end/start of class: use it. | |
6624 * Or found the place to be at. */ | |
6625 if ((c == findc && norm) || (n == 1 && !norm)) | |
6626 { | |
6627 new_pos = curwin->w_cursor; | |
6628 pos = &new_pos; | |
6629 n = 0; | |
6630 } | |
6631 /* if no match found at all, we started outside of the | |
6632 * class and we're inside now. Just go on. */ | |
6633 else if (new_pos.lnum == 0) | |
6634 { | |
6635 new_pos = curwin->w_cursor; | |
6636 pos = &new_pos; | |
6637 } | |
6638 /* found start/end of other method: go to match */ | |
6639 else if ((pos = findmatchlimit(cap->oap, findc, | |
6640 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, | |
6641 0)) == NULL) | |
6642 n = 0; | |
6643 else | |
6644 curwin->w_cursor = *pos; | |
6645 break; | |
6646 } | |
6647 } | |
6648 --n; | |
6649 } | |
6650 curwin->w_cursor = old_pos; | |
6651 if (pos == NULL && new_pos.lnum != 0) | |
6652 clearopbeep(cap->oap); | |
6653 } | |
6654 if (pos != NULL) | |
6655 { | |
6656 setpcmark(); | |
6657 curwin->w_cursor = *pos; | |
6658 curwin->w_set_curswant = TRUE; | |
6659 #ifdef FEAT_FOLDING | |
6660 if ((fdo_flags & FDO_BLOCK) && KeyTyped | |
6661 && cap->oap->op_type == OP_NOP) | |
6662 foldOpenCursor(); | |
6663 #endif | |
6664 } | |
6665 } | |
6666 | |
6667 /* | |
6668 * "[[", "[]", "]]" and "][": move to start or end of function | |
6669 */ | |
6670 else if (cap->nchar == '[' || cap->nchar == ']') | |
6671 { | |
6672 if (cap->nchar == cap->cmdchar) /* "]]" or "[[" */ | |
6673 flag = '{'; | |
6674 else | |
6675 flag = '}'; /* "][" or "[]" */ | |
6676 | |
6677 curwin->w_set_curswant = TRUE; | |
6678 /* | |
6679 * Imitate strange Vi behaviour: When using "]]" with an operator | |
6680 * we also stop at '}'. | |
6681 */ | |
503 | 6682 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, flag, |
7 | 6683 (cap->oap->op_type != OP_NOP |
6684 && cap->arg == FORWARD && flag == '{'))) | |
6685 clearopbeep(cap->oap); | |
6686 else | |
6687 { | |
6688 if (cap->oap->op_type == OP_NOP) | |
6689 beginline(BL_WHITE | BL_FIX); | |
6690 #ifdef FEAT_FOLDING | |
6691 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6692 foldOpenCursor(); | |
6693 #endif | |
6694 } | |
6695 } | |
6696 | |
6697 /* | |
6698 * "[p", "[P", "]P" and "]p": put with indent adjustment | |
6699 */ | |
6700 else if (cap->nchar == 'p' || cap->nchar == 'P') | |
6701 { | |
1312 | 6702 if (!checkclearop(cap->oap)) |
7 | 6703 { |
5708 | 6704 int dir = (cap->cmdchar == ']' && cap->nchar == 'p') |
6705 ? FORWARD : BACKWARD; | |
6706 int regname = cap->oap->regname; | |
6707 int was_visual = VIsual_active; | |
6708 int line_count = curbuf->b_ml.ml_line_count; | |
6709 pos_T start, end; | |
6710 | |
6711 if (VIsual_active) | |
6712 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6713 start = LTOREQ_POS(VIsual, curwin->w_cursor) |
5708 | 6714 ? VIsual : curwin->w_cursor; |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6715 end = EQUAL_POS(start,VIsual) ? curwin->w_cursor : VIsual; |
5708 | 6716 curwin->w_cursor = (dir == BACKWARD ? start : end); |
6717 } | |
6718 # ifdef FEAT_CLIPBOARD | |
6719 adjust_clip_reg(®name); | |
6720 # endif | |
7 | 6721 prep_redo_cmd(cap); |
5708 | 6722 |
6723 do_put(regname, dir, cap->count1, PUT_FIXINDENT); | |
6724 if (was_visual) | |
6725 { | |
6726 VIsual = start; | |
6727 curwin->w_cursor = end; | |
6728 if (dir == BACKWARD) | |
6729 { | |
6730 /* adjust lines */ | |
6731 VIsual.lnum += curbuf->b_ml.ml_line_count - line_count; | |
6732 curwin->w_cursor.lnum += | |
6733 curbuf->b_ml.ml_line_count - line_count; | |
6734 } | |
6735 | |
6736 VIsual_active = TRUE; | |
6737 if (VIsual_mode == 'V') | |
6738 { | |
6739 /* delete visually selected lines */ | |
6740 cap->cmdchar = 'd'; | |
6741 cap->nchar = NUL; | |
6742 cap->oap->regname = regname; | |
6743 nv_operator(cap); | |
6744 do_pending_operator(cap, 0, FALSE); | |
6745 } | |
6746 if (VIsual_active) | |
6747 { | |
6748 end_visual_mode(); | |
6749 redraw_later(SOME_VALID); | |
6750 } | |
6751 } | |
7 | 6752 } |
6753 } | |
6754 | |
6755 /* | |
6756 * "['", "[`", "]'" and "]`": jump to next mark | |
6757 */ | |
6758 else if (cap->nchar == '\'' || cap->nchar == '`') | |
6759 { | |
6760 pos = &curwin->w_cursor; | |
6761 for (n = cap->count1; n > 0; --n) | |
6762 { | |
6763 prev_pos = *pos; | |
6764 pos = getnextmark(pos, cap->cmdchar == '[' ? BACKWARD : FORWARD, | |
6765 cap->nchar == '\''); | |
6766 if (pos == NULL) | |
6767 break; | |
6768 } | |
6769 if (pos == NULL) | |
6770 pos = &prev_pos; | |
6771 nv_cursormark(cap, cap->nchar == '\'', pos); | |
6772 } | |
6773 | |
6774 #ifdef FEAT_MOUSE | |
6775 /* | |
6776 * [ or ] followed by a middle mouse click: put selected text with | |
6777 * indent adjustment. Any other button just does as usual. | |
6778 */ | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
6779 else if (cap->nchar >= K_RIGHTRELEASE && cap->nchar <= K_LEFTMOUSE) |
7 | 6780 { |
6781 (void)do_mouse(cap->oap, cap->nchar, | |
6782 (cap->cmdchar == ']') ? FORWARD : BACKWARD, | |
6783 cap->count1, PUT_FIXINDENT); | |
6784 } | |
6785 #endif /* FEAT_MOUSE */ | |
6786 | |
6787 #ifdef FEAT_FOLDING | |
6788 /* | |
6789 * "[z" and "]z": move to start or end of open fold. | |
6790 */ | |
6791 else if (cap->nchar == 'z') | |
6792 { | |
6793 if (foldMoveTo(FALSE, cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
6794 cap->count1) == FAIL) | |
6795 clearopbeep(cap->oap); | |
6796 } | |
6797 #endif | |
6798 | |
6799 #ifdef FEAT_DIFF | |
6800 /* | |
6801 * "[c" and "]c": move to next or previous diff-change. | |
6802 */ | |
6803 else if (cap->nchar == 'c') | |
6804 { | |
6805 if (diff_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
6806 cap->count1) == FAIL) | |
6807 clearopbeep(cap->oap); | |
6808 } | |
6809 #endif | |
6810 | |
737 | 6811 #ifdef FEAT_SPELL |
236 | 6812 /* |
6813 * "[s", "[S", "]s" and "]S": move to next spell error. | |
6814 */ | |
6815 else if (cap->nchar == 's' || cap->nchar == 'S') | |
6816 { | |
249 | 6817 setpcmark(); |
6818 for (n = 0; n < cap->count1; ++n) | |
498 | 6819 if (spell_move_to(curwin, cap->cmdchar == ']' ? FORWARD : BACKWARD, |
6820 cap->nchar == 's' ? TRUE : FALSE, FALSE, NULL) == 0) | |
249 | 6821 { |
6822 clearopbeep(cap->oap); | |
6823 break; | |
6824 } | |
13088
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
6825 else |
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
6826 curwin->w_set_curswant = TRUE; |
819 | 6827 # ifdef FEAT_FOLDING |
6828 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
6829 foldOpenCursor(); | |
6830 # endif | |
236 | 6831 } |
6832 #endif | |
6833 | |
7 | 6834 /* Not a valid cap->nchar. */ |
6835 else | |
6836 clearopbeep(cap->oap); | |
6837 } | |
6838 | |
6839 /* | |
6840 * Handle Normal mode "%" command. | |
6841 */ | |
6842 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6843 nv_percent(cmdarg_T *cap) |
7 | 6844 { |
6845 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
|
6846 #if defined(FEAT_FOLDING) |
7 | 6847 linenr_T lnum = curwin->w_cursor.lnum; |
6848 #endif | |
6849 | |
6850 cap->oap->inclusive = TRUE; | |
6851 if (cap->count0) /* {cnt}% : goto {cnt} percentage in file */ | |
6852 { | |
6853 if (cap->count0 > 100) | |
6854 clearopbeep(cap->oap); | |
6855 else | |
6856 { | |
6857 cap->oap->motion_type = MLINE; | |
6858 setpcmark(); | |
6859 /* Round up, so CTRL-G will give same value. Watch out for a | |
6860 * large line count, the line number must not go negative! */ | |
6861 if (curbuf->b_ml.ml_line_count > 1000000) | |
6862 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) | |
6863 / 100L * cap->count0; | |
6864 else | |
6865 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count * | |
6866 cap->count0 + 99L) / 100L; | |
6867 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
6868 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
6869 beginline(BL_SOL | BL_FIX); | |
6870 } | |
6871 } | |
6872 else /* "%" : go to matching paren */ | |
6873 { | |
6874 cap->oap->motion_type = MCHAR; | |
6875 cap->oap->use_reg_one = TRUE; | |
6876 if ((pos = findmatch(cap->oap, NUL)) == NULL) | |
6877 clearopbeep(cap->oap); | |
6878 else | |
6879 { | |
6880 setpcmark(); | |
6881 curwin->w_cursor = *pos; | |
6882 curwin->w_set_curswant = TRUE; | |
6883 #ifdef FEAT_VIRTUALEDIT | |
6884 curwin->w_cursor.coladd = 0; | |
6885 #endif | |
6886 adjust_for_sel(cap); | |
6887 } | |
6888 } | |
6889 #ifdef FEAT_FOLDING | |
6890 if (cap->oap->op_type == OP_NOP | |
6891 && lnum != curwin->w_cursor.lnum | |
6892 && (fdo_flags & FDO_PERCENT) | |
6893 && KeyTyped) | |
6894 foldOpenCursor(); | |
6895 #endif | |
6896 } | |
6897 | |
6898 /* | |
6899 * Handle "(" and ")" commands. | |
6900 * cap->arg is BACKWARD for "(" and FORWARD for ")". | |
6901 */ | |
6902 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6903 nv_brace(cmdarg_T *cap) |
7 | 6904 { |
6905 cap->oap->motion_type = MCHAR; | |
6906 cap->oap->use_reg_one = TRUE; | |
620 | 6907 /* The motion used to be inclusive for "(", but that is not what Vi does. */ |
6908 cap->oap->inclusive = FALSE; | |
7 | 6909 curwin->w_set_curswant = TRUE; |
6910 | |
6911 if (findsent(cap->arg, cap->count1) == FAIL) | |
6912 clearopbeep(cap->oap); | |
6913 else | |
6914 { | |
1505 | 6915 /* Don't leave the cursor on the NUL past end of line. */ |
6916 adjust_cursor(cap->oap); | |
7 | 6917 #ifdef FEAT_VIRTUALEDIT |
6918 curwin->w_cursor.coladd = 0; | |
6919 #endif | |
6920 #ifdef FEAT_FOLDING | |
6921 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6922 foldOpenCursor(); | |
6923 #endif | |
6924 } | |
6925 } | |
6926 | |
6927 /* | |
6928 * "m" command: Mark a position. | |
6929 */ | |
6930 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6931 nv_mark(cmdarg_T *cap) |
7 | 6932 { |
6933 if (!checkclearop(cap->oap)) | |
6934 { | |
6935 if (setmark(cap->nchar) == FAIL) | |
6936 clearopbeep(cap->oap); | |
6937 } | |
6938 } | |
6939 | |
6940 /* | |
6941 * "{" and "}" commands. | |
6942 * cmd->arg is BACKWARD for "{" and FORWARD for "}". | |
6943 */ | |
6944 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6945 nv_findpar(cmdarg_T *cap) |
7 | 6946 { |
6947 cap->oap->motion_type = MCHAR; | |
6948 cap->oap->inclusive = FALSE; | |
6949 cap->oap->use_reg_one = TRUE; | |
6950 curwin->w_set_curswant = TRUE; | |
503 | 6951 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, FALSE)) |
7 | 6952 clearopbeep(cap->oap); |
6953 else | |
6954 { | |
6955 #ifdef FEAT_VIRTUALEDIT | |
6956 curwin->w_cursor.coladd = 0; | |
6957 #endif | |
6958 #ifdef FEAT_FOLDING | |
6959 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6960 foldOpenCursor(); | |
6961 #endif | |
6962 } | |
6963 } | |
6964 | |
6965 /* | |
6966 * "u" command: Undo or make lower case. | |
6967 */ | |
6968 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6969 nv_undo(cmdarg_T *cap) |
7 | 6970 { |
5735 | 6971 if (cap->oap->op_type == OP_LOWER || VIsual_active) |
7 | 6972 { |
6973 /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */ | |
6974 cap->cmdchar = 'g'; | |
6975 cap->nchar = 'u'; | |
6976 nv_operator(cap); | |
6977 } | |
6978 else | |
6979 nv_kundo(cap); | |
6980 } | |
6981 | |
6982 /* | |
6983 * <Undo> command. | |
6984 */ | |
6985 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6986 nv_kundo(cmdarg_T *cap) |
7 | 6987 { |
6988 if (!checkclearopq(cap->oap)) | |
6989 { | |
6990 u_undo((int)cap->count1); | |
6991 curwin->w_set_curswant = TRUE; | |
6992 } | |
6993 } | |
6994 | |
6995 /* | |
6996 * Handle the "r" command. | |
6997 */ | |
6998 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6999 nv_replace(cmdarg_T *cap) |
7 | 7000 { |
7001 char_u *ptr; | |
7002 int had_ctrl_v; | |
7003 long n; | |
7004 | |
7005 if (checkclearop(cap->oap)) | |
7006 return; | |
7007 | |
7008 /* get another character */ | |
7009 if (cap->nchar == Ctrl_V) | |
7010 { | |
7011 had_ctrl_v = Ctrl_V; | |
7012 cap->nchar = get_literal(); | |
7013 /* Don't redo a multibyte character with CTRL-V. */ | |
7014 if (cap->nchar > DEL) | |
7015 had_ctrl_v = NUL; | |
7016 } | |
7017 else | |
7018 had_ctrl_v = NUL; | |
7019 | |
1343 | 7020 /* Abort if the character is a special key. */ |
7021 if (IS_SPECIAL(cap->nchar)) | |
7022 { | |
7023 clearopbeep(cap->oap); | |
7024 return; | |
7025 } | |
7026 | |
7 | 7027 /* Visual mode "r" */ |
7028 if (VIsual_active) | |
7029 { | |
1797 | 7030 if (got_int) |
7031 reset_VIsual(); | |
5428 | 7032 if (had_ctrl_v) |
7033 { | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
7034 /* 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
|
7035 * 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
|
7036 if (cap->nchar == CAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
7037 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
|
7038 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
|
7039 cap->nchar = REPLACE_NL_NCHAR; |
5428 | 7040 } |
7 | 7041 nv_operator(cap); |
7042 return; | |
7043 } | |
7044 | |
7045 #ifdef FEAT_VIRTUALEDIT | |
7046 /* Break tabs, etc. */ | |
7047 if (virtual_active()) | |
7048 { | |
7049 if (u_save_cursor() == FAIL) | |
7050 return; | |
7051 if (gchar_cursor() == NUL) | |
7052 { | |
7053 /* Add extra space and put the cursor on the first one. */ | |
7054 coladvance_force((colnr_T)(getviscol() + cap->count1)); | |
7055 curwin->w_cursor.col -= cap->count1; | |
7056 } | |
7057 else if (gchar_cursor() == TAB) | |
7058 coladvance_force(getviscol()); | |
7059 } | |
7060 #endif | |
7061 | |
1343 | 7062 /* Abort if not enough characters to replace. */ |
7 | 7063 ptr = ml_get_cursor(); |
1343 | 7064 if (STRLEN(ptr) < (unsigned)cap->count1 |
7 | 7065 #ifdef FEAT_MBYTE |
7066 || (has_mbyte && mb_charlen(ptr) < cap->count1) | |
7067 #endif | |
7068 ) | |
7069 { | |
7070 clearopbeep(cap->oap); | |
7071 return; | |
7072 } | |
7073 | |
7074 /* | |
7075 * Replacing with a TAB is done by edit() when it is complicated because | |
7076 * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB. | |
7077 * Other characters are done below to avoid problems with things like | |
7078 * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC). | |
7079 */ | |
7080 if (had_ctrl_v != Ctrl_V && cap->nchar == '\t' && (curbuf->b_p_et || p_sta)) | |
7081 { | |
7082 stuffnumReadbuff(cap->count1); | |
7083 stuffcharReadbuff('R'); | |
7084 stuffcharReadbuff('\t'); | |
7085 stuffcharReadbuff(ESC); | |
7086 return; | |
7087 } | |
7088 | |
7089 /* save line for undo */ | |
7090 if (u_save_cursor() == FAIL) | |
7091 return; | |
7092 | |
7093 if (had_ctrl_v != Ctrl_V && (cap->nchar == '\r' || cap->nchar == '\n')) | |
7094 { | |
7095 /* | |
7096 * Replace character(s) by a single newline. | |
7097 * Strange vi behaviour: Only one newline is inserted. | |
7098 * Delete the characters here. | |
7099 * Insert the newline with an insert command, takes care of | |
7100 * autoindent. The insert command depends on being on the last | |
7101 * character of a line or not. | |
7102 */ | |
7103 #ifdef FEAT_MBYTE | |
7104 (void)del_chars(cap->count1, FALSE); /* delete the characters */ | |
7105 #else | |
608 | 7106 (void)del_bytes(cap->count1, FALSE, FALSE); /* delete the characters */ |
7 | 7107 #endif |
7108 stuffcharReadbuff('\r'); | |
7109 stuffcharReadbuff(ESC); | |
7110 | |
7111 /* Give 'r' to edit(), to get the redo command right. */ | |
7112 invoke_edit(cap, TRUE, 'r', FALSE); | |
7113 } | |
7114 else | |
7115 { | |
7116 prep_redo(cap->oap->regname, cap->count1, | |
7117 NUL, 'r', NUL, had_ctrl_v, cap->nchar); | |
7118 | |
7119 curbuf->b_op_start = curwin->w_cursor; | |
7120 #ifdef FEAT_MBYTE | |
7121 if (has_mbyte) | |
7122 { | |
7123 int old_State = State; | |
7124 | |
7125 if (cap->ncharC1 != 0) | |
7126 AppendCharToRedobuff(cap->ncharC1); | |
7127 if (cap->ncharC2 != 0) | |
7128 AppendCharToRedobuff(cap->ncharC2); | |
7129 | |
7130 /* This is slow, but it handles replacing a single-byte with a | |
7131 * multi-byte and the other way around. Also handles adding | |
7132 * composing characters for utf-8. */ | |
7133 for (n = cap->count1; n > 0; --n) | |
7134 { | |
7135 State = REPLACE; | |
3501 | 7136 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7137 { | |
7138 int c = ins_copychar(curwin->w_cursor.lnum | |
7139 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7140 if (c != NUL) | |
7141 ins_char(c); | |
7142 else | |
7143 /* will be decremented further down */ | |
7144 ++curwin->w_cursor.col; | |
7145 } | |
7146 else | |
7147 ins_char(cap->nchar); | |
7 | 7148 State = old_State; |
7149 if (cap->ncharC1 != 0) | |
7150 ins_char(cap->ncharC1); | |
7151 if (cap->ncharC2 != 0) | |
7152 ins_char(cap->ncharC2); | |
7153 } | |
7154 } | |
7155 else | |
7156 #endif | |
7157 { | |
7158 /* | |
7159 * Replace the characters within one line. | |
7160 */ | |
7161 for (n = cap->count1; n > 0; --n) | |
7162 { | |
7163 /* | |
7164 * Get ptr again, because u_save and/or showmatch() will have | |
7165 * released the line. At the same time we let know that the | |
7166 * line will be changed. | |
7167 */ | |
7168 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); | |
3501 | 7169 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7170 { | |
7171 int c = ins_copychar(curwin->w_cursor.lnum | |
7172 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7173 if (c != NUL) | |
7174 ptr[curwin->w_cursor.col] = c; | |
7175 } | |
7176 else | |
7177 ptr[curwin->w_cursor.col] = cap->nchar; | |
7 | 7178 if (p_sm && msg_silent == 0) |
7179 showmatch(cap->nchar); | |
7180 ++curwin->w_cursor.col; | |
7181 } | |
7182 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7183 if (netbeans_active()) |
7 | 7184 { |
2210 | 7185 colnr_T start = (colnr_T)(curwin->w_cursor.col - cap->count1); |
7 | 7186 |
33 | 7187 netbeans_removed(curbuf, curwin->w_cursor.lnum, start, |
2210 | 7188 (long)cap->count1); |
7 | 7189 netbeans_inserted(curbuf, curwin->w_cursor.lnum, start, |
33 | 7190 &ptr[start], (int)cap->count1); |
7 | 7191 } |
7192 #endif | |
7193 | |
7194 /* mark the buffer as changed and prepare for displaying */ | |
7195 changed_bytes(curwin->w_cursor.lnum, | |
7196 (colnr_T)(curwin->w_cursor.col - cap->count1)); | |
7197 } | |
7198 --curwin->w_cursor.col; /* cursor on the last replaced char */ | |
7199 #ifdef FEAT_MBYTE | |
7200 /* if the character on the left of the current cursor is a multi-byte | |
7201 * character, move two characters left */ | |
7202 if (has_mbyte) | |
7203 mb_adjust_cursor(); | |
7204 #endif | |
7205 curbuf->b_op_end = curwin->w_cursor; | |
7206 curwin->w_set_curswant = TRUE; | |
7207 set_last_insert(cap->nchar); | |
7208 } | |
7209 } | |
7210 | |
7211 /* | |
7212 * 'o': Exchange start and end of Visual area. | |
7213 * 'O': same, but in block mode exchange left and right corners. | |
7214 */ | |
7215 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7216 v_swap_corners(int cmdchar) |
7 | 7217 { |
7218 pos_T old_cursor; | |
7219 colnr_T left, right; | |
7220 | |
7221 if (cmdchar == 'O' && VIsual_mode == Ctrl_V) | |
7222 { | |
7223 old_cursor = curwin->w_cursor; | |
7224 getvcols(curwin, &old_cursor, &VIsual, &left, &right); | |
7225 curwin->w_cursor.lnum = VIsual.lnum; | |
7226 coladvance(left); | |
7227 VIsual = curwin->w_cursor; | |
7228 | |
7229 curwin->w_cursor.lnum = old_cursor.lnum; | |
7230 curwin->w_curswant = right; | |
7231 /* 'selection "exclusive" and cursor at right-bottom corner: move it | |
7232 * right one column */ | |
7233 if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') | |
7234 ++curwin->w_curswant; | |
7235 coladvance(curwin->w_curswant); | |
7236 if (curwin->w_cursor.col == old_cursor.col | |
7237 #ifdef FEAT_VIRTUALEDIT | |
7238 && (!virtual_active() | |
7239 || curwin->w_cursor.coladd == old_cursor.coladd) | |
7240 #endif | |
7241 ) | |
7242 { | |
7243 curwin->w_cursor.lnum = VIsual.lnum; | |
7244 if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') | |
7245 ++right; | |
7246 coladvance(right); | |
7247 VIsual = curwin->w_cursor; | |
7248 | |
7249 curwin->w_cursor.lnum = old_cursor.lnum; | |
7250 coladvance(left); | |
7251 curwin->w_curswant = left; | |
7252 } | |
7253 } | |
7254 else | |
7255 { | |
7256 old_cursor = curwin->w_cursor; | |
7257 curwin->w_cursor = VIsual; | |
7258 VIsual = old_cursor; | |
7259 curwin->w_set_curswant = TRUE; | |
7260 } | |
7261 } | |
7262 | |
7263 /* | |
7264 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE). | |
7265 */ | |
7266 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7267 nv_Replace(cmdarg_T *cap) |
7 | 7268 { |
7269 if (VIsual_active) /* "R" is replace lines */ | |
7270 { | |
7271 cap->cmdchar = 'c'; | |
7272 cap->nchar = NUL; | |
4213 | 7273 VIsual_mode_orig = VIsual_mode; /* remember original area for gv */ |
7 | 7274 VIsual_mode = 'V'; |
7275 nv_operator(cap); | |
7276 } | |
5735 | 7277 else if (!checkclearopq(cap->oap)) |
7 | 7278 { |
7279 if (!curbuf->b_p_ma) | |
7280 EMSG(_(e_modifiable)); | |
7281 else | |
7282 { | |
7283 #ifdef FEAT_VIRTUALEDIT | |
7284 if (virtual_active()) | |
7285 coladvance(getviscol()); | |
7286 #endif | |
7287 invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE); | |
7288 } | |
7289 } | |
7290 } | |
7291 | |
7292 #ifdef FEAT_VREPLACE | |
7293 /* | |
7294 * "gr". | |
7295 */ | |
7296 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7297 nv_vreplace(cmdarg_T *cap) |
7 | 7298 { |
7299 if (VIsual_active) | |
7300 { | |
7301 cap->cmdchar = 'r'; | |
7302 cap->nchar = cap->extra_char; | |
7303 nv_replace(cap); /* Do same as "r" in Visual mode for now */ | |
7304 } | |
5735 | 7305 else if (!checkclearopq(cap->oap)) |
7 | 7306 { |
7307 if (!curbuf->b_p_ma) | |
7308 EMSG(_(e_modifiable)); | |
7309 else | |
7310 { | |
7311 if (cap->extra_char == Ctrl_V) /* get another character */ | |
7312 cap->extra_char = get_literal(); | |
7313 stuffcharReadbuff(cap->extra_char); | |
7314 stuffcharReadbuff(ESC); | |
7315 # ifdef FEAT_VIRTUALEDIT | |
7316 if (virtual_active()) | |
7317 coladvance(getviscol()); | |
7318 # endif | |
7319 invoke_edit(cap, TRUE, 'v', FALSE); | |
7320 } | |
7321 } | |
7322 } | |
7323 #endif | |
7324 | |
7325 /* | |
7326 * Swap case for "~" command, when it does not work like an operator. | |
7327 */ | |
7328 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7329 n_swapchar(cmdarg_T *cap) |
7 | 7330 { |
7331 long n; | |
7332 pos_T startpos; | |
7333 int did_change = 0; | |
7334 #ifdef FEAT_NETBEANS_INTG | |
7335 pos_T pos; | |
7336 char_u *ptr; | |
7337 int count; | |
7338 #endif | |
7339 | |
7340 if (checkclearopq(cap->oap)) | |
7341 return; | |
7342 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7343 if (LINEEMPTY(curwin->w_cursor.lnum) && vim_strchr(p_ww, '~') == NULL) |
7 | 7344 { |
7345 clearopbeep(cap->oap); | |
7346 return; | |
7347 } | |
7348 | |
7349 prep_redo_cmd(cap); | |
7350 | |
7351 if (u_save_cursor() == FAIL) | |
7352 return; | |
7353 | |
7354 startpos = curwin->w_cursor; | |
7355 #ifdef FEAT_NETBEANS_INTG | |
7356 pos = startpos; | |
7357 #endif | |
7358 for (n = cap->count1; n > 0; --n) | |
7359 { | |
7360 did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor); | |
7361 inc_cursor(); | |
7362 if (gchar_cursor() == NUL) | |
7363 { | |
7364 if (vim_strchr(p_ww, '~') != NULL | |
7365 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
7366 { | |
7367 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7368 if (netbeans_active()) |
7 | 7369 { |
7370 if (did_change) | |
7371 { | |
7372 ptr = ml_get(pos.lnum); | |
835 | 7373 count = (int)STRLEN(ptr) - pos.col; |
33 | 7374 netbeans_removed(curbuf, pos.lnum, pos.col, |
7375 (long)count); | |
7 | 7376 netbeans_inserted(curbuf, pos.lnum, pos.col, |
33 | 7377 &ptr[pos.col], count); |
7 | 7378 } |
7379 pos.col = 0; | |
7380 pos.lnum++; | |
7381 } | |
7382 #endif | |
7383 ++curwin->w_cursor.lnum; | |
7384 curwin->w_cursor.col = 0; | |
7385 if (n > 1) | |
7386 { | |
7387 if (u_savesub(curwin->w_cursor.lnum) == FAIL) | |
7388 break; | |
7389 u_clearline(); | |
7390 } | |
7391 } | |
7392 else | |
7393 break; | |
7394 } | |
7395 } | |
7396 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7397 if (did_change && netbeans_active()) |
7 | 7398 { |
7399 ptr = ml_get(pos.lnum); | |
7400 count = curwin->w_cursor.col - pos.col; | |
33 | 7401 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7402 netbeans_inserted(curbuf, pos.lnum, pos.col, &ptr[pos.col], count); | |
7 | 7403 } |
7404 #endif | |
7405 | |
7406 | |
7407 check_cursor(); | |
7408 curwin->w_set_curswant = TRUE; | |
7409 if (did_change) | |
7410 { | |
7411 changed_lines(startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1, | |
7412 0L); | |
7413 curbuf->b_op_start = startpos; | |
7414 curbuf->b_op_end = curwin->w_cursor; | |
7415 if (curbuf->b_op_end.col > 0) | |
7416 --curbuf->b_op_end.col; | |
7417 } | |
7418 } | |
7419 | |
7420 /* | |
7421 * Move cursor to mark. | |
7422 */ | |
7423 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7424 nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos) |
7 | 7425 { |
7426 if (check_mark(pos) == FAIL) | |
7427 clearop(cap->oap); | |
7428 else | |
7429 { | |
7430 if (cap->cmdchar == '\'' | |
7431 || cap->cmdchar == '`' | |
7432 || cap->cmdchar == '[' | |
7433 || cap->cmdchar == ']') | |
7434 setpcmark(); | |
7435 curwin->w_cursor = *pos; | |
7436 if (flag) | |
7437 beginline(BL_WHITE | BL_FIX); | |
7438 else | |
7439 check_cursor(); | |
7440 } | |
7441 cap->oap->motion_type = flag ? MLINE : MCHAR; | |
7442 if (cap->cmdchar == '`') | |
7443 cap->oap->use_reg_one = TRUE; | |
7444 cap->oap->inclusive = FALSE; /* ignored if not MCHAR */ | |
7445 curwin->w_set_curswant = TRUE; | |
7446 } | |
7447 | |
7448 /* | |
7449 * Handle commands that are operators in Visual mode. | |
7450 */ | |
7451 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7452 v_visop(cmdarg_T *cap) |
7 | 7453 { |
7454 static char_u trans[] = "YyDdCcxdXdAAIIrr"; | |
7455 | |
7456 /* Uppercase means linewise, except in block mode, then "D" deletes till | |
4352 | 7457 * the end of the line, and "C" replaces till EOL */ |
7 | 7458 if (isupper(cap->cmdchar)) |
7459 { | |
7460 if (VIsual_mode != Ctrl_V) | |
4213 | 7461 { |
7462 VIsual_mode_orig = VIsual_mode; | |
7 | 7463 VIsual_mode = 'V'; |
4213 | 7464 } |
7 | 7465 else if (cap->cmdchar == 'C' || cap->cmdchar == 'D') |
7466 curwin->w_curswant = MAXCOL; | |
7467 } | |
7468 cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1); | |
7469 nv_operator(cap); | |
7470 } | |
7471 | |
7472 /* | |
7473 * "s" and "S" commands. | |
7474 */ | |
7475 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7476 nv_subst(cmdarg_T *cap) |
7 | 7477 { |
7478 if (VIsual_active) /* "vs" and "vS" are the same as "vc" */ | |
7479 { | |
7480 if (cap->cmdchar == 'S') | |
4213 | 7481 { |
7482 VIsual_mode_orig = VIsual_mode; | |
7 | 7483 VIsual_mode = 'V'; |
4213 | 7484 } |
7 | 7485 cap->cmdchar = 'c'; |
7486 nv_operator(cap); | |
7487 } | |
7488 else | |
7489 nv_optrans(cap); | |
7490 } | |
7491 | |
7492 /* | |
7493 * Abbreviated commands. | |
7494 */ | |
7495 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7496 nv_abbrev(cmdarg_T *cap) |
7 | 7497 { |
7498 if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) | |
7499 cap->cmdchar = 'x'; /* DEL key behaves like 'x' */ | |
7500 | |
7501 /* in Visual mode these commands are operators */ | |
7502 if (VIsual_active) | |
7503 v_visop(cap); | |
7504 else | |
7505 nv_optrans(cap); | |
7506 } | |
7507 | |
7508 /* | |
7509 * Translate a command into another command. | |
7510 */ | |
7511 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7512 nv_optrans(cmdarg_T *cap) |
7 | 7513 { |
7514 static char_u *(ar[8]) = {(char_u *)"dl", (char_u *)"dh", | |
7515 (char_u *)"d$", (char_u *)"c$", | |
7516 (char_u *)"cl", (char_u *)"cc", | |
7517 (char_u *)"yy", (char_u *)":s\r"}; | |
7518 static char_u *str = (char_u *)"xXDCsSY&"; | |
7519 | |
7520 if (!checkclearopq(cap->oap)) | |
7521 { | |
164 | 7522 /* In Vi "2D" doesn't delete the next line. Can't translate it |
7523 * either, because "2." should also not use the count. */ | |
7524 if (cap->cmdchar == 'D' && vim_strchr(p_cpo, CPO_HASH) != NULL) | |
7525 { | |
7526 cap->oap->start = curwin->w_cursor; | |
7527 cap->oap->op_type = OP_DELETE; | |
1490 | 7528 #ifdef FEAT_EVAL |
7529 set_op_var(OP_DELETE); | |
7530 #endif | |
164 | 7531 cap->count1 = 1; |
7532 nv_dollar(cap); | |
7533 finish_op = TRUE; | |
7534 ResetRedobuff(); | |
7535 AppendCharToRedobuff('D'); | |
7536 } | |
7537 else | |
7538 { | |
7539 if (cap->count0) | |
7540 stuffnumReadbuff(cap->count0); | |
7541 stuffReadbuff(ar[(int)(vim_strchr(str, cap->cmdchar) - str)]); | |
7542 } | |
7 | 7543 } |
7544 cap->opcount = 0; | |
7545 } | |
7546 | |
7547 /* | |
7548 * "'" and "`" commands. Also for "g'" and "g`". | |
7549 * cap->arg is TRUE for "'" and "g'". | |
7550 */ | |
7551 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7552 nv_gomark(cmdarg_T *cap) |
7 | 7553 { |
7554 pos_T *pos; | |
7555 int c; | |
7556 #ifdef FEAT_FOLDING | |
4017 | 7557 pos_T old_cursor = curwin->w_cursor; |
7 | 7558 int old_KeyTyped = KeyTyped; /* getting file may reset it */ |
7559 #endif | |
7560 | |
7561 if (cap->cmdchar == 'g') | |
7562 c = cap->extra_char; | |
7563 else | |
7564 c = cap->nchar; | |
7565 pos = getmark(c, (cap->oap->op_type == OP_NOP)); | |
7566 if (pos == (pos_T *)-1) /* jumped to other file */ | |
7567 { | |
7568 if (cap->arg) | |
7569 { | |
7570 check_cursor_lnum(); | |
7571 beginline(BL_WHITE | BL_FIX); | |
7572 } | |
7573 else | |
7574 check_cursor(); | |
7575 } | |
7576 else | |
7577 nv_cursormark(cap, cap->arg, pos); | |
7578 | |
7579 #ifdef FEAT_VIRTUALEDIT | |
7580 /* May need to clear the coladd that a mark includes. */ | |
7581 if (!virtual_active()) | |
7582 curwin->w_cursor.coladd = 0; | |
7583 #endif | |
12164
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
7584 check_cursor_col(); |
7 | 7585 #ifdef FEAT_FOLDING |
7586 if (cap->oap->op_type == OP_NOP | |
4057 | 7587 && pos != NULL |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7588 && (pos == (pos_T *)-1 || !EQUAL_POS(old_cursor, *pos)) |
7 | 7589 && (fdo_flags & FDO_MARK) |
7590 && old_KeyTyped) | |
7591 foldOpenCursor(); | |
7592 #endif | |
7593 } | |
7594 | |
7595 /* | |
7596 * Handle CTRL-O, CTRL-I, "g;" and "g," commands. | |
7597 */ | |
7598 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7599 nv_pcmark(cmdarg_T *cap) |
7 | 7600 { |
7601 #ifdef FEAT_JUMPLIST | |
7602 pos_T *pos; | |
7603 # ifdef FEAT_FOLDING | |
7604 linenr_T lnum = curwin->w_cursor.lnum; | |
7605 int old_KeyTyped = KeyTyped; /* getting file may reset it */ | |
7606 # endif | |
7607 | |
7608 if (!checkclearopq(cap->oap)) | |
7609 { | |
7610 if (cap->cmdchar == 'g') | |
7611 pos = movechangelist((int)cap->count1); | |
7612 else | |
7613 pos = movemark((int)cap->count1); | |
7614 if (pos == (pos_T *)-1) /* jump to other file */ | |
7615 { | |
7616 curwin->w_set_curswant = TRUE; | |
7617 check_cursor(); | |
7618 } | |
7619 else if (pos != NULL) /* can jump */ | |
7620 nv_cursormark(cap, FALSE, pos); | |
7621 else if (cap->cmdchar == 'g') | |
7622 { | |
7623 if (curbuf->b_changelistlen == 0) | |
7624 EMSG(_("E664: changelist is empty")); | |
7625 else if (cap->count1 < 0) | |
7626 EMSG(_("E662: At start of changelist")); | |
7627 else | |
7628 EMSG(_("E663: At end of changelist")); | |
7629 } | |
7630 else | |
7631 clearopbeep(cap->oap); | |
7632 # ifdef FEAT_FOLDING | |
7633 if (cap->oap->op_type == OP_NOP | |
7634 && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum) | |
7635 && (fdo_flags & FDO_MARK) | |
7636 && old_KeyTyped) | |
7637 foldOpenCursor(); | |
7638 # endif | |
7639 } | |
7640 #else | |
7641 clearopbeep(cap->oap); | |
7642 #endif | |
7643 } | |
7644 | |
7645 /* | |
7646 * Handle '"' command. | |
7647 */ | |
7648 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7649 nv_regname(cmdarg_T *cap) |
7 | 7650 { |
7651 if (checkclearop(cap->oap)) | |
7652 return; | |
7653 #ifdef FEAT_EVAL | |
7654 if (cap->nchar == '=') | |
7655 cap->nchar = get_expr_register(); | |
7656 #endif | |
7657 if (cap->nchar != NUL && valid_yank_reg(cap->nchar, FALSE)) | |
7658 { | |
7659 cap->oap->regname = cap->nchar; | |
7660 cap->opcount = cap->count0; /* remember count before '"' */ | |
7661 #ifdef FEAT_EVAL | |
7662 set_reg_var(cap->oap->regname); | |
7663 #endif | |
7664 } | |
7665 else | |
7666 clearopbeep(cap->oap); | |
7667 } | |
7668 | |
7669 /* | |
7670 * Handle "v", "V" and "CTRL-V" commands. | |
7671 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg | |
7672 * is TRUE. | |
167 | 7673 * Handle CTRL-Q just like CTRL-V. |
7 | 7674 */ |
7675 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7676 nv_visual(cmdarg_T *cap) |
7 | 7677 { |
167 | 7678 if (cap->cmdchar == Ctrl_Q) |
7679 cap->cmdchar = Ctrl_V; | |
7680 | |
7 | 7681 /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it |
7682 * characterwise, linewise, or blockwise. */ | |
7683 if (cap->oap->op_type != OP_NOP) | |
7684 { | |
7685 cap->oap->motion_force = cap->cmdchar; | |
7686 finish_op = FALSE; /* operator doesn't finish now but later */ | |
7687 return; | |
7688 } | |
7689 | |
7690 VIsual_select = cap->arg; | |
7691 if (VIsual_active) /* change Visual mode */ | |
7692 { | |
7693 if (VIsual_mode == cap->cmdchar) /* stop visual mode */ | |
7694 end_visual_mode(); | |
7695 else /* toggle char/block mode */ | |
7696 { /* or char/line mode */ | |
7697 VIsual_mode = cap->cmdchar; | |
7698 showmode(); | |
7699 } | |
7700 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
7701 } | |
7702 else /* start Visual mode */ | |
7703 { | |
7704 check_visual_highlight(); | |
3537 | 7705 if (cap->count0 > 0 && resel_VIsual_mode != NUL) |
7706 { | |
7707 /* use previously selected part */ | |
7 | 7708 VIsual = curwin->w_cursor; |
7709 | |
7710 VIsual_active = TRUE; | |
7711 VIsual_reselect = TRUE; | |
7712 if (!cap->arg) | |
7713 /* start Select mode when 'selectmode' contains "cmd" */ | |
7714 may_start_select('c'); | |
7715 #ifdef FEAT_MOUSE | |
7716 setmouse(); | |
7717 #endif | |
641 | 7718 if (p_smd && msg_silent == 0) |
7 | 7719 redraw_cmdline = TRUE; /* show visual mode later */ |
7720 /* | |
7721 * For V and ^V, we multiply the number of lines even if there | |
7722 * was only one -- webb | |
7723 */ | |
7724 if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) | |
7725 { | |
7726 curwin->w_cursor.lnum += | |
7727 resel_VIsual_line_count * cap->count0 - 1; | |
7728 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
7729 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7730 } | |
7731 VIsual_mode = resel_VIsual_mode; | |
7732 if (VIsual_mode == 'v') | |
7733 { | |
7734 if (resel_VIsual_line_count <= 1) | |
3125 | 7735 { |
7736 validate_virtcol(); | |
7737 curwin->w_curswant = curwin->w_virtcol | |
7738 + resel_VIsual_vcol * cap->count0 - 1; | |
7739 } | |
7 | 7740 else |
3125 | 7741 curwin->w_curswant = resel_VIsual_vcol; |
7742 coladvance(curwin->w_curswant); | |
7 | 7743 } |
3125 | 7744 if (resel_VIsual_vcol == MAXCOL) |
7 | 7745 { |
7746 curwin->w_curswant = MAXCOL; | |
7747 coladvance((colnr_T)MAXCOL); | |
7748 } | |
7749 else if (VIsual_mode == Ctrl_V) | |
7750 { | |
7751 validate_virtcol(); | |
7752 curwin->w_curswant = curwin->w_virtcol | |
3125 | 7753 + resel_VIsual_vcol * cap->count0 - 1; |
7 | 7754 coladvance(curwin->w_curswant); |
7755 } | |
7756 else | |
7757 curwin->w_set_curswant = TRUE; | |
7758 redraw_curbuf_later(INVERTED); /* show the inversion */ | |
7759 } | |
7760 else | |
7761 { | |
7762 if (!cap->arg) | |
7763 /* start Select mode when 'selectmode' contains "cmd" */ | |
7764 may_start_select('c'); | |
7765 n_start_visual_mode(cap->cmdchar); | |
3537 | 7766 if (VIsual_mode != 'V' && *p_sel == 'e') |
7767 ++cap->count1; /* include one more char */ | |
7768 if (cap->count0 > 0 && --cap->count1 > 0) | |
7769 { | |
7770 /* With a count select that many characters or lines. */ | |
7771 if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) | |
7772 nv_right(cap); | |
7773 else if (VIsual_mode == 'V') | |
7774 nv_down(cap); | |
7775 } | |
7 | 7776 } |
7777 } | |
7778 } | |
7779 | |
7780 /* | |
7781 * Start selection for Shift-movement keys. | |
7782 */ | |
7783 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7784 start_selection(void) |
7 | 7785 { |
7786 /* if 'selectmode' contains "key", start Select mode */ | |
7787 may_start_select('k'); | |
7788 n_start_visual_mode('v'); | |
7789 } | |
7790 | |
7791 /* | |
7792 * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu. | |
7793 */ | |
7794 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7795 may_start_select(int c) |
7 | 7796 { |
7797 VIsual_select = (stuff_empty() && typebuf_typed() | |
7798 && (vim_strchr(p_slm, c) != NULL)); | |
7799 } | |
7800 | |
7801 /* | |
7802 * Start Visual mode "c". | |
7803 * Should set VIsual_select before calling this. | |
7804 */ | |
7805 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7806 n_start_visual_mode(int c) |
7 | 7807 { |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7808 #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
|
7809 /* Check for redraw before changing the state. */ |
2428
33148c37f3c9
Changes for VMS. Mostly by Zoltan Arpadffy.
Bram Moolenaar <bram@vim.org>
parents:
2416
diff
changeset
|
7810 conceal_check_cursur_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
|
7811 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7812 |
7 | 7813 VIsual_mode = c; |
7814 VIsual_active = TRUE; | |
7815 VIsual_reselect = TRUE; | |
7816 #ifdef FEAT_VIRTUALEDIT | |
7817 /* Corner case: the 0 position in a tab may change when going into | |
7818 * virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting. | |
7819 */ | |
7820 if (c == Ctrl_V && (ve_flags & VE_BLOCK) && gchar_cursor() == TAB) | |
3742 | 7821 { |
7822 validate_virtcol(); | |
7 | 7823 coladvance(curwin->w_virtcol); |
3742 | 7824 } |
7 | 7825 #endif |
7826 VIsual = curwin->w_cursor; | |
7827 | |
7828 #ifdef FEAT_FOLDING | |
7829 foldAdjustVisual(); | |
7830 #endif | |
7831 | |
7832 #ifdef FEAT_MOUSE | |
7833 setmouse(); | |
7834 #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
|
7835 #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
|
7836 /* Check for redraw after changing the state. */ |
2428
33148c37f3c9
Changes for VMS. Mostly by Zoltan Arpadffy.
Bram Moolenaar <bram@vim.org>
parents:
2416
diff
changeset
|
7837 conceal_check_cursur_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
|
7838 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7839 |
641 | 7840 if (p_smd && msg_silent == 0) |
7 | 7841 redraw_cmdline = TRUE; /* show visual mode later */ |
7842 #ifdef FEAT_CLIPBOARD | |
7843 /* Make sure the clipboard gets updated. Needed because start and | |
7844 * end may still be the same, and the selection needs to be owned */ | |
7845 clip_star.vmode = NUL; | |
7846 #endif | |
7847 | |
7848 /* Only need to redraw this line, unless still need to redraw an old | |
7849 * Visual area (when 'lazyredraw' is set). */ | |
7850 if (curwin->w_redr_type < INVERTED) | |
7851 { | |
7852 curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
7853 curwin->w_old_visual_lnum = curwin->w_cursor.lnum; | |
7854 } | |
7855 } | |
7856 | |
7857 | |
7858 /* | |
7859 * CTRL-W: Window commands | |
7860 */ | |
7861 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7862 nv_window(cmdarg_T *cap) |
7 | 7863 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7864 if (cap->nchar == ':') |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7865 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7866 /* "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
|
7867 cap->cmdchar = ':'; |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7868 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
|
7869 nv_colon(cap); |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7870 } |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7871 else if (!checkclearop(cap->oap)) |
7 | 7872 do_window(cap->nchar, cap->count0, NUL); /* everything is in window.c */ |
7873 } | |
7874 | |
7875 /* | |
7876 * CTRL-Z: Suspend | |
7877 */ | |
7878 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7879 nv_suspend(cmdarg_T *cap) |
7 | 7880 { |
7881 clearop(cap->oap); | |
7882 if (VIsual_active) | |
7883 end_visual_mode(); /* stop Visual mode */ | |
7884 do_cmdline_cmd((char_u *)"st"); | |
7885 } | |
7886 | |
7887 /* | |
7888 * Commands starting with "g". | |
7889 */ | |
7890 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7891 nv_g_cmd(cmdarg_T *cap) |
7 | 7892 { |
7893 oparg_T *oap = cap->oap; | |
7894 pos_T tpos; | |
7895 int i; | |
7896 int flag = FALSE; | |
7897 | |
7898 switch (cap->nchar) | |
7899 { | |
6868 | 7900 case Ctrl_A: |
7901 case Ctrl_X: | |
7 | 7902 #ifdef MEM_PROFILE |
7903 /* | |
7904 * "g^A": dump log of used memory. | |
7905 */ | |
6868 | 7906 if (!VIsual_active && cap->nchar == Ctrl_A) |
7907 vim_mem_profile_dump(); | |
7908 else | |
7909 #endif | |
7910 /* | |
7911 * "g^A/g^X": sequentially increment visually selected region | |
7912 */ | |
7913 if (VIsual_active) | |
7914 { | |
7915 cap->arg = TRUE; | |
7916 cap->cmdchar = cap->nchar; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
7917 cap->nchar = NUL; |
6868 | 7918 nv_addsub(cap); |
7919 } | |
7920 else | |
7921 clearopbeep(oap); | |
7 | 7922 break; |
7923 | |
7924 #ifdef FEAT_VREPLACE | |
7925 /* | |
7926 * "gR": Enter virtual replace mode. | |
7927 */ | |
7928 case 'R': | |
7929 cap->arg = TRUE; | |
7930 nv_Replace(cap); | |
7931 break; | |
7932 | |
7933 case 'r': | |
7934 nv_vreplace(cap); | |
7935 break; | |
7936 #endif | |
7937 | |
7938 case '&': | |
7939 do_cmdline_cmd((char_u *)"%s//~/&"); | |
7940 break; | |
7941 | |
7942 /* | |
7943 * "gv": Reselect the previous Visual area. If Visual already active, | |
7944 * exchange previous and current Visual area. | |
7945 */ | |
7946 case 'v': | |
7947 if (checkclearop(oap)) | |
7948 break; | |
7949 | |
690 | 7950 if ( curbuf->b_visual.vi_start.lnum == 0 |
7951 || curbuf->b_visual.vi_start.lnum > curbuf->b_ml.ml_line_count | |
7952 || curbuf->b_visual.vi_end.lnum == 0) | |
7 | 7953 beep_flush(); |
7954 else | |
7955 { | |
7956 /* set w_cursor to the start of the Visual area, tpos to the end */ | |
7957 if (VIsual_active) | |
7958 { | |
7959 i = VIsual_mode; | |
690 | 7960 VIsual_mode = curbuf->b_visual.vi_mode; |
7961 curbuf->b_visual.vi_mode = i; | |
7 | 7962 # ifdef FEAT_EVAL |
7963 curbuf->b_visual_mode_eval = i; | |
7964 # endif | |
7965 i = curwin->w_curswant; | |
690 | 7966 curwin->w_curswant = curbuf->b_visual.vi_curswant; |
7967 curbuf->b_visual.vi_curswant = i; | |
7968 | |
7969 tpos = curbuf->b_visual.vi_end; | |
7970 curbuf->b_visual.vi_end = curwin->w_cursor; | |
7971 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7972 curbuf->b_visual.vi_start = VIsual; | |
7 | 7973 } |
7974 else | |
7975 { | |
690 | 7976 VIsual_mode = curbuf->b_visual.vi_mode; |
7977 curwin->w_curswant = curbuf->b_visual.vi_curswant; | |
7978 tpos = curbuf->b_visual.vi_end; | |
7979 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7 | 7980 } |
7981 | |
7982 VIsual_active = TRUE; | |
7983 VIsual_reselect = TRUE; | |
7984 | |
7985 /* Set Visual to the start and w_cursor to the end of the Visual | |
7986 * area. Make sure they are on an existing character. */ | |
7987 check_cursor(); | |
7988 VIsual = curwin->w_cursor; | |
7989 curwin->w_cursor = tpos; | |
7990 check_cursor(); | |
7991 update_topline(); | |
7992 /* | |
7993 * When called from normal "g" command: start Select mode when | |
7994 * 'selectmode' contains "cmd". When called for K_SELECT, always | |
7995 * start Select mode. | |
7996 */ | |
7997 if (cap->arg) | |
7998 VIsual_select = TRUE; | |
7999 else | |
8000 may_start_select('c'); | |
8001 #ifdef FEAT_MOUSE | |
8002 setmouse(); | |
8003 #endif | |
8004 #ifdef FEAT_CLIPBOARD | |
8005 /* Make sure the clipboard gets updated. Needed because start and | |
8006 * end are still the same, and the selection needs to be owned */ | |
8007 clip_star.vmode = NUL; | |
8008 #endif | |
8009 redraw_curbuf_later(INVERTED); | |
8010 showmode(); | |
8011 } | |
8012 break; | |
8013 /* | |
8014 * "gV": Don't reselect the previous Visual area after a Select mode | |
8015 * mapping of menu. | |
8016 */ | |
8017 case 'V': | |
8018 VIsual_reselect = FALSE; | |
8019 break; | |
8020 | |
8021 /* | |
8022 * "gh": start Select mode. | |
8023 * "gH": start Select line mode. | |
8024 * "g^H": start Select block mode. | |
8025 */ | |
8026 case K_BS: | |
8027 cap->nchar = Ctrl_H; | |
8028 /* FALLTHROUGH */ | |
8029 case 'h': | |
8030 case 'H': | |
8031 case Ctrl_H: | |
8032 # ifdef EBCDIC | |
8033 /* EBCDIC: 'v'-'h' != '^v'-'^h' */ | |
8034 if (cap->nchar == Ctrl_H) | |
8035 cap->cmdchar = Ctrl_V; | |
8036 else | |
8037 # endif | |
8038 cap->cmdchar = cap->nchar + ('v' - 'h'); | |
8039 cap->arg = TRUE; | |
8040 nv_visual(cap); | |
8041 break; | |
3701 | 8042 |
8043 /* "gn", "gN" visually select next/previous search match | |
8044 * "gn" selects next match | |
8045 * "gN" selects previous match | |
8046 */ | |
8047 case 'N': | |
8048 case 'n': | |
8049 if (!current_search(cap->count1, cap->nchar == 'n')) | |
3896 | 8050 clearopbeep(oap); |
3701 | 8051 break; |
7 | 8052 |
8053 /* | |
8054 * "gj" and "gk" two new funny movement keys -- up and down | |
8055 * movement based on *screen* line rather than *file* line. | |
8056 */ | |
8057 case 'j': | |
8058 case K_DOWN: | |
8059 /* with 'nowrap' it works just like the normal "j" command; also when | |
8060 * in a closed fold */ | |
8061 if (!curwin->w_p_wrap | |
8062 #ifdef FEAT_FOLDING | |
8063 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
8064 #endif | |
8065 ) | |
8066 { | |
8067 oap->motion_type = MLINE; | |
8068 i = cursor_down(cap->count1, oap->op_type == OP_NOP); | |
8069 } | |
8070 else | |
8071 i = nv_screengo(oap, FORWARD, cap->count1); | |
8072 if (i == FAIL) | |
8073 clearopbeep(oap); | |
8074 break; | |
8075 | |
8076 case 'k': | |
8077 case K_UP: | |
8078 /* with 'nowrap' it works just like the normal "k" command; also when | |
8079 * in a closed fold */ | |
8080 if (!curwin->w_p_wrap | |
8081 #ifdef FEAT_FOLDING | |
8082 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
8083 #endif | |
8084 ) | |
8085 { | |
8086 oap->motion_type = MLINE; | |
8087 i = cursor_up(cap->count1, oap->op_type == OP_NOP); | |
8088 } | |
8089 else | |
8090 i = nv_screengo(oap, BACKWARD, cap->count1); | |
8091 if (i == FAIL) | |
8092 clearopbeep(oap); | |
8093 break; | |
8094 | |
8095 /* | |
8096 * "gJ": join two lines without inserting a space. | |
8097 */ | |
8098 case 'J': | |
8099 nv_join(cap); | |
8100 break; | |
8101 | |
8102 /* | |
8103 * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines. | |
8104 * "gm": middle of "g0" and "g$". | |
8105 */ | |
8106 case '^': | |
8107 flag = TRUE; | |
8108 /* FALLTHROUGH */ | |
8109 | |
8110 case '0': | |
8111 case 'm': | |
8112 case K_HOME: | |
8113 case K_KHOME: | |
8114 oap->motion_type = MCHAR; | |
8115 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
|
8116 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 8117 { |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8118 int width1 = curwin->w_width - curwin_col_off(); |
7 | 8119 int width2 = width1 + curwin_col_off2(); |
8120 | |
8121 validate_virtcol(); | |
8122 i = 0; | |
8123 if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0) | |
8124 i = (curwin->w_virtcol - width1) / width2 * width2 + width1; | |
8125 } | |
8126 else | |
8127 i = curwin->w_leftcol; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2139
diff
changeset
|
8128 /* 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
|
8129 * '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
|
8130 * to the left. */ |
7 | 8131 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
|
8132 i += (curwin->w_width - curwin_col_off() |
7 | 8133 + ((curwin->w_p_wrap && i > 0) |
8134 ? curwin_col_off2() : 0)) / 2; | |
8135 coladvance((colnr_T)i); | |
8136 if (flag) | |
8137 { | |
8138 do | |
8139 i = gchar_cursor(); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
8140 while (VIM_ISWHITE(i) && oneright() == OK); |
7 | 8141 } |
8142 curwin->w_set_curswant = TRUE; | |
8143 break; | |
8144 | |
8145 case '_': | |
8146 /* "g_": to the last non-blank character in the line or <count> lines | |
8147 * downward. */ | |
8148 cap->oap->motion_type = MCHAR; | |
8149 cap->oap->inclusive = TRUE; | |
8150 curwin->w_curswant = MAXCOL; | |
8151 if (cursor_down((long)(cap->count1 - 1), | |
8152 cap->oap->op_type == OP_NOP) == FAIL) | |
8153 clearopbeep(cap->oap); | |
8154 else | |
8155 { | |
8156 char_u *ptr = ml_get_curline(); | |
8157 | |
8158 /* In Visual mode we may end up after the line. */ | |
8159 if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) | |
8160 --curwin->w_cursor.col; | |
8161 | |
8162 /* Decrease the cursor column until it's on a non-blank. */ | |
8163 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
|
8164 && VIM_ISWHITE(ptr[curwin->w_cursor.col])) |
7 | 8165 --curwin->w_cursor.col; |
8166 curwin->w_set_curswant = TRUE; | |
2040
70c67b1bb1f1
updated for version 7.2.329
Bram Moolenaar <bram@zimbu.org>
parents:
2024
diff
changeset
|
8167 adjust_for_sel(cap); |
7 | 8168 } |
8169 break; | |
8170 | |
8171 case '$': | |
8172 case K_END: | |
8173 case K_KEND: | |
8174 { | |
8175 int col_off = curwin_col_off(); | |
8176 | |
8177 oap->motion_type = MCHAR; | |
8178 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
|
8179 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 8180 { |
8181 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
8182 if (cap->count1 == 1) | |
8183 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8184 int width1 = curwin->w_width - col_off; |
7 | 8185 int width2 = width1 + curwin_col_off2(); |
8186 | |
8187 validate_virtcol(); | |
8188 i = width1 - 1; | |
8189 if (curwin->w_virtcol >= (colnr_T)width1) | |
8190 i += ((curwin->w_virtcol - width1) / width2 + 1) | |
8191 * width2; | |
8192 coladvance((colnr_T)i); | |
5162
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8193 |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8194 /* Make sure we stick in this column. */ |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8195 validate_virtcol(); |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8196 curwin->w_curswant = curwin->w_virtcol; |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8197 curwin->w_set_curswant = FALSE; |
7 | 8198 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE) |
8199 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
8200 { | |
8201 /* | |
8202 * Check for landing on a character that got split at | |
8203 * the end of the line. We do not want to advance to | |
8204 * the next screen line. | |
8205 */ | |
8206 if (curwin->w_virtcol > (colnr_T)i) | |
8207 --curwin->w_cursor.col; | |
8208 } | |
8209 #endif | |
8210 } | |
8211 else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == FAIL) | |
8212 clearopbeep(oap); | |
8213 } | |
8214 else | |
8215 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8216 i = curwin->w_leftcol + curwin->w_width - col_off - 1; |
7 | 8217 coladvance((colnr_T)i); |
40 | 8218 |
8219 /* Make sure we stick in this column. */ | |
8220 validate_virtcol(); | |
8221 curwin->w_curswant = curwin->w_virtcol; | |
8222 curwin->w_set_curswant = FALSE; | |
7 | 8223 } |
8224 } | |
8225 break; | |
8226 | |
8227 /* | |
8228 * "g*" and "g#", like "*" and "#" but without using "\<" and "\>" | |
8229 */ | |
8230 case '*': | |
8231 case '#': | |
8232 #if POUND != '#' | |
8233 case POUND: /* pound sign (sometimes equal to '#') */ | |
8234 #endif | |
8235 case Ctrl_RSB: /* :tag or :tselect for current identifier */ | |
8236 case ']': /* :tselect for current identifier */ | |
8237 nv_ident(cap); | |
8238 break; | |
8239 | |
8240 /* | |
8241 * ge and gE: go back to end of word | |
8242 */ | |
8243 case 'e': | |
8244 case 'E': | |
8245 oap->motion_type = MCHAR; | |
8246 curwin->w_set_curswant = TRUE; | |
8247 oap->inclusive = TRUE; | |
8248 if (bckend_word(cap->count1, cap->nchar == 'E', FALSE) == FAIL) | |
8249 clearopbeep(oap); | |
8250 break; | |
8251 | |
8252 /* | |
8253 * "g CTRL-G": display info about cursor position | |
8254 */ | |
8255 case Ctrl_G: | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7311
diff
changeset
|
8256 cursor_pos_info(NULL); |
7 | 8257 break; |
8258 | |
8259 /* | |
8260 * "gi": start Insert at the last position. | |
8261 */ | |
8262 case 'i': | |
8263 if (curbuf->b_last_insert.lnum != 0) | |
8264 { | |
8265 curwin->w_cursor = curbuf->b_last_insert; | |
8266 check_cursor_lnum(); | |
8267 i = (int)STRLEN(ml_get_curline()); | |
8268 if (curwin->w_cursor.col > (colnr_T)i) | |
8269 { | |
8270 #ifdef FEAT_VIRTUALEDIT | |
8271 if (virtual_active()) | |
8272 curwin->w_cursor.coladd += curwin->w_cursor.col - i; | |
8273 #endif | |
8274 curwin->w_cursor.col = i; | |
8275 } | |
8276 } | |
8277 cap->cmdchar = 'i'; | |
8278 nv_edit(cap); | |
8279 break; | |
8280 | |
8281 /* | |
8282 * "gI": Start insert in column 1. | |
8283 */ | |
8284 case 'I': | |
8285 beginline(0); | |
8286 if (!checkclearopq(oap)) | |
8287 invoke_edit(cap, FALSE, 'g', FALSE); | |
8288 break; | |
8289 | |
8290 #ifdef FEAT_SEARCHPATH | |
8291 /* | |
8292 * "gf": goto file, edit file under cursor | |
8293 * "]f" and "[f": can also be used. | |
8294 */ | |
8295 case 'f': | |
681 | 8296 case 'F': |
7 | 8297 nv_gotofile(cap); |
8298 break; | |
8299 #endif | |
8300 | |
8301 /* "g'm" and "g`m": jump to mark without setting pcmark */ | |
8302 case '\'': | |
8303 cap->arg = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
8304 /* FALLTHROUGH */ |
7 | 8305 case '`': |
8306 nv_gomark(cap); | |
8307 break; | |
8308 | |
8309 /* | |
8310 * "gs": Goto sleep. | |
8311 */ | |
8312 case 's': | |
8313 do_sleep(cap->count1 * 1000L); | |
8314 break; | |
8315 | |
8316 /* | |
8317 * "ga": Display the ascii value of the character under the | |
8318 * cursor. It is displayed in decimal, hex, and octal. -- webb | |
8319 */ | |
8320 case 'a': | |
8321 do_ascii(NULL); | |
8322 break; | |
8323 | |
8324 #ifdef FEAT_MBYTE | |
8325 /* | |
8326 * "g8": Display the bytes used for the UTF-8 character under the | |
8327 * cursor. It is displayed in hex. | |
775 | 8328 * "8g8" finds illegal byte sequence. |
7 | 8329 */ |
8330 case '8': | |
775 | 8331 if (cap->count0 == 8) |
8332 utf_find_illegal(); | |
8333 else | |
8334 show_utf8(); | |
7 | 8335 break; |
8336 #endif | |
8337 | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
8338 /* "g<": show scrollback text */ |
447 | 8339 case '<': |
8340 show_sb_text(); | |
8341 break; | |
8342 | |
7 | 8343 /* |
8344 * "gg": Goto the first line in file. With a count it goes to | |
8345 * that line number like for "G". -- webb | |
8346 */ | |
8347 case 'g': | |
8348 cap->arg = FALSE; | |
8349 nv_goto(cap); | |
8350 break; | |
8351 | |
8352 /* | |
8353 * Two-character operators: | |
8354 * "gq" Format text | |
8355 * "gw" Format text and keep cursor position | |
8356 * "g~" Toggle the case of the text. | |
8357 * "gu" Change text to lower case. | |
8358 * "gU" Change text to upper case. | |
8359 * "g?" rot13 encoding | |
602 | 8360 * "g@" call 'operatorfunc' |
7 | 8361 */ |
8362 case 'q': | |
8363 case 'w': | |
8364 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
|
8365 /* FALLTHROUGH */ |
7 | 8366 case '~': |
8367 case 'u': | |
8368 case 'U': | |
8369 case '?': | |
602 | 8370 case '@': |
7 | 8371 nv_operator(cap); |
8372 break; | |
8373 | |
8374 /* | |
1188 | 8375 * "gd": Find first occurrence of pattern under the cursor in the |
7 | 8376 * current function |
8377 * "gD": idem, but in the current file. | |
8378 */ | |
8379 case 'd': | |
8380 case 'D': | |
523 | 8381 nv_gd(oap, cap->nchar, (int)cap->count0); |
7 | 8382 break; |
8383 | |
8384 #ifdef FEAT_MOUSE | |
8385 /* | |
8386 * g<*Mouse> : <C-*mouse> | |
8387 */ | |
8388 case K_MIDDLEMOUSE: | |
8389 case K_MIDDLEDRAG: | |
8390 case K_MIDDLERELEASE: | |
8391 case K_LEFTMOUSE: | |
8392 case K_LEFTDRAG: | |
8393 case K_LEFTRELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
8394 case K_MOUSEMOVE: |
7 | 8395 case K_RIGHTMOUSE: |
8396 case K_RIGHTDRAG: | |
8397 case K_RIGHTRELEASE: | |
8398 case K_X1MOUSE: | |
8399 case K_X1DRAG: | |
8400 case K_X1RELEASE: | |
8401 case K_X2MOUSE: | |
8402 case K_X2DRAG: | |
8403 case K_X2RELEASE: | |
8404 mod_mask = MOD_MASK_CTRL; | |
8405 (void)do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0); | |
8406 break; | |
8407 #endif | |
8408 | |
8409 case K_IGNORE: | |
8410 break; | |
8411 | |
8412 /* | |
8413 * "gP" and "gp": same as "P" and "p" but leave cursor just after new text | |
8414 */ | |
8415 case 'p': | |
8416 case 'P': | |
8417 nv_put(cap); | |
8418 break; | |
8419 | |
8420 #ifdef FEAT_BYTEOFF | |
8421 /* "go": goto byte count from start of buffer */ | |
8422 case 'o': | |
8423 goto_byte(cap->count0); | |
8424 break; | |
8425 #endif | |
8426 | |
8427 /* "gQ": improved Ex mode */ | |
8428 case 'Q': | |
633 | 8429 if (text_locked()) |
7 | 8430 { |
8431 clearopbeep(cap->oap); | |
633 | 8432 text_locked_msg(); |
7 | 8433 break; |
8434 } | |
631 | 8435 |
7 | 8436 if (!checkclearopq(oap)) |
8437 do_exmode(TRUE); | |
8438 break; | |
8439 | |
8440 #ifdef FEAT_JUMPLIST | |
8441 case ',': | |
8442 nv_pcmark(cap); | |
8443 break; | |
8444 | |
8445 case ';': | |
8446 cap->count1 = -cap->count1; | |
8447 nv_pcmark(cap); | |
8448 break; | |
8449 #endif | |
8450 | |
667 | 8451 case 't': |
3630 | 8452 if (!checkclearop(oap)) |
8453 goto_tabpage((int)cap->count0); | |
667 | 8454 break; |
682 | 8455 case 'T': |
3630 | 8456 if (!checkclearop(oap)) |
8457 goto_tabpage(-(int)cap->count1); | |
682 | 8458 break; |
667 | 8459 |
750 | 8460 case '+': |
8461 case '-': /* "g+" and "g-": undo or redo along the timeline */ | |
8462 if (!checkclearopq(oap)) | |
771 | 8463 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
|
8464 FALSE, FALSE, FALSE); |
750 | 8465 break; |
8466 | |
7 | 8467 default: |
8468 clearopbeep(oap); | |
8469 break; | |
8470 } | |
8471 } | |
8472 | |
8473 /* | |
8474 * Handle "o" and "O" commands. | |
8475 */ | |
8476 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8477 n_opencmd(cmdarg_T *cap) |
7 | 8478 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8479 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8480 linenr_T oldline = curwin->w_cursor.lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8481 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8482 |
7 | 8483 if (!checkclearopq(cap->oap)) |
8484 { | |
8485 #ifdef FEAT_FOLDING | |
8486 if (cap->cmdchar == 'O') | |
8487 /* Open above the first line of a folded sequence of lines */ | |
8488 (void)hasFolding(curwin->w_cursor.lnum, | |
8489 &curwin->w_cursor.lnum, NULL); | |
8490 else | |
8491 /* Open below the last line of a folded sequence of lines */ | |
8492 (void)hasFolding(curwin->w_cursor.lnum, | |
8493 NULL, &curwin->w_cursor.lnum); | |
8494 #endif | |
8495 if (u_save((linenr_T)(curwin->w_cursor.lnum - | |
8496 (cap->cmdchar == 'O' ? 1 : 0)), | |
8497 (linenr_T)(curwin->w_cursor.lnum + | |
8498 (cap->cmdchar == 'o' ? 1 : 0)) | |
8499 ) == OK | |
8500 && open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD, | |
8501 #ifdef FEAT_COMMENTS | |
8502 has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM : | |
8503 #endif | |
8504 0, 0)) | |
8505 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8506 #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
|
8507 if (curwin->w_p_cole > 0 && oldline != curwin->w_cursor.lnum) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8508 update_single_line(curwin, oldline); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8509 #endif |
164 | 8510 /* When '#' is in 'cpoptions' ignore the count. */ |
8511 if (vim_strchr(p_cpo, CPO_HASH) != NULL) | |
8512 cap->count1 = 1; | |
6834 | 8513 #ifdef FEAT_SYN_HL |
6821 | 8514 if (curwin->w_p_cul) |
8515 /* force redraw of cursorline */ | |
8516 curwin->w_valid &= ~VALID_CROW; | |
6834 | 8517 #endif |
7 | 8518 invoke_edit(cap, FALSE, cap->cmdchar, TRUE); |
8519 } | |
8520 } | |
8521 } | |
8522 | |
8523 /* | |
8524 * "." command: redo last change. | |
8525 */ | |
8526 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8527 nv_dot(cmdarg_T *cap) |
7 | 8528 { |
8529 if (!checkclearopq(cap->oap)) | |
8530 { | |
8531 /* | |
8532 * If "restart_edit" is TRUE, the last but one command is repeated | |
8533 * instead of the last command (inserting text). This is used for | |
8534 * CTRL-O <.> in insert mode. | |
8535 */ | |
8536 if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == FAIL) | |
8537 clearopbeep(cap->oap); | |
8538 } | |
8539 } | |
8540 | |
8541 /* | |
8542 * CTRL-R: undo undo | |
8543 */ | |
8544 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8545 nv_redo(cmdarg_T *cap) |
7 | 8546 { |
8547 if (!checkclearopq(cap->oap)) | |
8548 { | |
8549 u_redo((int)cap->count1); | |
8550 curwin->w_set_curswant = TRUE; | |
8551 } | |
8552 } | |
8553 | |
8554 /* | |
8555 * Handle "U" command. | |
8556 */ | |
8557 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8558 nv_Undo(cmdarg_T *cap) |
7 | 8559 { |
8560 /* In Visual mode and typing "gUU" triggers an operator */ | |
5735 | 8561 if (cap->oap->op_type == OP_UPPER || VIsual_active) |
7 | 8562 { |
8563 /* translate "gUU" to "gUgU" */ | |
8564 cap->cmdchar = 'g'; | |
8565 cap->nchar = 'U'; | |
8566 nv_operator(cap); | |
8567 } | |
8568 else if (!checkclearopq(cap->oap)) | |
8569 { | |
8570 u_undoline(); | |
8571 curwin->w_set_curswant = TRUE; | |
8572 } | |
8573 } | |
8574 | |
8575 /* | |
8576 * '~' command: If tilde is not an operator and Visual is off: swap case of a | |
8577 * single character. | |
8578 */ | |
8579 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8580 nv_tilde(cmdarg_T *cap) |
7 | 8581 { |
5735 | 8582 if (!p_to && !VIsual_active && cap->oap->op_type != OP_TILDE) |
7 | 8583 n_swapchar(cap); |
8584 else | |
8585 nv_operator(cap); | |
8586 } | |
8587 | |
8588 /* | |
8589 * Handle an operator command. | |
8590 * The actual work is done by do_pending_operator(). | |
8591 */ | |
8592 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8593 nv_operator(cmdarg_T *cap) |
7 | 8594 { |
8595 int op_type; | |
8596 | |
8597 op_type = get_op_type(cap->cmdchar, cap->nchar); | |
8598 | |
8599 if (op_type == cap->oap->op_type) /* double operator works on lines */ | |
8600 nv_lineop(cap); | |
8601 else if (!checkclearop(cap->oap)) | |
8602 { | |
8603 cap->oap->start = curwin->w_cursor; | |
8604 cap->oap->op_type = op_type; | |
1490 | 8605 #ifdef FEAT_EVAL |
8606 set_op_var(op_type); | |
8607 #endif | |
8608 } | |
8609 } | |
8610 | |
8611 #ifdef FEAT_EVAL | |
8612 /* | |
8613 * Set v:operator to the characters for "optype". | |
8614 */ | |
8615 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8616 set_op_var(int optype) |
1490 | 8617 { |
8618 char_u opchars[3]; | |
8619 | |
8620 if (optype == OP_NOP) | |
8621 set_vim_var_string(VV_OP, NULL, 0); | |
8622 else | |
8623 { | |
8624 opchars[0] = get_op_char(optype); | |
8625 opchars[1] = get_extra_op_char(optype); | |
8626 opchars[2] = NUL; | |
8627 set_vim_var_string(VV_OP, opchars, -1); | |
8628 } | |
8629 } | |
8630 #endif | |
7 | 8631 |
8632 /* | |
8633 * Handle linewise operator "dd", "yy", etc. | |
8634 * | |
8635 * "_" is is a strange motion command that helps make operators more logical. | |
8636 * It is actually implemented, but not documented in the real Vi. This motion | |
8637 * command actually refers to "the current line". Commands like "dd" and "yy" | |
8638 * are really an alternate form of "d_" and "y_". It does accept a count, so | |
8639 * "d3_" works to delete 3 lines. | |
8640 */ | |
8641 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8642 nv_lineop(cmdarg_T *cap) |
7 | 8643 { |
8644 cap->oap->motion_type = MLINE; | |
8645 if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL) | |
8646 clearopbeep(cap->oap); | |
4011 | 8647 else if ( (cap->oap->op_type == OP_DELETE /* only with linewise motions */ |
8648 && cap->oap->motion_force != 'v' | |
8649 && cap->oap->motion_force != Ctrl_V) | |
7 | 8650 || cap->oap->op_type == OP_LSHIFT |
8651 || cap->oap->op_type == OP_RSHIFT) | |
8652 beginline(BL_SOL | BL_FIX); | |
8653 else if (cap->oap->op_type != OP_YANK) /* 'Y' does not move cursor */ | |
8654 beginline(BL_WHITE | BL_FIX); | |
8655 } | |
8656 | |
8657 /* | |
8658 * <Home> command. | |
8659 */ | |
8660 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8661 nv_home(cmdarg_T *cap) |
7 | 8662 { |
180 | 8663 /* CTRL-HOME is like "gg" */ |
8664 if (mod_mask & MOD_MASK_CTRL) | |
8665 nv_goto(cap); | |
8666 else | |
8667 { | |
8668 cap->count0 = 1; | |
8669 nv_pipe(cap); | |
8670 } | |
229 | 8671 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8672 one-character line). */ | |
7 | 8673 } |
8674 | |
8675 /* | |
8676 * "|" command. | |
8677 */ | |
8678 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8679 nv_pipe(cmdarg_T *cap) |
7 | 8680 { |
8681 cap->oap->motion_type = MCHAR; | |
8682 cap->oap->inclusive = FALSE; | |
8683 beginline(0); | |
8684 if (cap->count0 > 0) | |
8685 { | |
8686 coladvance((colnr_T)(cap->count0 - 1)); | |
8687 curwin->w_curswant = (colnr_T)(cap->count0 - 1); | |
8688 } | |
8689 else | |
8690 curwin->w_curswant = 0; | |
8691 /* keep curswant at the column where we wanted to go, not where | |
2667 | 8692 * we ended; differs if line is too short */ |
7 | 8693 curwin->w_set_curswant = FALSE; |
8694 } | |
8695 | |
8696 /* | |
8697 * Handle back-word command "b" and "B". | |
8698 * cap->arg is 1 for "B" | |
8699 */ | |
8700 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8701 nv_bck_word(cmdarg_T *cap) |
7 | 8702 { |
8703 cap->oap->motion_type = MCHAR; | |
8704 cap->oap->inclusive = FALSE; | |
8705 curwin->w_set_curswant = TRUE; | |
8706 if (bck_word(cap->count1, cap->arg, FALSE) == FAIL) | |
8707 clearopbeep(cap->oap); | |
8708 #ifdef FEAT_FOLDING | |
8709 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8710 foldOpenCursor(); | |
8711 #endif | |
8712 } | |
8713 | |
8714 /* | |
8715 * Handle word motion commands "e", "E", "w" and "W". | |
8716 * cap->arg is TRUE for "E" and "W". | |
8717 */ | |
8718 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8719 nv_wordcmd(cmdarg_T *cap) |
7 | 8720 { |
8721 int n; | |
8722 int word_end; | |
8723 int flag = FALSE; | |
1573 | 8724 pos_T startpos = curwin->w_cursor; |
7 | 8725 |
8726 /* | |
8727 * Set inclusive for the "E" and "e" command. | |
8728 */ | |
8729 if (cap->cmdchar == 'e' || cap->cmdchar == 'E') | |
8730 word_end = TRUE; | |
8731 else | |
8732 word_end = FALSE; | |
8733 cap->oap->inclusive = word_end; | |
8734 | |
8735 /* | |
8736 * "cw" and "cW" are a special case. | |
8737 */ | |
8738 if (!word_end && cap->oap->op_type == OP_CHANGE) | |
8739 { | |
8740 n = gchar_cursor(); | |
8741 if (n != NUL) /* not an empty line */ | |
8742 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
8743 if (VIM_ISWHITE(n)) |
7 | 8744 { |
8745 /* | |
8746 * Reproduce a funny Vi behaviour: "cw" on a blank only | |
8747 * changes one character, not all blanks until the start of | |
8748 * the next word. Only do this when the 'w' flag is included | |
8749 * in 'cpoptions'. | |
8750 */ | |
8751 if (cap->count1 == 1 && vim_strchr(p_cpo, CPO_CW) != NULL) | |
8752 { | |
8753 cap->oap->inclusive = TRUE; | |
8754 cap->oap->motion_type = MCHAR; | |
8755 return; | |
8756 } | |
8757 } | |
8758 else | |
8759 { | |
8760 /* | |
8761 * This is a little strange. To match what the real Vi does, | |
8762 * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided | |
8763 * that we are not on a space or a TAB. This seems impolite | |
8764 * at first, but it's really more what we mean when we say | |
8765 * 'cw'. | |
8766 * Another strangeness: When standing on the end of a word | |
4352 | 8767 * "ce" will change until the end of the next word, but "cw" |
7 | 8768 * will change only one character! This is done by setting |
8769 * flag. | |
8770 */ | |
8771 cap->oap->inclusive = TRUE; | |
8772 word_end = TRUE; | |
8773 flag = TRUE; | |
8774 } | |
8775 } | |
8776 } | |
8777 | |
8778 cap->oap->motion_type = MCHAR; | |
8779 curwin->w_set_curswant = TRUE; | |
8780 if (word_end) | |
8781 n = end_word(cap->count1, cap->arg, flag, FALSE); | |
8782 else | |
8783 n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP); | |
8784 | |
1573 | 8785 /* Don't leave the cursor on the NUL past the end of line. Unless we |
8786 * 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
|
8787 if (LT_POS(startpos, curwin->w_cursor)) |
1505 | 8788 adjust_cursor(cap->oap); |
7 | 8789 |
8790 if (n == FAIL && cap->oap->op_type == OP_NOP) | |
8791 clearopbeep(cap->oap); | |
8792 else | |
8793 { | |
8794 adjust_for_sel(cap); | |
8795 #ifdef FEAT_FOLDING | |
8796 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8797 foldOpenCursor(); | |
8798 #endif | |
8799 } | |
8800 } | |
8801 | |
8802 /* | |
1505 | 8803 * Used after a movement command: If the cursor ends up on the NUL after the |
8804 * end of the line, may move it back to the last character and make the motion | |
8805 * inclusive. | |
8806 */ | |
8807 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8808 adjust_cursor(oparg_T *oap) |
1505 | 8809 { |
8810 /* The cursor cannot remain on the NUL when: | |
8811 * - the column is > 0 | |
8812 * - not in Visual mode or 'selection' is "o" | |
8813 * - 'virtualedit' is not "all" and not "onemore". | |
8814 */ | |
8815 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL | |
8816 && (!VIsual_active || *p_sel == 'o') | |
8817 #ifdef FEAT_VIRTUALEDIT | |
8818 && !virtual_active() && (ve_flags & VE_ONEMORE) == 0 | |
8819 #endif | |
8820 ) | |
8821 { | |
8822 --curwin->w_cursor.col; | |
8823 #ifdef FEAT_MBYTE | |
8824 /* prevent cursor from moving on the trail byte */ | |
8825 if (has_mbyte) | |
8826 mb_adjust_cursor(); | |
8827 #endif | |
8828 oap->inclusive = TRUE; | |
8829 } | |
8830 } | |
8831 | |
8832 /* | |
7 | 8833 * "0" and "^" commands. |
8834 * cap->arg is the argument for beginline(). | |
8835 */ | |
8836 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8837 nv_beginline(cmdarg_T *cap) |
7 | 8838 { |
8839 cap->oap->motion_type = MCHAR; | |
8840 cap->oap->inclusive = FALSE; | |
8841 beginline(cap->arg); | |
8842 #ifdef FEAT_FOLDING | |
8843 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8844 foldOpenCursor(); | |
8845 #endif | |
557 | 8846 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8847 one-character line). */ | |
7 | 8848 } |
8849 | |
8850 /* | |
8851 * In exclusive Visual mode, may include the last character. | |
8852 */ | |
8853 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8854 adjust_for_sel(cmdarg_T *cap) |
7 | 8855 { |
8856 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
|
8857 && gchar_cursor() != NUL && LT_POS(VIsual, curwin->w_cursor)) |
7 | 8858 { |
5735 | 8859 #ifdef FEAT_MBYTE |
7 | 8860 if (has_mbyte) |
8861 inc_cursor(); | |
8862 else | |
5735 | 8863 #endif |
7 | 8864 ++curwin->w_cursor.col; |
8865 cap->oap->inclusive = FALSE; | |
8866 } | |
8867 } | |
8868 | |
8869 /* | |
8870 * Exclude last character at end of Visual area for 'selection' == "exclusive". | |
8871 * Should check VIsual_mode before calling this. | |
8872 * Returns TRUE when backed up to the previous line. | |
8873 */ | |
8874 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8875 unadjust_for_sel(void) |
7 | 8876 { |
8877 pos_T *pp; | |
8878 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8879 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
|
8880 { |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8881 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 8882 pp = &curwin->w_cursor; |
8883 else | |
8884 pp = &VIsual; | |
8885 #ifdef FEAT_VIRTUALEDIT | |
8886 if (pp->coladd > 0) | |
8887 --pp->coladd; | |
8888 else | |
8889 #endif | |
8890 if (pp->col > 0) | |
8891 { | |
8892 --pp->col; | |
8893 #ifdef FEAT_MBYTE | |
2933 | 8894 mb_adjustpos(curbuf, pp); |
7 | 8895 #endif |
8896 } | |
8897 else if (pp->lnum > 1) | |
8898 { | |
8899 --pp->lnum; | |
8900 pp->col = (colnr_T)STRLEN(ml_get(pp->lnum)); | |
8901 return TRUE; | |
8902 } | |
8903 } | |
8904 return FALSE; | |
8905 } | |
8906 | |
8907 /* | |
8908 * SELECT key in Normal or Visual mode: end of Select mode mapping. | |
8909 */ | |
8910 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8911 nv_select(cmdarg_T *cap) |
7 | 8912 { |
8913 if (VIsual_active) | |
8914 VIsual_select = TRUE; | |
8915 else if (VIsual_reselect) | |
8916 { | |
8917 cap->nchar = 'v'; /* fake "gv" command */ | |
8918 cap->arg = TRUE; | |
8919 nv_g_cmd(cap); | |
8920 } | |
8921 } | |
8922 | |
8923 | |
8924 /* | |
8925 * "G", "gg", CTRL-END, CTRL-HOME. | |
8926 * cap->arg is TRUE for "G". | |
8927 */ | |
8928 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8929 nv_goto(cmdarg_T *cap) |
7 | 8930 { |
8931 linenr_T lnum; | |
8932 | |
8933 if (cap->arg) | |
8934 lnum = curbuf->b_ml.ml_line_count; | |
8935 else | |
8936 lnum = 1L; | |
8937 cap->oap->motion_type = MLINE; | |
8938 setpcmark(); | |
8939 | |
8940 /* When a count is given, use it instead of the default lnum */ | |
8941 if (cap->count0 != 0) | |
8942 lnum = cap->count0; | |
8943 if (lnum < 1L) | |
8944 lnum = 1L; | |
8945 else if (lnum > curbuf->b_ml.ml_line_count) | |
8946 lnum = curbuf->b_ml.ml_line_count; | |
8947 curwin->w_cursor.lnum = lnum; | |
8948 beginline(BL_SOL | BL_FIX); | |
8949 #ifdef FEAT_FOLDING | |
8950 if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8951 foldOpenCursor(); | |
8952 #endif | |
8953 } | |
8954 | |
8955 /* | |
8956 * CTRL-\ in Normal mode. | |
8957 */ | |
8958 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8959 nv_normal(cmdarg_T *cap) |
7 | 8960 { |
8961 if (cap->nchar == Ctrl_N || cap->nchar == Ctrl_G) | |
8962 { | |
8963 clearop(cap->oap); | |
643 | 8964 if (restart_edit != 0 && mode_displayed) |
7 | 8965 clear_cmdline = TRUE; /* unshow mode later */ |
8966 restart_edit = 0; | |
8967 #ifdef FEAT_CMDWIN | |
8968 if (cmdwin_type != 0) | |
8969 cmdwin_result = Ctrl_C; | |
8970 #endif | |
8971 if (VIsual_active) | |
8972 { | |
8973 end_visual_mode(); /* stop Visual */ | |
8974 redraw_curbuf_later(INVERTED); | |
8975 } | |
8976 /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */ | |
8977 if (cap->nchar == Ctrl_G && p_im) | |
8978 restart_edit = 'a'; | |
8979 } | |
8980 else | |
8981 clearopbeep(cap->oap); | |
8982 } | |
8983 | |
8984 /* | |
8985 * ESC in Normal mode: beep, but don't flush buffers. | |
8986 * Don't even beep if we are canceling a command. | |
8987 */ | |
8988 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8989 nv_esc(cmdarg_T *cap) |
7 | 8990 { |
8991 int no_reason; | |
8992 | |
8993 no_reason = (cap->oap->op_type == OP_NOP | |
8994 && cap->opcount == 0 | |
8995 && cap->count0 == 0 | |
8996 && cap->oap->regname == 0 | |
8997 && !p_im); | |
8998 | |
8999 if (cap->arg) /* TRUE for CTRL-C */ | |
9000 { | |
9001 if (restart_edit == 0 | |
9002 #ifdef FEAT_CMDWIN | |
9003 && cmdwin_type == 0 | |
9004 #endif | |
9005 && !VIsual_active | |
9006 && no_reason) | |
11451
be76f4eca0d7
patch 8.0.0609: some people still don't know how to quit
Christian Brabandt <cb@256bit.org>
parents:
11436
diff
changeset
|
9007 MSG(_("Type :qa! and press <Enter> to abandon all changes and exit Vim")); |
7 | 9008 |
9009 /* Don't reset "restart_edit" when 'insertmode' is set, it won't be | |
9010 * set again below when halfway a mapping. */ | |
9011 if (!p_im) | |
9012 restart_edit = 0; | |
9013 #ifdef FEAT_CMDWIN | |
9014 if (cmdwin_type != 0) | |
9015 { | |
9016 cmdwin_result = K_IGNORE; | |
9017 got_int = FALSE; /* don't stop executing autocommands et al. */ | |
9018 return; | |
9019 } | |
9020 #endif | |
9021 } | |
9022 | |
9023 if (VIsual_active) | |
9024 { | |
9025 end_visual_mode(); /* stop Visual */ | |
9026 check_cursor_col(); /* make sure cursor is not beyond EOL */ | |
9027 curwin->w_set_curswant = TRUE; | |
9028 redraw_curbuf_later(INVERTED); | |
9029 } | |
5735 | 9030 else if (no_reason) |
6949 | 9031 vim_beep(BO_ESC); |
7 | 9032 clearop(cap->oap); |
9033 | |
9034 /* A CTRL-C is often used at the start of a menu. When 'insertmode' is | |
9035 * 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
|
9036 if (restart_edit == 0 && goto_im() && ex_normal_busy == 0) |
7 | 9037 restart_edit = 'a'; |
9038 } | |
9039 | |
9040 /* | |
9041 * 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
|
9042 * Also handle K_PS, start bracketed paste. |
7 | 9043 */ |
9044 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9045 nv_edit(cmdarg_T *cap) |
7 | 9046 { |
9047 /* <Insert> is equal to "i" */ | |
9048 if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) | |
9049 cap->cmdchar = 'i'; | |
9050 | |
9051 /* in Visual mode "A" and "I" are an operator */ | |
9052 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
|
9053 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9054 #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
|
9055 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
|
9056 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9057 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
|
9058 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
|
9059 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
|
9060 return; |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9061 } |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9062 #endif |
7 | 9063 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
|
9064 } |
7 | 9065 |
9066 /* in Visual mode and after an operator "a" and "i" are for text objects */ | |
5735 | 9067 else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') |
9068 && (cap->oap->op_type != OP_NOP || VIsual_active)) | |
7 | 9069 { |
9070 #ifdef FEAT_TEXTOBJ | |
9071 nv_object(cap); | |
9072 #else | |
9073 clearopbeep(cap->oap); | |
9074 #endif | |
9075 } | |
11892
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9076 #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
|
9077 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
|
9078 { |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9079 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
|
9080 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
|
9081 return; |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9082 } |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9083 #endif |
7 | 9084 else if (!curbuf->b_p_ma && !p_im) |
9085 { | |
9086 /* Only give this error when 'insertmode' is off. */ | |
9087 EMSG(_(e_modifiable)); | |
9088 clearop(cap->oap); | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9089 if (cap->cmdchar == K_PS) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9090 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9091 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 9092 } |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9093 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
|
9094 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9095 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
|
9096 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
|
9097 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9098 /* 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
|
9099 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
|
9100 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9101 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
|
9102 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
|
9103 } |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9104 else |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9105 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
|
9106 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
|
9107 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
|
9108 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
|
9109 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
|
9110 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
|
9111 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9112 /* 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
|
9113 * 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
|
9114 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
|
9115 && 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
|
9116 inc_cursor(); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9117 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9118 /* 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
|
9119 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
|
9120 } |
7 | 9121 else if (!checkclearopq(cap->oap)) |
9122 { | |
9123 switch (cap->cmdchar) | |
9124 { | |
9125 case 'A': /* "A"ppend after the line */ | |
9126 curwin->w_set_curswant = TRUE; | |
9127 #ifdef FEAT_VIRTUALEDIT | |
9128 if (ve_flags == VE_ALL) | |
9129 { | |
9130 int save_State = State; | |
9131 | |
4352 | 9132 /* Pretend Insert mode here to allow the cursor on the |
7 | 9133 * character past the end of the line */ |
9134 State = INSERT; | |
9135 coladvance((colnr_T)MAXCOL); | |
9136 State = save_State; | |
9137 } | |
9138 else | |
9139 #endif | |
9140 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor()); | |
9141 break; | |
9142 | |
9143 case 'I': /* "I"nsert before the first non-blank */ | |
164 | 9144 if (vim_strchr(p_cpo, CPO_INSEND) == NULL) |
9145 beginline(BL_WHITE); | |
9146 else | |
9147 beginline(BL_WHITE|BL_FIX); | |
7 | 9148 break; |
9149 | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9150 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
|
9151 /* 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
|
9152 * 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
|
9153 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
|
9154 break; |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
9155 /* FALLTHROUGH */ |
10813
09eb5fd275e0
patch 8.0.0296: bracketed paste can only append, not insert
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
9156 |
7 | 9157 case 'a': /* "a"ppend is like "i"nsert on the next character. */ |
9158 #ifdef FEAT_VIRTUALEDIT | |
9159 /* increment coladd when in virtual space, increment the | |
9160 * column otherwise, also to append after an unprintable char */ | |
9161 if (virtual_active() | |
9162 && (curwin->w_cursor.coladd > 0 | |
9163 || *ml_get_cursor() == NUL | |
9164 || *ml_get_cursor() == TAB)) | |
9165 curwin->w_cursor.coladd++; | |
9166 else | |
9167 #endif | |
9168 if (*ml_get_cursor() != NUL) | |
9169 inc_cursor(); | |
9170 break; | |
9171 } | |
9172 | |
9173 #ifdef FEAT_VIRTUALEDIT | |
9174 if (curwin->w_cursor.coladd && cap->cmdchar != 'A') | |
9175 { | |
9176 int save_State = State; | |
9177 | |
4352 | 9178 /* Pretend Insert mode here to allow the cursor on the |
7 | 9179 * character past the end of the line */ |
9180 State = INSERT; | |
9181 coladvance(getviscol()); | |
9182 State = save_State; | |
9183 } | |
9184 #endif | |
9185 | |
9186 invoke_edit(cap, FALSE, cap->cmdchar, FALSE); | |
9187 } | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9188 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
|
9189 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9190 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 9191 } |
9192 | |
9193 /* | |
9194 * Invoke edit() and take care of "restart_edit" and the return value. | |
9195 */ | |
9196 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9197 invoke_edit( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9198 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9199 int repl, /* "r" or "gr" command */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9200 int cmd, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9201 int startln) |
7 | 9202 { |
9203 int restart_edit_save = 0; | |
9204 | |
9205 /* Complicated: When the user types "a<C-O>a" we don't want to do Insert | |
9206 * mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow | |
9207 * it. */ | |
9208 if (repl || !stuff_empty()) | |
9209 restart_edit_save = restart_edit; | |
9210 else | |
9211 restart_edit_save = 0; | |
9212 | |
9213 /* Always reset "restart_edit", this is not a restarted edit. */ | |
9214 restart_edit = 0; | |
9215 | |
9216 if (edit(cmd, startln, cap->count1)) | |
9217 cap->retval |= CA_COMMAND_BUSY; | |
9218 | |
9219 if (restart_edit == 0) | |
9220 restart_edit = restart_edit_save; | |
9221 } | |
9222 | |
9223 #ifdef FEAT_TEXTOBJ | |
9224 /* | |
9225 * "a" or "i" while an operator is pending or in Visual mode: object motion. | |
9226 */ | |
9227 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9228 nv_object( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9229 cmdarg_T *cap) |
7 | 9230 { |
9231 int flag; | |
9232 int include; | |
9233 char_u *mps_save; | |
9234 | |
9235 if (cap->cmdchar == 'i') | |
9236 include = FALSE; /* "ix" = inner object: exclude white space */ | |
9237 else | |
9238 include = TRUE; /* "ax" = an object: include white space */ | |
9239 | |
9240 /* Make sure (), [], {} and <> are in 'matchpairs' */ | |
9241 mps_save = curbuf->b_p_mps; | |
9242 curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>"; | |
9243 | |
9244 switch (cap->nchar) | |
9245 { | |
9246 case 'w': /* "aw" = a word */ | |
9247 flag = current_word(cap->oap, cap->count1, include, FALSE); | |
9248 break; | |
9249 case 'W': /* "aW" = a WORD */ | |
9250 flag = current_word(cap->oap, cap->count1, include, TRUE); | |
9251 break; | |
9252 case 'b': /* "ab" = a braces block */ | |
9253 case '(': | |
9254 case ')': | |
9255 flag = current_block(cap->oap, cap->count1, include, '(', ')'); | |
9256 break; | |
9257 case 'B': /* "aB" = a Brackets block */ | |
9258 case '{': | |
9259 case '}': | |
9260 flag = current_block(cap->oap, cap->count1, include, '{', '}'); | |
9261 break; | |
9262 case '[': /* "a[" = a [] block */ | |
9263 case ']': | |
9264 flag = current_block(cap->oap, cap->count1, include, '[', ']'); | |
9265 break; | |
9266 case '<': /* "a<" = a <> block */ | |
9267 case '>': | |
9268 flag = current_block(cap->oap, cap->count1, include, '<', '>'); | |
9269 break; | |
420 | 9270 case 't': /* "at" = a tag block (xml and html) */ |
6661 | 9271 /* Do not adjust oap->end in do_pending_operator() |
9272 * otherwise there are different results for 'dit' | |
9273 * (note leading whitespace in last line): | |
9274 * 1) <b> 2) <b> | |
9275 * foobar foobar | |
9276 * </b> </b> | |
9277 */ | |
9278 cap->retval |= CA_NO_ADJ_OP_END; | |
420 | 9279 flag = current_tagblock(cap->oap, cap->count1, include); |
9280 break; | |
7 | 9281 case 'p': /* "ap" = a paragraph */ |
9282 flag = current_par(cap->oap, cap->count1, include, 'p'); | |
9283 break; | |
9284 case 's': /* "as" = a sentence */ | |
9285 flag = current_sent(cap->oap, cap->count1, include); | |
9286 break; | |
12 | 9287 case '"': /* "a"" = a double quoted string */ |
9288 case '\'': /* "a'" = a single quoted string */ | |
9289 case '`': /* "a`" = a backtick quoted string */ | |
9290 flag = current_quote(cap->oap, cap->count1, include, | |
9291 cap->nchar); | |
9292 break; | |
7 | 9293 #if 0 /* TODO */ |
9294 case 'S': /* "aS" = a section */ | |
9295 case 'f': /* "af" = a filename */ | |
9296 case 'u': /* "au" = a URL */ | |
9297 #endif | |
9298 default: | |
9299 flag = FAIL; | |
9300 break; | |
9301 } | |
9302 | |
9303 curbuf->b_p_mps = mps_save; | |
9304 if (flag == FAIL) | |
9305 clearopbeep(cap->oap); | |
9306 adjust_cursor_col(); | |
9307 curwin->w_set_curswant = TRUE; | |
9308 } | |
9309 #endif | |
9310 | |
9311 /* | |
9312 * "q" command: Start/stop recording. | |
9313 * "q:", "q/", "q?": edit command-line in command-line window. | |
9314 */ | |
9315 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9316 nv_record(cmdarg_T *cap) |
7 | 9317 { |
9318 if (cap->oap->op_type == OP_FORMAT) | |
9319 { | |
9320 /* "gqq" is the same as "gqgq": format line */ | |
9321 cap->cmdchar = 'g'; | |
9322 cap->nchar = 'q'; | |
9323 nv_operator(cap); | |
9324 } | |
9325 else if (!checkclearop(cap->oap)) | |
9326 { | |
9327 #ifdef FEAT_CMDWIN | |
9328 if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?') | |
9329 { | |
9330 stuffcharReadbuff(cap->nchar); | |
9331 stuffcharReadbuff(K_CMDWIN); | |
9332 } | |
9333 else | |
9334 #endif | |
9335 /* (stop) recording into a named register, unless executing a | |
9336 * register */ | |
9337 if (!Exec_reg && do_record(cap->nchar) == FAIL) | |
9338 clearopbeep(cap->oap); | |
9339 } | |
9340 } | |
9341 | |
9342 /* | |
9343 * Handle the "@r" command. | |
9344 */ | |
9345 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9346 nv_at(cmdarg_T *cap) |
7 | 9347 { |
9348 if (checkclearop(cap->oap)) | |
9349 return; | |
9350 #ifdef FEAT_EVAL | |
9351 if (cap->nchar == '=') | |
9352 { | |
9353 if (get_expr_register() == NUL) | |
9354 return; | |
9355 } | |
9356 #endif | |
9357 while (cap->count1-- && !got_int) | |
9358 { | |
1034 | 9359 if (do_execreg(cap->nchar, FALSE, FALSE, FALSE) == FAIL) |
7 | 9360 { |
9361 clearopbeep(cap->oap); | |
9362 break; | |
9363 } | |
9364 line_breakcheck(); | |
9365 } | |
9366 } | |
9367 | |
9368 /* | |
9369 * Handle the CTRL-U and CTRL-D commands. | |
9370 */ | |
9371 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9372 nv_halfpage(cmdarg_T *cap) |
7 | 9373 { |
9374 if ((cap->cmdchar == Ctrl_U && curwin->w_cursor.lnum == 1) | |
9375 || (cap->cmdchar == Ctrl_D | |
9376 && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)) | |
9377 clearopbeep(cap->oap); | |
9378 else if (!checkclearop(cap->oap)) | |
9379 halfpage(cap->cmdchar == Ctrl_D, cap->count0); | |
9380 } | |
9381 | |
9382 /* | |
9383 * Handle "J" or "gJ" command. | |
9384 */ | |
9385 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9386 nv_join(cmdarg_T *cap) |
7 | 9387 { |
9388 if (VIsual_active) /* join the visual lines */ | |
9389 nv_operator(cap); | |
5735 | 9390 else if (!checkclearop(cap->oap)) |
7 | 9391 { |
9392 if (cap->count0 <= 1) | |
9393 cap->count0 = 2; /* default for join is two lines! */ | |
9394 if (curwin->w_cursor.lnum + cap->count0 - 1 > | |
9395 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
|
9396 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9397 /* 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
|
9398 if (cap->count0 <= 2) |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9399 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9400 clearopbeep(cap->oap); |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9401 return; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9402 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9403 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
|
9404 - curwin->w_cursor.lnum + 1; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9405 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9406 |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9407 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
|
9408 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
|
9409 (void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE, TRUE); |
7 | 9410 } |
9411 } | |
9412 | |
9413 /* | |
9414 * "P", "gP", "p" and "gp" commands. | |
9415 */ | |
9416 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9417 nv_put(cmdarg_T *cap) |
7 | 9418 { |
9419 int regname = 0; | |
9420 void *reg1 = NULL, *reg2 = NULL; | |
84 | 9421 int empty = FALSE; |
236 | 9422 int was_visual = FALSE; |
7 | 9423 int dir; |
9424 int flags = 0; | |
9425 | |
9426 if (cap->oap->op_type != OP_NOP) | |
9427 { | |
9428 #ifdef FEAT_DIFF | |
9429 /* "dp" is ":diffput" */ | |
9430 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') | |
9431 { | |
9432 clearop(cap->oap); | |
6314 | 9433 nv_diffgetput(TRUE, cap->opcount); |
7 | 9434 } |
9435 else | |
9436 #endif | |
9437 clearopbeep(cap->oap); | |
9438 } | |
9439 else | |
9440 { | |
9441 dir = (cap->cmdchar == 'P' | |
9442 || (cap->cmdchar == 'g' && cap->nchar == 'P')) | |
9443 ? BACKWARD : FORWARD; | |
9444 prep_redo_cmd(cap); | |
9445 if (cap->cmdchar == 'g') | |
9446 flags |= PUT_CURSEND; | |
9447 | |
9448 if (VIsual_active) | |
9449 { | |
9450 /* Putting in Visual mode: The put text replaces the selected | |
9451 * text. First delete the selected text, then put the new text. | |
9452 * Need to save and restore the registers that the delete | |
9453 * overwrites if the old contents is being put. | |
9454 */ | |
236 | 9455 was_visual = TRUE; |
7 | 9456 regname = cap->oap->regname; |
5735 | 9457 #ifdef FEAT_CLIPBOARD |
7 | 9458 adjust_clip_reg(®name); |
5735 | 9459 #endif |
5682 | 9460 if (regname == 0 || regname == '"' |
4013 | 9461 || VIM_ISDIGIT(regname) || regname == '-' |
5735 | 9462 #ifdef FEAT_CLIPBOARD |
7 | 9463 || (clip_unnamed && (regname == '*' || regname == '+')) |
5735 | 9464 #endif |
7 | 9465 |
9466 ) | |
9467 { | |
4013 | 9468 /* The delete is going to overwrite the register we want to |
7 | 9469 * put, save it first. */ |
9470 reg1 = get_register(regname, TRUE); | |
9471 } | |
9472 | |
9473 /* Now delete the selected text. */ | |
9474 cap->cmdchar = 'd'; | |
9475 cap->nchar = NUL; | |
9476 cap->oap->regname = NUL; | |
9477 nv_operator(cap); | |
9478 do_pending_operator(cap, 0, FALSE); | |
84 | 9479 empty = (curbuf->b_ml.ml_flags & ML_EMPTY); |
7 | 9480 |
9481 /* delete PUT_LINE_BACKWARD; */ | |
9482 cap->oap->regname = regname; | |
9483 | |
9484 if (reg1 != NULL) | |
9485 { | |
9486 /* Delete probably changed the register we want to put, save | |
9487 * it first. Then put back what was there before the delete. */ | |
9488 reg2 = get_register(regname, FALSE); | |
9489 put_register(regname, reg1); | |
9490 } | |
9491 | |
9492 /* When deleted a linewise Visual area, put the register as | |
9493 * lines to avoid it joined with the next line. When deletion was | |
9494 * characterwise, split a line when putting lines. */ | |
9495 if (VIsual_mode == 'V') | |
9496 flags |= PUT_LINE; | |
9497 else if (VIsual_mode == 'v') | |
9498 flags |= PUT_LINE_SPLIT; | |
9499 if (VIsual_mode == Ctrl_V && dir == FORWARD) | |
9500 flags |= PUT_LINE_FORWARD; | |
9501 dir = BACKWARD; | |
9502 if ((VIsual_mode != 'V' | |
9503 && curwin->w_cursor.col < curbuf->b_op_start.col) | |
9504 || (VIsual_mode == 'V' | |
9505 && curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) | |
9506 /* cursor is at the end of the line or end of file, put | |
9507 * forward. */ | |
9508 dir = FORWARD; | |
5365 | 9509 /* May have been reset in do_put(). */ |
9510 VIsual_active = TRUE; | |
7 | 9511 } |
9512 do_put(cap->oap->regname, dir, cap->count1, flags); | |
9513 | |
9514 /* If a register was saved, put it back now. */ | |
9515 if (reg2 != NULL) | |
9516 put_register(regname, reg2); | |
236 | 9517 |
9518 /* What to reselect with "gv"? Selecting the just put text seems to | |
9519 * be the most useful, since the original text was removed. */ | |
9520 if (was_visual) | |
9521 { | |
690 | 9522 curbuf->b_visual.vi_start = curbuf->b_op_start; |
9523 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
|
9524 /* need to adjust cursor position */ |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
9525 if (*p_sel == 'e') |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
9526 inc(&curbuf->b_visual.vi_end); |
236 | 9527 } |
9528 | |
84 | 9529 /* When all lines were selected and deleted do_put() leaves an empty |
236 | 9530 * line that needs to be deleted now. */ |
84 | 9531 if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) |
817 | 9532 { |
84 | 9533 ml_delete(curbuf->b_ml.ml_line_count, TRUE); |
817 | 9534 |
9535 /* If the cursor was in that line, move it to the end of the last | |
9536 * line. */ | |
9537 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
9538 { | |
9539 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
9540 coladvance((colnr_T)MAXCOL); | |
9541 } | |
9542 } | |
7 | 9543 auto_format(FALSE, TRUE); |
9544 } | |
9545 } | |
9546 | |
9547 /* | |
9548 * "o" and "O" commands. | |
9549 */ | |
9550 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9551 nv_open(cmdarg_T *cap) |
7 | 9552 { |
9553 #ifdef FEAT_DIFF | |
9554 /* "do" is ":diffget" */ | |
9555 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') | |
9556 { | |
9557 clearop(cap->oap); | |
6314 | 9558 nv_diffgetput(FALSE, cap->opcount); |
7 | 9559 } |
9560 else | |
9561 #endif | |
9562 if (VIsual_active) /* switch start and end of visual */ | |
9563 v_swap_corners(cap->cmdchar); | |
9564 else | |
9565 n_opencmd(cap); | |
9566 } | |
9567 | |
9568 #ifdef FEAT_NETBEANS_INTG | |
9569 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9570 nv_nbcmd(cmdarg_T *cap) |
7 | 9571 { |
9572 netbeans_keycommand(cap->nchar); | |
9573 } | |
9574 #endif | |
9575 | |
9576 #ifdef FEAT_DND | |
9577 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9578 nv_drop(cmdarg_T *cap UNUSED) |
7 | 9579 { |
9580 do_put('~', BACKWARD, 1L, PUT_CURSEND); | |
9581 } | |
9582 #endif | |
203 | 9583 |
9584 #ifdef FEAT_AUTOCMD | |
9585 /* | |
9586 * Trigger CursorHold event. | |
9587 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the | |
9588 * input buffer. "did_cursorhold" is set to avoid retriggering. | |
9589 */ | |
9590 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9591 nv_cursorhold(cmdarg_T *cap) |
203 | 9592 { |
9593 apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); | |
9594 did_cursorhold = TRUE; | |
226 | 9595 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
9596 } | |
9597 #endif | |
6866 | 9598 |
9599 /* | |
7001 | 9600 * Calculate start/end virtual columns for operating in block mode. |
6866 | 9601 */ |
9602 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9603 get_op_vcol( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9604 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9605 colnr_T redo_VIsual_vcol, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9606 int initial) /* when TRUE adjust position for 'selectmode' */ |
6866 | 9607 { |
9608 colnr_T start, end; | |
9609 | |
7001 | 9610 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
|
9611 || (!initial && oap->end.col < curwin->w_width)) |
6866 | 9612 return; |
9613 | |
7143
fe6d525d12f4
commit https://github.com/vim/vim/commit/10ad1d90da8c464e1bf08bf23d92d4888378a8a1
Christian Brabandt <cb@256bit.org>
parents:
7090
diff
changeset
|
9614 oap->block_mode = TRUE; |
6866 | 9615 |
9616 #ifdef FEAT_MBYTE | |
9617 /* prevent from moving onto a trail byte */ | |
9618 if (has_mbyte) | |
9619 mb_adjustpos(curwin->w_buffer, &oap->end); | |
9620 #endif | |
9621 | |
9622 getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol); | |
6961 | 9623 |
9624 if (!redo_VIsual_busy) | |
9625 { | |
9626 getvvcol(curwin, &(oap->end), &start, NULL, &end); | |
9627 | |
9628 if (start < oap->start_vcol) | |
9629 oap->start_vcol = start; | |
9630 if (end > oap->end_vcol) | |
9631 { | |
9632 if (initial && *p_sel == 'e' && start >= 1 | |
9633 && start - 1 >= oap->end_vcol) | |
9634 oap->end_vcol = start - 1; | |
9635 else | |
9636 oap->end_vcol = end; | |
9637 } | |
9638 } | |
9639 | |
6866 | 9640 /* if '$' was used, get oap->end_vcol from longest line */ |
9641 if (curwin->w_curswant == MAXCOL) | |
9642 { | |
9643 curwin->w_cursor.col = MAXCOL; | |
9644 oap->end_vcol = 0; | |
9645 for (curwin->w_cursor.lnum = oap->start.lnum; | |
9646 curwin->w_cursor.lnum <= oap->end.lnum; | |
9647 ++curwin->w_cursor.lnum) | |
9648 { | |
9649 getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end); | |
9650 if (end > oap->end_vcol) | |
9651 oap->end_vcol = end; | |
9652 } | |
9653 } | |
9654 else if (redo_VIsual_busy) | |
9655 oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1; | |
9656 /* | |
9657 * Correct oap->end.col and oap->start.col to be the | |
9658 * upper-left and lower-right corner of the block area. | |
9659 * | |
9660 * (Actually, this does convert column positions into character | |
9661 * positions) | |
9662 */ | |
9663 curwin->w_cursor.lnum = oap->end.lnum; | |
9664 coladvance(oap->end_vcol); | |
9665 oap->end = curwin->w_cursor; | |
9666 | |
9667 curwin->w_cursor = oap->start; | |
9668 coladvance(oap->start_vcol); | |
9669 oap->start = curwin->w_cursor; | |
9670 } |