Mercurial > vim
annotate src/normal.c @ 13369:244ff1b6d2ad v8.0.1558
patch 8.0.1558: no right-click menu in a terminal
commit https://github.com/vim/vim/commit/aef8c3da2ba59285b7cfde559ae21cdce6ba6919
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Mar 3 18:59:16 2018 +0100
patch 8.0.1558: no right-click menu in a terminal
Problem: No right-click menu in a terminal.
Solution: Implement the right click menu for the terminal.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 03 Mar 2018 19:00:06 +0100 |
parents | a88c5e12b860 |
children | 69517d67421f |
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); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
1485 VIM_CLEAR(repeat_cmdline); |
7 | 1486 } |
1487 } | |
1488 } | |
1489 | |
1490 if (redo_VIsual_busy) | |
1491 { | |
3125 | 1492 /* Redo of an operation on a Visual area. Use the same size from |
1493 * redo_VIsual_line_count and redo_VIsual_vcol. */ | |
7 | 1494 oap->start = curwin->w_cursor; |
1495 curwin->w_cursor.lnum += redo_VIsual_line_count - 1; | |
1496 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
1497 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
1498 VIsual_mode = redo_VIsual_mode; | |
3125 | 1499 if (redo_VIsual_vcol == MAXCOL || VIsual_mode == 'v') |
7 | 1500 { |
3125 | 1501 if (VIsual_mode == 'v') |
1502 { | |
1503 if (redo_VIsual_line_count <= 1) | |
1504 { | |
1505 validate_virtcol(); | |
1506 curwin->w_curswant = | |
1507 curwin->w_virtcol + redo_VIsual_vcol - 1; | |
1508 } | |
1509 else | |
1510 curwin->w_curswant = redo_VIsual_vcol; | |
1511 } | |
7 | 1512 else |
3125 | 1513 { |
1514 curwin->w_curswant = MAXCOL; | |
1515 } | |
1516 coladvance(curwin->w_curswant); | |
7 | 1517 } |
1518 cap->count0 = redo_VIsual_count; | |
1519 if (redo_VIsual_count != 0) | |
1520 cap->count1 = redo_VIsual_count; | |
1521 else | |
1522 cap->count1 = 1; | |
1523 } | |
1524 else if (VIsual_active) | |
1525 { | |
999 | 1526 if (!gui_yank) |
1527 { | |
1528 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
1529 curbuf->b_visual.vi_start = VIsual; | |
1530 curbuf->b_visual.vi_end = curwin->w_cursor; | |
1531 curbuf->b_visual.vi_mode = VIsual_mode; | |
4213 | 1532 if (VIsual_mode_orig != NUL) |
1533 { | |
1534 curbuf->b_visual.vi_mode = VIsual_mode_orig; | |
1535 VIsual_mode_orig = NUL; | |
1536 } | |
999 | 1537 curbuf->b_visual.vi_curswant = curwin->w_curswant; |
7 | 1538 # ifdef FEAT_EVAL |
999 | 1539 curbuf->b_visual_mode_eval = VIsual_mode; |
7 | 1540 # endif |
999 | 1541 } |
7 | 1542 |
1543 /* In Select mode, a linewise selection is operated upon like a | |
6826 | 1544 * characterwise selection. |
1545 * Special case: gH<Del> deletes the last line. */ | |
1546 if (VIsual_select && VIsual_mode == 'V' | |
1547 && cap->oap->op_type != OP_DELETE) | |
7 | 1548 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1549 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 1550 { |
1551 VIsual.col = 0; | |
1552 curwin->w_cursor.col = | |
1553 (colnr_T)STRLEN(ml_get(curwin->w_cursor.lnum)); | |
1554 } | |
1555 else | |
1556 { | |
1557 curwin->w_cursor.col = 0; | |
1558 VIsual.col = (colnr_T)STRLEN(ml_get(VIsual.lnum)); | |
1559 } | |
1560 VIsual_mode = 'v'; | |
1561 } | |
1562 /* If 'selection' is "exclusive", backup one character for | |
1563 * charwise selections. */ | |
1564 else if (VIsual_mode == 'v') | |
1565 { | |
1566 # ifdef FEAT_VIRTUALEDIT | |
1567 include_line_break = | |
1568 # endif | |
1569 unadjust_for_sel(); | |
1570 } | |
1571 | |
1572 oap->start = VIsual; | |
1573 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
|
1574 { |
7 | 1575 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
|
1576 # ifdef FEAT_VIRTUALEDIT |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1577 oap->start.coladd = 0; |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1578 # endif |
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
1579 } |
7 | 1580 } |
1581 | |
1582 /* | |
1583 * Set oap->start to the first position of the operated text, oap->end | |
1584 * to the end of the operated text. w_cursor is equal to oap->start. | |
1585 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
1586 if (LT_POS(oap->start, curwin->w_cursor)) |
7 | 1587 { |
1588 #ifdef FEAT_FOLDING | |
1589 /* Include folded lines completely. */ | |
1590 if (!VIsual_active) | |
1591 { | |
1592 if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL)) | |
1593 oap->start.col = 0; | |
1594 if (hasFolding(curwin->w_cursor.lnum, NULL, | |
1595 &curwin->w_cursor.lnum)) | |
1596 curwin->w_cursor.col = (colnr_T)STRLEN(ml_get_curline()); | |
1597 } | |
1598 #endif | |
1599 oap->end = curwin->w_cursor; | |
1600 curwin->w_cursor = oap->start; | |
1601 | |
1602 /* w_virtcol may have been updated; if the cursor goes back to its | |
1603 * previous position w_virtcol becomes invalid and isn't updated | |
1604 * automatically. */ | |
1605 curwin->w_valid &= ~VALID_VIRTCOL; | |
1606 } | |
1607 else | |
1608 { | |
1609 #ifdef FEAT_FOLDING | |
1610 /* Include folded lines completely. */ | |
1611 if (!VIsual_active && oap->motion_type == MLINE) | |
1612 { | |
1613 if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, | |
1614 NULL)) | |
1615 curwin->w_cursor.col = 0; | |
1616 if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) | |
1617 oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum)); | |
1618 } | |
1619 #endif | |
1620 oap->end = oap->start; | |
1621 oap->start = curwin->w_cursor; | |
1622 } | |
1623 | |
10154
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10110
diff
changeset
|
1624 /* 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
|
1625 check_pos(curwin->w_buffer, &oap->end); |
7 | 1626 oap->line_count = oap->end.lnum - oap->start.lnum + 1; |
1627 | |
1628 #ifdef FEAT_VIRTUALEDIT | |
1629 /* Set "virtual_op" before resetting VIsual_active. */ | |
1630 virtual_op = virtual_active(); | |
1631 #endif | |
1632 | |
1633 if (VIsual_active || redo_VIsual_busy) | |
1634 { | |
6866 | 1635 get_op_vcol(oap, redo_VIsual_vcol, TRUE); |
7 | 1636 |
1637 if (!redo_VIsual_busy && !gui_yank) | |
1638 { | |
1639 /* | |
1640 * Prepare to reselect and redo Visual: this is based on the | |
1641 * size of the Visual text | |
1642 */ | |
1643 resel_VIsual_mode = VIsual_mode; | |
1644 if (curwin->w_curswant == MAXCOL) | |
3125 | 1645 resel_VIsual_vcol = MAXCOL; |
7 | 1646 else |
3125 | 1647 { |
1648 if (VIsual_mode != Ctrl_V) | |
1649 getvvcol(curwin, &(oap->end), | |
1650 NULL, NULL, &oap->end_vcol); | |
1651 if (VIsual_mode == Ctrl_V || oap->line_count <= 1) | |
1652 { | |
1653 if (VIsual_mode != Ctrl_V) | |
1654 getvvcol(curwin, &(oap->start), | |
1655 &oap->start_vcol, NULL, NULL); | |
1656 resel_VIsual_vcol = oap->end_vcol - oap->start_vcol + 1; | |
1657 } | |
1658 else | |
1659 resel_VIsual_vcol = oap->end_vcol; | |
1660 } | |
7 | 1661 resel_VIsual_line_count = oap->line_count; |
1662 } | |
1663 | |
1664 /* can't redo yank (unless 'y' is in 'cpoptions') and ":" */ | |
1665 if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK) | |
1666 && oap->op_type != OP_COLON | |
1667 #ifdef FEAT_FOLDING | |
1668 && oap->op_type != OP_FOLD | |
1669 && oap->op_type != OP_FOLDOPEN | |
1670 && oap->op_type != OP_FOLDOPENREC | |
1671 && oap->op_type != OP_FOLDCLOSE | |
1672 && oap->op_type != OP_FOLDCLOSEREC | |
1673 && oap->op_type != OP_FOLDDEL | |
1674 && oap->op_type != OP_FOLDDELREC | |
1675 #endif | |
1676 && oap->motion_force == NUL | |
1677 ) | |
1678 { | |
1679 /* Prepare for redoing. Only use the nchar field for "r", | |
1680 * otherwise it might be the second char of the operator. */ | |
3701 | 1681 if (cap->cmdchar == 'g' && (cap->nchar == 'n' |
1682 || cap->nchar == 'N')) | |
5523 | 1683 prep_redo(oap->regname, cap->count0, |
1684 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | |
1685 oap->motion_force, cap->cmdchar, cap->nchar); | |
4337 | 1686 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
|
1687 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1688 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
|
1689 |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1690 /* 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
|
1691 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
|
1692 nchar = CAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1693 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
|
1694 nchar = NL; |
3701 | 1695 prep_redo(oap->regname, 0L, NUL, 'v', |
1696 get_op_char(oap->op_type), | |
1697 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
|
1698 nchar); |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
1699 } |
7 | 1700 if (!redo_VIsual_busy) |
1701 { | |
1702 redo_VIsual_mode = resel_VIsual_mode; | |
3125 | 1703 redo_VIsual_vcol = resel_VIsual_vcol; |
7 | 1704 redo_VIsual_line_count = resel_VIsual_line_count; |
1705 redo_VIsual_count = cap->count0; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
1706 redo_VIsual_arg = cap->arg; |
7 | 1707 } |
1708 } | |
1709 | |
1710 /* | |
1711 * oap->inclusive defaults to TRUE. | |
1712 * If oap->end is on a NUL (empty line) oap->inclusive becomes | |
1713 * FALSE. This makes "d}P" and "v}dP" work the same. | |
1714 */ | |
1715 if (oap->motion_force == NUL || oap->motion_type == MLINE) | |
1716 oap->inclusive = TRUE; | |
1717 if (VIsual_mode == 'V') | |
1718 oap->motion_type = MLINE; | |
1719 else | |
1720 { | |
1721 oap->motion_type = MCHAR; | |
1722 if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL | |
5735 | 1723 #ifdef FEAT_VIRTUALEDIT |
7 | 1724 && (include_line_break || !virtual_op) |
5735 | 1725 #endif |
7 | 1726 ) |
1727 { | |
1728 oap->inclusive = FALSE; | |
1729 /* Try to include the newline, unless it's an operator | |
2957 | 1730 * that works on lines only. */ |
6826 | 1731 if (*p_sel != 'o' |
1732 && !op_on_lines(oap->op_type) | |
1733 && oap->end.lnum < curbuf->b_ml.ml_line_count) | |
7 | 1734 { |
6826 | 1735 ++oap->end.lnum; |
1736 oap->end.col = 0; | |
5735 | 1737 #ifdef FEAT_VIRTUALEDIT |
6826 | 1738 oap->end.coladd = 0; |
1739 #endif | |
1740 ++oap->line_count; | |
7 | 1741 } |
1742 } | |
1743 } | |
1744 | |
1745 redo_VIsual_busy = FALSE; | |
592 | 1746 |
7 | 1747 /* |
1748 * Switch Visual off now, so screen updating does | |
1749 * not show inverted text when the screen is redrawn. | |
1750 * With OP_YANK and sometimes with OP_COLON and OP_FILTER there is | |
1751 * no screen redraw, so it is done here to remove the inverted | |
1752 * part. | |
1753 */ | |
1754 if (!gui_yank) | |
1755 { | |
1756 VIsual_active = FALSE; | |
5735 | 1757 #ifdef FEAT_MOUSE |
7 | 1758 setmouse(); |
1759 mouse_dragging = 0; | |
5735 | 1760 #endif |
6979 | 1761 may_clear_cmdline(); |
7 | 1762 if ((oap->op_type == OP_YANK |
1763 || oap->op_type == OP_COLON | |
592 | 1764 || oap->op_type == OP_FUNCTION |
7 | 1765 || oap->op_type == OP_FILTER) |
1766 && oap->motion_force == NUL) | |
6497 | 1767 { |
1768 #ifdef FEAT_LINEBREAK | |
1769 /* make sure redrawing is correct */ | |
1770 curwin->w_p_lbr = lbr_saved; | |
1771 #endif | |
7 | 1772 redraw_curbuf_later(INVERTED); |
6497 | 1773 } |
7 | 1774 } |
1775 } | |
1776 | |
1777 #ifdef FEAT_MBYTE | |
1778 /* Include the trailing byte of a multi-byte char. */ | |
1779 if (has_mbyte && oap->inclusive) | |
1780 { | |
1781 int l; | |
1782 | |
474 | 1783 l = (*mb_ptr2len)(ml_get_pos(&oap->end)); |
7 | 1784 if (l > 1) |
1785 oap->end.col += l - 1; | |
1786 } | |
1787 #endif | |
1788 curwin->w_set_curswant = TRUE; | |
1789 | |
1790 /* | |
1791 * oap->empty is set when start and end are the same. The inclusive | |
1792 * flag affects this too, unless yanking and the end is on a NUL. | |
1793 */ | |
1794 oap->empty = (oap->motion_type == MCHAR | |
1795 && (!oap->inclusive | |
1796 || (oap->op_type == OP_YANK | |
1797 && 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
|
1798 && EQUAL_POS(oap->start, oap->end) |
7 | 1799 #ifdef FEAT_VIRTUALEDIT |
1800 && !(virtual_op && oap->start.coladd != oap->end.coladd) | |
1801 #endif | |
1802 ); | |
1803 /* | |
1804 * For delete, change and yank, it's an error to operate on an | |
1805 * empty region, when 'E' included in 'cpoptions' (Vi compatible). | |
1806 */ | |
1807 empty_region_error = (oap->empty | |
1808 && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL); | |
1809 | |
1810 /* Force a redraw when operating on an empty Visual region, when | |
1811 * 'modifiable is off or creating a fold. */ | |
1812 if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma | |
5735 | 1813 #ifdef FEAT_FOLDING |
7 | 1814 || oap->op_type == OP_FOLD |
5735 | 1815 #endif |
7 | 1816 )) |
6497 | 1817 { |
1818 #ifdef FEAT_LINEBREAK | |
1819 curwin->w_p_lbr = lbr_saved; | |
1820 #endif | |
7 | 1821 redraw_curbuf_later(INVERTED); |
6497 | 1822 } |
7 | 1823 |
1824 /* | |
1825 * If the end of an operator is in column one while oap->motion_type | |
1826 * is MCHAR and oap->inclusive is FALSE, we put op_end after the last | |
1827 * character in the previous line. If op_start is on or before the | |
1828 * first non-blank in the line, the operator becomes linewise | |
1829 * (strange, but that's the way vi does it). | |
1830 */ | |
1831 if ( oap->motion_type == MCHAR | |
1832 && oap->inclusive == FALSE | |
1833 && !(cap->retval & CA_NO_ADJ_OP_END) | |
1834 && oap->end.col == 0 | |
1835 && (!oap->is_VIsual || *p_sel == 'o') | |
47 | 1836 && !oap->block_mode |
7 | 1837 && oap->line_count > 1) |
1838 { | |
1839 oap->end_adjusted = TRUE; /* remember that we did this */ | |
1840 --oap->line_count; | |
1841 --oap->end.lnum; | |
1842 if (inindent(0)) | |
1843 oap->motion_type = MLINE; | |
1844 else | |
1845 { | |
1846 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
1847 if (oap->end.col) | |
1848 { | |
1849 --oap->end.col; | |
1850 oap->inclusive = TRUE; | |
1851 } | |
1852 } | |
1853 } | |
1854 else | |
1855 oap->end_adjusted = FALSE; | |
1856 | |
1857 switch (oap->op_type) | |
1858 { | |
1859 case OP_LSHIFT: | |
1860 case OP_RSHIFT: | |
5735 | 1861 op_shift(oap, TRUE, oap->is_VIsual ? (int)cap->count1 : 1); |
7 | 1862 auto_format(FALSE, TRUE); |
1863 break; | |
1864 | |
1865 case OP_JOIN_NS: | |
1866 case OP_JOIN: | |
1867 if (oap->line_count < 2) | |
1868 oap->line_count = 2; | |
1869 if (curwin->w_cursor.lnum + oap->line_count - 1 > | |
1870 curbuf->b_ml.ml_line_count) | |
1871 beep_flush(); | |
1872 else | |
1873 { | |
5735 | 1874 (void)do_join(oap->line_count, oap->op_type == OP_JOIN, |
5848 | 1875 TRUE, TRUE, TRUE); |
7 | 1876 auto_format(FALSE, TRUE); |
1877 } | |
1878 break; | |
1879 | |
1880 case OP_DELETE: | |
1881 VIsual_reselect = FALSE; /* don't reselect now */ | |
1882 if (empty_region_error) | |
3324 | 1883 { |
6949 | 1884 vim_beep(BO_OPER); |
3324 | 1885 CancelRedo(); |
1886 } | |
7 | 1887 else |
1888 { | |
1889 (void)op_delete(oap); | |
1890 if (oap->motion_type == MLINE && has_format_option(FO_AUTO)) | |
1891 u_save_cursor(); /* cursor line wasn't saved yet */ | |
1892 auto_format(FALSE, TRUE); | |
1893 } | |
1894 break; | |
1895 | |
1896 case OP_YANK: | |
1897 if (empty_region_error) | |
1898 { | |
1899 if (!gui_yank) | |
3324 | 1900 { |
6949 | 1901 vim_beep(BO_OPER); |
3324 | 1902 CancelRedo(); |
1903 } | |
7 | 1904 } |
1905 else | |
6497 | 1906 { |
1907 #ifdef FEAT_LINEBREAK | |
1908 curwin->w_p_lbr = lbr_saved; | |
1909 #endif | |
7 | 1910 (void)op_yank(oap, FALSE, !gui_yank); |
6497 | 1911 } |
7 | 1912 check_cursor_col(); |
1913 break; | |
1914 | |
1915 case OP_CHANGE: | |
1916 VIsual_reselect = FALSE; /* don't reselect now */ | |
1917 if (empty_region_error) | |
3324 | 1918 { |
6949 | 1919 vim_beep(BO_OPER); |
3324 | 1920 CancelRedo(); |
1921 } | |
7 | 1922 else |
1923 { | |
1924 /* This is a new edit command, not a restart. Need to | |
1925 * remember it to make 'insertmode' work with mappings for | |
1926 * Visual mode. But do this only once and not when typed and | |
1927 * 'insertmode' isn't set. */ | |
1928 if (p_im || !KeyTyped) | |
1929 restart_edit_save = restart_edit; | |
1930 else | |
1931 restart_edit_save = 0; | |
1932 restart_edit = 0; | |
6497 | 1933 #ifdef FEAT_LINEBREAK |
1934 /* Restore linebreak, so that when the user edits it looks as | |
1935 * before. */ | |
6866 | 1936 if (curwin->w_p_lbr != lbr_saved) |
1937 { | |
1938 curwin->w_p_lbr = lbr_saved; | |
1939 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
1940 } | |
6497 | 1941 #endif |
7 | 1942 /* Reset finish_op now, don't want it set inside edit(). */ |
1943 finish_op = FALSE; | |
1944 if (op_change(oap)) /* will call edit() */ | |
1945 cap->retval |= CA_COMMAND_BUSY; | |
1946 if (restart_edit == 0) | |
1947 restart_edit = restart_edit_save; | |
1948 } | |
1949 break; | |
1950 | |
1951 case OP_FILTER: | |
1952 if (vim_strchr(p_cpo, CPO_FILTER) != NULL) | |
1953 AppendToRedobuff((char_u *)"!\r"); /* use any last used !cmd */ | |
1954 else | |
1955 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
|
1956 /* FALLTHROUGH */ |
7 | 1957 |
1958 case OP_INDENT: | |
1959 case OP_COLON: | |
1960 | |
1961 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
1962 /* | |
1963 * If 'equalprg' is empty, do the indenting internally. | |
1964 */ | |
1965 if (oap->op_type == OP_INDENT && *get_equalprg() == NUL) | |
1966 { | |
1967 # ifdef FEAT_LISP | |
1968 if (curbuf->b_p_lisp) | |
1969 { | |
1970 op_reindent(oap, get_lisp_indent); | |
1971 break; | |
1972 } | |
1973 # endif | |
1974 # ifdef FEAT_CINDENT | |
1975 op_reindent(oap, | |
1976 # ifdef FEAT_EVAL | |
1977 *curbuf->b_p_inde != NUL ? get_expr_indent : | |
1978 # endif | |
1979 get_c_indent); | |
1980 break; | |
1981 # endif | |
1982 } | |
1983 #endif | |
1984 | |
1985 op_colon(oap); | |
1986 break; | |
1987 | |
1988 case OP_TILDE: | |
1989 case OP_UPPER: | |
1990 case OP_LOWER: | |
1991 case OP_ROT13: | |
1992 if (empty_region_error) | |
3324 | 1993 { |
6949 | 1994 vim_beep(BO_OPER); |
3324 | 1995 CancelRedo(); |
1996 } | |
7 | 1997 else |
1998 op_tilde(oap); | |
1999 check_cursor_col(); | |
2000 break; | |
2001 | |
2002 case OP_FORMAT: | |
667 | 2003 #if defined(FEAT_EVAL) |
2004 if (*curbuf->b_p_fex != NUL) | |
2005 op_formatexpr(oap); /* use expression */ | |
2006 else | |
2007 #endif | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2008 if (*p_fp != NUL || *curbuf->b_p_fp != NUL) |
7 | 2009 op_colon(oap); /* use external command */ |
2010 else | |
2011 op_format(oap, FALSE); /* use internal function */ | |
2012 break; | |
2013 | |
2014 case OP_FORMAT2: | |
2015 op_format(oap, TRUE); /* use internal function */ | |
2016 break; | |
2017 | |
592 | 2018 case OP_FUNCTION: |
10342
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2019 #ifdef FEAT_LINEBREAK |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2020 /* 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
|
2021 * before. */ |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2022 curwin->w_p_lbr = lbr_saved; |
ae0faad76f9a
commit https://github.com/vim/vim/commit/4a08b0dc4dd70334056fc1bf069b5e938f2ed7d5
Christian Brabandt <cb@256bit.org>
parents:
10330
diff
changeset
|
2023 #endif |
592 | 2024 op_function(oap); /* call 'operatorfunc' */ |
2025 break; | |
2026 | |
7 | 2027 case OP_INSERT: |
2028 case OP_APPEND: | |
2029 VIsual_reselect = FALSE; /* don't reselect now */ | |
2030 #ifdef FEAT_VISUALEXTRA | |
2031 if (empty_region_error) | |
3324 | 2032 { |
6949 | 2033 vim_beep(BO_OPER); |
3324 | 2034 CancelRedo(); |
2035 } | |
7 | 2036 else |
2037 { | |
2038 /* This is a new edit command, not a restart. Need to | |
2039 * remember it to make 'insertmode' work with mappings for | |
2040 * Visual mode. But do this only once. */ | |
2041 restart_edit_save = restart_edit; | |
2042 restart_edit = 0; | |
6497 | 2043 #ifdef FEAT_LINEBREAK |
2044 /* Restore linebreak, so that when the user edits it looks as | |
2045 * before. */ | |
6866 | 2046 if (curwin->w_p_lbr != lbr_saved) |
2047 { | |
2048 curwin->w_p_lbr = lbr_saved; | |
2049 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
2050 } | |
6497 | 2051 #endif |
7 | 2052 op_insert(oap, cap->count1); |
6497 | 2053 #ifdef FEAT_LINEBREAK |
2054 /* Reset linebreak, so that formatting works correctly. */ | |
2055 curwin->w_p_lbr = FALSE; | |
2056 #endif | |
7 | 2057 |
2058 /* TODO: when inserting in several lines, should format all | |
2059 * the lines. */ | |
2060 auto_format(FALSE, TRUE); | |
2061 | |
2062 if (restart_edit == 0) | |
2063 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
|
2064 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
|
2065 cap->retval |= CA_COMMAND_BUSY; |
7 | 2066 } |
2067 #else | |
6949 | 2068 vim_beep(BO_OPER); |
7 | 2069 #endif |
2070 break; | |
2071 | |
2072 case OP_REPLACE: | |
2073 VIsual_reselect = FALSE; /* don't reselect now */ | |
2074 #ifdef FEAT_VISUALEXTRA | |
2075 if (empty_region_error) | |
2076 #endif | |
3324 | 2077 { |
6949 | 2078 vim_beep(BO_OPER); |
3324 | 2079 CancelRedo(); |
2080 } | |
7 | 2081 #ifdef FEAT_VISUALEXTRA |
2082 else | |
6497 | 2083 { |
6866 | 2084 # ifdef FEAT_LINEBREAK |
6497 | 2085 /* Restore linebreak, so that when the user edits it looks as |
2086 * before. */ | |
6866 | 2087 if (curwin->w_p_lbr != lbr_saved) |
2088 { | |
2089 curwin->w_p_lbr = lbr_saved; | |
2090 get_op_vcol(oap, redo_VIsual_mode, FALSE); | |
2091 } | |
2092 # endif | |
7 | 2093 op_replace(oap, cap->nchar); |
6497 | 2094 } |
7 | 2095 #endif |
2096 break; | |
2097 | |
2098 #ifdef FEAT_FOLDING | |
2099 case OP_FOLD: | |
2100 VIsual_reselect = FALSE; /* don't reselect now */ | |
2101 foldCreate(oap->start.lnum, oap->end.lnum); | |
2102 break; | |
2103 | |
2104 case OP_FOLDOPEN: | |
2105 case OP_FOLDOPENREC: | |
2106 case OP_FOLDCLOSE: | |
2107 case OP_FOLDCLOSEREC: | |
2108 VIsual_reselect = FALSE; /* don't reselect now */ | |
2109 opFoldRange(oap->start.lnum, oap->end.lnum, | |
2110 oap->op_type == OP_FOLDOPEN | |
2111 || oap->op_type == OP_FOLDOPENREC, | |
2112 oap->op_type == OP_FOLDOPENREC | |
2113 || oap->op_type == OP_FOLDCLOSEREC, | |
2114 oap->is_VIsual); | |
2115 break; | |
2116 | |
2117 case OP_FOLDDEL: | |
2118 case OP_FOLDDELREC: | |
2119 VIsual_reselect = FALSE; /* don't reselect now */ | |
2120 deleteFold(oap->start.lnum, oap->end.lnum, | |
2121 oap->op_type == OP_FOLDDELREC, oap->is_VIsual); | |
2122 break; | |
2123 #endif | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2124 case OP_NR_ADD: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2125 case OP_NR_SUB: |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2126 if (empty_region_error) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2127 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2128 vim_beep(BO_OPER); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2129 CancelRedo(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2130 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2131 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2132 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2133 VIsual_active = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2134 #ifdef FEAT_LINEBREAK |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2135 curwin->w_p_lbr = lbr_saved; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2136 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2137 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
|
2138 VIsual_active = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2139 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2140 check_cursor_col(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
2141 break; |
7 | 2142 default: |
2143 clearopbeep(oap); | |
2144 } | |
2145 #ifdef FEAT_VIRTUALEDIT | |
2146 virtual_op = MAYBE; | |
2147 #endif | |
2148 if (!gui_yank) | |
2149 { | |
2150 /* | |
2151 * if 'sol' not set, go back to old column for some commands | |
2152 */ | |
2153 if (!p_sol && oap->motion_type == MLINE && !oap->end_adjusted | |
2154 && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT | |
2155 || oap->op_type == OP_DELETE)) | |
6497 | 2156 { |
2157 #ifdef FEAT_LINEBREAK | |
2158 curwin->w_p_lbr = FALSE; | |
2159 #endif | |
7 | 2160 coladvance(curwin->w_curswant = old_col); |
6497 | 2161 } |
7 | 2162 } |
2163 else | |
2164 { | |
2165 curwin->w_cursor = old_cursor; | |
2166 } | |
2167 oap->block_mode = FALSE; | |
2168 clearop(oap); | |
2169 } | |
6266 | 2170 #ifdef FEAT_LINEBREAK |
2171 curwin->w_p_lbr = lbr_saved; | |
2172 #endif | |
7 | 2173 } |
2174 | |
2175 /* | |
2176 * Handle indent and format operators and visual mode ":". | |
2177 */ | |
2178 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2179 op_colon(oparg_T *oap) |
7 | 2180 { |
2181 stuffcharReadbuff(':'); | |
2182 if (oap->is_VIsual) | |
2183 stuffReadbuff((char_u *)"'<,'>"); | |
2184 else | |
2185 { | |
2186 /* | |
2187 * Make the range look nice, so it can be repeated. | |
2188 */ | |
2189 if (oap->start.lnum == curwin->w_cursor.lnum) | |
2190 stuffcharReadbuff('.'); | |
2191 else | |
2192 stuffnumReadbuff((long)oap->start.lnum); | |
2193 if (oap->end.lnum != oap->start.lnum) | |
2194 { | |
2195 stuffcharReadbuff(','); | |
2196 if (oap->end.lnum == curwin->w_cursor.lnum) | |
2197 stuffcharReadbuff('.'); | |
2198 else if (oap->end.lnum == curbuf->b_ml.ml_line_count) | |
2199 stuffcharReadbuff('$'); | |
2200 else if (oap->start.lnum == curwin->w_cursor.lnum) | |
2201 { | |
2202 stuffReadbuff((char_u *)".+"); | |
2203 stuffnumReadbuff((long)oap->line_count - 1); | |
2204 } | |
2205 else | |
2206 stuffnumReadbuff((long)oap->end.lnum); | |
2207 } | |
2208 } | |
2209 if (oap->op_type != OP_COLON) | |
2210 stuffReadbuff((char_u *)"!"); | |
2211 if (oap->op_type == OP_INDENT) | |
2212 { | |
2213 #ifndef FEAT_CINDENT | |
2214 if (*get_equalprg() == NUL) | |
2215 stuffReadbuff((char_u *)"indent"); | |
2216 else | |
2217 #endif | |
2218 stuffReadbuff(get_equalprg()); | |
2219 stuffReadbuff((char_u *)"\n"); | |
2220 } | |
2221 else if (oap->op_type == OP_FORMAT) | |
2222 { | |
10579
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2223 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
|
2224 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
|
2225 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
|
2226 stuffReadbuff(p_fp); |
688b97124d23
patch 8.0.0179: cannot have a local value for 'formatprg'
Christian Brabandt <cb@256bit.org>
parents:
10342
diff
changeset
|
2227 else |
7 | 2228 stuffReadbuff((char_u *)"fmt"); |
216 | 2229 stuffReadbuff((char_u *)"\n']"); |
7 | 2230 } |
2231 | |
2232 /* | |
2233 * do_cmdline() does the rest | |
2234 */ | |
2235 } | |
2236 | |
592 | 2237 /* |
602 | 2238 * Handle the "g@" operator: call 'operatorfunc'. |
592 | 2239 */ |
690 | 2240 static void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2241 op_function(oparg_T *oap UNUSED) |
592 | 2242 { |
2243 #ifdef FEAT_EVAL | |
2244 char_u *(argv[1]); | |
4133 | 2245 # ifdef FEAT_VIRTUALEDIT |
3431 | 2246 int save_virtual_op = virtual_op; |
4133 | 2247 # endif |
592 | 2248 |
2249 if (*p_opfunc == NUL) | |
2250 EMSG(_("E774: 'operatorfunc' is empty")); | |
2251 else | |
2252 { | |
2253 /* Set '[ and '] marks to text to be operated on. */ | |
2254 curbuf->b_op_start = oap->start; | |
2255 curbuf->b_op_end = oap->end; | |
2256 if (oap->motion_type != MLINE && !oap->inclusive) | |
2257 /* Exclude the end position. */ | |
2258 decl(&curbuf->b_op_end); | |
2259 | |
2260 if (oap->block_mode) | |
2261 argv[0] = (char_u *)"block"; | |
2262 else if (oap->motion_type == MLINE) | |
2263 argv[0] = (char_u *)"line"; | |
2264 else | |
2265 argv[0] = (char_u *)"char"; | |
3431 | 2266 |
4133 | 2267 # ifdef FEAT_VIRTUALEDIT |
3431 | 2268 /* Reset virtual_op so that 'virtualedit' can be changed in the |
2269 * function. */ | |
2270 virtual_op = MAYBE; | |
4133 | 2271 # endif |
3431 | 2272 |
592 | 2273 (void)call_func_retnr(p_opfunc, 1, argv, FALSE); |
3431 | 2274 |
4133 | 2275 # ifdef FEAT_VIRTUALEDIT |
3431 | 2276 virtual_op = save_virtual_op; |
4133 | 2277 # endif |
592 | 2278 } |
2279 #else | |
2280 EMSG(_("E775: Eval feature not available")); | |
2281 #endif | |
2282 } | |
2283 | |
7 | 2284 #if defined(FEAT_MOUSE) || defined(PROTO) |
2285 /* | |
2286 * Do the appropriate action for the current mouse click in the current mode. | |
2287 * Not used for Command-line mode. | |
2288 * | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2289 * Normal and Visual Mode: |
7 | 2290 * event modi- position visual change action |
2291 * fier cursor window | |
2292 * left press - yes end yes | |
2293 * left press C yes end yes "^]" (2) | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2294 * left press S yes end (popup: extend) yes "*" (2) |
7 | 2295 * left drag - yes start if moved no |
2296 * left relse - yes start if moved no | |
2297 * middle press - yes if not active no put register | |
2298 * middle press - yes if active no yank and put | |
2299 * right press - yes start or extend yes | |
2300 * right press S yes no change yes "#" (2) | |
2301 * right drag - yes extend no | |
2302 * right relse - yes extend no | |
2303 * | |
2304 * Insert or Replace Mode: | |
2305 * event modi- position visual change action | |
2306 * fier cursor window | |
2307 * left press - yes (cannot be active) yes | |
2308 * left press C yes (cannot be active) yes "CTRL-O^]" (2) | |
2309 * left press S yes (cannot be active) yes "CTRL-O*" (2) | |
2310 * left drag - yes start or extend (1) no CTRL-O (1) | |
2311 * left relse - yes start or extend (1) no CTRL-O (1) | |
2312 * middle press - no (cannot be active) no put register | |
2313 * right press - yes start or extend yes CTRL-O | |
2314 * right press S yes (cannot be active) yes "CTRL-O#" (2) | |
2315 * | |
2316 * (1) only if mouse pointer moved since press | |
2317 * (2) only if click is in same buffer | |
2318 * | |
2319 * Return TRUE if start_arrow() should be called for edit mode. | |
2320 */ | |
2321 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2322 do_mouse( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2323 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
|
2324 int c, /* K_LEFTMOUSE, etc */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2325 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
|
2326 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2327 int fixindent) /* PUT_FIXINDENT if fixing indent necessary */ |
7 | 2328 { |
2329 static int do_always = FALSE; /* ignore 'mouse' setting next time */ | |
2330 static int got_click = FALSE; /* got a click some time back */ | |
2331 | |
2332 int which_button; /* MOUSE_LEFT, _MIDDLE or _RIGHT */ | |
2333 int is_click; /* If FALSE it's a drag or release event */ | |
2334 int is_drag; /* If TRUE it's a drag event */ | |
2335 int jump_flags = 0; /* flags for jump_to_mouse() */ | |
2336 pos_T start_visual; | |
2337 int moved; /* Has cursor moved? */ | |
2338 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
|
2339 static int in_tab_line = FALSE; /* mouse clicked in tab line */ |
7 | 2340 int in_sep_line; /* mouse in vertical separator line */ |
2341 int c1, c2; | |
2342 #if defined(FEAT_FOLDING) | |
2343 pos_T save_cursor; | |
2344 #endif | |
2345 win_T *old_curwin = curwin; | |
2346 static pos_T orig_cursor; | |
2347 colnr_T leftcol, rightcol; | |
2348 pos_T end_visual; | |
2349 int diff; | |
2350 int old_active = VIsual_active; | |
2351 int old_mode = VIsual_mode; | |
2352 int regname; | |
2353 | |
2354 #if defined(FEAT_FOLDING) | |
2355 save_cursor = curwin->w_cursor; | |
2356 #endif | |
2357 | |
2358 /* | |
2359 * When GUI is active, always recognize mouse events, otherwise: | |
2360 * - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'. | |
2361 * - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'. | |
2362 * - For command line and insert mode 'mouse' is checked before calling | |
2363 * do_mouse(). | |
2364 */ | |
2365 if (do_always) | |
2366 do_always = FALSE; | |
2367 else | |
2368 #ifdef FEAT_GUI | |
2369 if (!gui.in_use) | |
2370 #endif | |
2371 { | |
2372 if (VIsual_active) | |
2373 { | |
2374 if (!mouse_has(MOUSE_VISUAL)) | |
2375 return FALSE; | |
2376 } | |
5735 | 2377 else if (State == NORMAL && !mouse_has(MOUSE_NORMAL)) |
7 | 2378 return FALSE; |
2379 } | |
2380 | |
4221 | 2381 for (;;) |
2382 { | |
2383 which_button = get_mouse_button(KEY2TERMCAP1(c), &is_click, &is_drag); | |
2384 if (is_drag) | |
2385 { | |
2386 /* If the next character is the same mouse event then use that | |
2387 * one. Speeds up dragging the status line. */ | |
2388 if (vpeekc() != NUL) | |
2389 { | |
2390 int nc; | |
2391 int save_mouse_row = mouse_row; | |
2392 int save_mouse_col = mouse_col; | |
2393 | |
2394 /* Need to get the character, peeking doesn't get the actual | |
2395 * one. */ | |
2396 nc = safe_vgetc(); | |
2397 if (c == nc) | |
2398 continue; | |
2399 vungetc(nc); | |
2400 mouse_row = save_mouse_row; | |
2401 mouse_col = save_mouse_col; | |
2402 } | |
2403 } | |
2404 break; | |
2405 } | |
7 | 2406 |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2407 if (c == K_MOUSEMOVE) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2408 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2409 /* 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
|
2410 #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
|
2411 ui_may_remove_balloon(); |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2412 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
|
2413 { |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2414 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
|
2415 bevalexpr_due_set = TRUE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2416 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2417 #endif |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2418 return FALSE; |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2419 } |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2420 |
7 | 2421 #ifdef FEAT_MOUSESHAPE |
2422 /* May have stopped dragging the status or separator line. The pointer is | |
2423 * most likely still on the status or separator line. */ | |
2424 if (!is_drag && drag_status_line) | |
2425 { | |
2426 drag_status_line = FALSE; | |
2427 update_mouseshape(SHAPE_IDX_STATUS); | |
2428 } | |
2429 if (!is_drag && drag_sep_line) | |
2430 { | |
2431 drag_sep_line = FALSE; | |
2432 update_mouseshape(SHAPE_IDX_VSEP); | |
2433 } | |
2434 #endif | |
2435 | |
2436 /* | |
2437 * Ignore drag and release events if we didn't get a click. | |
2438 */ | |
2439 if (is_click) | |
2440 got_click = TRUE; | |
2441 else | |
2442 { | |
2443 if (!got_click) /* didn't get click, ignore */ | |
2444 return FALSE; | |
2445 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
|
2446 { |
7 | 2447 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
|
2448 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
|
2449 { |
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 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
|
2451 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
|
2452 } |
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 } |
7 | 2454 } |
2455 | |
2456 /* | |
2457 * CTRL right mouse button does CTRL-T | |
2458 */ | |
2459 if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT) | |
2460 { | |
2461 if (State & INSERT) | |
2462 stuffcharReadbuff(Ctrl_O); | |
2463 if (count > 1) | |
2464 stuffnumReadbuff(count); | |
2465 stuffcharReadbuff(Ctrl_T); | |
2466 got_click = FALSE; /* ignore drag&release now */ | |
2467 return FALSE; | |
2468 } | |
2469 | |
2470 /* | |
2471 * CTRL only works with left mouse button | |
2472 */ | |
2473 if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT) | |
2474 return FALSE; | |
2475 | |
2476 /* | |
2477 * When a modifier is down, ignore drag and release events, as well as | |
2478 * multiple clicks and the middle mouse button. | |
2479 * Accept shift-leftmouse drags when 'mousemodel' is "popup.*". | |
2480 */ | |
179 | 2481 if ((mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT |
2482 | MOD_MASK_META)) | |
7 | 2483 && (!is_click |
2484 || (mod_mask & MOD_MASK_MULTI_CLICK) | |
2485 || which_button == MOUSE_MIDDLE) | |
598 | 2486 && !((mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT)) |
7 | 2487 && mouse_model_popup() |
2488 && which_button == MOUSE_LEFT) | |
598 | 2489 && !((mod_mask & MOD_MASK_ALT) |
2490 && !mouse_model_popup() | |
2491 && which_button == MOUSE_RIGHT) | |
7 | 2492 ) |
2493 return FALSE; | |
2494 | |
2495 /* | |
2496 * If the button press was used as the movement command for an operator | |
2497 * (eg "d<MOUSE>"), or it is the middle button that is held down, ignore | |
2498 * drag/release events. | |
2499 */ | |
2500 if (!is_click && which_button == MOUSE_MIDDLE) | |
2501 return FALSE; | |
2502 | |
2503 if (oap != NULL) | |
2504 regname = oap->regname; | |
2505 else | |
2506 regname = 0; | |
2507 | |
2508 /* | |
2509 * Middle mouse button does a 'put' of the selected text | |
2510 */ | |
2511 if (which_button == MOUSE_MIDDLE) | |
2512 { | |
2513 if (State == NORMAL) | |
2514 { | |
2515 /* | |
2516 * If an operator was pending, we don't know what the user wanted | |
2517 * to do. Go back to normal mode: Clear the operator and beep(). | |
2518 */ | |
2519 if (oap != NULL && oap->op_type != OP_NOP) | |
2520 { | |
2521 clearopbeep(oap); | |
2522 return FALSE; | |
2523 } | |
2524 | |
2525 /* | |
2526 * If visual was active, yank the highlighted text and put it | |
2527 * before the mouse pointer position. | |
1016 | 2528 * In Select mode replace the highlighted text with the clipboard. |
7 | 2529 */ |
2530 if (VIsual_active) | |
2531 { | |
1016 | 2532 if (VIsual_select) |
2533 { | |
2534 stuffcharReadbuff(Ctrl_G); | |
1019 | 2535 stuffReadbuff((char_u *)"\"+p"); |
1016 | 2536 } |
2537 else | |
2538 { | |
2539 stuffcharReadbuff('y'); | |
2540 stuffcharReadbuff(K_MIDDLEMOUSE); | |
2541 } | |
7 | 2542 do_always = TRUE; /* ignore 'mouse' setting next time */ |
2543 return FALSE; | |
2544 } | |
2545 /* | |
2546 * The rest is below jump_to_mouse() | |
2547 */ | |
2548 } | |
2549 | |
2550 else if ((State & INSERT) == 0) | |
2551 return FALSE; | |
2552 | |
2553 /* | |
2554 * Middle click in insert mode doesn't move the mouse, just insert the | |
2555 * contents of a register. '.' register is special, can't insert that | |
2556 * with do_put(). | |
2557 * Also paste at the cursor if the current mode isn't in 'mouse' (only | |
2558 * happens for the GUI). | |
2559 */ | |
2560 if ((State & INSERT) || !mouse_has(MOUSE_NORMAL)) | |
2561 { | |
2562 if (regname == '.') | |
2563 insert_reg(regname, TRUE); | |
2564 else | |
2565 { | |
2566 #ifdef FEAT_CLIPBOARD | |
2567 if (clip_star.available && regname == 0) | |
2568 regname = '*'; | |
2569 #endif | |
2570 if ((State & REPLACE_FLAG) && !yank_register_mline(regname)) | |
2571 insert_reg(regname, TRUE); | |
2572 else | |
2573 { | |
2574 do_put(regname, BACKWARD, 1L, fixindent | PUT_CURSEND); | |
2575 | |
2576 /* Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r */ | |
2577 AppendCharToRedobuff(Ctrl_R); | |
2578 AppendCharToRedobuff(fixindent ? Ctrl_P : Ctrl_O); | |
2579 AppendCharToRedobuff(regname == 0 ? '"' : regname); | |
2580 } | |
2581 } | |
2582 return FALSE; | |
2583 } | |
2584 } | |
2585 | |
2586 /* When dragging or button-up stay in the same window. */ | |
2587 if (!is_click) | |
2588 jump_flags |= MOUSE_FOCUS | MOUSE_DID_MOVE; | |
2589 | |
2590 start_visual.lnum = 0; | |
2591 | |
671 | 2592 /* Check for clicking in the tab page line. */ |
2593 if (mouse_row == 0 && firstwin->w_winrow > 0) | |
2594 { | |
1619 | 2595 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
|
2596 { |
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 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
|
2598 { |
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 c1 = TabPageIdxs[mouse_col]; |
7090
052043fc57ab
commit https://github.com/vim/vim/commit/4a4b821085847651b71d8ad9fab9f180635cb453
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2600 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
|
2601 ? 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
|
2602 } |
1619 | 2603 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
|
2604 } |
671 | 2605 |
2606 /* click in a tab selects that tab page */ | |
2607 if (is_click | |
2608 # ifdef FEAT_CMDWIN | |
2609 && cmdwin_type == 0 | |
2610 # endif | |
681 | 2611 && mouse_col < Columns) |
2612 { | |
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
|
2613 in_tab_line = TRUE; |
681 | 2614 c1 = TabPageIdxs[mouse_col]; |
2615 if (c1 >= 0) | |
2616 { | |
682 | 2617 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) |
2618 { | |
2619 /* double click opens new page */ | |
681 | 2620 end_visual_mode(); |
682 | 2621 tabpage_new(); |
2622 tabpage_move(c1 == 0 ? 9999 : c1 - 1); | |
2623 } | |
2624 else | |
2625 { | |
2626 /* Go to specified tab page, or next one if not clicking | |
2627 * on a label. */ | |
2628 goto_tabpage(c1); | |
2629 | |
2630 /* It's like clicking on the status line of a window. */ | |
2631 if (curwin != old_curwin) | |
2632 end_visual_mode(); | |
2633 } | |
681 | 2634 } |
2635 else if (c1 < 0) | |
2636 { | |
2637 tabpage_T *tp; | |
2638 | |
2639 /* Close the current or specified tab page. */ | |
2640 if (c1 == -999) | |
2641 tp = curtab; | |
2642 else | |
2643 tp = find_tabpage(-c1); | |
2644 if (tp == curtab) | |
2645 { | |
2646 if (first_tabpage->tp_next != NULL) | |
2647 tabpage_close(FALSE); | |
2648 } | |
2649 else if (tp != NULL) | |
2650 tabpage_close_other(tp, FALSE); | |
2651 } | |
2652 } | |
2653 return TRUE; | |
671 | 2654 } |
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
|
2655 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
|
2656 { |
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 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
|
2658 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
|
2659 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
|
2660 } |
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 |
7 | 2662 /* |
2663 * When 'mousemodel' is "popup" or "popup_setpos", translate mouse events: | |
2664 * right button up -> pop-up menu | |
2665 * shift-left button -> right button | |
598 | 2666 * alt-left button -> alt-right button |
7 | 2667 */ |
2668 if (mouse_model_popup()) | |
2669 { | |
2670 if (which_button == MOUSE_RIGHT | |
2671 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | |
2672 { | |
573 | 2673 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \ |
7 | 2674 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \ |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2675 || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_PHOTON) \ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2676 || defined(FEAT_TERM_POPUP_MENU) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2677 # ifdef FEAT_GUI |
7 | 2678 if (gui.in_use) |
2679 { | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2680 # if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2681 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2682 if (!is_click) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2683 /* Ignore right button release events, only shows the popup |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2684 * menu on the button down event. */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2685 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2686 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2687 # if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2688 if (is_click || is_drag) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2689 /* Ignore right button down and drag mouse events. Windows |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2690 * only shows the popup menu on the button up event. */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2691 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2692 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2693 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2694 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2695 # if defined(FEAT_GUI) && defined(FEAT_TERM_POPUP_MENU) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2696 else |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2697 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2698 # if defined(FEAT_TERM_POPUP_MENU) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2699 if (!is_click) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2700 /* Ignore right button release events, only shows the popup |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2701 * menu on the button down event. */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2702 return FALSE; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2703 #endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2704 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2705 jump_flags = 0; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2706 if (STRCMP(p_mousem, "popup_setpos") == 0) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2707 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2708 /* First set the cursor position before showing the popup |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2709 * menu. */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2710 if (VIsual_active) |
7 | 2711 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2712 pos_T m_pos; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2713 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2714 /* |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2715 * set MOUSE_MAY_STOP_VIS if we are outside the |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2716 * selection or the current window (might have false |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2717 * negative here) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2718 */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2719 if (mouse_row < curwin->w_winrow |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2720 || mouse_row |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2721 > (curwin->w_winrow + curwin->w_height)) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2722 jump_flags = MOUSE_MAY_STOP_VIS; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2723 else if (get_fpos_of_mouse(&m_pos) != IN_BUFFER) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2724 jump_flags = MOUSE_MAY_STOP_VIS; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2725 else |
7 | 2726 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2727 if ((LT_POS(curwin->w_cursor, VIsual) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2728 && (LT_POS(m_pos, curwin->w_cursor) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2729 || LT_POS(VIsual, m_pos))) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2730 || (LT_POS(VIsual, curwin->w_cursor) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2731 && (LT_POS(m_pos, VIsual) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2732 || LT_POS(curwin->w_cursor, m_pos)))) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2733 { |
7 | 2734 jump_flags = MOUSE_MAY_STOP_VIS; |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2735 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2736 else if (VIsual_mode == Ctrl_V) |
7 | 2737 { |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2738 getvcols(curwin, &curwin->w_cursor, &VIsual, |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2739 &leftcol, &rightcol); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2740 getvcol(curwin, &m_pos, NULL, &m_pos.col, NULL); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2741 if (m_pos.col < leftcol || m_pos.col > rightcol) |
7 | 2742 jump_flags = MOUSE_MAY_STOP_VIS; |
2743 } | |
2744 } | |
2745 } | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2746 else |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2747 jump_flags = MOUSE_MAY_STOP_VIS; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2748 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2749 if (jump_flags) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2750 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2751 jump_flags = jump_to_mouse(jump_flags, NULL, which_button); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2752 update_curbuf(VIsual_active ? INVERTED : VALID); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2753 setcursor(); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2754 out_flush(); /* Update before showing popup menu */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2755 } |
7 | 2756 # ifdef FEAT_MENU |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2757 show_popupmenu(); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2758 got_click = FALSE; /* ignore release events */ |
7 | 2759 # endif |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
2760 return (jump_flags & CURSOR_MOVED) != 0; |
7 | 2761 #else |
2762 return FALSE; | |
2763 #endif | |
2764 } | |
598 | 2765 if (which_button == MOUSE_LEFT |
2766 && (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT))) | |
7 | 2767 { |
2768 which_button = MOUSE_RIGHT; | |
2769 mod_mask &= ~MOD_MASK_SHIFT; | |
2770 } | |
2771 } | |
2772 | |
2773 if ((State & (NORMAL | INSERT)) | |
2774 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))) | |
2775 { | |
2776 if (which_button == MOUSE_LEFT) | |
2777 { | |
2778 if (is_click) | |
2779 { | |
2780 /* stop Visual mode for a left click in a window, but not when | |
2781 * on a status line */ | |
2782 if (VIsual_active) | |
2783 jump_flags |= MOUSE_MAY_STOP_VIS; | |
2784 } | |
2785 else if (mouse_has(MOUSE_VISUAL)) | |
2786 jump_flags |= MOUSE_MAY_VIS; | |
2787 } | |
2788 else if (which_button == MOUSE_RIGHT) | |
2789 { | |
2790 if (is_click && VIsual_active) | |
2791 { | |
2792 /* | |
2793 * Remember the start and end of visual before moving the | |
2794 * cursor. | |
2795 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2796 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 2797 { |
2798 start_visual = curwin->w_cursor; | |
2799 end_visual = VIsual; | |
2800 } | |
2801 else | |
2802 { | |
2803 start_visual = VIsual; | |
2804 end_visual = curwin->w_cursor; | |
2805 } | |
2806 } | |
2807 jump_flags |= MOUSE_FOCUS; | |
2808 if (mouse_has(MOUSE_VISUAL)) | |
2809 jump_flags |= MOUSE_MAY_VIS; | |
2810 } | |
2811 } | |
2812 | |
2813 /* | |
2814 * If an operator is pending, ignore all drags and releases until the | |
2815 * next mouse click. | |
2816 */ | |
2817 if (!is_drag && oap != NULL && oap->op_type != OP_NOP) | |
2818 { | |
2819 got_click = FALSE; | |
2820 oap->motion_type = MCHAR; | |
2821 } | |
2822 | |
2823 /* When releasing the button let jump_to_mouse() know. */ | |
2824 if (!is_click && !is_drag) | |
2825 jump_flags |= MOUSE_RELEASED; | |
2826 | |
2827 /* | |
2828 * JUMP! | |
2829 */ | |
2830 jump_flags = jump_to_mouse(jump_flags, | |
2831 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
|
2832 |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2833 #ifdef FEAT_MENU |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2834 /* 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
|
2835 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
|
2836 return FALSE; |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2837 #endif |
7 | 2838 moved = (jump_flags & CURSOR_MOVED); |
2839 in_status_line = (jump_flags & IN_STATUS_LINE); | |
2840 in_sep_line = (jump_flags & IN_SEP_LINE); | |
2841 | |
2842 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2843 if (isNetbeansBuffer(curbuf) |
7 | 2844 && !(jump_flags & (IN_STATUS_LINE | IN_SEP_LINE))) |
2845 { | |
2846 int key = KEY2TERMCAP1(c); | |
2847 | |
2848 if (key == (int)KE_LEFTRELEASE || key == (int)KE_MIDDLERELEASE | |
2849 || key == (int)KE_RIGHTRELEASE) | |
2850 netbeans_button_release(which_button); | |
2851 } | |
2852 #endif | |
2853 | |
2854 /* When jumping to another window, clear a pending operator. That's a bit | |
2855 * friendlier than beeping and not jumping to that window. */ | |
2856 if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP) | |
2857 clearop(oap); | |
2858 | |
2859 #ifdef FEAT_FOLDING | |
2860 if (mod_mask == 0 | |
2861 && !is_drag | |
2862 && (jump_flags & (MOUSE_FOLD_CLOSE | MOUSE_FOLD_OPEN)) | |
2863 && which_button == MOUSE_LEFT) | |
2864 { | |
2865 /* open or close a fold at this line */ | |
2866 if (jump_flags & MOUSE_FOLD_OPEN) | |
2867 openFold(curwin->w_cursor.lnum, 1L); | |
2868 else | |
2869 closeFold(curwin->w_cursor.lnum, 1L); | |
2870 /* don't move the cursor if still in the same window */ | |
2871 if (curwin == old_curwin) | |
2872 curwin->w_cursor = save_cursor; | |
2873 } | |
2874 #endif | |
2875 | |
2876 #if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN) | |
2877 if ((jump_flags & IN_OTHER_WIN) && !VIsual_active && clip_star.available) | |
2878 { | |
2879 clip_modeless(which_button, is_click, is_drag); | |
2880 return FALSE; | |
2881 } | |
2882 #endif | |
2883 | |
2884 /* Set global flag that we are extending the Visual area with mouse | |
1188 | 2885 * dragging; temporarily minimize 'scrolloff'. */ |
7 | 2886 if (VIsual_active && is_drag && p_so) |
2887 { | |
2888 /* In the very first line, allow scrolling one line */ | |
2889 if (mouse_row == 0) | |
2890 mouse_dragging = 2; | |
2891 else | |
2892 mouse_dragging = 1; | |
2893 } | |
2894 | |
2895 /* When dragging the mouse above the window, scroll down. */ | |
2896 if (is_drag && mouse_row < 0 && !in_status_line) | |
2897 { | |
2898 scroll_redraw(FALSE, 1L); | |
2899 mouse_row = 0; | |
2900 } | |
2901 | |
2902 if (start_visual.lnum) /* right click in visual mode */ | |
2903 { | |
598 | 2904 /* When ALT is pressed make Visual mode blockwise. */ |
2905 if (mod_mask & MOD_MASK_ALT) | |
2906 VIsual_mode = Ctrl_V; | |
2907 | |
7 | 2908 /* |
2909 * In Visual-block mode, divide the area in four, pick up the corner | |
2910 * that is in the quarter that the cursor is in. | |
2911 */ | |
2912 if (VIsual_mode == Ctrl_V) | |
2913 { | |
2914 getvcols(curwin, &start_visual, &end_visual, &leftcol, &rightcol); | |
2915 if (curwin->w_curswant > (leftcol + rightcol) / 2) | |
2916 end_visual.col = leftcol; | |
2917 else | |
2918 end_visual.col = rightcol; | |
7009 | 2919 if (curwin->w_cursor.lnum >= |
7 | 2920 (start_visual.lnum + end_visual.lnum) / 2) |
2921 end_visual.lnum = start_visual.lnum; | |
2922 | |
2923 /* move VIsual to the right column */ | |
2924 start_visual = curwin->w_cursor; /* save the cursor pos */ | |
2925 curwin->w_cursor = end_visual; | |
2926 coladvance(end_visual.col); | |
2927 VIsual = curwin->w_cursor; | |
2928 curwin->w_cursor = start_visual; /* restore the cursor */ | |
2929 } | |
2930 else | |
2931 { | |
2932 /* | |
2933 * If the click is before the start of visual, change the start. | |
2934 * If the click is after the end of visual, change the end. If | |
2935 * the click is inside the visual, change the closest side. | |
2936 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2937 if (LT_POS(curwin->w_cursor, start_visual)) |
7 | 2938 VIsual = end_visual; |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
2939 else if (LT_POS(end_visual, curwin->w_cursor)) |
7 | 2940 VIsual = start_visual; |
2941 else | |
2942 { | |
2943 /* In the same line, compare column number */ | |
2944 if (end_visual.lnum == start_visual.lnum) | |
2945 { | |
2946 if (curwin->w_cursor.col - start_visual.col > | |
2947 end_visual.col - curwin->w_cursor.col) | |
2948 VIsual = start_visual; | |
2949 else | |
2950 VIsual = end_visual; | |
2951 } | |
2952 | |
2953 /* In different lines, compare line number */ | |
2954 else | |
2955 { | |
2956 diff = (curwin->w_cursor.lnum - start_visual.lnum) - | |
2957 (end_visual.lnum - curwin->w_cursor.lnum); | |
2958 | |
2959 if (diff > 0) /* closest to end */ | |
2960 VIsual = start_visual; | |
2961 else if (diff < 0) /* closest to start */ | |
2962 VIsual = end_visual; | |
2963 else /* in the middle line */ | |
2964 { | |
2965 if (curwin->w_cursor.col < | |
2966 (start_visual.col + end_visual.col) / 2) | |
2967 VIsual = end_visual; | |
2968 else | |
2969 VIsual = start_visual; | |
2970 } | |
2971 } | |
2972 } | |
2973 } | |
2974 } | |
2975 /* | |
2976 * If Visual mode started in insert mode, execute "CTRL-O" | |
2977 */ | |
2978 else if ((State & INSERT) && VIsual_active) | |
2979 stuffcharReadbuff(Ctrl_O); | |
2980 | |
2981 /* | |
2982 * Middle mouse click: Put text before cursor. | |
2983 */ | |
2984 if (which_button == MOUSE_MIDDLE) | |
2985 { | |
2986 #ifdef FEAT_CLIPBOARD | |
2987 if (clip_star.available && regname == 0) | |
2988 regname = '*'; | |
2989 #endif | |
2990 if (yank_register_mline(regname)) | |
2991 { | |
2992 if (mouse_past_bottom) | |
2993 dir = FORWARD; | |
2994 } | |
2995 else if (mouse_past_eol) | |
2996 dir = FORWARD; | |
2997 | |
2998 if (fixindent) | |
2999 { | |
3000 c1 = (dir == BACKWARD) ? '[' : ']'; | |
3001 c2 = 'p'; | |
3002 } | |
3003 else | |
3004 { | |
3005 c1 = (dir == FORWARD) ? 'p' : 'P'; | |
3006 c2 = NUL; | |
3007 } | |
3008 prep_redo(regname, count, NUL, c1, NUL, c2, NUL); | |
3009 | |
3010 /* | |
3011 * Remember where the paste started, so in edit() Insstart can be set | |
3012 * to this position | |
3013 */ | |
3014 if (restart_edit != 0) | |
3015 where_paste_started = curwin->w_cursor; | |
3016 do_put(regname, dir, count, fixindent | PUT_CURSEND); | |
3017 } | |
3018 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3019 #if defined(FEAT_QUICKFIX) |
7 | 3020 /* |
3021 * Ctrl-Mouse click or double click in a quickfix window jumps to the | |
3022 * error under the mouse pointer. | |
3023 */ | |
3024 else if (((mod_mask & MOD_MASK_CTRL) | |
3025 || (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
3026 && bt_quickfix(curbuf)) | |
3027 { | |
643 | 3028 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
|
3029 do_cmdline_cmd((char_u *)".cc"); |
643 | 3030 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
|
3031 do_cmdline_cmd((char_u *)".ll"); |
7 | 3032 got_click = FALSE; /* ignore drag&release now */ |
3033 } | |
3034 #endif | |
3035 | |
3036 /* | |
3037 * Ctrl-Mouse click (or double click in a help window) jumps to the tag | |
3038 * under the mouse pointer. | |
3039 */ | |
3040 else if ((mod_mask & MOD_MASK_CTRL) || (curbuf->b_help | |
3041 && (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)) | |
3042 { | |
3043 if (State & INSERT) | |
3044 stuffcharReadbuff(Ctrl_O); | |
3045 stuffcharReadbuff(Ctrl_RSB); | |
3046 got_click = FALSE; /* ignore drag&release now */ | |
3047 } | |
3048 | |
3049 /* | |
3050 * Shift-Mouse click searches for the next occurrence of the word under | |
3051 * the mouse pointer | |
3052 */ | |
3053 else if ((mod_mask & MOD_MASK_SHIFT)) | |
3054 { | |
5735 | 3055 if ((State & INSERT) || (VIsual_active && VIsual_select)) |
7 | 3056 stuffcharReadbuff(Ctrl_O); |
3057 if (which_button == MOUSE_LEFT) | |
3058 stuffcharReadbuff('*'); | |
3059 else /* MOUSE_RIGHT */ | |
3060 stuffcharReadbuff('#'); | |
3061 } | |
3062 | |
3063 /* Handle double clicks, unless on status line */ | |
3064 else if (in_status_line) | |
3065 { | |
3066 #ifdef FEAT_MOUSESHAPE | |
3067 if ((is_drag || is_click) && !drag_status_line) | |
3068 { | |
3069 drag_status_line = TRUE; | |
3070 update_mouseshape(-1); | |
3071 } | |
3072 #endif | |
3073 } | |
3074 else if (in_sep_line) | |
3075 { | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3076 #ifdef FEAT_MOUSESHAPE |
7 | 3077 if ((is_drag || is_click) && !drag_sep_line) |
3078 { | |
3079 drag_sep_line = TRUE; | |
3080 update_mouseshape(-1); | |
3081 } | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3082 #endif |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
3083 } |
7 | 3084 else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT)) |
3085 && mouse_has(MOUSE_VISUAL)) | |
3086 { | |
3087 if (is_click || !VIsual_active) | |
3088 { | |
3089 if (VIsual_active) | |
3090 orig_cursor = VIsual; | |
3091 else | |
3092 { | |
3093 check_visual_highlight(); | |
3094 VIsual = curwin->w_cursor; | |
3095 orig_cursor = VIsual; | |
3096 VIsual_active = TRUE; | |
3097 VIsual_reselect = TRUE; | |
3098 /* start Select mode if 'selectmode' contains "mouse" */ | |
3099 may_start_select('o'); | |
3100 setmouse(); | |
3101 } | |
3102 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
598 | 3103 { |
3104 /* Double click with ALT pressed makes it blockwise. */ | |
3105 if (mod_mask & MOD_MASK_ALT) | |
3106 VIsual_mode = Ctrl_V; | |
3107 else | |
3108 VIsual_mode = 'v'; | |
3109 } | |
7 | 3110 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK) |
3111 VIsual_mode = 'V'; | |
3112 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK) | |
3113 VIsual_mode = Ctrl_V; | |
3114 #ifdef FEAT_CLIPBOARD | |
3115 /* Make sure the clipboard gets updated. Needed because start and | |
3116 * end may still be the same, and the selection needs to be owned */ | |
3117 clip_star.vmode = NUL; | |
3118 #endif | |
3119 } | |
3120 /* | |
3121 * A double click selects a word or a block. | |
3122 */ | |
3123 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK) | |
3124 { | |
3125 pos_T *pos = NULL; | |
300 | 3126 int gc; |
7 | 3127 |
3128 if (is_click) | |
3129 { | |
3130 /* If the character under the cursor (skipping white space) is | |
3131 * not a word character, try finding a match and select a (), | |
3132 * {}, [], #if/#endif, etc. block. */ | |
3133 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
|
3134 while (gc = gchar_pos(&end_visual), VIM_ISWHITE(gc)) |
7 | 3135 inc(&end_visual); |
3136 if (oap != NULL) | |
3137 oap->motion_type = MCHAR; | |
3138 if (oap != NULL | |
3139 && VIsual_mode == 'v' | |
3140 && !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
|
3141 && EQUAL_POS(curwin->w_cursor, VIsual) |
7 | 3142 && (pos = findmatch(oap, NUL)) != NULL) |
3143 { | |
3144 curwin->w_cursor = *pos; | |
3145 if (oap->motion_type == MLINE) | |
3146 VIsual_mode = 'V'; | |
3147 else if (*p_sel == 'e') | |
3148 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3149 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 3150 ++VIsual.col; |
3151 else | |
3152 ++curwin->w_cursor.col; | |
3153 } | |
3154 } | |
3155 } | |
3156 | |
3157 if (pos == NULL && (is_click || is_drag)) | |
3158 { | |
3159 /* When not found a match or when dragging: extend to include | |
3160 * a word. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3161 if (LT_POS(curwin->w_cursor, orig_cursor)) |
7 | 3162 { |
3163 find_start_of_word(&curwin->w_cursor); | |
3164 find_end_of_word(&VIsual); | |
3165 } | |
3166 else | |
3167 { | |
3168 find_start_of_word(&VIsual); | |
3169 if (*p_sel == 'e' && *ml_get_cursor() != NUL) | |
3170 #ifdef FEAT_MBYTE | |
3171 curwin->w_cursor.col += | |
474 | 3172 (*mb_ptr2len)(ml_get_cursor()); |
7 | 3173 #else |
3174 ++curwin->w_cursor.col; | |
3175 #endif | |
3176 find_end_of_word(&curwin->w_cursor); | |
3177 } | |
3178 } | |
3179 curwin->w_set_curswant = TRUE; | |
3180 } | |
3181 if (is_click) | |
3182 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
3183 } | |
3184 else if (VIsual_active && !old_active) | |
598 | 3185 { |
3186 if (mod_mask & MOD_MASK_ALT) | |
3187 VIsual_mode = Ctrl_V; | |
3188 else | |
3189 VIsual_mode = 'v'; | |
3190 } | |
7 | 3191 |
3192 /* If Visual mode changed show it later. */ | |
643 | 3193 if ((!VIsual_active && old_active && mode_displayed) |
3194 || (VIsual_active && p_smd && msg_silent == 0 | |
3195 && (!old_active || VIsual_mode != old_mode))) | |
7 | 3196 redraw_cmdline = TRUE; |
3197 | |
3198 return moved; | |
3199 } | |
3200 | |
3201 /* | |
3202 * Move "pos" back to the start of the word it's in. | |
3203 */ | |
3204 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3205 find_start_of_word(pos_T *pos) |
7 | 3206 { |
3207 char_u *line; | |
3208 int cclass; | |
3209 int col; | |
3210 | |
3211 line = ml_get(pos->lnum); | |
3212 cclass = get_mouse_class(line + pos->col); | |
3213 | |
3214 while (pos->col > 0) | |
3215 { | |
3216 col = pos->col - 1; | |
3217 #ifdef FEAT_MBYTE | |
3218 col -= (*mb_head_off)(line, line + col); | |
3219 #endif | |
3220 if (get_mouse_class(line + col) != cclass) | |
3221 break; | |
3222 pos->col = col; | |
3223 } | |
3224 } | |
3225 | |
3226 /* | |
3227 * Move "pos" forward to the end of the word it's in. | |
3228 * When 'selection' is "exclusive", the position is just after the word. | |
3229 */ | |
3230 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3231 find_end_of_word(pos_T *pos) |
7 | 3232 { |
3233 char_u *line; | |
3234 int cclass; | |
3235 int col; | |
3236 | |
3237 line = ml_get(pos->lnum); | |
3238 if (*p_sel == 'e' && pos->col > 0) | |
3239 { | |
3240 --pos->col; | |
3241 #ifdef FEAT_MBYTE | |
3242 pos->col -= (*mb_head_off)(line, line + pos->col); | |
3243 #endif | |
3244 } | |
3245 cclass = get_mouse_class(line + pos->col); | |
3246 while (line[pos->col] != NUL) | |
3247 { | |
3248 #ifdef FEAT_MBYTE | |
474 | 3249 col = pos->col + (*mb_ptr2len)(line + pos->col); |
7 | 3250 #else |
3251 col = pos->col + 1; | |
3252 #endif | |
3253 if (get_mouse_class(line + col) != cclass) | |
3254 { | |
3255 if (*p_sel == 'e') | |
3256 pos->col = col; | |
3257 break; | |
3258 } | |
3259 pos->col = col; | |
3260 } | |
3261 } | |
3262 | |
3263 /* | |
3264 * Get class of a character for selection: same class means same word. | |
3265 * 0: blank | |
3266 * 1: punctuation groups | |
3267 * 2: normal word character | |
3268 * >2: multi-byte word character. | |
3269 */ | |
3270 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3271 get_mouse_class(char_u *p) |
7 | 3272 { |
3273 int c; | |
3274 | |
3275 #ifdef FEAT_MBYTE | |
3276 if (has_mbyte && MB_BYTE2LEN(p[0]) > 1) | |
3277 return mb_get_class(p); | |
3278 #endif | |
3279 | |
3280 c = *p; | |
3281 if (c == ' ' || c == '\t') | |
3282 return 0; | |
3283 | |
3284 if (vim_iswordc(c)) | |
3285 return 2; | |
3286 | |
3287 /* | |
3288 * There are a few special cases where we want certain combinations of | |
3289 * characters to be considered as a single word. These are things like | |
3290 * "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
3291 * character is in its own class. |
7 | 3292 */ |
3293 if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL) | |
3294 return 1; | |
3295 return c; | |
3296 } | |
3297 #endif /* FEAT_MOUSE */ | |
3298 | |
3299 /* | |
3300 * Check if highlighting for visual mode is possible, give a warning message | |
3301 * if not. | |
3302 */ | |
3303 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3304 check_visual_highlight(void) |
7 | 3305 { |
3306 static int did_check = FALSE; | |
3307 | |
3308 if (full_screen) | |
3309 { | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3310 if (!did_check && HL_ATTR(HLF_V) == 0) |
7 | 3311 MSG(_("Warning: terminal cannot highlight")); |
3312 did_check = TRUE; | |
3313 } | |
3314 } | |
3315 | |
3316 /* | |
638 | 3317 * End Visual mode. |
7 | 3318 * This function should ALWAYS be called to end Visual mode, except from |
3319 * do_pending_operator(). | |
3320 */ | |
3321 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3322 end_visual_mode(void) |
7 | 3323 { |
3324 #ifdef FEAT_CLIPBOARD | |
3325 /* | |
3326 * If we are using the clipboard, then remember what was selected in case | |
3327 * we need to paste it somewhere while we still own the selection. | |
3328 * Only do this when the clipboard is already owned. Don't want to grab | |
3329 * the selection when hitting ESC. | |
3330 */ | |
3331 if (clip_star.available && clip_star.owned) | |
3332 clip_auto_select(); | |
3333 #endif | |
3334 | |
3335 VIsual_active = FALSE; | |
3336 #ifdef FEAT_MOUSE | |
3337 setmouse(); | |
3338 mouse_dragging = 0; | |
3339 #endif | |
3340 | |
3341 /* Save the current VIsual area for '< and '> marks, and "gv" */ | |
690 | 3342 curbuf->b_visual.vi_mode = VIsual_mode; |
3343 curbuf->b_visual.vi_start = VIsual; | |
3344 curbuf->b_visual.vi_end = curwin->w_cursor; | |
3345 curbuf->b_visual.vi_curswant = curwin->w_curswant; | |
7 | 3346 #ifdef FEAT_EVAL |
3347 curbuf->b_visual_mode_eval = VIsual_mode; | |
3348 #endif | |
3349 #ifdef FEAT_VIRTUALEDIT | |
3350 if (!virtual_active()) | |
3351 curwin->w_cursor.coladd = 0; | |
3352 #endif | |
6979 | 3353 may_clear_cmdline(); |
7 | 3354 |
844 | 3355 adjust_cursor_eol(); |
7 | 3356 } |
3357 | |
3358 /* | |
3359 * Reset VIsual_active and VIsual_reselect. | |
3360 */ | |
3361 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3362 reset_VIsual_and_resel(void) |
7 | 3363 { |
3364 if (VIsual_active) | |
3365 { | |
3366 end_visual_mode(); | |
3367 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
3368 } | |
3369 VIsual_reselect = FALSE; | |
3370 } | |
3371 | |
3372 /* | |
3373 * Reset VIsual_active and VIsual_reselect if it's set. | |
3374 */ | |
3375 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3376 reset_VIsual(void) |
7 | 3377 { |
3378 if (VIsual_active) | |
3379 { | |
3380 end_visual_mode(); | |
3381 redraw_curbuf_later(INVERTED); /* delete the inversion later */ | |
3382 VIsual_reselect = FALSE; | |
3383 } | |
3384 } | |
3385 | |
3386 /* | |
3387 * Check for a balloon-eval special item to include when searching for an | |
3388 * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid! | |
3389 * Returns TRUE if the character at "*ptr" should be included. | |
3390 * "dir" is FORWARD or BACKWARD, the direction of searching. | |
3391 * "*colp" is in/decremented if "ptr[-dir]" should also be included. | |
3392 * "bnp" points to a counter for square brackets. | |
3393 */ | |
3394 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3395 find_is_eval_item( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3396 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3397 int *colp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3398 int *bnp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3399 int dir) |
7 | 3400 { |
3401 /* Accept everything inside []. */ | |
3402 if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD)) | |
3403 ++*bnp; | |
3404 if (*bnp > 0) | |
3405 { | |
3406 if ((*ptr == '[' && dir == BACKWARD) || (*ptr == ']' && dir == FORWARD)) | |
3407 --*bnp; | |
3408 return TRUE; | |
3409 } | |
3410 | |
3411 /* skip over "s.var" */ | |
3412 if (*ptr == '.') | |
3413 return TRUE; | |
3414 | |
3415 /* two-character item: s->var */ | |
3416 if (ptr[dir == BACKWARD ? 0 : 1] == '>' | |
3417 && ptr[dir == BACKWARD ? -1 : 0] == '-') | |
3418 { | |
3419 *colp += dir; | |
3420 return TRUE; | |
3421 } | |
3422 return FALSE; | |
3423 } | |
3424 | |
3425 /* | |
3426 * Find the identifier under or to the right of the cursor. | |
3427 * "find_type" can have one of three values: | |
3428 * FIND_IDENT: find an identifier (keyword) | |
3429 * FIND_STRING: find any non-white string | |
3430 * FIND_IDENT + FIND_STRING: find any non-white string, identifier preferred. | |
184 | 3431 * FIND_EVAL: find text useful for C program debugging |
7 | 3432 * |
3433 * There are three steps: | |
3434 * 1. Search forward for the start of an identifier/string. Doesn't move if | |
3435 * already on one. | |
3436 * 2. Search backward for the start of this identifier/string. | |
3437 * This doesn't match the real Vi but I like it a little better and it | |
3438 * shouldn't bother anyone. | |
3439 * 3. Search forward to the end of this identifier/string. | |
3440 * When FIND_IDENT isn't defined, we backup until a blank. | |
3441 * | |
3442 * Returns the length of the string, or zero if no string is found. | |
3443 * If a string is found, a pointer to the string is put in "*string". This | |
3444 * string is not always NUL terminated. | |
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_under_cursor(char_u **string, int find_type) |
7 | 3448 { |
3449 return find_ident_at_pos(curwin, curwin->w_cursor.lnum, | |
3450 curwin->w_cursor.col, string, find_type); | |
3451 } | |
3452 | |
3453 /* | |
3454 * Like find_ident_under_cursor(), but for any window and any position. | |
3455 * However: Uses 'iskeyword' from the current window!. | |
3456 */ | |
3457 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3458 find_ident_at_pos( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3459 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3460 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3461 colnr_T startcol, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3462 char_u **string, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3463 int find_type) |
7 | 3464 { |
3465 char_u *ptr; | |
3466 int col = 0; /* init to shut up GCC */ | |
3467 int i; | |
3468 #ifdef FEAT_MBYTE | |
3469 int this_class = 0; | |
3470 int prev_class; | |
3471 int prevcol; | |
3472 #endif | |
3473 int bn = 0; /* bracket nesting */ | |
3474 | |
3475 /* | |
3476 * if i == 0: try to find an identifier | |
3477 * if i == 1: try to find any non-white string | |
3478 */ | |
3479 ptr = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3480 for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; ++i) | |
3481 { | |
3482 /* | |
3483 * 1. skip to start of identifier/string | |
3484 */ | |
3485 col = startcol; | |
3486 #ifdef FEAT_MBYTE | |
3487 if (has_mbyte) | |
3488 { | |
3489 while (ptr[col] != NUL) | |
3490 { | |
3491 /* Stop at a ']' to evaluate "a[x]". */ | |
3492 if ((find_type & FIND_EVAL) && ptr[col] == ']') | |
3493 break; | |
3494 this_class = mb_get_class(ptr + col); | |
3495 if (this_class != 0 && (i == 1 || this_class != 1)) | |
3496 break; | |
474 | 3497 col += (*mb_ptr2len)(ptr + col); |
7 | 3498 } |
3499 } | |
3500 else | |
3501 #endif | |
3502 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
|
3503 && (i == 0 ? !vim_iswordc(ptr[col]) : VIM_ISWHITE(ptr[col])) |
7 | 3504 && (!(find_type & FIND_EVAL) || ptr[col] != ']') |
3505 ) | |
3506 ++col; | |
3507 | |
3508 /* When starting on a ']' count it, so that we include the '['. */ | |
3509 bn = ptr[col] == ']'; | |
3510 | |
3511 /* | |
3512 * 2. Back up to start of identifier/string. | |
3513 */ | |
3514 #ifdef FEAT_MBYTE | |
3515 if (has_mbyte) | |
3516 { | |
3517 /* Remember class of character under cursor. */ | |
3518 if ((find_type & FIND_EVAL) && ptr[col] == ']') | |
3519 this_class = mb_get_class((char_u *)"a"); | |
3520 else | |
3521 this_class = mb_get_class(ptr + col); | |
835 | 3522 while (col > 0 && this_class != 0) |
7 | 3523 { |
3524 prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1); | |
3525 prev_class = mb_get_class(ptr + prevcol); | |
3526 if (this_class != prev_class | |
3527 && (i == 0 | |
3528 || prev_class == 0 | |
3529 || (find_type & FIND_IDENT)) | |
3530 && (!(find_type & FIND_EVAL) | |
3531 || prevcol == 0 | |
3532 || !find_is_eval_item(ptr + prevcol, &prevcol, | |
3533 &bn, BACKWARD)) | |
3534 ) | |
3535 break; | |
3536 col = prevcol; | |
3537 } | |
3538 | |
3539 /* If we don't want just any old string, or we've found an | |
3540 * identifier, stop searching. */ | |
3541 if (this_class > 2) | |
3542 this_class = 2; | |
3543 if (!(find_type & FIND_STRING) || this_class == 2) | |
3544 break; | |
3545 } | |
3546 else | |
3547 #endif | |
3548 { | |
3549 while (col > 0 | |
3550 && ((i == 0 | |
3551 ? 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
|
3552 : (!VIM_ISWHITE(ptr[col - 1]) |
7 | 3553 && (!(find_type & FIND_IDENT) |
3554 || !vim_iswordc(ptr[col - 1])))) | |
3555 || ((find_type & FIND_EVAL) | |
3556 && col > 1 | |
3557 && find_is_eval_item(ptr + col - 1, &col, | |
3558 &bn, BACKWARD)) | |
3559 )) | |
3560 --col; | |
3561 | |
3562 /* If we don't want just any old string, or we've found an | |
3563 * identifier, stop searching. */ | |
3564 if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col])) | |
3565 break; | |
3566 } | |
3567 } | |
3568 | |
3569 if (ptr[col] == NUL || (i == 0 && ( | |
3570 #ifdef FEAT_MBYTE | |
3571 has_mbyte ? this_class != 2 : | |
3572 #endif | |
3573 !vim_iswordc(ptr[col])))) | |
3574 { | |
3575 /* | |
3576 * didn't find an identifier or string | |
3577 */ | |
3578 if (find_type & FIND_STRING) | |
3579 EMSG(_("E348: No string under cursor")); | |
3580 else | |
1728 | 3581 EMSG(_(e_noident)); |
7 | 3582 return 0; |
3583 } | |
3584 ptr += col; | |
3585 *string = ptr; | |
3586 | |
3587 /* | |
3588 * 3. Find the end if the identifier/string. | |
3589 */ | |
3590 bn = 0; | |
3591 startcol -= col; | |
3592 col = 0; | |
3593 #ifdef FEAT_MBYTE | |
3594 if (has_mbyte) | |
3595 { | |
3596 /* Search for point of changing multibyte character class. */ | |
3597 this_class = mb_get_class(ptr); | |
3598 while (ptr[col] != NUL | |
3599 && ((i == 0 ? mb_get_class(ptr + col) == this_class | |
3600 : mb_get_class(ptr + col) != 0) | |
3601 || ((find_type & FIND_EVAL) | |
3602 && col <= (int)startcol | |
3603 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
3604 )) | |
474 | 3605 col += (*mb_ptr2len)(ptr + col); |
7 | 3606 } |
3607 else | |
3608 #endif | |
3609 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
|
3610 : (ptr[col] != NUL && !VIM_ISWHITE(ptr[col]))) |
7 | 3611 || ((find_type & FIND_EVAL) |
3612 && col <= (int)startcol | |
3613 && find_is_eval_item(ptr + col, &col, &bn, FORWARD)) | |
3614 ) | |
3615 { | |
3616 ++col; | |
3617 } | |
3618 | |
3619 return col; | |
3620 } | |
3621 | |
3622 /* | |
3623 * Prepare for redo of a normal command. | |
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_cmd(cmdarg_T *cap) |
7 | 3627 { |
3628 prep_redo(cap->oap->regname, cap->count0, | |
3629 NUL, cap->cmdchar, NUL, NUL, cap->nchar); | |
3630 } | |
3631 | |
3632 /* | |
3633 * Prepare for redo of any command. | |
3634 * Note that only the last argument can be a multi-byte char. | |
3635 */ | |
3636 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3637 prep_redo( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3638 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3639 long num, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3640 int cmd1, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3641 int cmd2, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3642 int cmd3, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3643 int cmd4, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3644 int cmd5) |
7 | 3645 { |
3646 ResetRedobuff(); | |
3647 if (regname != 0) /* yank from specified buffer */ | |
3648 { | |
3649 AppendCharToRedobuff('"'); | |
3650 AppendCharToRedobuff(regname); | |
3651 } | |
3652 if (num) | |
3653 AppendNumberToRedobuff(num); | |
3654 | |
3655 if (cmd1 != NUL) | |
3656 AppendCharToRedobuff(cmd1); | |
3657 if (cmd2 != NUL) | |
3658 AppendCharToRedobuff(cmd2); | |
3659 if (cmd3 != NUL) | |
3660 AppendCharToRedobuff(cmd3); | |
3661 if (cmd4 != NUL) | |
3662 AppendCharToRedobuff(cmd4); | |
3663 if (cmd5 != NUL) | |
3664 AppendCharToRedobuff(cmd5); | |
3665 } | |
3666 | |
3667 /* | |
3668 * check for operator active and clear it | |
3669 * | |
3670 * return TRUE if operator was active | |
3671 */ | |
3672 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3673 checkclearop(oparg_T *oap) |
7 | 3674 { |
3675 if (oap->op_type == OP_NOP) | |
3676 return FALSE; | |
3677 clearopbeep(oap); | |
3678 return TRUE; | |
3679 } | |
3680 | |
3681 /* | |
1131 | 3682 * Check for operator or Visual active. Clear active operator. |
7 | 3683 * |
1131 | 3684 * Return TRUE if operator or Visual was active. |
7 | 3685 */ |
3686 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3687 checkclearopq(oparg_T *oap) |
7 | 3688 { |
5735 | 3689 if (oap->op_type == OP_NOP && !VIsual_active) |
7 | 3690 return FALSE; |
3691 clearopbeep(oap); | |
3692 return TRUE; | |
3693 } | |
3694 | |
3695 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3696 clearop(oparg_T *oap) |
7 | 3697 { |
3698 oap->op_type = OP_NOP; | |
3699 oap->regname = 0; | |
3700 oap->motion_force = NUL; | |
3701 oap->use_reg_one = FALSE; | |
3702 } | |
3703 | |
3704 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3705 clearopbeep(oparg_T *oap) |
7 | 3706 { |
3707 clearop(oap); | |
3708 beep_flush(); | |
3709 } | |
3710 | |
3711 /* | |
3712 * Remove the shift modifier from a special key. | |
3713 */ | |
3714 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3715 unshift_special(cmdarg_T *cap) |
7 | 3716 { |
3717 switch (cap->cmdchar) | |
3718 { | |
3719 case K_S_RIGHT: cap->cmdchar = K_RIGHT; break; | |
3720 case K_S_LEFT: cap->cmdchar = K_LEFT; break; | |
3721 case K_S_UP: cap->cmdchar = K_UP; break; | |
3722 case K_S_DOWN: cap->cmdchar = K_DOWN; break; | |
3723 case K_S_HOME: cap->cmdchar = K_HOME; break; | |
3724 case K_S_END: cap->cmdchar = K_END; break; | |
3725 } | |
3726 cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask); | |
3727 } | |
3728 | |
6979 | 3729 /* |
3730 * If the mode is currently displayed clear the command line or update the | |
3731 * command displayed. | |
3732 */ | |
3733 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3734 may_clear_cmdline(void) |
6979 | 3735 { |
3736 if (mode_displayed) | |
3737 clear_cmdline = TRUE; /* unshow visual mode later */ | |
3738 #ifdef FEAT_CMDL_INFO | |
3739 else | |
3740 clear_showcmd(); | |
3741 #endif | |
3742 } | |
3743 | |
7 | 3744 #if defined(FEAT_CMDL_INFO) || defined(PROTO) |
3745 /* | |
3746 * Routines for displaying a partly typed command | |
3747 */ | |
3748 | |
5735 | 3749 #define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30 |
7 | 3750 static char_u showcmd_buf[SHOWCMD_BUFLEN]; |
3751 static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */ | |
3752 static int showcmd_is_clear = TRUE; | |
3753 static int showcmd_visual = FALSE; | |
3754 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7703
diff
changeset
|
3755 static void display_showcmd(void); |
7 | 3756 |
3757 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3758 clear_showcmd(void) |
7 | 3759 { |
3760 if (!p_sc) | |
3761 return; | |
3762 | |
3763 if (VIsual_active && !char_avail()) | |
3764 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
3765 int cursor_bot = LT_POS(VIsual, curwin->w_cursor); |
7 | 3766 long lines; |
3767 colnr_T leftcol, rightcol; | |
3768 linenr_T top, bot; | |
3769 | |
3770 /* Show the size of the Visual area. */ | |
1866 | 3771 if (cursor_bot) |
7 | 3772 { |
3773 top = VIsual.lnum; | |
3774 bot = curwin->w_cursor.lnum; | |
3775 } | |
3776 else | |
3777 { | |
3778 top = curwin->w_cursor.lnum; | |
3779 bot = VIsual.lnum; | |
3780 } | |
3781 # ifdef FEAT_FOLDING | |
3782 /* Include closed folds as a whole. */ | |
7009 | 3783 (void)hasFolding(top, &top, NULL); |
3784 (void)hasFolding(bot, NULL, &bot); | |
7 | 3785 # endif |
3786 lines = bot - top + 1; | |
3787 | |
3788 if (VIsual_mode == Ctrl_V) | |
3789 { | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3790 # ifdef FEAT_LINEBREAK |
1866 | 3791 char_u *saved_sbr = p_sbr; |
3792 | |
3793 /* Make 'sbr' empty for a moment to get the correct size. */ | |
3794 p_sbr = empty_option; | |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3795 # endif |
7 | 3796 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
|
3797 # ifdef FEAT_LINEBREAK |
1866 | 3798 p_sbr = saved_sbr; |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3799 # endif |
7 | 3800 sprintf((char *)showcmd_buf, "%ldx%ld", lines, |
3801 (long)(rightcol - leftcol + 1)); | |
3802 } | |
3803 else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum) | |
3804 sprintf((char *)showcmd_buf, "%ld", lines); | |
3805 else | |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3806 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3807 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
|
3808 int l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3809 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
|
3810 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
|
3811 |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3812 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
|
3813 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3814 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
|
3815 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
|
3816 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3817 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3818 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3819 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
|
3820 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
|
3821 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3822 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
|
3823 { |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3824 # 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
|
3825 l = (*mb_ptr2len)(s); |
2335
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3826 # else |
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3827 l = (*s == NUL) ? 0 : 1; |
2a5478294078
Fix build broken without multi-byte feature.
Bram Moolenaar <bram@vim.org>
parents:
2326
diff
changeset
|
3828 # endif |
2324
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3829 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
|
3830 { |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3831 ++bytes; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3832 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3833 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
|
3834 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3835 bytes += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3836 ++chars; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3837 s += l; |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3838 } |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3839 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
|
3840 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
|
3841 else |
0a258a67051d
In Visual mode with 'showcmd' display the number of bytes and characters.
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
3842 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
|
3843 } |
7 | 3844 showcmd_buf[SHOWCMD_COLS] = NUL; /* truncate */ |
3845 showcmd_visual = TRUE; | |
3846 } | |
3847 else | |
3848 { | |
3849 showcmd_buf[0] = NUL; | |
3850 showcmd_visual = FALSE; | |
3851 | |
3852 /* Don't actually display something if there is nothing to clear. */ | |
3853 if (showcmd_is_clear) | |
3854 return; | |
3855 } | |
3856 | |
3857 display_showcmd(); | |
3858 } | |
3859 | |
3860 /* | |
3861 * Add 'c' to string of shown command chars. | |
3862 * Return TRUE if output has been written (and setcursor() has been called). | |
3863 */ | |
3864 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3865 add_to_showcmd(int c) |
7 | 3866 { |
3867 char_u *p; | |
3868 int old_len; | |
3869 int extra_len; | |
3870 int overflow; | |
3871 #if defined(FEAT_MOUSE) | |
3872 int i; | |
3873 static int ignore[] = | |
3874 { | |
660 | 3875 # ifdef FEAT_GUI |
7 | 3876 K_VER_SCROLLBAR, K_HOR_SCROLLBAR, |
3877 K_LEFTMOUSE_NM, K_LEFTRELEASE_NM, | |
660 | 3878 # endif |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
3879 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
|
3880 K_LEFTMOUSE, K_LEFTDRAG, K_LEFTRELEASE, K_MOUSEMOVE, |
7 | 3881 K_MIDDLEMOUSE, K_MIDDLEDRAG, K_MIDDLERELEASE, |
3882 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
|
3883 K_MOUSEDOWN, K_MOUSEUP, K_MOUSELEFT, K_MOUSERIGHT, |
7 | 3884 K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE, |
631 | 3885 K_CURSORHOLD, |
7 | 3886 0 |
3887 }; | |
3888 #endif | |
3889 | |
641 | 3890 if (!p_sc || msg_silent != 0) |
7 | 3891 return FALSE; |
3892 | |
3893 if (showcmd_visual) | |
3894 { | |
3895 showcmd_buf[0] = NUL; | |
3896 showcmd_visual = FALSE; | |
3897 } | |
3898 | |
3899 #if defined(FEAT_MOUSE) | |
3900 /* Ignore keys that are scrollbar updates and mouse clicks */ | |
3901 if (IS_SPECIAL(c)) | |
3902 for (i = 0; ignore[i] != 0; ++i) | |
3903 if (ignore[i] == c) | |
3904 return FALSE; | |
3905 #endif | |
3906 | |
3907 p = transchar(c); | |
5535 | 3908 if (*p == ' ') |
3909 STRCPY(p, "<20>"); | |
7 | 3910 old_len = (int)STRLEN(showcmd_buf); |
3911 extra_len = (int)STRLEN(p); | |
3912 overflow = old_len + extra_len - SHOWCMD_COLS; | |
3913 if (overflow > 0) | |
1362 | 3914 mch_memmove(showcmd_buf, showcmd_buf + overflow, |
3915 old_len - overflow + 1); | |
7 | 3916 STRCAT(showcmd_buf, p); |
3917 | |
3918 if (char_avail()) | |
3919 return FALSE; | |
3920 | |
3921 display_showcmd(); | |
3922 | |
3923 return TRUE; | |
3924 } | |
3925 | |
3926 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3927 add_to_showcmd_c(int c) |
7 | 3928 { |
3929 if (!add_to_showcmd(c)) | |
3930 setcursor(); | |
3931 } | |
3932 | |
3933 /* | |
3934 * Delete 'len' characters from the end of the shown command. | |
3935 */ | |
3936 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3937 del_from_showcmd(int len) |
7 | 3938 { |
3939 int old_len; | |
3940 | |
3941 if (!p_sc) | |
3942 return; | |
3943 | |
3944 old_len = (int)STRLEN(showcmd_buf); | |
3945 if (len > old_len) | |
3946 len = old_len; | |
3947 showcmd_buf[old_len - len] = NUL; | |
3948 | |
3949 if (!char_avail()) | |
3950 display_showcmd(); | |
3951 } | |
3952 | |
3953 /* | |
3954 * push_showcmd() and pop_showcmd() are used when waiting for the user to type | |
3955 * something and there is a partial mapping. | |
3956 */ | |
3957 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3958 push_showcmd(void) |
7 | 3959 { |
3960 if (p_sc) | |
3961 STRCPY(old_showcmd_buf, showcmd_buf); | |
3962 } | |
3963 | |
3964 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3965 pop_showcmd(void) |
7 | 3966 { |
3967 if (!p_sc) | |
3968 return; | |
3969 | |
3970 STRCPY(showcmd_buf, old_showcmd_buf); | |
3971 | |
3972 display_showcmd(); | |
3973 } | |
3974 | |
3975 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3976 display_showcmd(void) |
7 | 3977 { |
3978 int len; | |
3979 | |
3980 cursor_off(); | |
3981 | |
3982 len = (int)STRLEN(showcmd_buf); | |
3983 if (len == 0) | |
3984 showcmd_is_clear = TRUE; | |
3985 else | |
3986 { | |
3987 screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0); | |
3988 showcmd_is_clear = FALSE; | |
3989 } | |
3990 | |
3991 /* | |
1188 | 3992 * clear the rest of an old message by outputting up to SHOWCMD_COLS |
3993 * spaces | |
7 | 3994 */ |
3995 screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0); | |
3996 | |
3997 setcursor(); /* put cursor back where it belongs */ | |
3998 } | |
3999 #endif | |
4000 | |
4001 #ifdef FEAT_SCROLLBIND | |
4002 /* | |
4003 * When "check" is FALSE, prepare for commands that scroll the window. | |
4004 * When "check" is TRUE, take care of scroll-binding after the window has | |
4005 * scrolled. Called from normal_cmd() and edit(). | |
4006 */ | |
4007 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4008 do_check_scrollbind(int check) |
7 | 4009 { |
4010 static win_T *old_curwin = NULL; | |
4011 static linenr_T old_topline = 0; | |
4012 #ifdef FEAT_DIFF | |
4013 static int old_topfill = 0; | |
4014 #endif | |
4015 static buf_T *old_buf = NULL; | |
4016 static colnr_T old_leftcol = 0; | |
4017 | |
4018 if (check && curwin->w_p_scb) | |
4019 { | |
4020 /* If a ":syncbind" command was just used, don't scroll, only reset | |
4021 * the values. */ | |
4022 if (did_syncbind) | |
4023 did_syncbind = FALSE; | |
4024 else if (curwin == old_curwin) | |
4025 { | |
4026 /* | |
4027 * Synchronize other windows, as necessary according to | |
4028 * 'scrollbind'. Don't do this after an ":edit" command, except | |
4029 * when 'diff' is set. | |
4030 */ | |
4031 if ((curwin->w_buffer == old_buf | |
4032 #ifdef FEAT_DIFF | |
4033 || curwin->w_p_diff | |
4034 #endif | |
4035 ) | |
4036 && (curwin->w_topline != old_topline | |
4037 #ifdef FEAT_DIFF | |
4038 || curwin->w_topfill != old_topfill | |
4039 #endif | |
4040 || curwin->w_leftcol != old_leftcol)) | |
4041 { | |
4042 check_scrollbind(curwin->w_topline - old_topline, | |
4043 (long)(curwin->w_leftcol - old_leftcol)); | |
4044 } | |
4045 } | |
4046 else if (vim_strchr(p_sbo, 'j')) /* jump flag set in 'scrollopt' */ | |
4047 { | |
4048 /* | |
4049 * When switching between windows, make sure that the relative | |
4050 * vertical offset is valid for the new window. The relative | |
4051 * offset is invalid whenever another 'scrollbind' window has | |
4052 * scrolled to a point that would force the current window to | |
4053 * scroll past the beginning or end of its buffer. When the | |
4054 * resync is performed, some of the other 'scrollbind' windows may | |
4055 * need to jump so that the current window's relative position is | |
4056 * visible on-screen. | |
4057 */ | |
4058 check_scrollbind(curwin->w_topline - curwin->w_scbind_pos, 0L); | |
4059 } | |
4060 curwin->w_scbind_pos = curwin->w_topline; | |
4061 } | |
4062 | |
4063 old_curwin = curwin; | |
4064 old_topline = curwin->w_topline; | |
4065 #ifdef FEAT_DIFF | |
4066 old_topfill = curwin->w_topfill; | |
4067 #endif | |
4068 old_buf = curwin->w_buffer; | |
4069 old_leftcol = curwin->w_leftcol; | |
4070 } | |
4071 | |
4072 /* | |
4073 * Synchronize any windows that have "scrollbind" set, based on the | |
4074 * number of rows by which the current window has changed | |
4075 * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>) | |
4076 */ | |
4077 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4078 check_scrollbind(linenr_T topline_diff, long leftcol_diff) |
7 | 4079 { |
4080 int want_ver; | |
4081 int want_hor; | |
4082 win_T *old_curwin = curwin; | |
4083 buf_T *old_curbuf = curbuf; | |
4084 int old_VIsual_select = VIsual_select; | |
4085 int old_VIsual_active = VIsual_active; | |
4086 colnr_T tgt_leftcol = curwin->w_leftcol; | |
4087 long topline; | |
4088 long y; | |
4089 | |
4090 /* | |
4091 * check 'scrollopt' string for vertical and horizontal scroll options | |
4092 */ | |
4093 want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0); | |
4094 #ifdef FEAT_DIFF | |
4095 want_ver |= old_curwin->w_p_diff; | |
4096 #endif | |
4097 want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0)); | |
4098 | |
4099 /* | |
4100 * loop through the scrollbound windows and scroll accordingly | |
4101 */ | |
4102 VIsual_select = VIsual_active = 0; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9399
diff
changeset
|
4103 FOR_ALL_WINDOWS(curwin) |
7 | 4104 { |
4105 curbuf = curwin->w_buffer; | |
4106 /* skip original window and windows with 'noscrollbind' */ | |
4107 if (curwin != old_curwin && curwin->w_p_scb) | |
4108 { | |
4109 /* | |
4110 * do the vertical scroll | |
4111 */ | |
4112 if (want_ver) | |
4113 { | |
4114 #ifdef FEAT_DIFF | |
4115 if (old_curwin->w_p_diff && curwin->w_p_diff) | |
4116 { | |
4117 diff_set_topline(old_curwin, curwin); | |
4118 } | |
4119 else | |
4120 #endif | |
4121 { | |
4122 curwin->w_scbind_pos += topline_diff; | |
4123 topline = curwin->w_scbind_pos; | |
4124 if (topline > curbuf->b_ml.ml_line_count) | |
4125 topline = curbuf->b_ml.ml_line_count; | |
4126 if (topline < 1) | |
4127 topline = 1; | |
4128 | |
4129 y = topline - curwin->w_topline; | |
4130 if (y > 0) | |
4131 scrollup(y, FALSE); | |
4132 else | |
4133 scrolldown(-y, FALSE); | |
4134 } | |
4135 | |
4136 redraw_later(VALID); | |
4137 cursor_correct(); | |
4138 curwin->w_redr_status = TRUE; | |
4139 } | |
4140 | |
4141 /* | |
4142 * do the horizontal scroll | |
4143 */ | |
4144 if (want_hor && curwin->w_leftcol != tgt_leftcol) | |
4145 { | |
4146 curwin->w_leftcol = tgt_leftcol; | |
4147 leftcol_changed(); | |
4148 } | |
4149 } | |
4150 } | |
4151 | |
4152 /* | |
4153 * reset current-window | |
4154 */ | |
4155 VIsual_select = old_VIsual_select; | |
4156 VIsual_active = old_VIsual_active; | |
4157 curwin = old_curwin; | |
4158 curbuf = old_curbuf; | |
4159 } | |
4160 #endif /* #ifdef FEAT_SCROLLBIND */ | |
4161 | |
4162 /* | |
4163 * Command character that's ignored. | |
4164 * 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
|
4165 * xon/xoff. |
7 | 4166 */ |
4167 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4168 nv_ignore(cmdarg_T *cap) |
7 | 4169 { |
226 | 4170 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
7 | 4171 } |
4172 | |
4173 /* | |
620 | 4174 * Command character that doesn't do anything, but unlike nv_ignore() does |
4175 * start edit(). Used for "startinsert" executed while starting up. | |
4176 */ | |
4177 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4178 nv_nop(cmdarg_T *cap UNUSED) |
620 | 4179 { |
4180 } | |
4181 | |
4182 /* | |
7 | 4183 * Command character doesn't exist. |
4184 */ | |
4185 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4186 nv_error(cmdarg_T *cap) |
7 | 4187 { |
4188 clearopbeep(cap->oap); | |
4189 } | |
4190 | |
4191 /* | |
4192 * <Help> and <F1> commands. | |
4193 */ | |
4194 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4195 nv_help(cmdarg_T *cap) |
7 | 4196 { |
4197 if (!checkclearopq(cap->oap)) | |
4198 ex_help(NULL); | |
4199 } | |
4200 | |
4201 /* | |
4202 * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor. | |
4203 */ | |
4204 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4205 nv_addsub(cmdarg_T *cap) |
7 | 4206 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4207 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
|
4208 { |
7578
fdae4c496775
commit https://github.com/vim/vim/commit/ef2b5036b3005f1ce15d146dce72379a9834c56d
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
4209 prep_redo_cmd(cap); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4210 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
|
4211 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
|
4212 cap->oap->op_type = OP_NOP; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4213 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4214 else if (VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4215 nv_operator(cap); |
6868 | 4216 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
4217 clearop(cap->oap); |
7 | 4218 } |
4219 | |
4220 /* | |
4221 * CTRL-F, CTRL-B, etc: Scroll page up or down. | |
4222 */ | |
4223 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4224 nv_page(cmdarg_T *cap) |
7 | 4225 { |
4226 if (!checkclearop(cap->oap)) | |
819 | 4227 { |
4228 if (mod_mask & MOD_MASK_CTRL) | |
4229 { | |
4230 /* <C-PageUp>: tab page back; <C-PageDown>: tab page forward */ | |
4231 if (cap->arg == BACKWARD) | |
4232 goto_tabpage(-(int)cap->count1); | |
4233 else | |
4234 goto_tabpage((int)cap->count0); | |
4235 } | |
4236 else | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
4237 (void)onepage(cap->arg, cap->count1); |
819 | 4238 } |
7 | 4239 } |
4240 | |
4241 /* | |
4242 * Implementation of "gd" and "gD" command. | |
4243 */ | |
4244 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4245 nv_gd( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4246 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4247 int nchar, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4248 int thisblock) /* 1 for "1gd" and "1gD" */ |
7 | 4249 { |
4250 int len; | |
503 | 4251 char_u *ptr; |
4252 | |
4253 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
|
4254 || 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
|
4255 == FAIL) |
503 | 4256 clearopbeep(oap); |
4257 #ifdef FEAT_FOLDING | |
4258 else if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP) | |
4259 foldOpenCursor(); | |
4260 #endif | |
4261 } | |
4262 | |
4263 /* | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4264 * 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
|
4265 * otherwise. |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4266 */ |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4267 static int |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4268 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
|
4269 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4270 int i; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4271 int incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4272 int instring = 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4273 int prev = 0; |
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 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
|
4276 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4277 if (instring != 0) |
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] == instring) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4280 instring = 0; |
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 ((line[i] == '"' || line[i] == '\'') && !incomment) |
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 instring = line[i]; |
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 |
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 if (incomment) |
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 if (prev == '*' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4291 incomment = FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4292 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4293 else if (prev == '/' && line[i] == '*') |
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 incomment = TRUE; |
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 else if (prev == '/' && line[i] == '/') |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4298 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4299 return FALSE; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4300 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4301 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4302 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4303 prev = line[i]; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4304 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4305 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4306 return incomment == FALSE && instring == 0; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4307 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4308 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4309 /* |
523 | 4310 * Search for variable declaration of "ptr[len]". |
4311 * When "locally" is TRUE in the current function ("gd"), otherwise in the | |
4312 * current file ("gD"). | |
4313 * When "thisblock" is TRUE check the {} block scope. | |
503 | 4314 * Return FAIL when not found. |
4315 */ | |
4316 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4317 find_decl( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4318 char_u *ptr, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4319 int len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4320 int locally, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4321 int thisblock, |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4322 int flags_arg) /* flags passed to searchit() */ |
503 | 4323 { |
7 | 4324 char_u *pat; |
4325 pos_T old_pos; | |
503 | 4326 pos_T par_pos; |
4327 pos_T found_pos; | |
7 | 4328 int t; |
4329 int save_p_ws; | |
4330 int save_p_scs; | |
503 | 4331 int retval = OK; |
944 | 4332 int incll; |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4333 int searchflags = flags_arg; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4334 int valid; |
503 | 4335 |
4336 if ((pat = alloc(len + 7)) == NULL) | |
4337 return FAIL; | |
268 | 4338 |
4339 /* Put "\V" before the pattern to avoid that the special meaning of "." | |
4340 * and "~" causes trouble. */ | |
4341 sprintf((char *)pat, vim_iswordp(ptr) ? "\\V\\<%.*s\\>" : "\\V%.*s", | |
4342 len, ptr); | |
7 | 4343 old_pos = curwin->w_cursor; |
4344 save_p_ws = p_ws; | |
4345 save_p_scs = p_scs; | |
4346 p_ws = FALSE; /* don't wrap around end of file now */ | |
4347 p_scs = FALSE; /* don't switch ignorecase off now */ | |
4348 | |
4349 /* | |
4350 * With "gD" go to line 1. | |
4351 * With "gd" Search back for the start of the current function, then go | |
4352 * back until a blank line. If this fails go to line 1. | |
4353 */ | |
944 | 4354 if (!locally || !findpar(&incll, BACKWARD, 1L, '{', FALSE)) |
7 | 4355 { |
4356 setpcmark(); /* Set in findpar() otherwise */ | |
4357 curwin->w_cursor.lnum = 1; | |
539 | 4358 par_pos = curwin->w_cursor; |
7 | 4359 } |
4360 else | |
4361 { | |
539 | 4362 par_pos = curwin->w_cursor; |
7 | 4363 while (curwin->w_cursor.lnum > 1 && *skipwhite(ml_get_curline()) != NUL) |
4364 --curwin->w_cursor.lnum; | |
4365 } | |
4366 curwin->w_cursor.col = 0; | |
4367 | |
4368 /* 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
|
4369 CLEAR_POS(&found_pos); |
503 | 4370 for (;;) |
4371 { | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4372 valid = FALSE; |
503 | 4373 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
|
4374 pat, 1L, searchflags, RE_LAST, (linenr_T)0, NULL, NULL); |
503 | 4375 if (curwin->w_cursor.lnum >= old_pos.lnum) |
4376 t = FAIL; /* match after start is failure too */ | |
523 | 4377 |
718 | 4378 if (thisblock && t != FAIL) |
523 | 4379 { |
4380 pos_T *pos; | |
4381 | |
4382 /* Check that the block the match is in doesn't end before the | |
4383 * position where we started the search from. */ | |
4384 if ((pos = findmatchlimit(NULL, '}', FM_FORWARD, | |
4385 (int)(old_pos.lnum - curwin->w_cursor.lnum + 1))) != NULL | |
4386 && pos->lnum < old_pos.lnum) | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4387 { |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4388 /* 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
|
4389 * Skip to the end. */ |
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4390 curwin->w_cursor = *pos; |
523 | 4391 continue; |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
4392 } |
523 | 4393 } |
4394 | |
503 | 4395 if (t == FAIL) |
4396 { | |
4397 /* If we previously found a valid position, use it. */ | |
4398 if (found_pos.lnum != 0) | |
4399 { | |
4400 curwin->w_cursor = found_pos; | |
4401 t = OK; | |
4402 } | |
4403 break; | |
4404 } | |
7 | 4405 #ifdef FEAT_COMMENTS |
3562 | 4406 if (get_leader_len(ml_get_curline(), NULL, FALSE, TRUE) > 0) |
503 | 4407 { |
4408 /* Ignore this line, continue at start of next line. */ | |
4409 ++curwin->w_cursor.lnum; | |
4410 curwin->w_cursor.col = 0; | |
4411 continue; | |
4412 } | |
4413 #endif | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4414 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
|
4415 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4416 /* 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
|
4417 * 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
|
4418 if (!valid && found_pos.lnum != 0) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4419 { |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4420 curwin->w_cursor = found_pos; |
503 | 4421 break; |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4422 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4423 |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4424 /* 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
|
4425 if (valid && !locally) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4426 break; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4427 if (valid && curwin->w_cursor.lnum >= par_pos.lnum) |
503 | 4428 { |
4429 /* If we previously found a valid position, use it. */ | |
4430 if (found_pos.lnum != 0) | |
4431 curwin->w_cursor = found_pos; | |
4432 break; | |
4433 } | |
4434 | |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4435 /* 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
|
4436 * 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
|
4437 * 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
|
4438 if (!valid) |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4439 { |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
4440 CLEAR_POS(&found_pos); |
10251
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4441 } |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4442 else |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4443 found_pos = curwin->w_cursor; |
bc442c2296a7
commit https://github.com/vim/vim/commit/226630a030c0d41145e1109f09633360fc9c999d
Christian Brabandt <cb@256bit.org>
parents:
10192
diff
changeset
|
4444 /* 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
|
4445 * position. */ |
9315
1b4946fa3777
commit https://github.com/vim/vim/commit/23c60f21b07b04351d846e6fbf4f4abd9aa09345
Christian Brabandt <cb@256bit.org>
parents:
9098
diff
changeset
|
4446 searchflags &= ~SEARCH_START; |
503 | 4447 } |
4448 | |
4449 if (t == FAIL) | |
4450 { | |
4451 retval = FAIL; | |
7 | 4452 curwin->w_cursor = old_pos; |
4453 } | |
4454 else | |
4455 { | |
4456 curwin->w_set_curswant = TRUE; | |
4457 /* "n" searches forward now */ | |
4458 reset_search_dir(); | |
4459 } | |
4460 | |
4461 vim_free(pat); | |
4462 p_ws = save_p_ws; | |
4463 p_scs = save_p_scs; | |
503 | 4464 |
4465 return retval; | |
7 | 4466 } |
4467 | |
4468 /* | |
4469 * Move 'dist' lines in direction 'dir', counting lines by *screen* | |
4470 * lines rather than lines in the file. | |
4471 * 'dist' must be positive. | |
4472 * | |
4473 * Return OK if able to move cursor, FAIL otherwise. | |
4474 */ | |
4475 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4476 nv_screengo(oparg_T *oap, int dir, long dist) |
7 | 4477 { |
4478 int linelen = linetabsize(ml_get_curline()); | |
4479 int retval = OK; | |
4480 int atend = FALSE; | |
4481 int n; | |
4482 int col_off1; /* margin offset for first screen line */ | |
4483 int col_off2; /* margin offset for wrapped screen line */ | |
4484 int width1; /* text width for first screen line */ | |
4485 int width2; /* test width for wrapped screen line */ | |
4486 | |
4487 oap->motion_type = MCHAR; | |
5192
c28202427d71
updated for version 7.4a.022
Bram Moolenaar <bram@vim.org>
parents:
5162
diff
changeset
|
4488 oap->inclusive = (curwin->w_curswant == MAXCOL); |
7 | 4489 |
4490 col_off1 = curwin_col_off(); | |
4491 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
|
4492 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
|
4493 width2 = curwin->w_width - col_off2; |
6559 | 4494 if (width2 == 0) |
4495 width2 = 1; /* avoid divide by zero */ | |
7 | 4496 |
4497 if (curwin->w_width != 0) | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4498 { |
7 | 4499 /* |
4500 * Instead of sticking at the last character of the buffer line we | |
4501 * try to stick in the last column of the screen. | |
4502 */ | |
4503 if (curwin->w_curswant == MAXCOL) | |
4504 { | |
4505 atend = TRUE; | |
4506 validate_virtcol(); | |
4507 if (width1 <= 0) | |
4508 curwin->w_curswant = 0; | |
4509 else | |
4510 { | |
4511 curwin->w_curswant = width1 - 1; | |
4512 if (curwin->w_virtcol > curwin->w_curswant) | |
4513 curwin->w_curswant += ((curwin->w_virtcol | |
4514 - curwin->w_curswant - 1) / width2 + 1) * width2; | |
4515 } | |
4516 } | |
4517 else | |
4518 { | |
4519 if (linelen > width1) | |
4520 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
4521 else | |
4522 n = width1; | |
4523 if (curwin->w_curswant > (colnr_T)n + 1) | |
4524 curwin->w_curswant -= ((curwin->w_curswant - n) / width2 + 1) | |
4525 * width2; | |
4526 } | |
4527 | |
4528 while (dist--) | |
4529 { | |
4530 if (dir == BACKWARD) | |
4531 { | |
4532 if ((long)curwin->w_curswant >= width2) | |
4533 /* move back within line */ | |
4534 curwin->w_curswant -= width2; | |
4535 else | |
4536 { | |
4537 /* to previous line */ | |
4538 if (curwin->w_cursor.lnum == 1) | |
4539 { | |
4540 retval = FAIL; | |
4541 break; | |
4542 } | |
4543 --curwin->w_cursor.lnum; | |
4544 #ifdef FEAT_FOLDING | |
4545 /* Move to the start of a closed fold. Don't do that when | |
4546 * 'foldopen' contains "all": it will open in a moment. */ | |
4547 if (!(fdo_flags & FDO_ALL)) | |
4548 (void)hasFolding(curwin->w_cursor.lnum, | |
4549 &curwin->w_cursor.lnum, NULL); | |
4550 #endif | |
4551 linelen = linetabsize(ml_get_curline()); | |
4552 if (linelen > width1) | |
4553 curwin->w_curswant += (((linelen - width1 - 1) / width2) | |
4554 + 1) * width2; | |
4555 } | |
4556 } | |
4557 else /* dir == FORWARD */ | |
4558 { | |
4559 if (linelen > width1) | |
4560 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1; | |
4561 else | |
4562 n = width1; | |
4563 if (curwin->w_curswant + width2 < (colnr_T)n) | |
4564 /* move forward within line */ | |
4565 curwin->w_curswant += width2; | |
4566 else | |
4567 { | |
4568 /* to next line */ | |
4569 #ifdef FEAT_FOLDING | |
4570 /* Move to the end of a closed fold. */ | |
4571 (void)hasFolding(curwin->w_cursor.lnum, NULL, | |
4572 &curwin->w_cursor.lnum); | |
4573 #endif | |
4574 if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
4575 { | |
4576 retval = FAIL; | |
4577 break; | |
4578 } | |
4579 curwin->w_cursor.lnum++; | |
4580 curwin->w_curswant %= width2; | |
2911 | 4581 linelen = linetabsize(ml_get_curline()); |
7 | 4582 } |
4583 } | |
4584 } | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8445
diff
changeset
|
4585 } |
7 | 4586 |
5600 | 4587 if (virtual_active() && atend) |
4588 coladvance(MAXCOL); | |
4589 else | |
4590 coladvance(curwin->w_curswant); | |
7 | 4591 |
4592 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE) | |
4593 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
4594 { | |
6178 | 4595 colnr_T virtcol; |
4596 | |
7 | 4597 /* |
4598 * Check for landing on a character that got split at the end of the | |
4599 * last line. We want to advance a screenline, not end up in the same | |
4600 * screenline or move two screenlines. | |
4601 */ | |
4602 validate_virtcol(); | |
6178 | 4603 virtcol = curwin->w_virtcol; |
6187 | 4604 # if defined(FEAT_LINEBREAK) |
6178 | 4605 if (virtcol > (colnr_T)width1 && *p_sbr != NUL) |
4606 virtcol -= vim_strsize(p_sbr); | |
6187 | 4607 # endif |
6178 | 4608 |
4609 if (virtcol > curwin->w_curswant | |
7 | 4610 && (curwin->w_curswant < (colnr_T)width1 |
4611 ? (curwin->w_curswant > (colnr_T)width1 / 2) | |
4612 : ((curwin->w_curswant - width1) % width2 | |
4613 > (colnr_T)width2 / 2))) | |
4614 --curwin->w_cursor.col; | |
4615 } | |
4616 #endif | |
4617 | |
4618 if (atend) | |
4619 curwin->w_curswant = MAXCOL; /* stick in the last column */ | |
4620 | |
4621 return retval; | |
4622 } | |
4623 | |
4624 #ifdef FEAT_MOUSE | |
4625 /* | |
4626 * Mouse scroll wheel: Default action is to scroll three lines, or one page | |
4627 * 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
|
4628 * 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
|
4629 * K_MOUSELEFT (cap->arg == -1) or K_MOUSERIGHT (cap->arg == -2) |
7 | 4630 */ |
4631 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4632 nv_mousescroll(cmdarg_T *cap) |
7 | 4633 { |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4634 win_T *old_curwin = curwin, *wp; |
7 | 4635 |
4162 | 4636 if (mouse_row >= 0 && mouse_col >= 0) |
7 | 4637 { |
4638 int row, col; | |
4639 | |
4640 row = mouse_row; | |
4641 col = mouse_col; | |
4642 | |
4643 /* 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
|
4644 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
|
4645 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
|
4646 return; |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12134
diff
changeset
|
4647 curwin = wp; |
7 | 4648 curbuf = curwin->w_buffer; |
4649 } | |
4650 | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4651 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
|
4652 { |
11983
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4653 # 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
|
4654 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
|
4655 /* 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
|
4656 * 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
|
4657 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
|
4658 else |
448635f73e09
patch 8.0.0872: no mouse scroll with a terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
4659 # endif |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4660 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
|
4661 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4662 (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
|
4663 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4664 else |
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 cap->count1 = 3; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4667 cap->count0 = 3; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4668 nv_scroll_line(cap); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4669 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4670 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4671 # ifdef FEAT_GUI |
7 | 4672 else |
4673 { | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4674 /* 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
|
4675 if (!curwin->w_p_wrap) |
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 int val, step = 6; |
2416
1a9c16dd76d4
Fix compiler warnings on 64 bit systems.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4678 |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4679 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
|
4680 step = curwin->w_width; |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4681 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
|
4682 if (val < 0) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4683 val = 0; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4684 |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4685 gui_do_horiz_scroll(val, TRUE); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4686 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4687 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4688 # endif |
7 | 4689 |
4690 curwin->w_redr_status = TRUE; | |
4691 | |
4692 curwin = old_curwin; | |
4693 curbuf = curwin->w_buffer; | |
4694 } | |
4695 | |
4696 /* | |
4697 * Mouse clicks and drags. | |
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_mouse(cmdarg_T *cap) |
7 | 4701 { |
4702 (void)do_mouse(cap->oap, cap->cmdchar, BACKWARD, cap->count1, 0); | |
4703 } | |
4704 #endif | |
4705 | |
4706 /* | |
4707 * Handle CTRL-E and CTRL-Y commands: scroll a line up or down. | |
4708 * cap->arg must be TRUE for CTRL-E. | |
4709 */ | |
4710 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4711 nv_scroll_line(cmdarg_T *cap) |
7 | 4712 { |
4713 if (!checkclearop(cap->oap)) | |
4714 scroll_redraw(cap->arg, cap->count1); | |
4715 } | |
4716 | |
4717 /* | |
4718 * Scroll "count" lines up or down, and redraw. | |
4719 */ | |
4720 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4721 scroll_redraw(int up, long count) |
7 | 4722 { |
4723 linenr_T prev_topline = curwin->w_topline; | |
4724 #ifdef FEAT_DIFF | |
4725 int prev_topfill = curwin->w_topfill; | |
4726 #endif | |
4727 linenr_T prev_lnum = curwin->w_cursor.lnum; | |
4728 | |
4729 if (up) | |
4730 scrollup(count, TRUE); | |
4731 else | |
4732 scrolldown(count, TRUE); | |
4733 if (p_so) | |
4734 { | |
4735 /* Adjust the cursor position for 'scrolloff'. Mark w_topline as | |
4736 * valid, otherwise the screen jumps back at the end of the file. */ | |
4737 cursor_correct(); | |
4738 check_cursor_moved(curwin); | |
4739 curwin->w_valid |= VALID_TOPLINE; | |
4740 | |
4741 /* If moved back to where we were, at least move the cursor, otherwise | |
4742 * we get stuck at one position. Don't move the cursor up if the | |
4743 * first line of the buffer is already on the screen */ | |
4744 while (curwin->w_topline == prev_topline | |
4745 #ifdef FEAT_DIFF | |
4746 && curwin->w_topfill == prev_topfill | |
4747 #endif | |
4748 ) | |
4749 { | |
4750 if (up) | |
4751 { | |
4752 if (curwin->w_cursor.lnum > prev_lnum | |
4753 || cursor_down(1L, FALSE) == FAIL) | |
4754 break; | |
4755 } | |
4756 else | |
4757 { | |
4758 if (curwin->w_cursor.lnum < prev_lnum | |
4759 || prev_topline == 1L | |
4760 || cursor_up(1L, FALSE) == FAIL) | |
4761 break; | |
4762 } | |
4763 /* Mark w_topline as valid, otherwise the screen jumps back at the | |
4764 * end of the file. */ | |
4765 check_cursor_moved(curwin); | |
4766 curwin->w_valid |= VALID_TOPLINE; | |
4767 } | |
4768 } | |
4769 if (curwin->w_cursor.lnum != prev_lnum) | |
4770 coladvance(curwin->w_curswant); | |
4771 redraw_later(VALID); | |
4772 } | |
4773 | |
4774 /* | |
4775 * Commands that start with "z". | |
4776 */ | |
4777 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4778 nv_zet(cmdarg_T *cap) |
7 | 4779 { |
4780 long n; | |
4781 colnr_T col; | |
4782 int nchar = cap->nchar; | |
4783 #ifdef FEAT_FOLDING | |
4784 long old_fdl = curwin->w_p_fdl; | |
4785 int old_fen = curwin->w_p_fen; | |
4786 #endif | |
737 | 4787 #ifdef FEAT_SPELL |
710 | 4788 int undo = FALSE; |
4789 #endif | |
7 | 4790 |
4791 if (VIM_ISDIGIT(nchar)) | |
4792 { | |
4793 /* | |
4794 * "z123{nchar}": edit the count before obtaining {nchar} | |
4795 */ | |
4796 if (checkclearop(cap->oap)) | |
4797 return; | |
4798 n = nchar - '0'; | |
4799 for (;;) | |
4800 { | |
4801 #ifdef USE_ON_FLY_SCROLL | |
4802 dont_scroll = TRUE; /* disallow scrolling here */ | |
4803 #endif | |
4804 ++no_mapping; | |
4805 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 4806 nchar = plain_vgetc(); |
7 | 4807 LANGMAP_ADJUST(nchar, TRUE); |
4808 --no_mapping; | |
4809 --allow_keys; | |
4810 #ifdef FEAT_CMDL_INFO | |
4811 (void)add_to_showcmd(nchar); | |
4812 #endif | |
4813 if (nchar == K_DEL || nchar == K_KDEL) | |
4814 n /= 10; | |
4815 else if (VIM_ISDIGIT(nchar)) | |
4816 n = n * 10 + (nchar - '0'); | |
4817 else if (nchar == CAR) | |
4818 { | |
4819 #ifdef FEAT_GUI | |
4820 need_mouse_correct = TRUE; | |
4821 #endif | |
4822 win_setheight((int)n); | |
4823 break; | |
4824 } | |
4825 else if (nchar == 'l' | |
4826 || nchar == 'h' | |
4827 || nchar == K_LEFT | |
229 | 4828 || nchar == K_RIGHT) |
7 | 4829 { |
4830 cap->count1 = n ? n * cap->count1 : cap->count1; | |
4831 goto dozet; | |
4832 } | |
4833 else | |
4834 { | |
4835 clearopbeep(cap->oap); | |
4836 break; | |
4837 } | |
4838 } | |
4839 cap->oap->op_type = OP_NOP; | |
4840 return; | |
4841 } | |
4842 | |
4843 dozet: | |
4844 if ( | |
4845 #ifdef FEAT_FOLDING | |
4846 /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc" | |
4847 * and "zC" only in Visual mode. "zj" and "zk" are motion | |
4848 * commands. */ | |
4849 cap->nchar != 'f' && cap->nchar != 'F' | |
4850 && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar)) | |
4851 && cap->nchar != 'j' && cap->nchar != 'k' | |
4852 && | |
4853 #endif | |
4854 checkclearop(cap->oap)) | |
4855 return; | |
4856 | |
4857 /* | |
4858 * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb": | |
4859 * If line number given, set cursor. | |
4860 */ | |
4861 if ((vim_strchr((char_u *)"+\r\nt.z^-b", nchar) != NULL) | |
4862 && cap->count0 | |
4863 && cap->count0 != curwin->w_cursor.lnum) | |
4864 { | |
4865 setpcmark(); | |
4866 if (cap->count0 > curbuf->b_ml.ml_line_count) | |
4867 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4868 else | |
4869 curwin->w_cursor.lnum = cap->count0; | |
22 | 4870 check_cursor_col(); |
7 | 4871 } |
4872 | |
4873 switch (nchar) | |
4874 { | |
4875 /* "z+", "z<CR>" and "zt": put cursor at top of screen */ | |
4876 case '+': | |
4877 if (cap->count0 == 0) | |
4878 { | |
4879 /* No count given: put cursor at the line below screen */ | |
4880 validate_botline(); /* make sure w_botline is valid */ | |
4881 if (curwin->w_botline > curbuf->b_ml.ml_line_count) | |
4882 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4883 else | |
4884 curwin->w_cursor.lnum = curwin->w_botline; | |
4885 } | |
4886 /* FALLTHROUGH */ | |
4887 case NL: | |
4888 case CAR: | |
4889 case K_KENTER: | |
4890 beginline(BL_WHITE | BL_FIX); | |
4891 /* FALLTHROUGH */ | |
4892 | |
4893 case 't': scroll_cursor_top(0, TRUE); | |
4894 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4895 set_fraction(curwin); |
7 | 4896 break; |
4897 | |
4898 /* "z." and "zz": put cursor in middle of screen */ | |
4899 case '.': beginline(BL_WHITE | BL_FIX); | |
4900 /* FALLTHROUGH */ | |
4901 | |
4902 case 'z': scroll_cursor_halfway(TRUE); | |
4903 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4904 set_fraction(curwin); |
7 | 4905 break; |
4906 | |
4907 /* "z^", "z-" and "zb": put cursor at bottom of screen */ | |
4908 case '^': /* Strange Vi behavior: <count>z^ finds line at top of window | |
4909 * when <count> is at bottom of window, and puts that one at | |
4910 * bottom of window. */ | |
4911 if (cap->count0 != 0) | |
4912 { | |
4913 scroll_cursor_bot(0, TRUE); | |
4914 curwin->w_cursor.lnum = curwin->w_topline; | |
4915 } | |
4916 else if (curwin->w_topline == 1) | |
4917 curwin->w_cursor.lnum = 1; | |
4918 else | |
4919 curwin->w_cursor.lnum = curwin->w_topline - 1; | |
4920 /* FALLTHROUGH */ | |
4921 case '-': | |
4922 beginline(BL_WHITE | BL_FIX); | |
4923 /* FALLTHROUGH */ | |
4924 | |
4925 case 'b': scroll_cursor_bot(0, TRUE); | |
4926 redraw_later(VALID); | |
7311
743c258ca3ab
commit https://github.com/vim/vim/commit/9dc2ce398bb3456cc8f590ef0260459798b34d2a
Christian Brabandt <cb@256bit.org>
parents:
7241
diff
changeset
|
4927 set_fraction(curwin); |
7 | 4928 break; |
4929 | |
4930 /* "zH" - scroll screen right half-page */ | |
4931 case 'H': | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
4932 cap->count1 *= curwin->w_width / 2; |
7 | 4933 /* FALLTHROUGH */ |
4934 | |
4935 /* "zh" - scroll screen to the right */ | |
4936 case 'h': | |
4937 case K_LEFT: | |
4938 if (!curwin->w_p_wrap) | |
4939 { | |
4940 if ((colnr_T)cap->count1 > curwin->w_leftcol) | |
4941 curwin->w_leftcol = 0; | |
4942 else | |
4943 curwin->w_leftcol -= (colnr_T)cap->count1; | |
4944 leftcol_changed(); | |
4945 } | |
4946 break; | |
4947 | |
4948 /* "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
|
4949 case 'L': cap->count1 *= curwin->w_width / 2; |
7 | 4950 /* FALLTHROUGH */ |
4951 | |
4952 /* "zl" - scroll screen to the left */ | |
4953 case 'l': | |
4954 case K_RIGHT: | |
4955 if (!curwin->w_p_wrap) | |
4956 { | |
4957 /* scroll the window left */ | |
4958 curwin->w_leftcol += (colnr_T)cap->count1; | |
4959 leftcol_changed(); | |
4960 } | |
4961 break; | |
4962 | |
4963 /* "zs" - scroll screen, cursor at the start */ | |
4964 case 's': if (!curwin->w_p_wrap) | |
4965 { | |
4966 #ifdef FEAT_FOLDING | |
4967 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4968 col = 0; /* like the cursor is in col 0 */ | |
4969 else | |
4970 #endif | |
4971 getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL); | |
4972 if ((long)col > p_siso) | |
4973 col -= p_siso; | |
4974 else | |
4975 col = 0; | |
4976 if (curwin->w_leftcol != col) | |
4977 { | |
4978 curwin->w_leftcol = col; | |
4979 redraw_later(NOT_VALID); | |
4980 } | |
4981 } | |
4982 break; | |
4983 | |
4984 /* "ze" - scroll screen, cursor at the end */ | |
4985 case 'e': if (!curwin->w_p_wrap) | |
4986 { | |
4987 #ifdef FEAT_FOLDING | |
4988 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
4989 col = 0; /* like the cursor is in col 0 */ | |
4990 else | |
4991 #endif | |
4992 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
|
4993 n = curwin->w_width - curwin_col_off(); |
7 | 4994 if ((long)col + p_siso < n) |
4995 col = 0; | |
4996 else | |
4997 col = col + p_siso - n + 1; | |
4998 if (curwin->w_leftcol != col) | |
4999 { | |
5000 curwin->w_leftcol = col; | |
5001 redraw_later(NOT_VALID); | |
5002 } | |
5003 } | |
5004 break; | |
5005 | |
5006 #ifdef FEAT_FOLDING | |
5007 /* "zF": create fold command */ | |
5008 /* "zf": create fold operator */ | |
5009 case 'F': | |
5010 case 'f': if (foldManualAllowed(TRUE)) | |
5011 { | |
5012 cap->nchar = 'f'; | |
5013 nv_operator(cap); | |
5014 curwin->w_p_fen = TRUE; | |
5015 | |
5016 /* "zF" is like "zfzf" */ | |
5017 if (nchar == 'F' && cap->oap->op_type == OP_FOLD) | |
5018 { | |
5019 nv_operator(cap); | |
5020 finish_op = TRUE; | |
5021 } | |
5022 } | |
5023 else | |
5024 clearopbeep(cap->oap); | |
5025 break; | |
5026 | |
5027 /* "zd": delete fold at cursor */ | |
5028 /* "zD": delete fold at cursor recursively */ | |
5029 case 'd': | |
5030 case 'D': if (foldManualAllowed(FALSE)) | |
5031 { | |
5032 if (VIsual_active) | |
5033 nv_operator(cap); | |
5034 else | |
5035 deleteFold(curwin->w_cursor.lnum, | |
5036 curwin->w_cursor.lnum, nchar == 'D', FALSE); | |
5037 } | |
5038 break; | |
5039 | |
4352 | 5040 /* "zE": erase all folds */ |
7 | 5041 case 'E': if (foldmethodIsManual(curwin)) |
5042 { | |
5043 clearFolding(curwin); | |
5044 changed_window_setting(); | |
5045 } | |
5046 else if (foldmethodIsMarker(curwin)) | |
5047 deleteFold((linenr_T)1, curbuf->b_ml.ml_line_count, | |
5048 TRUE, FALSE); | |
5049 else | |
5050 EMSG(_("E352: Cannot erase folds with current 'foldmethod'")); | |
5051 break; | |
5052 | |
5053 /* "zn": fold none: reset 'foldenable' */ | |
5054 case 'n': curwin->w_p_fen = FALSE; | |
5055 break; | |
5056 | |
5057 /* "zN": fold Normal: set 'foldenable' */ | |
5058 case 'N': curwin->w_p_fen = TRUE; | |
5059 break; | |
5060 | |
5061 /* "zi": invert folding: toggle 'foldenable' */ | |
5062 case 'i': curwin->w_p_fen = !curwin->w_p_fen; | |
5063 break; | |
5064 | |
5065 /* "za": open closed fold or close open fold at cursor */ | |
5066 case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
5067 openFold(curwin->w_cursor.lnum, cap->count1); | |
5068 else | |
5069 { | |
5070 closeFold(curwin->w_cursor.lnum, cap->count1); | |
5071 curwin->w_p_fen = TRUE; | |
5072 } | |
5073 break; | |
5074 | |
5075 /* "zA": open fold at cursor recursively */ | |
5076 case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL)) | |
5077 openFoldRecurse(curwin->w_cursor.lnum); | |
5078 else | |
5079 { | |
5080 closeFoldRecurse(curwin->w_cursor.lnum); | |
5081 curwin->w_p_fen = TRUE; | |
5082 } | |
5083 break; | |
5084 | |
5085 /* "zo": open fold at cursor or Visual area */ | |
5086 case 'o': if (VIsual_active) | |
5087 nv_operator(cap); | |
5088 else | |
5089 openFold(curwin->w_cursor.lnum, cap->count1); | |
5090 break; | |
5091 | |
5092 /* "zO": open fold recursively */ | |
5093 case 'O': if (VIsual_active) | |
5094 nv_operator(cap); | |
5095 else | |
5096 openFoldRecurse(curwin->w_cursor.lnum); | |
5097 break; | |
5098 | |
5099 /* "zc": close fold at cursor or Visual area */ | |
5100 case 'c': if (VIsual_active) | |
5101 nv_operator(cap); | |
5102 else | |
5103 closeFold(curwin->w_cursor.lnum, cap->count1); | |
5104 curwin->w_p_fen = TRUE; | |
5105 break; | |
5106 | |
5107 /* "zC": close fold recursively */ | |
5108 case 'C': if (VIsual_active) | |
5109 nv_operator(cap); | |
5110 else | |
5111 closeFoldRecurse(curwin->w_cursor.lnum); | |
5112 curwin->w_p_fen = TRUE; | |
5113 break; | |
5114 | |
5115 /* "zv": open folds at the cursor */ | |
5116 case 'v': foldOpenCursor(); | |
5117 break; | |
5118 | |
5119 /* "zx": re-apply 'foldlevel' and open folds at the cursor */ | |
5120 case 'x': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5121 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5122 newFoldLevel(); /* update right now */ |
7 | 5123 foldOpenCursor(); |
5124 break; | |
5125 | |
5126 /* "zX": undo manual opens/closes, re-apply 'foldlevel' */ | |
5127 case 'X': curwin->w_p_fen = TRUE; | |
2139
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5128 curwin->w_foldinvalid = TRUE; /* recompute folds */ |
35effbd07a25
updated for version 7.2.421
Bram Moolenaar <bram@zimbu.org>
parents:
2130
diff
changeset
|
5129 old_fdl = -1; /* force an update */ |
7 | 5130 break; |
5131 | |
5132 /* "zm": fold more */ | |
5133 case 'm': if (curwin->w_p_fdl > 0) | |
6725 | 5134 { |
5135 curwin->w_p_fdl -= cap->count1; | |
5136 if (curwin->w_p_fdl < 0) | |
5137 curwin->w_p_fdl = 0; | |
5138 } | |
7 | 5139 old_fdl = -1; /* force an update */ |
5140 curwin->w_p_fen = TRUE; | |
5141 break; | |
5142 | |
5143 /* "zM": close all folds */ | |
5144 case 'M': curwin->w_p_fdl = 0; | |
5145 old_fdl = -1; /* force an update */ | |
5146 curwin->w_p_fen = TRUE; | |
5147 break; | |
5148 | |
5149 /* "zr": reduce folding */ | |
6725 | 5150 case 'r': curwin->w_p_fdl += cap->count1; |
5151 { | |
5152 int d = getDeepestNesting(); | |
5153 | |
5154 if (curwin->w_p_fdl >= d) | |
5155 curwin->w_p_fdl = d; | |
5156 } | |
7 | 5157 break; |
5158 | |
5159 /* "zR": open all folds */ | |
5160 case 'R': curwin->w_p_fdl = getDeepestNesting(); | |
5161 old_fdl = -1; /* force an update */ | |
5162 break; | |
5163 | |
5164 case 'j': /* "zj" move to next fold downwards */ | |
5165 case 'k': /* "zk" move to next fold upwards */ | |
5166 if (foldMoveTo(TRUE, nchar == 'j' ? FORWARD : BACKWARD, | |
5167 cap->count1) == FAIL) | |
5168 clearopbeep(cap->oap); | |
5169 break; | |
5170 | |
5171 #endif /* FEAT_FOLDING */ | |
5172 | |
737 | 5173 #ifdef FEAT_SPELL |
710 | 5174 case 'u': /* "zug" and "zuw": undo "zg" and "zw" */ |
5175 ++no_mapping; | |
5176 ++allow_keys; /* no mapping for nchar, but allow key codes */ | |
1389 | 5177 nchar = plain_vgetc(); |
710 | 5178 LANGMAP_ADJUST(nchar, TRUE); |
5179 --no_mapping; | |
5180 --allow_keys; | |
5181 #ifdef FEAT_CMDL_INFO | |
5182 (void)add_to_showcmd(nchar); | |
5183 #endif | |
5184 if (vim_strchr((char_u *)"gGwW", nchar) == NULL) | |
5185 { | |
5186 clearopbeep(cap->oap); | |
5187 break; | |
5188 } | |
5189 undo = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
5190 /* FALLTHROUGH */ |
710 | 5191 |
310 | 5192 case 'g': /* "zg": add good word to word list */ |
5193 case 'w': /* "zw": add wrong word to word list */ | |
381 | 5194 case 'G': /* "zG": add good word to temp word list */ |
5195 case 'W': /* "zW": add wrong word to temp word list */ | |
310 | 5196 { |
5197 char_u *ptr = NULL; | |
5198 int len; | |
5199 | |
5200 if (checkclearop(cap->oap)) | |
5201 break; | |
5202 if (VIsual_active && get_visual_text(cap, &ptr, &len) | |
5203 == FAIL) | |
5204 return; | |
501 | 5205 if (ptr == NULL) |
5206 { | |
5207 pos_T pos = curwin->w_cursor; | |
5208 | |
5374 | 5209 /* Find bad word under the cursor. When 'spell' is |
5210 * off this fails and find_ident_under_cursor() is | |
5211 * used below. */ | |
5212 emsg_off++; | |
534 | 5213 len = spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL); |
5374 | 5214 emsg_off--; |
501 | 5215 if (len != 0 && curwin->w_cursor.col <= pos.col) |
5216 ptr = ml_get_pos(&curwin->w_cursor); | |
5217 curwin->w_cursor = pos; | |
5218 } | |
5219 | |
310 | 5220 if (ptr == NULL && (len = find_ident_under_cursor(&ptr, |
5221 FIND_IDENT)) == 0) | |
5222 return; | |
381 | 5223 spell_add_word(ptr, len, nchar == 'w' || nchar == 'W', |
710 | 5224 (nchar == 'G' || nchar == 'W') |
5225 ? 0 : (int)cap->count1, | |
5226 undo); | |
310 | 5227 } |
316 | 5228 break; |
323 | 5229 |
584 | 5230 case '=': /* "z=": suggestions for a badly spelled word */ |
638 | 5231 if (!checkclearop(cap->oap)) |
485 | 5232 spell_suggest((int)cap->count0); |
323 | 5233 break; |
310 | 5234 #endif |
5235 | |
7 | 5236 default: clearopbeep(cap->oap); |
5237 } | |
5238 | |
5239 #ifdef FEAT_FOLDING | |
5240 /* Redraw when 'foldenable' changed */ | |
5241 if (old_fen != curwin->w_p_fen) | |
5242 { | |
5243 # ifdef FEAT_DIFF | |
5244 win_T *wp; | |
5245 | |
5246 if (foldmethodIsDiff(curwin) && curwin->w_p_scb) | |
5247 { | |
5248 /* Adjust 'foldenable' in diff-synced windows. */ | |
5249 FOR_ALL_WINDOWS(wp) | |
5250 { | |
5251 if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) | |
5252 { | |
5253 wp->w_p_fen = curwin->w_p_fen; | |
5254 changed_window_setting_win(wp); | |
5255 } | |
5256 } | |
5257 } | |
5258 # endif | |
5259 changed_window_setting(); | |
5260 } | |
5261 | |
5262 /* Redraw when 'foldlevel' changed. */ | |
5263 if (old_fdl != curwin->w_p_fdl) | |
5264 newFoldLevel(); | |
5265 #endif | |
5266 } | |
5267 | |
5268 #ifdef FEAT_GUI | |
5269 /* | |
5270 * Vertical scrollbar movement. | |
5271 */ | |
5272 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5273 nv_ver_scrollbar(cmdarg_T *cap) |
7 | 5274 { |
5275 if (cap->oap->op_type != OP_NOP) | |
5276 clearopbeep(cap->oap); | |
5277 | |
5278 /* Even if an operator was pending, we still want to scroll */ | |
5279 gui_do_scroll(); | |
5280 } | |
5281 | |
5282 /* | |
5283 * Horizontal scrollbar movement. | |
5284 */ | |
5285 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5286 nv_hor_scrollbar(cmdarg_T *cap) |
7 | 5287 { |
5288 if (cap->oap->op_type != OP_NOP) | |
5289 clearopbeep(cap->oap); | |
5290 | |
5291 /* 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
|
5292 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 5293 } |
5294 #endif | |
5295 | |
690 | 5296 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
685 | 5297 /* |
5298 * Click in GUI tab. | |
5299 */ | |
5300 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5301 nv_tabline(cmdarg_T *cap) |
685 | 5302 { |
5303 if (cap->oap->op_type != OP_NOP) | |
5304 clearopbeep(cap->oap); | |
5305 | |
5306 /* Even if an operator was pending, we still want to jump tabs. */ | |
5307 goto_tabpage(current_tab); | |
5308 } | |
686 | 5309 |
5310 /* | |
5311 * Selected item in tab line menu. | |
5312 */ | |
5313 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5314 nv_tabmenu(cmdarg_T *cap) |
686 | 5315 { |
5316 if (cap->oap->op_type != OP_NOP) | |
5317 clearopbeep(cap->oap); | |
5318 | |
5319 /* Even if an operator was pending, we still want to jump tabs. */ | |
690 | 5320 handle_tabmenu(); |
5321 } | |
5322 | |
5323 /* | |
5324 * Handle selecting an item of the GUI tab line menu. | |
5325 * Used in Normal and Insert mode. | |
5326 */ | |
5327 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5328 handle_tabmenu(void) |
690 | 5329 { |
686 | 5330 switch (current_tabmenu) |
5331 { | |
5332 case TABLINE_MENU_CLOSE: | |
5333 if (current_tab == 0) | |
5334 do_cmdline_cmd((char_u *)"tabclose"); | |
5335 else | |
5336 { | |
5337 vim_snprintf((char *)IObuff, IOSIZE, "tabclose %d", | |
5338 current_tab); | |
5339 do_cmdline_cmd(IObuff); | |
5340 } | |
5341 break; | |
5342 | |
5343 case TABLINE_MENU_NEW: | |
6631 | 5344 if (current_tab == 0) |
5345 do_cmdline_cmd((char_u *)"$tabnew"); | |
5346 else | |
5347 { | |
5348 vim_snprintf((char *)IObuff, IOSIZE, "%dtabnew", | |
5349 current_tab - 1); | |
5350 do_cmdline_cmd(IObuff); | |
5351 } | |
686 | 5352 break; |
5353 | |
5354 case TABLINE_MENU_OPEN: | |
6631 | 5355 if (current_tab == 0) |
5356 do_cmdline_cmd((char_u *)"browse $tabnew"); | |
5357 else | |
5358 { | |
5359 vim_snprintf((char *)IObuff, IOSIZE, "browse %dtabnew", | |
5360 current_tab - 1); | |
5361 do_cmdline_cmd(IObuff); | |
5362 } | |
686 | 5363 break; |
5364 } | |
5365 } | |
685 | 5366 #endif |
5367 | |
7 | 5368 /* |
5369 * "Q" command. | |
5370 */ | |
5371 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5372 nv_exmode(cmdarg_T *cap) |
7 | 5373 { |
5374 /* | |
5375 * Ignore 'Q' in Visual mode, just give a beep. | |
5376 */ | |
5377 if (VIsual_active) | |
6949 | 5378 vim_beep(BO_EX); |
5735 | 5379 else if (!checkclearop(cap->oap)) |
7 | 5380 do_exmode(FALSE); |
5381 } | |
5382 | |
5383 /* | |
5384 * Handle a ":" command. | |
5385 */ | |
5386 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5387 nv_colon(cmdarg_T *cap) |
7 | 5388 { |
5389 int old_p_im; | |
4256 | 5390 int cmd_result; |
7 | 5391 |
5392 if (VIsual_active) | |
5393 nv_operator(cap); | |
5394 else | |
5395 { | |
5396 if (cap->oap->op_type != OP_NOP) | |
5397 { | |
5398 /* Using ":" as a movement is characterwise exclusive. */ | |
5399 cap->oap->motion_type = MCHAR; | |
5400 cap->oap->inclusive = FALSE; | |
5401 } | |
5402 else if (cap->count0) | |
5403 { | |
5404 /* translate "count:" into ":.,.+(count - 1)" */ | |
5405 stuffcharReadbuff('.'); | |
5406 if (cap->count0 > 1) | |
5407 { | |
5408 stuffReadbuff((char_u *)",.+"); | |
5409 stuffnumReadbuff((long)cap->count0 - 1L); | |
5410 } | |
5411 } | |
5412 | |
5413 /* When typing, don't type below an old message */ | |
5414 if (KeyTyped) | |
5415 compute_cmdrow(); | |
5416 | |
5417 old_p_im = p_im; | |
5418 | |
5419 /* get a command line and execute it */ | |
4256 | 5420 cmd_result = do_cmdline(NULL, getexline, NULL, |
7 | 5421 cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0); |
5422 | |
5423 /* If 'insertmode' changed, enter or exit Insert mode */ | |
5424 if (p_im != old_p_im) | |
5425 { | |
5426 if (p_im) | |
5427 restart_edit = 'i'; | |
5428 else | |
5429 restart_edit = 0; | |
5430 } | |
5431 | |
4256 | 5432 if (cmd_result == FAIL) |
5433 /* The Ex command failed, do not execute the operator. */ | |
5434 clearop(cap->oap); | |
5435 else if (cap->oap->op_type != OP_NOP | |
7 | 5436 && (cap->oap->start.lnum > curbuf->b_ml.ml_line_count |
5437 || cap->oap->start.col > | |
4256 | 5438 (colnr_T)STRLEN(ml_get(cap->oap->start.lnum)) |
5439 || did_emsg | |
5440 )) | |
5441 /* The start of the operator has become invalid by the Ex command. | |
5442 */ | |
7 | 5443 clearopbeep(cap->oap); |
5444 } | |
5445 } | |
5446 | |
5447 /* | |
5448 * Handle CTRL-G command. | |
5449 */ | |
5450 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5451 nv_ctrlg(cmdarg_T *cap) |
7 | 5452 { |
5453 if (VIsual_active) /* toggle Selection/Visual mode */ | |
5454 { | |
5455 VIsual_select = !VIsual_select; | |
5456 showmode(); | |
5457 } | |
5735 | 5458 else if (!checkclearop(cap->oap)) |
7 | 5459 /* print full name if count given or :cd used */ |
5460 fileinfo((int)cap->count0, FALSE, TRUE); | |
5461 } | |
5462 | |
5463 /* | |
5464 * Handle CTRL-H <Backspace> command. | |
5465 */ | |
5466 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5467 nv_ctrlh(cmdarg_T *cap) |
7 | 5468 { |
5469 if (VIsual_active && VIsual_select) | |
5470 { | |
5471 cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */ | |
5472 v_visop(cap); | |
5473 } | |
5474 else | |
5475 nv_left(cap); | |
5476 } | |
5477 | |
5478 /* | |
5479 * CTRL-L: clear screen and redraw. | |
5480 */ | |
5481 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5482 nv_clear(cmdarg_T *cap) |
7 | 5483 { |
5484 if (!checkclearop(cap->oap)) | |
5485 { | |
5486 #if defined(__BEOS__) && !USE_THREAD_FOR_INPUT_WITH_TIMEOUT | |
5487 /* | |
5488 * Right now, the BeBox doesn't seem to have an easy way to detect | |
5489 * window resizing, so we cheat and make the user detect it | |
5490 * manually with CTRL-L instead | |
5491 */ | |
5492 ui_get_shellsize(); | |
5493 #endif | |
5494 #ifdef FEAT_SYN_HL | |
5495 /* 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
|
5496 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
|
5497 # ifdef FEAT_RELTIME |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5498 { |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5499 win_T *wp; |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5500 |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5501 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
|
5502 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
|
5503 } |
998d2cf59caa
patch 8.0.0647: syntax highlighting can make cause a freeze
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
5504 # endif |
7 | 5505 #endif |
5506 redraw_later(CLEAR); | |
5507 } | |
5508 } | |
5509 | |
5510 /* | |
5511 * CTRL-O: In Select mode: switch to Visual mode for one command. | |
5512 * Otherwise: Go to older pcmark. | |
5513 */ | |
5514 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5515 nv_ctrlo(cmdarg_T *cap) |
7 | 5516 { |
5517 if (VIsual_active && VIsual_select) | |
5518 { | |
5519 VIsual_select = FALSE; | |
5520 showmode(); | |
5521 restart_VIsual_select = 2; /* restart Select mode later */ | |
5522 } | |
5523 else | |
5524 { | |
5525 cap->count1 = -cap->count1; | |
5526 nv_pcmark(cap); | |
5527 } | |
5528 } | |
5529 | |
5530 /* | |
5531 * CTRL-^ command, short for ":e #" | |
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_hat(cmdarg_T *cap) |
7 | 5535 { |
5536 if (!checkclearopq(cap->oap)) | |
5537 (void)buflist_getfile((int)cap->count0, (linenr_T)0, | |
5538 GETF_SETMARK|GETF_ALT, FALSE); | |
5539 } | |
5540 | |
5541 /* | |
5542 * "Z" commands. | |
5543 */ | |
5544 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5545 nv_Zet(cmdarg_T *cap) |
7 | 5546 { |
5547 if (!checkclearopq(cap->oap)) | |
5548 { | |
5549 switch (cap->nchar) | |
5550 { | |
5551 /* "ZZ": equivalent to ":x". */ | |
5552 case 'Z': do_cmdline_cmd((char_u *)"x"); | |
5553 break; | |
5554 | |
5555 /* "ZQ": equivalent to ":q!" (Elvis compatible). */ | |
5556 case 'Q': do_cmdline_cmd((char_u *)"q!"); | |
5557 break; | |
5558 | |
5559 default: clearopbeep(cap->oap); | |
5560 } | |
5561 } | |
5562 } | |
5563 | |
5564 /* | |
5565 * Call nv_ident() as if "c1" was used, with "c2" as next character. | |
5566 */ | |
5567 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5568 do_nv_ident(int c1, int c2) |
7 | 5569 { |
5570 oparg_T oa; | |
5571 cmdarg_T ca; | |
5572 | |
5573 clear_oparg(&oa); | |
5574 vim_memset(&ca, 0, sizeof(ca)); | |
5575 ca.oap = &oa; | |
5576 ca.cmdchar = c1; | |
5577 ca.nchar = c2; | |
5578 nv_ident(&ca); | |
5579 } | |
5580 | |
5581 /* | |
5582 * Handle the commands that use the word under the cursor. | |
5583 * [g] CTRL-] :ta to current identifier | |
5584 * [g] 'K' run program for current identifier | |
5585 * [g] '*' / to current identifier or string | |
5586 * [g] '#' ? to current identifier or string | |
5587 * g ']' :tselect for current identifier | |
5588 */ | |
5589 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5590 nv_ident(cmdarg_T *cap) |
7 | 5591 { |
5592 char_u *ptr = NULL; | |
5593 char_u *buf; | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5594 unsigned buflen; |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5595 char_u *newbuf; |
7 | 5596 char_u *p; |
5597 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
|
5598 int kp_help; /* 'keywordprg' is ":he" */ |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5599 int kp_ex; /* 'keywordprg' starts with ":" */ |
7 | 5600 int n = 0; /* init for GCC */ |
5601 int cmdchar; | |
5602 int g_cmd; /* "g" command */ | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5603 int tag_cmd = FALSE; |
7 | 5604 char_u *aux_ptr; |
5605 int isman; | |
5606 int isman_s; | |
5607 | |
5608 if (cap->cmdchar == 'g') /* "g*", "g#", "g]" and "gCTRL-]" */ | |
5609 { | |
5610 cmdchar = cap->nchar; | |
5611 g_cmd = TRUE; | |
5612 } | |
5613 else | |
5614 { | |
5615 cmdchar = cap->cmdchar; | |
5616 g_cmd = FALSE; | |
5617 } | |
5618 | |
5619 if (cmdchar == POUND) /* the pound sign, '#' for English keyboards */ | |
5620 cmdchar = '#'; | |
5621 | |
5622 /* | |
5623 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode. | |
5624 */ | |
5625 if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K') | |
5626 { | |
5627 if (VIsual_active && get_visual_text(cap, &ptr, &n) == FAIL) | |
5628 return; | |
5629 if (checkclearopq(cap->oap)) | |
5630 return; | |
5631 } | |
5632 | |
5633 if (ptr == NULL && (n = find_ident_under_cursor(&ptr, | |
5634 (cmdchar == '*' || cmdchar == '#') | |
5635 ? FIND_IDENT|FIND_STRING : FIND_IDENT)) == 0) | |
5636 { | |
5637 clearop(cap->oap); | |
5638 return; | |
5639 } | |
5640 | |
5641 /* Allocate buffer to put the command in. Inserting backslashes can | |
5642 * double the length of the word. p_kp / curbuf->b_p_kp could be added | |
5643 * and some numbers. */ | |
5644 kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp); | |
5645 kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 | |
5646 || 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
|
5647 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
|
5648 { |
55cf556d8ce1
patch 8.0.0998: strange error when using K while only spaces are selected
Christian Brabandt <cb@256bit.org>
parents:
12164
diff
changeset
|
5649 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
|
5650 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
|
5651 } |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5652 kp_ex = (*kp == ':'); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5653 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
|
5654 buf = alloc(buflen); |
7 | 5655 if (buf == NULL) |
5656 return; | |
5657 buf[0] = NUL; | |
5658 | |
5659 switch (cmdchar) | |
5660 { | |
5661 case '*': | |
5662 case '#': | |
5663 /* | |
5664 * Put cursor at start of word, makes search skip the word | |
5665 * under the cursor. | |
5666 * Call setpcmark() first, so "*``" puts the cursor back where | |
5667 * it was. | |
5668 */ | |
5669 setpcmark(); | |
5670 curwin->w_cursor.col = (colnr_T) (ptr - ml_get_curline()); | |
5671 | |
5672 if (!g_cmd && vim_iswordp(ptr)) | |
5673 STRCPY(buf, "\\<"); | |
5674 no_smartcase = TRUE; /* don't use 'smartcase' now */ | |
5675 break; | |
5676 | |
5677 case 'K': | |
5678 if (kp_help) | |
5679 STRCPY(buf, "he! "); | |
9098
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5680 else if (kp_ex) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5681 { |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5682 if (cap->count0 != 0) |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5683 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
|
5684 kp, cap->count0); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5685 else |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5686 STRCPY(buf, kp); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5687 STRCAT(buf, " "); |
0d52ddff8db4
commit https://github.com/vim/vim/commit/2ff8b64679242e73248774a388d54931c9ce49bd
Christian Brabandt <cb@256bit.org>
parents:
8923
diff
changeset
|
5688 } |
7 | 5689 else |
5690 { | |
1712 | 5691 /* An external command will probably use an argument starting |
5692 * with "-" as an option. To avoid trouble we skip the "-". */ | |
1728 | 5693 while (*ptr == '-' && n > 0) |
5694 { | |
1712 | 5695 ++ptr; |
1728 | 5696 --n; |
5697 } | |
5698 if (n == 0) | |
5699 { | |
5700 EMSG(_(e_noident)); /* found dashes only */ | |
5701 vim_free(buf); | |
5702 return; | |
5703 } | |
1712 | 5704 |
7 | 5705 /* When a count is given, turn it into a range. Is this |
5706 * really what we want? */ | |
5707 isman = (STRCMP(kp, "man") == 0); | |
5708 isman_s = (STRCMP(kp, "man -s") == 0); | |
5709 if (cap->count0 != 0 && !(isman || isman_s)) | |
5710 sprintf((char *)buf, ".,.+%ld", cap->count0 - 1); | |
5711 | |
5712 STRCAT(buf, "! "); | |
5713 if (cap->count0 == 0 && isman_s) | |
5714 STRCAT(buf, "man"); | |
5715 else | |
5716 STRCAT(buf, kp); | |
5717 STRCAT(buf, " "); | |
5718 if (cap->count0 != 0 && (isman || isman_s)) | |
5719 { | |
5720 sprintf((char *)buf + STRLEN(buf), "%ld", cap->count0); | |
5721 STRCAT(buf, " "); | |
5722 } | |
5723 } | |
5724 break; | |
5725 | |
5726 case ']': | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5727 tag_cmd = TRUE; |
7 | 5728 #ifdef FEAT_CSCOPE |
5729 if (p_cst) | |
5730 STRCPY(buf, "cstag "); | |
5731 else | |
5732 #endif | |
5733 STRCPY(buf, "ts "); | |
5734 break; | |
5735 | |
5736 default: | |
2112
6b5d641bcdd4
updated for version 7.2.395
Bram Moolenaar <bram@zimbu.org>
parents:
2049
diff
changeset
|
5737 tag_cmd = TRUE; |
7 | 5738 if (curbuf->b_help) |
5739 STRCPY(buf, "he! "); | |
5740 else | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5741 { |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5742 if (g_cmd) |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5743 STRCPY(buf, "tj "); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5744 else |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5745 sprintf((char *)buf, "%ldta ", cap->count0); |
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5746 } |
7 | 5747 } |
5748 | |
5749 /* | |
5750 * Now grab the chars in the identifier | |
5751 */ | |
1712 | 5752 if (cmdchar == 'K' && !kp_help) |
5753 { | |
1728 | 5754 ptr = vim_strnsave(ptr, n); |
10330
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5755 if (kp_ex) |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5756 /* 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
|
5757 p = vim_strsave_fnameescape(ptr, FALSE); |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5758 else |
71ca6a16e818
commit https://github.com/vim/vim/commit/426f3754223c8ff8a1bc51d6ba1eba11e8982ebc
Christian Brabandt <cb@256bit.org>
parents:
10251
diff
changeset
|
5759 /* 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
|
5760 p = vim_strsave_shellescape(ptr, TRUE, TRUE); |
1728 | 5761 vim_free(ptr); |
1712 | 5762 if (p == NULL) |
5763 { | |
5764 vim_free(buf); | |
5765 return; | |
5766 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5767 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
|
5768 if (newbuf == NULL) |
1712 | 5769 { |
5770 vim_free(buf); | |
5771 vim_free(p); | |
5772 return; | |
5773 } | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
5774 buf = newbuf; |
1712 | 5775 STRCAT(buf, p); |
5776 vim_free(p); | |
5777 } | |
7 | 5778 else |
1712 | 5779 { |
5780 if (cmdchar == '*') | |
5781 aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\"); | |
5782 else if (cmdchar == '#') | |
5783 aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\"); | |
2049
23d366df1938
updated for version 7.2.335
Bram Moolenaar <bram@zimbu.org>
parents:
2040
diff
changeset
|
5784 else if (tag_cmd) |
2603 | 5785 { |
5786 if (curbuf->b_help) | |
5787 /* ":help" handles unescaped argument */ | |
5788 aux_ptr = (char_u *)""; | |
5789 else | |
5790 aux_ptr = (char_u *)"\\|\"\n["; | |
5791 } | |
1712 | 5792 else |
5793 aux_ptr = (char_u *)"\\|\"\n*?["; | |
5794 | |
5795 p = buf + STRLEN(buf); | |
5796 while (n-- > 0) | |
5797 { | |
5798 /* put a backslash before \ and some others */ | |
5799 if (vim_strchr(aux_ptr, *ptr) != NULL) | |
5800 *p++ = '\\'; | |
7 | 5801 #ifdef FEAT_MBYTE |
1712 | 5802 /* When current byte is a part of multibyte character, copy all |
5803 * bytes of that character. */ | |
5804 if (has_mbyte) | |
5805 { | |
5806 int i; | |
5807 int len = (*mb_ptr2len)(ptr) - 1; | |
5808 | |
5809 for (i = 0; i < len && n >= 1; ++i, --n) | |
5810 *p++ = *ptr++; | |
5811 } | |
5812 #endif | |
5813 *p++ = *ptr++; | |
5814 } | |
5815 *p = NUL; | |
5816 } | |
7 | 5817 |
5818 /* | |
5819 * Execute the command. | |
5820 */ | |
5821 if (cmdchar == '*' || cmdchar == '#') | |
5822 { | |
5823 if (!g_cmd && ( | |
5824 #ifdef FEAT_MBYTE | |
5825 has_mbyte ? vim_iswordp(mb_prevptr(ml_get_curline(), ptr)) : | |
5826 #endif | |
5827 vim_iswordc(ptr[-1]))) | |
5828 STRCAT(buf, "\\>"); | |
5829 #ifdef FEAT_CMDHIST | |
5830 /* put pattern in search history */ | |
2024 | 5831 init_history(); |
7 | 5832 add_to_history(HIST_SEARCH, buf, TRUE, NUL); |
5833 #endif | |
6620 | 5834 (void)normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0); |
7 | 5835 } |
5836 else | |
5837 do_cmdline_cmd(buf); | |
5838 | |
5839 vim_free(buf); | |
5840 } | |
5841 | |
5842 /* | |
5843 * Get visually selected text, within one line only. | |
5844 * Returns FAIL if more than one line selected. | |
5845 */ | |
344 | 5846 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5847 get_visual_text( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5848 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5849 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
|
5850 int *lenp) /* return: length of selected text */ |
7 | 5851 { |
5852 if (VIsual_mode != 'V') | |
5853 unadjust_for_sel(); | |
5854 if (VIsual.lnum != curwin->w_cursor.lnum) | |
5855 { | |
344 | 5856 if (cap != NULL) |
5857 clearopbeep(cap->oap); | |
7 | 5858 return FAIL; |
5859 } | |
5860 if (VIsual_mode == 'V') | |
5861 { | |
5862 *pp = ml_get_curline(); | |
5863 *lenp = (int)STRLEN(*pp); | |
5864 } | |
5865 else | |
5866 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
5867 if (LT_POS(curwin->w_cursor, VIsual)) |
7 | 5868 { |
5869 *pp = ml_get_pos(&curwin->w_cursor); | |
5870 *lenp = VIsual.col - curwin->w_cursor.col + 1; | |
5871 } | |
5872 else | |
5873 { | |
5874 *pp = ml_get_pos(&VIsual); | |
5875 *lenp = curwin->w_cursor.col - VIsual.col + 1; | |
5876 } | |
5877 #ifdef FEAT_MBYTE | |
5878 if (has_mbyte) | |
5879 /* Correct the length to include the whole last character. */ | |
474 | 5880 *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; |
7 | 5881 #endif |
5882 } | |
5883 reset_VIsual_and_resel(); | |
5884 return OK; | |
5885 } | |
5886 | |
5887 /* | |
5888 * CTRL-T: backwards in tag stack | |
5889 */ | |
5890 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5891 nv_tagpop(cmdarg_T *cap) |
7 | 5892 { |
5893 if (!checkclearopq(cap->oap)) | |
5894 do_tag((char_u *)"", DT_POP, (int)cap->count1, FALSE, TRUE); | |
5895 } | |
5896 | |
5897 /* | |
5898 * Handle scrolling command 'H', 'L' and 'M'. | |
5899 */ | |
5900 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
5901 nv_scroll(cmdarg_T *cap) |
7 | 5902 { |
5903 int used = 0; | |
5904 long n; | |
5905 #ifdef FEAT_FOLDING | |
5906 linenr_T lnum; | |
5907 #endif | |
5908 int half; | |
5909 | |
5910 cap->oap->motion_type = MLINE; | |
5911 setpcmark(); | |
5912 | |
5913 if (cap->cmdchar == 'L') | |
5914 { | |
5915 validate_botline(); /* make sure curwin->w_botline is valid */ | |
5916 curwin->w_cursor.lnum = curwin->w_botline - 1; | |
5917 if (cap->count1 - 1 >= curwin->w_cursor.lnum) | |
5918 curwin->w_cursor.lnum = 1; | |
5919 else | |
9 | 5920 { |
5921 #ifdef FEAT_FOLDING | |
5922 if (hasAnyFolding(curwin)) | |
5923 { | |
5924 /* Count a fold for one screen line. */ | |
5925 for (n = cap->count1 - 1; n > 0 | |
5926 && curwin->w_cursor.lnum > curwin->w_topline; --n) | |
5927 { | |
5928 (void)hasFolding(curwin->w_cursor.lnum, | |
5929 &curwin->w_cursor.lnum, NULL); | |
5930 --curwin->w_cursor.lnum; | |
5931 } | |
5932 } | |
5933 else | |
5934 #endif | |
5935 curwin->w_cursor.lnum -= cap->count1 - 1; | |
5936 } | |
7 | 5937 } |
5938 else | |
5939 { | |
5940 if (cap->cmdchar == 'M') | |
5941 { | |
5942 #ifdef FEAT_DIFF | |
5943 /* Don't count filler lines above the window. */ | |
5944 used -= diff_check_fill(curwin, curwin->w_topline) | |
5945 - curwin->w_topfill; | |
5946 #endif | |
5947 validate_botline(); /* make sure w_empty_rows is valid */ | |
5948 half = (curwin->w_height - curwin->w_empty_rows + 1) / 2; | |
5949 for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n) | |
5950 { | |
5951 #ifdef FEAT_DIFF | |
5952 /* Count half he number of filler lines to be "below this | |
5953 * line" and half to be "above the next line". */ | |
5954 if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline | |
5955 + n) / 2 >= half) | |
5956 { | |
5957 --n; | |
5958 break; | |
5959 } | |
5960 #endif | |
5961 used += plines(curwin->w_topline + n); | |
5962 if (used >= half) | |
5963 break; | |
5964 #ifdef FEAT_FOLDING | |
5965 if (hasFolding(curwin->w_topline + n, NULL, &lnum)) | |
5966 n = lnum - curwin->w_topline; | |
5967 #endif | |
5968 } | |
5969 if (n > 0 && used > curwin->w_height) | |
5970 --n; | |
5971 } | |
9 | 5972 else /* (cap->cmdchar == 'H') */ |
5973 { | |
7 | 5974 n = cap->count1 - 1; |
9 | 5975 #ifdef FEAT_FOLDING |
5976 if (hasAnyFolding(curwin)) | |
5977 { | |
5978 /* Count a fold for one screen line. */ | |
5979 lnum = curwin->w_topline; | |
5980 while (n-- > 0 && lnum < curwin->w_botline - 1) | |
5981 { | |
7009 | 5982 (void)hasFolding(lnum, NULL, &lnum); |
9 | 5983 ++lnum; |
5984 } | |
5985 n = lnum - curwin->w_topline; | |
5986 } | |
5987 #endif | |
5988 } | |
7 | 5989 curwin->w_cursor.lnum = curwin->w_topline + n; |
5990 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
5991 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
5992 } | |
5993 | |
12646
b908a3682f6e
patch 8.0.1201: "yL" is affected by 'scrolloff'
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
5994 /* 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
|
5995 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
|
5996 cursor_correct(); |
7 | 5997 beginline(BL_SOL | BL_FIX); |
5998 } | |
5999 | |
6000 /* | |
6001 * Cursor right commands. | |
6002 */ | |
6003 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6004 nv_right(cmdarg_T *cap) |
7 | 6005 { |
6006 long n; | |
5735 | 6007 int past_line; |
7 | 6008 |
180 | 6009 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
6010 { | |
6011 /* <C-Right> and <S-Right> move a word or WORD right */ | |
6012 if (mod_mask & MOD_MASK_CTRL) | |
6013 cap->arg = TRUE; | |
6014 nv_wordcmd(cap); | |
6015 return; | |
6016 } | |
6017 | |
7 | 6018 cap->oap->motion_type = MCHAR; |
6019 cap->oap->inclusive = FALSE; | |
5735 | 6020 past_line = (VIsual_active && *p_sel != 'o'); |
6021 | |
6022 #ifdef FEAT_VIRTUALEDIT | |
7 | 6023 /* |
5735 | 6024 * In virtual edit mode, there's no such thing as "past_line", as lines |
6025 * are (theoretically) infinitely long. | |
7 | 6026 */ |
6027 if (virtual_active()) | |
5735 | 6028 past_line = 0; |
7 | 6029 #endif |
6030 | |
6031 for (n = cap->count1; n > 0; --n) | |
6032 { | |
5735 | 6033 if ((!past_line && oneright() == FAIL) |
6034 || (past_line && *ml_get_cursor() == NUL) | |
1877 | 6035 ) |
7 | 6036 { |
6037 /* | |
714 | 6038 * <Space> wraps to next line if 'whichwrap' has 's'. |
6039 * 'l' wraps to next line if 'whichwrap' has 'l'. | |
6040 * CURS_RIGHT wraps to next line if 'whichwrap' has '>'. | |
7 | 6041 */ |
6042 if ( ((cap->cmdchar == ' ' | |
6043 && vim_strchr(p_ww, 's') != NULL) | |
6044 || (cap->cmdchar == 'l' | |
6045 && vim_strchr(p_ww, 'l') != NULL) | |
229 | 6046 || (cap->cmdchar == K_RIGHT |
7 | 6047 && vim_strchr(p_ww, '>') != NULL)) |
6048 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
6049 { | |
6050 /* When deleting we also count the NL as a character. | |
6051 * Set cap->oap->inclusive when last char in the line is | |
6052 * included, move to next line after that */ | |
714 | 6053 if ( cap->oap->op_type != OP_NOP |
7 | 6054 && !cap->oap->inclusive |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6055 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6056 cap->oap->inclusive = TRUE; |
6057 else | |
6058 { | |
6059 ++curwin->w_cursor.lnum; | |
6060 curwin->w_cursor.col = 0; | |
6061 #ifdef FEAT_VIRTUALEDIT | |
6062 curwin->w_cursor.coladd = 0; | |
6063 #endif | |
6064 curwin->w_set_curswant = TRUE; | |
6065 cap->oap->inclusive = FALSE; | |
6066 } | |
6067 continue; | |
6068 } | |
6069 if (cap->oap->op_type == OP_NOP) | |
6070 { | |
6071 /* Only beep and flush if not moved at all */ | |
6072 if (n == cap->count1) | |
6073 beep_flush(); | |
6074 } | |
6075 else | |
6076 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6077 if (!LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6078 cap->oap->inclusive = TRUE; |
6079 } | |
6080 break; | |
6081 } | |
5735 | 6082 else if (past_line) |
7 | 6083 { |
6084 curwin->w_set_curswant = TRUE; | |
5735 | 6085 #ifdef FEAT_VIRTUALEDIT |
7 | 6086 if (virtual_active()) |
6087 oneright(); | |
6088 else | |
5735 | 6089 #endif |
6090 { | |
6091 #ifdef FEAT_MBYTE | |
7 | 6092 if (has_mbyte) |
6093 curwin->w_cursor.col += | |
474 | 6094 (*mb_ptr2len)(ml_get_cursor()); |
7 | 6095 else |
5735 | 6096 #endif |
7 | 6097 ++curwin->w_cursor.col; |
6098 } | |
6099 } | |
6100 } | |
6101 #ifdef FEAT_FOLDING | |
6102 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
6103 && cap->oap->op_type == OP_NOP) | |
6104 foldOpenCursor(); | |
6105 #endif | |
6106 } | |
6107 | |
6108 /* | |
6109 * Cursor left commands. | |
6110 * | |
6111 * Returns TRUE when operator end should not be adjusted. | |
6112 */ | |
6113 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6114 nv_left(cmdarg_T *cap) |
7 | 6115 { |
6116 long n; | |
6117 | |
180 | 6118 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) |
6119 { | |
6120 /* <C-Left> and <S-Left> move a word or WORD left */ | |
6121 if (mod_mask & MOD_MASK_CTRL) | |
6122 cap->arg = 1; | |
6123 nv_bck_word(cap); | |
6124 return; | |
6125 } | |
6126 | |
7 | 6127 cap->oap->motion_type = MCHAR; |
6128 cap->oap->inclusive = FALSE; | |
6129 for (n = cap->count1; n > 0; --n) | |
6130 { | |
6131 if (oneleft() == FAIL) | |
6132 { | |
6133 /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'. | |
6134 * 'h' wraps to previous line if 'whichwrap' has 'h'. | |
6135 * CURS_LEFT wraps to previous line if 'whichwrap' has '<'. | |
6136 */ | |
6137 if ( (((cap->cmdchar == K_BS | |
6138 || cap->cmdchar == Ctrl_H) | |
6139 && vim_strchr(p_ww, 'b') != NULL) | |
6140 || (cap->cmdchar == 'h' | |
6141 && vim_strchr(p_ww, 'h') != NULL) | |
229 | 6142 || (cap->cmdchar == K_LEFT |
7 | 6143 && vim_strchr(p_ww, '<') != NULL)) |
6144 && curwin->w_cursor.lnum > 1) | |
6145 { | |
6146 --(curwin->w_cursor.lnum); | |
6147 coladvance((colnr_T)MAXCOL); | |
6148 curwin->w_set_curswant = TRUE; | |
6149 | |
6150 /* When the NL before the first char has to be deleted we | |
6151 * put the cursor on the NUL after the previous line. | |
6152 * This is a very special case, be careful! | |
1469 | 6153 * Don't adjust op_end now, otherwise it won't work. */ |
7 | 6154 if ( (cap->oap->op_type == OP_DELETE |
6155 || 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
|
6156 && !LINEEMPTY(curwin->w_cursor.lnum)) |
7 | 6157 { |
5682 | 6158 char_u *cp = ml_get_cursor(); |
6159 | |
6160 if (*cp != NUL) | |
6161 { | |
6162 #ifdef FEAT_MBYTE | |
6163 if (has_mbyte) | |
6164 curwin->w_cursor.col += (*mb_ptr2len)(cp); | |
6165 else | |
6166 #endif | |
6167 ++curwin->w_cursor.col; | |
6168 } | |
7 | 6169 cap->retval |= CA_NO_ADJ_OP_END; |
6170 } | |
6171 continue; | |
6172 } | |
6173 /* Only beep and flush if not moved at all */ | |
6174 else if (cap->oap->op_type == OP_NOP && n == cap->count1) | |
6175 beep_flush(); | |
6176 break; | |
6177 } | |
6178 } | |
6179 #ifdef FEAT_FOLDING | |
6180 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped | |
6181 && cap->oap->op_type == OP_NOP) | |
6182 foldOpenCursor(); | |
6183 #endif | |
6184 } | |
6185 | |
6186 /* | |
6187 * Cursor up commands. | |
6188 * cap->arg is TRUE for "-": Move cursor to first non-blank. | |
6189 */ | |
6190 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6191 nv_up(cmdarg_T *cap) |
7 | 6192 { |
180 | 6193 if (mod_mask & MOD_MASK_SHIFT) |
6194 { | |
6195 /* <S-Up> is page up */ | |
6196 cap->arg = BACKWARD; | |
6197 nv_page(cap); | |
6198 } | |
6199 else | |
6200 { | |
6201 cap->oap->motion_type = MLINE; | |
6202 if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
6203 clearopbeep(cap->oap); | |
6204 else if (cap->arg) | |
6205 beginline(BL_WHITE | BL_FIX); | |
6206 } | |
7 | 6207 } |
6208 | |
6209 /* | |
6210 * Cursor down commands. | |
6211 * cap->arg is TRUE for CR and "+": Move cursor to first non-blank. | |
6212 */ | |
6213 static void | |
10192
758f3d5a463d
commit https://github.com/vim/vim/commit/1b010058235fb803c1d4f42a02d2883921be8ef4
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
6214 nv_down(cmdarg_T *cap) |
7 | 6215 { |
180 | 6216 if (mod_mask & MOD_MASK_SHIFT) |
6217 { | |
6218 /* <S-Down> is page down */ | |
6219 cap->arg = FORWARD; | |
6220 nv_page(cap); | |
6221 } | |
6222 else | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12467
diff
changeset
|
6223 #if defined(FEAT_QUICKFIX) |
7 | 6224 /* In a quickfix window a <CR> jumps to the error under the cursor. */ |
170 | 6225 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
|
6226 { |
643 | 6227 if (curwin->w_llist_ref == NULL) |
6228 do_cmdline_cmd((char_u *)".cc"); /* quickfix window */ | |
6229 else | |
6230 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
|
6231 } |
7 | 6232 else |
6233 #endif | |
6234 { | |
6235 #ifdef FEAT_CMDWIN | |
6236 /* In the cmdline window a <CR> executes the command. */ | |
170 | 6237 if (cmdwin_type != 0 && cap->cmdchar == CAR) |
7 | 6238 cmdwin_result = CAR; |
6239 else | |
6240 #endif | |
6241 { | |
6242 cap->oap->motion_type = MLINE; | |
6243 if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == FAIL) | |
6244 clearopbeep(cap->oap); | |
6245 else if (cap->arg) | |
6246 beginline(BL_WHITE | BL_FIX); | |
6247 } | |
6248 } | |
6249 } | |
6250 | |
6251 #ifdef FEAT_SEARCHPATH | |
6252 /* | |
6253 * Grab the file name under the cursor and edit it. | |
6254 */ | |
6255 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6256 nv_gotofile(cmdarg_T *cap) |
7 | 6257 { |
6258 char_u *ptr; | |
681 | 6259 linenr_T lnum = -1; |
7 | 6260 |
633 | 6261 if (text_locked()) |
7 | 6262 { |
6263 clearopbeep(cap->oap); | |
633 | 6264 text_locked_msg(); |
7 | 6265 return; |
6266 } | |
819 | 6267 #ifdef FEAT_AUTOCMD |
6268 if (curbuf_locked()) | |
6269 { | |
6270 clearop(cap->oap); | |
6271 return; | |
6272 } | |
6273 #endif | |
7 | 6274 |
681 | 6275 ptr = grab_file_name(cap->count1, &lnum); |
7 | 6276 |
6277 if (ptr != NULL) | |
6278 { | |
6279 /* 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
|
6280 if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !buf_hide(curbuf)) |
7009 | 6281 (void)autowrite(curbuf, FALSE); |
7 | 6282 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
|
6283 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
|
6284 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
|
6285 && cap->nchar == 'F' && lnum >= 0) |
681 | 6286 { |
6287 curwin->w_cursor.lnum = lnum; | |
6288 check_cursor_lnum(); | |
6289 beginline(BL_SOL | BL_FIX); | |
6290 } | |
7 | 6291 vim_free(ptr); |
6292 } | |
6293 else | |
6294 clearop(cap->oap); | |
6295 } | |
6296 #endif | |
6297 | |
6298 /* | |
6299 * <End> command: to end of current line or last line. | |
6300 */ | |
6301 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6302 nv_end(cmdarg_T *cap) |
7 | 6303 { |
180 | 6304 if (cap->arg || (mod_mask & MOD_MASK_CTRL)) /* CTRL-END = goto last line */ |
6305 { | |
6306 cap->arg = TRUE; | |
7 | 6307 nv_goto(cap); |
6308 cap->count1 = 1; /* to end of current line */ | |
6309 } | |
6310 nv_dollar(cap); | |
6311 } | |
6312 | |
6313 /* | |
6314 * Handle the "$" command. | |
6315 */ | |
6316 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6317 nv_dollar(cmdarg_T *cap) |
7 | 6318 { |
6319 cap->oap->motion_type = MCHAR; | |
6320 cap->oap->inclusive = TRUE; | |
6321 #ifdef FEAT_VIRTUALEDIT | |
6322 /* In virtual mode when off the edge of a line and an operator | |
6323 * is pending (whew!) keep the cursor where it is. | |
6324 * Otherwise, send it to the end of the line. */ | |
6325 if (!virtual_active() || gchar_cursor() != NUL | |
6326 || cap->oap->op_type == OP_NOP) | |
6327 #endif | |
6328 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
6329 if (cursor_down((long)(cap->count1 - 1), | |
6330 cap->oap->op_type == OP_NOP) == FAIL) | |
6331 clearopbeep(cap->oap); | |
6332 #ifdef FEAT_FOLDING | |
6333 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6334 foldOpenCursor(); | |
6335 #endif | |
6336 } | |
6337 | |
6338 /* | |
6339 * Implementation of '?' and '/' commands. | |
6340 * If cap->arg is TRUE don't set PC mark. | |
6341 */ | |
6342 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6343 nv_search(cmdarg_T *cap) |
7 | 6344 { |
6345 oparg_T *oap = cap->oap; | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6346 pos_T save_cursor = curwin->w_cursor; |
7 | 6347 |
6348 if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13) | |
6349 { | |
6350 /* Translate "g??" to "g?g?" */ | |
6351 cap->cmdchar = 'g'; | |
6352 cap->nchar = '?'; | |
6353 nv_operator(cap); | |
6354 return; | |
6355 } | |
6356 | |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
6357 /* 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
|
6358 * start position. */ |
7 | 6359 cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0); |
6360 | |
6361 if (cap->searchbuf == NULL) | |
6362 { | |
6363 clearop(oap); | |
6364 return; | |
6365 } | |
6366 | |
6620 | 6367 (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
|
6368 (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
|
6369 ? 0 : SEARCH_MARK); |
7 | 6370 } |
6371 | |
6372 /* | |
6373 * Handle "N" and "n" commands. | |
6374 * cap->arg is SEARCH_REV for "N", 0 for "n". | |
6375 */ | |
6376 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6377 nv_next(cmdarg_T *cap) |
7 | 6378 { |
6620 | 6379 pos_T old = curwin->w_cursor; |
6380 int i = normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
6381 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6382 if (i == 1 && EQUAL_POS(old, curwin->w_cursor)) |
6620 | 6383 { |
6384 /* Avoid getting stuck on the current cursor position, which can | |
6385 * happen when an offset is given and the cursor is on the last char | |
6386 * in the buffer: Repeat with count + 1. */ | |
6387 cap->count1 += 1; | |
6388 (void)normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg); | |
6389 cap->count1 -= 1; | |
6390 } | |
7 | 6391 } |
6392 | |
6393 /* | |
6394 * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat). | |
6395 * Uses only cap->count1 and cap->oap from "cap". | |
6620 | 6396 * Return 0 for failure, 1 for found, 2 for found and line offset added. |
6397 */ | |
6398 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6399 normal_search( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6400 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6401 int dir, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6402 char_u *pat, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6403 int opt) /* extra flags for do_search() */ |
7 | 6404 { |
6405 int i; | |
6406 | |
6407 cap->oap->motion_type = MCHAR; | |
6408 cap->oap->inclusive = FALSE; | |
6409 cap->oap->use_reg_one = TRUE; | |
6410 curwin->w_set_curswant = TRUE; | |
6411 | |
6412 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
|
6413 opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, NULL, NULL); |
7 | 6414 if (i == 0) |
6415 clearop(cap->oap); | |
6416 else | |
6417 { | |
6418 if (i == 2) | |
6419 cap->oap->motion_type = MLINE; | |
6420 #ifdef FEAT_VIRTUALEDIT | |
6421 curwin->w_cursor.coladd = 0; | |
6422 #endif | |
6423 #ifdef FEAT_FOLDING | |
6424 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
6425 foldOpenCursor(); | |
6426 #endif | |
6427 } | |
6428 | |
6429 /* "/$" will put the cursor after the end of the line, may need to | |
6430 * correct that here */ | |
6431 check_cursor(); | |
6620 | 6432 return i; |
7 | 6433 } |
6434 | |
6435 /* | |
6436 * Character search commands. | |
6437 * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for | |
6438 * ',' and FALSE for ';'. | |
6439 * cap->nchar is NUL for ',' and ';' (repeat the search) | |
6440 */ | |
6441 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6442 nv_csearch(cmdarg_T *cap) |
7 | 6443 { |
6444 int t_cmd; | |
6445 | |
6446 if (cap->cmdchar == 't' || cap->cmdchar == 'T') | |
6447 t_cmd = TRUE; | |
6448 else | |
6449 t_cmd = FALSE; | |
6450 | |
6451 cap->oap->motion_type = MCHAR; | |
6452 if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL) | |
6453 clearopbeep(cap->oap); | |
6454 else | |
6455 { | |
6456 curwin->w_set_curswant = TRUE; | |
6457 #ifdef FEAT_VIRTUALEDIT | |
6458 /* Include a Tab for "tx" and for "dfx". */ | |
6459 if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD | |
6460 && (t_cmd || cap->oap->op_type != OP_NOP)) | |
6461 { | |
6462 colnr_T scol, ecol; | |
6463 | |
6464 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
6465 curwin->w_cursor.coladd = ecol - scol; | |
6466 } | |
6467 else | |
6468 curwin->w_cursor.coladd = 0; | |
6469 #endif | |
6470 adjust_for_sel(cap); | |
6471 #ifdef FEAT_FOLDING | |
6472 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6473 foldOpenCursor(); | |
6474 #endif | |
6475 } | |
6476 } | |
6477 | |
6478 /* | |
6479 * "[" and "]" commands. | |
6480 * cap->arg is BACKWARD for "[" and FORWARD for "]". | |
6481 */ | |
6482 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6483 nv_brackets(cmdarg_T *cap) |
7 | 6484 { |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
6485 pos_T new_pos = INIT_POS_T(0, 0, 0); |
7 | 6486 pos_T prev_pos; |
6487 pos_T *pos = NULL; /* init for GCC */ | |
6488 pos_T old_pos; /* cursor position before command */ | |
6489 int flag; | |
6490 long n; | |
6491 int findc; | |
6492 int c; | |
6493 | |
6494 cap->oap->motion_type = MCHAR; | |
6495 cap->oap->inclusive = FALSE; | |
6496 old_pos = curwin->w_cursor; | |
6497 #ifdef FEAT_VIRTUALEDIT | |
6498 curwin->w_cursor.coladd = 0; /* TODO: don't do this for an error. */ | |
6499 #endif | |
6500 | |
6501 #ifdef FEAT_SEARCHPATH | |
6502 /* | |
6503 * "[f" or "]f" : Edit file under the cursor (same as "gf") | |
6504 */ | |
6505 if (cap->nchar == 'f') | |
6506 nv_gotofile(cap); | |
6507 else | |
6508 #endif | |
6509 | |
6510 #ifdef FEAT_FIND_ID | |
6511 /* | |
1188 | 6512 * Find the occurrence(s) of the identifier or define under cursor |
6513 * in current and included files or jump to the first occurrence. | |
7 | 6514 * |
6515 * search list jump | |
6516 * fwd bwd fwd bwd fwd bwd | |
6517 * identifier "]i" "[i" "]I" "[I" "]^I" "[^I" | |
6518 * define "]d" "[d" "]D" "[D" "]^D" "[^D" | |
6519 */ | |
6520 if (vim_strchr((char_u *) | |
6521 #ifdef EBCDIC | |
6522 "iI\005dD\067", | |
6523 #else | |
6524 "iI\011dD\004", | |
6525 #endif | |
6526 cap->nchar) != NULL) | |
6527 { | |
6528 char_u *ptr; | |
6529 int len; | |
6530 | |
6531 if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) | |
6532 clearop(cap->oap); | |
6533 else | |
6534 { | |
6535 find_pattern_in_path(ptr, 0, len, TRUE, | |
6536 cap->count0 == 0 ? !isupper(cap->nchar) : FALSE, | |
6537 ((cap->nchar & 0xf) == ('d' & 0xf)) ? FIND_DEFINE : FIND_ANY, | |
6538 cap->count1, | |
6539 isupper(cap->nchar) ? ACTION_SHOW_ALL : | |
6540 islower(cap->nchar) ? ACTION_SHOW : ACTION_GOTO, | |
6541 cap->cmdchar == ']' ? curwin->w_cursor.lnum + 1 : (linenr_T)1, | |
6542 (linenr_T)MAXLNUM); | |
6543 curwin->w_set_curswant = TRUE; | |
6544 } | |
6545 } | |
6546 else | |
6547 #endif | |
6548 | |
6549 /* | |
6550 * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')' | |
6551 * "[#", "]#": go to start/end of Nth innermost #if..#endif construct. | |
6552 * "[/", "[*", "]/", "]*": go to Nth comment start/end. | |
6553 * "[m" or "]m" search for prev/next start of (Java) method. | |
6554 * "[M" or "]M" search for prev/next end of (Java) method. | |
6555 */ | |
6556 if ( (cap->cmdchar == '[' | |
6557 && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL) | |
6558 || (cap->cmdchar == ']' | |
6559 && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL)) | |
6560 { | |
6561 if (cap->nchar == '*') | |
6562 cap->nchar = '/'; | |
6563 prev_pos.lnum = 0; | |
6564 if (cap->nchar == 'm' || cap->nchar == 'M') | |
6565 { | |
6566 if (cap->cmdchar == '[') | |
6567 findc = '{'; | |
6568 else | |
6569 findc = '}'; | |
6570 n = 9999; | |
6571 } | |
6572 else | |
6573 { | |
6574 findc = cap->nchar; | |
6575 n = cap->count1; | |
6576 } | |
6577 for ( ; n > 0; --n) | |
6578 { | |
6579 if ((pos = findmatchlimit(cap->oap, findc, | |
6580 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL) | |
6581 { | |
6582 if (new_pos.lnum == 0) /* nothing found */ | |
6583 { | |
6584 if (cap->nchar != 'm' && cap->nchar != 'M') | |
6585 clearopbeep(cap->oap); | |
6586 } | |
6587 else | |
6588 pos = &new_pos; /* use last one found */ | |
6589 break; | |
6590 } | |
6591 prev_pos = new_pos; | |
6592 curwin->w_cursor = *pos; | |
6593 new_pos = *pos; | |
6594 } | |
6595 curwin->w_cursor = old_pos; | |
6596 | |
6597 /* | |
6598 * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only | |
6599 * brought us to the match for "[m" and "]M" when inside a method. | |
6600 * Try finding the '{' or '}' we want to be at. | |
6601 * Also repeat for the given count. | |
6602 */ | |
6603 if (cap->nchar == 'm' || cap->nchar == 'M') | |
6604 { | |
6605 /* norm is TRUE for "]M" and "[m" */ | |
6606 int norm = ((findc == '{') == (cap->nchar == 'm')); | |
6607 | |
6608 n = cap->count1; | |
6609 /* found a match: we were inside a method */ | |
6610 if (prev_pos.lnum != 0) | |
6611 { | |
6612 pos = &prev_pos; | |
6613 curwin->w_cursor = prev_pos; | |
6614 if (norm) | |
6615 --n; | |
6616 } | |
6617 else | |
6618 pos = NULL; | |
6619 while (n > 0) | |
6620 { | |
6621 for (;;) | |
6622 { | |
6623 if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0) | |
6624 { | |
6625 /* if not found anything, that's an error */ | |
6626 if (pos == NULL) | |
6627 clearopbeep(cap->oap); | |
6628 n = 0; | |
6629 break; | |
6630 } | |
6631 c = gchar_cursor(); | |
6632 if (c == '{' || c == '}') | |
6633 { | |
6634 /* Must have found end/start of class: use it. | |
6635 * Or found the place to be at. */ | |
6636 if ((c == findc && norm) || (n == 1 && !norm)) | |
6637 { | |
6638 new_pos = curwin->w_cursor; | |
6639 pos = &new_pos; | |
6640 n = 0; | |
6641 } | |
6642 /* if no match found at all, we started outside of the | |
6643 * class and we're inside now. Just go on. */ | |
6644 else if (new_pos.lnum == 0) | |
6645 { | |
6646 new_pos = curwin->w_cursor; | |
6647 pos = &new_pos; | |
6648 } | |
6649 /* found start/end of other method: go to match */ | |
6650 else if ((pos = findmatchlimit(cap->oap, findc, | |
6651 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, | |
6652 0)) == NULL) | |
6653 n = 0; | |
6654 else | |
6655 curwin->w_cursor = *pos; | |
6656 break; | |
6657 } | |
6658 } | |
6659 --n; | |
6660 } | |
6661 curwin->w_cursor = old_pos; | |
6662 if (pos == NULL && new_pos.lnum != 0) | |
6663 clearopbeep(cap->oap); | |
6664 } | |
6665 if (pos != NULL) | |
6666 { | |
6667 setpcmark(); | |
6668 curwin->w_cursor = *pos; | |
6669 curwin->w_set_curswant = TRUE; | |
6670 #ifdef FEAT_FOLDING | |
6671 if ((fdo_flags & FDO_BLOCK) && KeyTyped | |
6672 && cap->oap->op_type == OP_NOP) | |
6673 foldOpenCursor(); | |
6674 #endif | |
6675 } | |
6676 } | |
6677 | |
6678 /* | |
6679 * "[[", "[]", "]]" and "][": move to start or end of function | |
6680 */ | |
6681 else if (cap->nchar == '[' || cap->nchar == ']') | |
6682 { | |
6683 if (cap->nchar == cap->cmdchar) /* "]]" or "[[" */ | |
6684 flag = '{'; | |
6685 else | |
6686 flag = '}'; /* "][" or "[]" */ | |
6687 | |
6688 curwin->w_set_curswant = TRUE; | |
6689 /* | |
6690 * Imitate strange Vi behaviour: When using "]]" with an operator | |
6691 * we also stop at '}'. | |
6692 */ | |
503 | 6693 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, flag, |
7 | 6694 (cap->oap->op_type != OP_NOP |
6695 && cap->arg == FORWARD && flag == '{'))) | |
6696 clearopbeep(cap->oap); | |
6697 else | |
6698 { | |
6699 if (cap->oap->op_type == OP_NOP) | |
6700 beginline(BL_WHITE | BL_FIX); | |
6701 #ifdef FEAT_FOLDING | |
6702 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6703 foldOpenCursor(); | |
6704 #endif | |
6705 } | |
6706 } | |
6707 | |
6708 /* | |
6709 * "[p", "[P", "]P" and "]p": put with indent adjustment | |
6710 */ | |
6711 else if (cap->nchar == 'p' || cap->nchar == 'P') | |
6712 { | |
1312 | 6713 if (!checkclearop(cap->oap)) |
7 | 6714 { |
5708 | 6715 int dir = (cap->cmdchar == ']' && cap->nchar == 'p') |
6716 ? FORWARD : BACKWARD; | |
6717 int regname = cap->oap->regname; | |
6718 int was_visual = VIsual_active; | |
6719 int line_count = curbuf->b_ml.ml_line_count; | |
6720 pos_T start, end; | |
6721 | |
6722 if (VIsual_active) | |
6723 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
6724 start = LTOREQ_POS(VIsual, curwin->w_cursor) |
5708 | 6725 ? 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
|
6726 end = EQUAL_POS(start,VIsual) ? curwin->w_cursor : VIsual; |
5708 | 6727 curwin->w_cursor = (dir == BACKWARD ? start : end); |
6728 } | |
6729 # ifdef FEAT_CLIPBOARD | |
6730 adjust_clip_reg(®name); | |
6731 # endif | |
7 | 6732 prep_redo_cmd(cap); |
5708 | 6733 |
6734 do_put(regname, dir, cap->count1, PUT_FIXINDENT); | |
6735 if (was_visual) | |
6736 { | |
6737 VIsual = start; | |
6738 curwin->w_cursor = end; | |
6739 if (dir == BACKWARD) | |
6740 { | |
6741 /* adjust lines */ | |
6742 VIsual.lnum += curbuf->b_ml.ml_line_count - line_count; | |
6743 curwin->w_cursor.lnum += | |
6744 curbuf->b_ml.ml_line_count - line_count; | |
6745 } | |
6746 | |
6747 VIsual_active = TRUE; | |
6748 if (VIsual_mode == 'V') | |
6749 { | |
6750 /* delete visually selected lines */ | |
6751 cap->cmdchar = 'd'; | |
6752 cap->nchar = NUL; | |
6753 cap->oap->regname = regname; | |
6754 nv_operator(cap); | |
6755 do_pending_operator(cap, 0, FALSE); | |
6756 } | |
6757 if (VIsual_active) | |
6758 { | |
6759 end_visual_mode(); | |
6760 redraw_later(SOME_VALID); | |
6761 } | |
6762 } | |
7 | 6763 } |
6764 } | |
6765 | |
6766 /* | |
6767 * "['", "[`", "]'" and "]`": jump to next mark | |
6768 */ | |
6769 else if (cap->nchar == '\'' || cap->nchar == '`') | |
6770 { | |
6771 pos = &curwin->w_cursor; | |
6772 for (n = cap->count1; n > 0; --n) | |
6773 { | |
6774 prev_pos = *pos; | |
6775 pos = getnextmark(pos, cap->cmdchar == '[' ? BACKWARD : FORWARD, | |
6776 cap->nchar == '\''); | |
6777 if (pos == NULL) | |
6778 break; | |
6779 } | |
6780 if (pos == NULL) | |
6781 pos = &prev_pos; | |
6782 nv_cursormark(cap, cap->nchar == '\'', pos); | |
6783 } | |
6784 | |
6785 #ifdef FEAT_MOUSE | |
6786 /* | |
6787 * [ or ] followed by a middle mouse click: put selected text with | |
6788 * indent adjustment. Any other button just does as usual. | |
6789 */ | |
2130
279380a812ad
updated for version 7.2.412
Bram Moolenaar <bram@zimbu.org>
parents:
2112
diff
changeset
|
6790 else if (cap->nchar >= K_RIGHTRELEASE && cap->nchar <= K_LEFTMOUSE) |
7 | 6791 { |
6792 (void)do_mouse(cap->oap, cap->nchar, | |
6793 (cap->cmdchar == ']') ? FORWARD : BACKWARD, | |
6794 cap->count1, PUT_FIXINDENT); | |
6795 } | |
6796 #endif /* FEAT_MOUSE */ | |
6797 | |
6798 #ifdef FEAT_FOLDING | |
6799 /* | |
6800 * "[z" and "]z": move to start or end of open fold. | |
6801 */ | |
6802 else if (cap->nchar == 'z') | |
6803 { | |
6804 if (foldMoveTo(FALSE, cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
6805 cap->count1) == FAIL) | |
6806 clearopbeep(cap->oap); | |
6807 } | |
6808 #endif | |
6809 | |
6810 #ifdef FEAT_DIFF | |
6811 /* | |
6812 * "[c" and "]c": move to next or previous diff-change. | |
6813 */ | |
6814 else if (cap->nchar == 'c') | |
6815 { | |
6816 if (diff_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD, | |
6817 cap->count1) == FAIL) | |
6818 clearopbeep(cap->oap); | |
6819 } | |
6820 #endif | |
6821 | |
737 | 6822 #ifdef FEAT_SPELL |
236 | 6823 /* |
6824 * "[s", "[S", "]s" and "]S": move to next spell error. | |
6825 */ | |
6826 else if (cap->nchar == 's' || cap->nchar == 'S') | |
6827 { | |
249 | 6828 setpcmark(); |
6829 for (n = 0; n < cap->count1; ++n) | |
498 | 6830 if (spell_move_to(curwin, cap->cmdchar == ']' ? FORWARD : BACKWARD, |
6831 cap->nchar == 's' ? TRUE : FALSE, FALSE, NULL) == 0) | |
249 | 6832 { |
6833 clearopbeep(cap->oap); | |
6834 break; | |
6835 } | |
13088
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
6836 else |
3dd37eec73f0
patch 8.0.1419: cursor column is not updated after ]s
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
6837 curwin->w_set_curswant = TRUE; |
819 | 6838 # ifdef FEAT_FOLDING |
6839 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped) | |
6840 foldOpenCursor(); | |
6841 # endif | |
236 | 6842 } |
6843 #endif | |
6844 | |
7 | 6845 /* Not a valid cap->nchar. */ |
6846 else | |
6847 clearopbeep(cap->oap); | |
6848 } | |
6849 | |
6850 /* | |
6851 * Handle Normal mode "%" command. | |
6852 */ | |
6853 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6854 nv_percent(cmdarg_T *cap) |
7 | 6855 { |
6856 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
|
6857 #if defined(FEAT_FOLDING) |
7 | 6858 linenr_T lnum = curwin->w_cursor.lnum; |
6859 #endif | |
6860 | |
6861 cap->oap->inclusive = TRUE; | |
6862 if (cap->count0) /* {cnt}% : goto {cnt} percentage in file */ | |
6863 { | |
6864 if (cap->count0 > 100) | |
6865 clearopbeep(cap->oap); | |
6866 else | |
6867 { | |
6868 cap->oap->motion_type = MLINE; | |
6869 setpcmark(); | |
6870 /* Round up, so CTRL-G will give same value. Watch out for a | |
6871 * large line count, the line number must not go negative! */ | |
6872 if (curbuf->b_ml.ml_line_count > 1000000) | |
6873 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L) | |
6874 / 100L * cap->count0; | |
6875 else | |
6876 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count * | |
6877 cap->count0 + 99L) / 100L; | |
6878 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
6879 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
6880 beginline(BL_SOL | BL_FIX); | |
6881 } | |
6882 } | |
6883 else /* "%" : go to matching paren */ | |
6884 { | |
6885 cap->oap->motion_type = MCHAR; | |
6886 cap->oap->use_reg_one = TRUE; | |
6887 if ((pos = findmatch(cap->oap, NUL)) == NULL) | |
6888 clearopbeep(cap->oap); | |
6889 else | |
6890 { | |
6891 setpcmark(); | |
6892 curwin->w_cursor = *pos; | |
6893 curwin->w_set_curswant = TRUE; | |
6894 #ifdef FEAT_VIRTUALEDIT | |
6895 curwin->w_cursor.coladd = 0; | |
6896 #endif | |
6897 adjust_for_sel(cap); | |
6898 } | |
6899 } | |
6900 #ifdef FEAT_FOLDING | |
6901 if (cap->oap->op_type == OP_NOP | |
6902 && lnum != curwin->w_cursor.lnum | |
6903 && (fdo_flags & FDO_PERCENT) | |
6904 && KeyTyped) | |
6905 foldOpenCursor(); | |
6906 #endif | |
6907 } | |
6908 | |
6909 /* | |
6910 * Handle "(" and ")" commands. | |
6911 * cap->arg is BACKWARD for "(" and FORWARD for ")". | |
6912 */ | |
6913 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6914 nv_brace(cmdarg_T *cap) |
7 | 6915 { |
6916 cap->oap->motion_type = MCHAR; | |
6917 cap->oap->use_reg_one = TRUE; | |
620 | 6918 /* The motion used to be inclusive for "(", but that is not what Vi does. */ |
6919 cap->oap->inclusive = FALSE; | |
7 | 6920 curwin->w_set_curswant = TRUE; |
6921 | |
6922 if (findsent(cap->arg, cap->count1) == FAIL) | |
6923 clearopbeep(cap->oap); | |
6924 else | |
6925 { | |
1505 | 6926 /* Don't leave the cursor on the NUL past end of line. */ |
6927 adjust_cursor(cap->oap); | |
7 | 6928 #ifdef FEAT_VIRTUALEDIT |
6929 curwin->w_cursor.coladd = 0; | |
6930 #endif | |
6931 #ifdef FEAT_FOLDING | |
6932 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6933 foldOpenCursor(); | |
6934 #endif | |
6935 } | |
6936 } | |
6937 | |
6938 /* | |
6939 * "m" command: Mark a position. | |
6940 */ | |
6941 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6942 nv_mark(cmdarg_T *cap) |
7 | 6943 { |
6944 if (!checkclearop(cap->oap)) | |
6945 { | |
6946 if (setmark(cap->nchar) == FAIL) | |
6947 clearopbeep(cap->oap); | |
6948 } | |
6949 } | |
6950 | |
6951 /* | |
6952 * "{" and "}" commands. | |
6953 * cmd->arg is BACKWARD for "{" and FORWARD for "}". | |
6954 */ | |
6955 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6956 nv_findpar(cmdarg_T *cap) |
7 | 6957 { |
6958 cap->oap->motion_type = MCHAR; | |
6959 cap->oap->inclusive = FALSE; | |
6960 cap->oap->use_reg_one = TRUE; | |
6961 curwin->w_set_curswant = TRUE; | |
503 | 6962 if (!findpar(&cap->oap->inclusive, cap->arg, cap->count1, NUL, FALSE)) |
7 | 6963 clearopbeep(cap->oap); |
6964 else | |
6965 { | |
6966 #ifdef FEAT_VIRTUALEDIT | |
6967 curwin->w_cursor.coladd = 0; | |
6968 #endif | |
6969 #ifdef FEAT_FOLDING | |
6970 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP) | |
6971 foldOpenCursor(); | |
6972 #endif | |
6973 } | |
6974 } | |
6975 | |
6976 /* | |
6977 * "u" command: Undo or make lower case. | |
6978 */ | |
6979 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6980 nv_undo(cmdarg_T *cap) |
7 | 6981 { |
5735 | 6982 if (cap->oap->op_type == OP_LOWER || VIsual_active) |
7 | 6983 { |
6984 /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */ | |
6985 cap->cmdchar = 'g'; | |
6986 cap->nchar = 'u'; | |
6987 nv_operator(cap); | |
6988 } | |
6989 else | |
6990 nv_kundo(cap); | |
6991 } | |
6992 | |
6993 /* | |
6994 * <Undo> command. | |
6995 */ | |
6996 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
6997 nv_kundo(cmdarg_T *cap) |
7 | 6998 { |
6999 if (!checkclearopq(cap->oap)) | |
7000 { | |
7001 u_undo((int)cap->count1); | |
7002 curwin->w_set_curswant = TRUE; | |
7003 } | |
7004 } | |
7005 | |
7006 /* | |
7007 * Handle the "r" command. | |
7008 */ | |
7009 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7010 nv_replace(cmdarg_T *cap) |
7 | 7011 { |
7012 char_u *ptr; | |
7013 int had_ctrl_v; | |
7014 long n; | |
7015 | |
7016 if (checkclearop(cap->oap)) | |
7017 return; | |
7018 | |
7019 /* get another character */ | |
7020 if (cap->nchar == Ctrl_V) | |
7021 { | |
7022 had_ctrl_v = Ctrl_V; | |
7023 cap->nchar = get_literal(); | |
7024 /* Don't redo a multibyte character with CTRL-V. */ | |
7025 if (cap->nchar > DEL) | |
7026 had_ctrl_v = NUL; | |
7027 } | |
7028 else | |
7029 had_ctrl_v = NUL; | |
7030 | |
1343 | 7031 /* Abort if the character is a special key. */ |
7032 if (IS_SPECIAL(cap->nchar)) | |
7033 { | |
7034 clearopbeep(cap->oap); | |
7035 return; | |
7036 } | |
7037 | |
7 | 7038 /* Visual mode "r" */ |
7039 if (VIsual_active) | |
7040 { | |
1797 | 7041 if (got_int) |
7042 reset_VIsual(); | |
5428 | 7043 if (had_ctrl_v) |
7044 { | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
7045 /* 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
|
7046 * 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
|
7047 if (cap->nchar == CAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13088
diff
changeset
|
7048 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
|
7049 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
|
7050 cap->nchar = REPLACE_NL_NCHAR; |
5428 | 7051 } |
7 | 7052 nv_operator(cap); |
7053 return; | |
7054 } | |
7055 | |
7056 #ifdef FEAT_VIRTUALEDIT | |
7057 /* Break tabs, etc. */ | |
7058 if (virtual_active()) | |
7059 { | |
7060 if (u_save_cursor() == FAIL) | |
7061 return; | |
7062 if (gchar_cursor() == NUL) | |
7063 { | |
7064 /* Add extra space and put the cursor on the first one. */ | |
7065 coladvance_force((colnr_T)(getviscol() + cap->count1)); | |
7066 curwin->w_cursor.col -= cap->count1; | |
7067 } | |
7068 else if (gchar_cursor() == TAB) | |
7069 coladvance_force(getviscol()); | |
7070 } | |
7071 #endif | |
7072 | |
1343 | 7073 /* Abort if not enough characters to replace. */ |
7 | 7074 ptr = ml_get_cursor(); |
1343 | 7075 if (STRLEN(ptr) < (unsigned)cap->count1 |
7 | 7076 #ifdef FEAT_MBYTE |
7077 || (has_mbyte && mb_charlen(ptr) < cap->count1) | |
7078 #endif | |
7079 ) | |
7080 { | |
7081 clearopbeep(cap->oap); | |
7082 return; | |
7083 } | |
7084 | |
7085 /* | |
7086 * Replacing with a TAB is done by edit() when it is complicated because | |
7087 * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB. | |
7088 * Other characters are done below to avoid problems with things like | |
7089 * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC). | |
7090 */ | |
7091 if (had_ctrl_v != Ctrl_V && cap->nchar == '\t' && (curbuf->b_p_et || p_sta)) | |
7092 { | |
7093 stuffnumReadbuff(cap->count1); | |
7094 stuffcharReadbuff('R'); | |
7095 stuffcharReadbuff('\t'); | |
7096 stuffcharReadbuff(ESC); | |
7097 return; | |
7098 } | |
7099 | |
7100 /* save line for undo */ | |
7101 if (u_save_cursor() == FAIL) | |
7102 return; | |
7103 | |
7104 if (had_ctrl_v != Ctrl_V && (cap->nchar == '\r' || cap->nchar == '\n')) | |
7105 { | |
7106 /* | |
7107 * Replace character(s) by a single newline. | |
7108 * Strange vi behaviour: Only one newline is inserted. | |
7109 * Delete the characters here. | |
7110 * Insert the newline with an insert command, takes care of | |
7111 * autoindent. The insert command depends on being on the last | |
7112 * character of a line or not. | |
7113 */ | |
7114 #ifdef FEAT_MBYTE | |
7115 (void)del_chars(cap->count1, FALSE); /* delete the characters */ | |
7116 #else | |
608 | 7117 (void)del_bytes(cap->count1, FALSE, FALSE); /* delete the characters */ |
7 | 7118 #endif |
7119 stuffcharReadbuff('\r'); | |
7120 stuffcharReadbuff(ESC); | |
7121 | |
7122 /* Give 'r' to edit(), to get the redo command right. */ | |
7123 invoke_edit(cap, TRUE, 'r', FALSE); | |
7124 } | |
7125 else | |
7126 { | |
7127 prep_redo(cap->oap->regname, cap->count1, | |
7128 NUL, 'r', NUL, had_ctrl_v, cap->nchar); | |
7129 | |
7130 curbuf->b_op_start = curwin->w_cursor; | |
7131 #ifdef FEAT_MBYTE | |
7132 if (has_mbyte) | |
7133 { | |
7134 int old_State = State; | |
7135 | |
7136 if (cap->ncharC1 != 0) | |
7137 AppendCharToRedobuff(cap->ncharC1); | |
7138 if (cap->ncharC2 != 0) | |
7139 AppendCharToRedobuff(cap->ncharC2); | |
7140 | |
7141 /* This is slow, but it handles replacing a single-byte with a | |
7142 * multi-byte and the other way around. Also handles adding | |
7143 * composing characters for utf-8. */ | |
7144 for (n = cap->count1; n > 0; --n) | |
7145 { | |
7146 State = REPLACE; | |
3501 | 7147 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7148 { | |
7149 int c = ins_copychar(curwin->w_cursor.lnum | |
7150 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7151 if (c != NUL) | |
7152 ins_char(c); | |
7153 else | |
7154 /* will be decremented further down */ | |
7155 ++curwin->w_cursor.col; | |
7156 } | |
7157 else | |
7158 ins_char(cap->nchar); | |
7 | 7159 State = old_State; |
7160 if (cap->ncharC1 != 0) | |
7161 ins_char(cap->ncharC1); | |
7162 if (cap->ncharC2 != 0) | |
7163 ins_char(cap->ncharC2); | |
7164 } | |
7165 } | |
7166 else | |
7167 #endif | |
7168 { | |
7169 /* | |
7170 * Replace the characters within one line. | |
7171 */ | |
7172 for (n = cap->count1; n > 0; --n) | |
7173 { | |
7174 /* | |
7175 * Get ptr again, because u_save and/or showmatch() will have | |
7176 * released the line. At the same time we let know that the | |
7177 * line will be changed. | |
7178 */ | |
7179 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); | |
3501 | 7180 if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) |
7181 { | |
7182 int c = ins_copychar(curwin->w_cursor.lnum | |
7183 + (cap->nchar == Ctrl_Y ? -1 : 1)); | |
7184 if (c != NUL) | |
7185 ptr[curwin->w_cursor.col] = c; | |
7186 } | |
7187 else | |
7188 ptr[curwin->w_cursor.col] = cap->nchar; | |
7 | 7189 if (p_sm && msg_silent == 0) |
7190 showmatch(cap->nchar); | |
7191 ++curwin->w_cursor.col; | |
7192 } | |
7193 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7194 if (netbeans_active()) |
7 | 7195 { |
2210 | 7196 colnr_T start = (colnr_T)(curwin->w_cursor.col - cap->count1); |
7 | 7197 |
33 | 7198 netbeans_removed(curbuf, curwin->w_cursor.lnum, start, |
2210 | 7199 (long)cap->count1); |
7 | 7200 netbeans_inserted(curbuf, curwin->w_cursor.lnum, start, |
33 | 7201 &ptr[start], (int)cap->count1); |
7 | 7202 } |
7203 #endif | |
7204 | |
7205 /* mark the buffer as changed and prepare for displaying */ | |
7206 changed_bytes(curwin->w_cursor.lnum, | |
7207 (colnr_T)(curwin->w_cursor.col - cap->count1)); | |
7208 } | |
7209 --curwin->w_cursor.col; /* cursor on the last replaced char */ | |
7210 #ifdef FEAT_MBYTE | |
7211 /* if the character on the left of the current cursor is a multi-byte | |
7212 * character, move two characters left */ | |
7213 if (has_mbyte) | |
7214 mb_adjust_cursor(); | |
7215 #endif | |
7216 curbuf->b_op_end = curwin->w_cursor; | |
7217 curwin->w_set_curswant = TRUE; | |
7218 set_last_insert(cap->nchar); | |
7219 } | |
7220 } | |
7221 | |
7222 /* | |
7223 * 'o': Exchange start and end of Visual area. | |
7224 * 'O': same, but in block mode exchange left and right corners. | |
7225 */ | |
7226 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7227 v_swap_corners(int cmdchar) |
7 | 7228 { |
7229 pos_T old_cursor; | |
7230 colnr_T left, right; | |
7231 | |
7232 if (cmdchar == 'O' && VIsual_mode == Ctrl_V) | |
7233 { | |
7234 old_cursor = curwin->w_cursor; | |
7235 getvcols(curwin, &old_cursor, &VIsual, &left, &right); | |
7236 curwin->w_cursor.lnum = VIsual.lnum; | |
7237 coladvance(left); | |
7238 VIsual = curwin->w_cursor; | |
7239 | |
7240 curwin->w_cursor.lnum = old_cursor.lnum; | |
7241 curwin->w_curswant = right; | |
7242 /* 'selection "exclusive" and cursor at right-bottom corner: move it | |
7243 * right one column */ | |
7244 if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e') | |
7245 ++curwin->w_curswant; | |
7246 coladvance(curwin->w_curswant); | |
7247 if (curwin->w_cursor.col == old_cursor.col | |
7248 #ifdef FEAT_VIRTUALEDIT | |
7249 && (!virtual_active() | |
7250 || curwin->w_cursor.coladd == old_cursor.coladd) | |
7251 #endif | |
7252 ) | |
7253 { | |
7254 curwin->w_cursor.lnum = VIsual.lnum; | |
7255 if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e') | |
7256 ++right; | |
7257 coladvance(right); | |
7258 VIsual = curwin->w_cursor; | |
7259 | |
7260 curwin->w_cursor.lnum = old_cursor.lnum; | |
7261 coladvance(left); | |
7262 curwin->w_curswant = left; | |
7263 } | |
7264 } | |
7265 else | |
7266 { | |
7267 old_cursor = curwin->w_cursor; | |
7268 curwin->w_cursor = VIsual; | |
7269 VIsual = old_cursor; | |
7270 curwin->w_set_curswant = TRUE; | |
7271 } | |
7272 } | |
7273 | |
7274 /* | |
7275 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE). | |
7276 */ | |
7277 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7278 nv_Replace(cmdarg_T *cap) |
7 | 7279 { |
7280 if (VIsual_active) /* "R" is replace lines */ | |
7281 { | |
7282 cap->cmdchar = 'c'; | |
7283 cap->nchar = NUL; | |
4213 | 7284 VIsual_mode_orig = VIsual_mode; /* remember original area for gv */ |
7 | 7285 VIsual_mode = 'V'; |
7286 nv_operator(cap); | |
7287 } | |
5735 | 7288 else if (!checkclearopq(cap->oap)) |
7 | 7289 { |
7290 if (!curbuf->b_p_ma) | |
7291 EMSG(_(e_modifiable)); | |
7292 else | |
7293 { | |
7294 #ifdef FEAT_VIRTUALEDIT | |
7295 if (virtual_active()) | |
7296 coladvance(getviscol()); | |
7297 #endif | |
7298 invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE); | |
7299 } | |
7300 } | |
7301 } | |
7302 | |
7303 #ifdef FEAT_VREPLACE | |
7304 /* | |
7305 * "gr". | |
7306 */ | |
7307 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7308 nv_vreplace(cmdarg_T *cap) |
7 | 7309 { |
7310 if (VIsual_active) | |
7311 { | |
7312 cap->cmdchar = 'r'; | |
7313 cap->nchar = cap->extra_char; | |
7314 nv_replace(cap); /* Do same as "r" in Visual mode for now */ | |
7315 } | |
5735 | 7316 else if (!checkclearopq(cap->oap)) |
7 | 7317 { |
7318 if (!curbuf->b_p_ma) | |
7319 EMSG(_(e_modifiable)); | |
7320 else | |
7321 { | |
7322 if (cap->extra_char == Ctrl_V) /* get another character */ | |
7323 cap->extra_char = get_literal(); | |
7324 stuffcharReadbuff(cap->extra_char); | |
7325 stuffcharReadbuff(ESC); | |
7326 # ifdef FEAT_VIRTUALEDIT | |
7327 if (virtual_active()) | |
7328 coladvance(getviscol()); | |
7329 # endif | |
7330 invoke_edit(cap, TRUE, 'v', FALSE); | |
7331 } | |
7332 } | |
7333 } | |
7334 #endif | |
7335 | |
7336 /* | |
7337 * Swap case for "~" command, when it does not work like an operator. | |
7338 */ | |
7339 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7340 n_swapchar(cmdarg_T *cap) |
7 | 7341 { |
7342 long n; | |
7343 pos_T startpos; | |
7344 int did_change = 0; | |
7345 #ifdef FEAT_NETBEANS_INTG | |
7346 pos_T pos; | |
7347 char_u *ptr; | |
7348 int count; | |
7349 #endif | |
7350 | |
7351 if (checkclearopq(cap->oap)) | |
7352 return; | |
7353 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7354 if (LINEEMPTY(curwin->w_cursor.lnum) && vim_strchr(p_ww, '~') == NULL) |
7 | 7355 { |
7356 clearopbeep(cap->oap); | |
7357 return; | |
7358 } | |
7359 | |
7360 prep_redo_cmd(cap); | |
7361 | |
7362 if (u_save_cursor() == FAIL) | |
7363 return; | |
7364 | |
7365 startpos = curwin->w_cursor; | |
7366 #ifdef FEAT_NETBEANS_INTG | |
7367 pos = startpos; | |
7368 #endif | |
7369 for (n = cap->count1; n > 0; --n) | |
7370 { | |
7371 did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor); | |
7372 inc_cursor(); | |
7373 if (gchar_cursor() == NUL) | |
7374 { | |
7375 if (vim_strchr(p_ww, '~') != NULL | |
7376 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
7377 { | |
7378 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7379 if (netbeans_active()) |
7 | 7380 { |
7381 if (did_change) | |
7382 { | |
7383 ptr = ml_get(pos.lnum); | |
835 | 7384 count = (int)STRLEN(ptr) - pos.col; |
33 | 7385 netbeans_removed(curbuf, pos.lnum, pos.col, |
7386 (long)count); | |
7 | 7387 netbeans_inserted(curbuf, pos.lnum, pos.col, |
33 | 7388 &ptr[pos.col], count); |
7 | 7389 } |
7390 pos.col = 0; | |
7391 pos.lnum++; | |
7392 } | |
7393 #endif | |
7394 ++curwin->w_cursor.lnum; | |
7395 curwin->w_cursor.col = 0; | |
7396 if (n > 1) | |
7397 { | |
7398 if (u_savesub(curwin->w_cursor.lnum) == FAIL) | |
7399 break; | |
7400 u_clearline(); | |
7401 } | |
7402 } | |
7403 else | |
7404 break; | |
7405 } | |
7406 } | |
7407 #ifdef FEAT_NETBEANS_INTG | |
2210 | 7408 if (did_change && netbeans_active()) |
7 | 7409 { |
7410 ptr = ml_get(pos.lnum); | |
7411 count = curwin->w_cursor.col - pos.col; | |
33 | 7412 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7413 netbeans_inserted(curbuf, pos.lnum, pos.col, &ptr[pos.col], count); | |
7 | 7414 } |
7415 #endif | |
7416 | |
7417 | |
7418 check_cursor(); | |
7419 curwin->w_set_curswant = TRUE; | |
7420 if (did_change) | |
7421 { | |
7422 changed_lines(startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1, | |
7423 0L); | |
7424 curbuf->b_op_start = startpos; | |
7425 curbuf->b_op_end = curwin->w_cursor; | |
7426 if (curbuf->b_op_end.col > 0) | |
7427 --curbuf->b_op_end.col; | |
7428 } | |
7429 } | |
7430 | |
7431 /* | |
7432 * Move cursor to mark. | |
7433 */ | |
7434 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7435 nv_cursormark(cmdarg_T *cap, int flag, pos_T *pos) |
7 | 7436 { |
7437 if (check_mark(pos) == FAIL) | |
7438 clearop(cap->oap); | |
7439 else | |
7440 { | |
7441 if (cap->cmdchar == '\'' | |
7442 || cap->cmdchar == '`' | |
7443 || cap->cmdchar == '[' | |
7444 || cap->cmdchar == ']') | |
7445 setpcmark(); | |
7446 curwin->w_cursor = *pos; | |
7447 if (flag) | |
7448 beginline(BL_WHITE | BL_FIX); | |
7449 else | |
7450 check_cursor(); | |
7451 } | |
7452 cap->oap->motion_type = flag ? MLINE : MCHAR; | |
7453 if (cap->cmdchar == '`') | |
7454 cap->oap->use_reg_one = TRUE; | |
7455 cap->oap->inclusive = FALSE; /* ignored if not MCHAR */ | |
7456 curwin->w_set_curswant = TRUE; | |
7457 } | |
7458 | |
7459 /* | |
7460 * Handle commands that are operators in Visual mode. | |
7461 */ | |
7462 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7463 v_visop(cmdarg_T *cap) |
7 | 7464 { |
7465 static char_u trans[] = "YyDdCcxdXdAAIIrr"; | |
7466 | |
7467 /* Uppercase means linewise, except in block mode, then "D" deletes till | |
4352 | 7468 * the end of the line, and "C" replaces till EOL */ |
7 | 7469 if (isupper(cap->cmdchar)) |
7470 { | |
7471 if (VIsual_mode != Ctrl_V) | |
4213 | 7472 { |
7473 VIsual_mode_orig = VIsual_mode; | |
7 | 7474 VIsual_mode = 'V'; |
4213 | 7475 } |
7 | 7476 else if (cap->cmdchar == 'C' || cap->cmdchar == 'D') |
7477 curwin->w_curswant = MAXCOL; | |
7478 } | |
7479 cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1); | |
7480 nv_operator(cap); | |
7481 } | |
7482 | |
7483 /* | |
7484 * "s" and "S" commands. | |
7485 */ | |
7486 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7487 nv_subst(cmdarg_T *cap) |
7 | 7488 { |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7489 #ifdef FEAT_TERMINAL |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7490 /* When showing output of term_dumpdiff() swap the top and botom. */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7491 if (term_swap_diff() == OK) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7492 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
7493 #endif |
7 | 7494 if (VIsual_active) /* "vs" and "vS" are the same as "vc" */ |
7495 { | |
7496 if (cap->cmdchar == 'S') | |
4213 | 7497 { |
7498 VIsual_mode_orig = VIsual_mode; | |
7 | 7499 VIsual_mode = 'V'; |
4213 | 7500 } |
7 | 7501 cap->cmdchar = 'c'; |
7502 nv_operator(cap); | |
7503 } | |
7504 else | |
7505 nv_optrans(cap); | |
7506 } | |
7507 | |
7508 /* | |
7509 * Abbreviated commands. | |
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_abbrev(cmdarg_T *cap) |
7 | 7513 { |
7514 if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL) | |
7515 cap->cmdchar = 'x'; /* DEL key behaves like 'x' */ | |
7516 | |
7517 /* in Visual mode these commands are operators */ | |
7518 if (VIsual_active) | |
7519 v_visop(cap); | |
7520 else | |
7521 nv_optrans(cap); | |
7522 } | |
7523 | |
7524 /* | |
7525 * Translate a command into another command. | |
7526 */ | |
7527 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7528 nv_optrans(cmdarg_T *cap) |
7 | 7529 { |
7530 static char_u *(ar[8]) = {(char_u *)"dl", (char_u *)"dh", | |
7531 (char_u *)"d$", (char_u *)"c$", | |
7532 (char_u *)"cl", (char_u *)"cc", | |
7533 (char_u *)"yy", (char_u *)":s\r"}; | |
7534 static char_u *str = (char_u *)"xXDCsSY&"; | |
7535 | |
7536 if (!checkclearopq(cap->oap)) | |
7537 { | |
164 | 7538 /* In Vi "2D" doesn't delete the next line. Can't translate it |
7539 * either, because "2." should also not use the count. */ | |
7540 if (cap->cmdchar == 'D' && vim_strchr(p_cpo, CPO_HASH) != NULL) | |
7541 { | |
7542 cap->oap->start = curwin->w_cursor; | |
7543 cap->oap->op_type = OP_DELETE; | |
1490 | 7544 #ifdef FEAT_EVAL |
7545 set_op_var(OP_DELETE); | |
7546 #endif | |
164 | 7547 cap->count1 = 1; |
7548 nv_dollar(cap); | |
7549 finish_op = TRUE; | |
7550 ResetRedobuff(); | |
7551 AppendCharToRedobuff('D'); | |
7552 } | |
7553 else | |
7554 { | |
7555 if (cap->count0) | |
7556 stuffnumReadbuff(cap->count0); | |
7557 stuffReadbuff(ar[(int)(vim_strchr(str, cap->cmdchar) - str)]); | |
7558 } | |
7 | 7559 } |
7560 cap->opcount = 0; | |
7561 } | |
7562 | |
7563 /* | |
7564 * "'" and "`" commands. Also for "g'" and "g`". | |
7565 * cap->arg is TRUE for "'" and "g'". | |
7566 */ | |
7567 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7568 nv_gomark(cmdarg_T *cap) |
7 | 7569 { |
7570 pos_T *pos; | |
7571 int c; | |
7572 #ifdef FEAT_FOLDING | |
4017 | 7573 pos_T old_cursor = curwin->w_cursor; |
7 | 7574 int old_KeyTyped = KeyTyped; /* getting file may reset it */ |
7575 #endif | |
7576 | |
7577 if (cap->cmdchar == 'g') | |
7578 c = cap->extra_char; | |
7579 else | |
7580 c = cap->nchar; | |
7581 pos = getmark(c, (cap->oap->op_type == OP_NOP)); | |
7582 if (pos == (pos_T *)-1) /* jumped to other file */ | |
7583 { | |
7584 if (cap->arg) | |
7585 { | |
7586 check_cursor_lnum(); | |
7587 beginline(BL_WHITE | BL_FIX); | |
7588 } | |
7589 else | |
7590 check_cursor(); | |
7591 } | |
7592 else | |
7593 nv_cursormark(cap, cap->arg, pos); | |
7594 | |
7595 #ifdef FEAT_VIRTUALEDIT | |
7596 /* May need to clear the coladd that a mark includes. */ | |
7597 if (!virtual_active()) | |
7598 curwin->w_cursor.coladd = 0; | |
7599 #endif | |
12164
5d82470552ce
patch 8.0.0962: crash with virtualedit and joining lines
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
7600 check_cursor_col(); |
7 | 7601 #ifdef FEAT_FOLDING |
7602 if (cap->oap->op_type == OP_NOP | |
4057 | 7603 && pos != NULL |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
7604 && (pos == (pos_T *)-1 || !EQUAL_POS(old_cursor, *pos)) |
7 | 7605 && (fdo_flags & FDO_MARK) |
7606 && old_KeyTyped) | |
7607 foldOpenCursor(); | |
7608 #endif | |
7609 } | |
7610 | |
7611 /* | |
7612 * Handle CTRL-O, CTRL-I, "g;" and "g," commands. | |
7613 */ | |
7614 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7615 nv_pcmark(cmdarg_T *cap) |
7 | 7616 { |
7617 #ifdef FEAT_JUMPLIST | |
7618 pos_T *pos; | |
7619 # ifdef FEAT_FOLDING | |
7620 linenr_T lnum = curwin->w_cursor.lnum; | |
7621 int old_KeyTyped = KeyTyped; /* getting file may reset it */ | |
7622 # endif | |
7623 | |
7624 if (!checkclearopq(cap->oap)) | |
7625 { | |
7626 if (cap->cmdchar == 'g') | |
7627 pos = movechangelist((int)cap->count1); | |
7628 else | |
7629 pos = movemark((int)cap->count1); | |
7630 if (pos == (pos_T *)-1) /* jump to other file */ | |
7631 { | |
7632 curwin->w_set_curswant = TRUE; | |
7633 check_cursor(); | |
7634 } | |
7635 else if (pos != NULL) /* can jump */ | |
7636 nv_cursormark(cap, FALSE, pos); | |
7637 else if (cap->cmdchar == 'g') | |
7638 { | |
7639 if (curbuf->b_changelistlen == 0) | |
7640 EMSG(_("E664: changelist is empty")); | |
7641 else if (cap->count1 < 0) | |
7642 EMSG(_("E662: At start of changelist")); | |
7643 else | |
7644 EMSG(_("E663: At end of changelist")); | |
7645 } | |
7646 else | |
7647 clearopbeep(cap->oap); | |
7648 # ifdef FEAT_FOLDING | |
7649 if (cap->oap->op_type == OP_NOP | |
7650 && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum) | |
7651 && (fdo_flags & FDO_MARK) | |
7652 && old_KeyTyped) | |
7653 foldOpenCursor(); | |
7654 # endif | |
7655 } | |
7656 #else | |
7657 clearopbeep(cap->oap); | |
7658 #endif | |
7659 } | |
7660 | |
7661 /* | |
7662 * Handle '"' command. | |
7663 */ | |
7664 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7665 nv_regname(cmdarg_T *cap) |
7 | 7666 { |
7667 if (checkclearop(cap->oap)) | |
7668 return; | |
7669 #ifdef FEAT_EVAL | |
7670 if (cap->nchar == '=') | |
7671 cap->nchar = get_expr_register(); | |
7672 #endif | |
7673 if (cap->nchar != NUL && valid_yank_reg(cap->nchar, FALSE)) | |
7674 { | |
7675 cap->oap->regname = cap->nchar; | |
7676 cap->opcount = cap->count0; /* remember count before '"' */ | |
7677 #ifdef FEAT_EVAL | |
7678 set_reg_var(cap->oap->regname); | |
7679 #endif | |
7680 } | |
7681 else | |
7682 clearopbeep(cap->oap); | |
7683 } | |
7684 | |
7685 /* | |
7686 * Handle "v", "V" and "CTRL-V" commands. | |
7687 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg | |
7688 * is TRUE. | |
167 | 7689 * Handle CTRL-Q just like CTRL-V. |
7 | 7690 */ |
7691 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7692 nv_visual(cmdarg_T *cap) |
7 | 7693 { |
167 | 7694 if (cap->cmdchar == Ctrl_Q) |
7695 cap->cmdchar = Ctrl_V; | |
7696 | |
7 | 7697 /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it |
7698 * characterwise, linewise, or blockwise. */ | |
7699 if (cap->oap->op_type != OP_NOP) | |
7700 { | |
7701 cap->oap->motion_force = cap->cmdchar; | |
7702 finish_op = FALSE; /* operator doesn't finish now but later */ | |
7703 return; | |
7704 } | |
7705 | |
7706 VIsual_select = cap->arg; | |
7707 if (VIsual_active) /* change Visual mode */ | |
7708 { | |
7709 if (VIsual_mode == cap->cmdchar) /* stop visual mode */ | |
7710 end_visual_mode(); | |
7711 else /* toggle char/block mode */ | |
7712 { /* or char/line mode */ | |
7713 VIsual_mode = cap->cmdchar; | |
7714 showmode(); | |
7715 } | |
7716 redraw_curbuf_later(INVERTED); /* update the inversion */ | |
7717 } | |
7718 else /* start Visual mode */ | |
7719 { | |
7720 check_visual_highlight(); | |
3537 | 7721 if (cap->count0 > 0 && resel_VIsual_mode != NUL) |
7722 { | |
7723 /* use previously selected part */ | |
7 | 7724 VIsual = curwin->w_cursor; |
7725 | |
7726 VIsual_active = TRUE; | |
7727 VIsual_reselect = TRUE; | |
7728 if (!cap->arg) | |
7729 /* start Select mode when 'selectmode' contains "cmd" */ | |
7730 may_start_select('c'); | |
7731 #ifdef FEAT_MOUSE | |
7732 setmouse(); | |
7733 #endif | |
641 | 7734 if (p_smd && msg_silent == 0) |
7 | 7735 redraw_cmdline = TRUE; /* show visual mode later */ |
7736 /* | |
7737 * For V and ^V, we multiply the number of lines even if there | |
7738 * was only one -- webb | |
7739 */ | |
7740 if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) | |
7741 { | |
7742 curwin->w_cursor.lnum += | |
7743 resel_VIsual_line_count * cap->count0 - 1; | |
7744 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
7745 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
7746 } | |
7747 VIsual_mode = resel_VIsual_mode; | |
7748 if (VIsual_mode == 'v') | |
7749 { | |
7750 if (resel_VIsual_line_count <= 1) | |
3125 | 7751 { |
7752 validate_virtcol(); | |
7753 curwin->w_curswant = curwin->w_virtcol | |
7754 + resel_VIsual_vcol * cap->count0 - 1; | |
7755 } | |
7 | 7756 else |
3125 | 7757 curwin->w_curswant = resel_VIsual_vcol; |
7758 coladvance(curwin->w_curswant); | |
7 | 7759 } |
3125 | 7760 if (resel_VIsual_vcol == MAXCOL) |
7 | 7761 { |
7762 curwin->w_curswant = MAXCOL; | |
7763 coladvance((colnr_T)MAXCOL); | |
7764 } | |
7765 else if (VIsual_mode == Ctrl_V) | |
7766 { | |
7767 validate_virtcol(); | |
7768 curwin->w_curswant = curwin->w_virtcol | |
3125 | 7769 + resel_VIsual_vcol * cap->count0 - 1; |
7 | 7770 coladvance(curwin->w_curswant); |
7771 } | |
7772 else | |
7773 curwin->w_set_curswant = TRUE; | |
7774 redraw_curbuf_later(INVERTED); /* show the inversion */ | |
7775 } | |
7776 else | |
7777 { | |
7778 if (!cap->arg) | |
7779 /* start Select mode when 'selectmode' contains "cmd" */ | |
7780 may_start_select('c'); | |
7781 n_start_visual_mode(cap->cmdchar); | |
3537 | 7782 if (VIsual_mode != 'V' && *p_sel == 'e') |
7783 ++cap->count1; /* include one more char */ | |
7784 if (cap->count0 > 0 && --cap->count1 > 0) | |
7785 { | |
7786 /* With a count select that many characters or lines. */ | |
7787 if (VIsual_mode == 'v' || VIsual_mode == Ctrl_V) | |
7788 nv_right(cap); | |
7789 else if (VIsual_mode == 'V') | |
7790 nv_down(cap); | |
7791 } | |
7 | 7792 } |
7793 } | |
7794 } | |
7795 | |
7796 /* | |
7797 * Start selection for Shift-movement keys. | |
7798 */ | |
7799 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7800 start_selection(void) |
7 | 7801 { |
7802 /* if 'selectmode' contains "key", start Select mode */ | |
7803 may_start_select('k'); | |
7804 n_start_visual_mode('v'); | |
7805 } | |
7806 | |
7807 /* | |
7808 * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu. | |
7809 */ | |
7810 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7811 may_start_select(int c) |
7 | 7812 { |
7813 VIsual_select = (stuff_empty() && typebuf_typed() | |
7814 && (vim_strchr(p_slm, c) != NULL)); | |
7815 } | |
7816 | |
7817 /* | |
7818 * Start Visual mode "c". | |
7819 * Should set VIsual_select before calling this. | |
7820 */ | |
7821 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7822 n_start_visual_mode(int c) |
7 | 7823 { |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7824 #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
|
7825 /* 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
|
7826 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
|
7827 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7828 |
7 | 7829 VIsual_mode = c; |
7830 VIsual_active = TRUE; | |
7831 VIsual_reselect = TRUE; | |
7832 #ifdef FEAT_VIRTUALEDIT | |
7833 /* Corner case: the 0 position in a tab may change when going into | |
7834 * virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting. | |
7835 */ | |
7836 if (c == Ctrl_V && (ve_flags & VE_BLOCK) && gchar_cursor() == TAB) | |
3742 | 7837 { |
7838 validate_virtcol(); | |
7 | 7839 coladvance(curwin->w_virtcol); |
3742 | 7840 } |
7 | 7841 #endif |
7842 VIsual = curwin->w_cursor; | |
7843 | |
7844 #ifdef FEAT_FOLDING | |
7845 foldAdjustVisual(); | |
7846 #endif | |
7847 | |
7848 #ifdef FEAT_MOUSE | |
7849 setmouse(); | |
7850 #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
|
7851 #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
|
7852 /* 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
|
7853 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
|
7854 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
7855 |
641 | 7856 if (p_smd && msg_silent == 0) |
7 | 7857 redraw_cmdline = TRUE; /* show visual mode later */ |
7858 #ifdef FEAT_CLIPBOARD | |
7859 /* Make sure the clipboard gets updated. Needed because start and | |
7860 * end may still be the same, and the selection needs to be owned */ | |
7861 clip_star.vmode = NUL; | |
7862 #endif | |
7863 | |
7864 /* Only need to redraw this line, unless still need to redraw an old | |
7865 * Visual area (when 'lazyredraw' is set). */ | |
7866 if (curwin->w_redr_type < INVERTED) | |
7867 { | |
7868 curwin->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
7869 curwin->w_old_visual_lnum = curwin->w_cursor.lnum; | |
7870 } | |
7871 } | |
7872 | |
7873 | |
7874 /* | |
7875 * CTRL-W: Window commands | |
7876 */ | |
7877 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7878 nv_window(cmdarg_T *cap) |
7 | 7879 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7880 if (cap->nchar == ':') |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7881 { |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7882 /* "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
|
7883 cap->cmdchar = ':'; |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7884 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
|
7885 nv_colon(cap); |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
7886 } |
11684
1ce1376fbbf8
patch 8.0.0725: a terminal window does not handle keyboard input
Christian Brabandt <cb@256bit.org>
parents:
11529
diff
changeset
|
7887 else if (!checkclearop(cap->oap)) |
7 | 7888 do_window(cap->nchar, cap->count0, NUL); /* everything is in window.c */ |
7889 } | |
7890 | |
7891 /* | |
7892 * CTRL-Z: Suspend | |
7893 */ | |
7894 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7895 nv_suspend(cmdarg_T *cap) |
7 | 7896 { |
7897 clearop(cap->oap); | |
7898 if (VIsual_active) | |
7899 end_visual_mode(); /* stop Visual mode */ | |
7900 do_cmdline_cmd((char_u *)"st"); | |
7901 } | |
7902 | |
7903 /* | |
7904 * Commands starting with "g". | |
7905 */ | |
7906 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
7907 nv_g_cmd(cmdarg_T *cap) |
7 | 7908 { |
7909 oparg_T *oap = cap->oap; | |
7910 pos_T tpos; | |
7911 int i; | |
7912 int flag = FALSE; | |
7913 | |
7914 switch (cap->nchar) | |
7915 { | |
6868 | 7916 case Ctrl_A: |
7917 case Ctrl_X: | |
7 | 7918 #ifdef MEM_PROFILE |
7919 /* | |
7920 * "g^A": dump log of used memory. | |
7921 */ | |
6868 | 7922 if (!VIsual_active && cap->nchar == Ctrl_A) |
7923 vim_mem_profile_dump(); | |
7924 else | |
7925 #endif | |
7926 /* | |
7927 * "g^A/g^X": sequentially increment visually selected region | |
7928 */ | |
7929 if (VIsual_active) | |
7930 { | |
7931 cap->arg = TRUE; | |
7932 cap->cmdchar = cap->nchar; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7568
diff
changeset
|
7933 cap->nchar = NUL; |
6868 | 7934 nv_addsub(cap); |
7935 } | |
7936 else | |
7937 clearopbeep(oap); | |
7 | 7938 break; |
7939 | |
7940 #ifdef FEAT_VREPLACE | |
7941 /* | |
7942 * "gR": Enter virtual replace mode. | |
7943 */ | |
7944 case 'R': | |
7945 cap->arg = TRUE; | |
7946 nv_Replace(cap); | |
7947 break; | |
7948 | |
7949 case 'r': | |
7950 nv_vreplace(cap); | |
7951 break; | |
7952 #endif | |
7953 | |
7954 case '&': | |
7955 do_cmdline_cmd((char_u *)"%s//~/&"); | |
7956 break; | |
7957 | |
7958 /* | |
7959 * "gv": Reselect the previous Visual area. If Visual already active, | |
7960 * exchange previous and current Visual area. | |
7961 */ | |
7962 case 'v': | |
7963 if (checkclearop(oap)) | |
7964 break; | |
7965 | |
690 | 7966 if ( curbuf->b_visual.vi_start.lnum == 0 |
7967 || curbuf->b_visual.vi_start.lnum > curbuf->b_ml.ml_line_count | |
7968 || curbuf->b_visual.vi_end.lnum == 0) | |
7 | 7969 beep_flush(); |
7970 else | |
7971 { | |
7972 /* set w_cursor to the start of the Visual area, tpos to the end */ | |
7973 if (VIsual_active) | |
7974 { | |
7975 i = VIsual_mode; | |
690 | 7976 VIsual_mode = curbuf->b_visual.vi_mode; |
7977 curbuf->b_visual.vi_mode = i; | |
7 | 7978 # ifdef FEAT_EVAL |
7979 curbuf->b_visual_mode_eval = i; | |
7980 # endif | |
7981 i = curwin->w_curswant; | |
690 | 7982 curwin->w_curswant = curbuf->b_visual.vi_curswant; |
7983 curbuf->b_visual.vi_curswant = i; | |
7984 | |
7985 tpos = curbuf->b_visual.vi_end; | |
7986 curbuf->b_visual.vi_end = curwin->w_cursor; | |
7987 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7988 curbuf->b_visual.vi_start = VIsual; | |
7 | 7989 } |
7990 else | |
7991 { | |
690 | 7992 VIsual_mode = curbuf->b_visual.vi_mode; |
7993 curwin->w_curswant = curbuf->b_visual.vi_curswant; | |
7994 tpos = curbuf->b_visual.vi_end; | |
7995 curwin->w_cursor = curbuf->b_visual.vi_start; | |
7 | 7996 } |
7997 | |
7998 VIsual_active = TRUE; | |
7999 VIsual_reselect = TRUE; | |
8000 | |
8001 /* Set Visual to the start and w_cursor to the end of the Visual | |
8002 * area. Make sure they are on an existing character. */ | |
8003 check_cursor(); | |
8004 VIsual = curwin->w_cursor; | |
8005 curwin->w_cursor = tpos; | |
8006 check_cursor(); | |
8007 update_topline(); | |
8008 /* | |
8009 * When called from normal "g" command: start Select mode when | |
8010 * 'selectmode' contains "cmd". When called for K_SELECT, always | |
8011 * start Select mode. | |
8012 */ | |
8013 if (cap->arg) | |
8014 VIsual_select = TRUE; | |
8015 else | |
8016 may_start_select('c'); | |
8017 #ifdef FEAT_MOUSE | |
8018 setmouse(); | |
8019 #endif | |
8020 #ifdef FEAT_CLIPBOARD | |
8021 /* Make sure the clipboard gets updated. Needed because start and | |
8022 * end are still the same, and the selection needs to be owned */ | |
8023 clip_star.vmode = NUL; | |
8024 #endif | |
8025 redraw_curbuf_later(INVERTED); | |
8026 showmode(); | |
8027 } | |
8028 break; | |
8029 /* | |
8030 * "gV": Don't reselect the previous Visual area after a Select mode | |
8031 * mapping of menu. | |
8032 */ | |
8033 case 'V': | |
8034 VIsual_reselect = FALSE; | |
8035 break; | |
8036 | |
8037 /* | |
8038 * "gh": start Select mode. | |
8039 * "gH": start Select line mode. | |
8040 * "g^H": start Select block mode. | |
8041 */ | |
8042 case K_BS: | |
8043 cap->nchar = Ctrl_H; | |
8044 /* FALLTHROUGH */ | |
8045 case 'h': | |
8046 case 'H': | |
8047 case Ctrl_H: | |
8048 # ifdef EBCDIC | |
8049 /* EBCDIC: 'v'-'h' != '^v'-'^h' */ | |
8050 if (cap->nchar == Ctrl_H) | |
8051 cap->cmdchar = Ctrl_V; | |
8052 else | |
8053 # endif | |
8054 cap->cmdchar = cap->nchar + ('v' - 'h'); | |
8055 cap->arg = TRUE; | |
8056 nv_visual(cap); | |
8057 break; | |
3701 | 8058 |
8059 /* "gn", "gN" visually select next/previous search match | |
8060 * "gn" selects next match | |
8061 * "gN" selects previous match | |
8062 */ | |
8063 case 'N': | |
8064 case 'n': | |
8065 if (!current_search(cap->count1, cap->nchar == 'n')) | |
3896 | 8066 clearopbeep(oap); |
3701 | 8067 break; |
7 | 8068 |
8069 /* | |
8070 * "gj" and "gk" two new funny movement keys -- up and down | |
8071 * movement based on *screen* line rather than *file* line. | |
8072 */ | |
8073 case 'j': | |
8074 case K_DOWN: | |
8075 /* with 'nowrap' it works just like the normal "j" command; also when | |
8076 * in a closed fold */ | |
8077 if (!curwin->w_p_wrap | |
8078 #ifdef FEAT_FOLDING | |
8079 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
8080 #endif | |
8081 ) | |
8082 { | |
8083 oap->motion_type = MLINE; | |
8084 i = cursor_down(cap->count1, oap->op_type == OP_NOP); | |
8085 } | |
8086 else | |
8087 i = nv_screengo(oap, FORWARD, cap->count1); | |
8088 if (i == FAIL) | |
8089 clearopbeep(oap); | |
8090 break; | |
8091 | |
8092 case 'k': | |
8093 case K_UP: | |
8094 /* with 'nowrap' it works just like the normal "k" command; also when | |
8095 * in a closed fold */ | |
8096 if (!curwin->w_p_wrap | |
8097 #ifdef FEAT_FOLDING | |
8098 || hasFolding(curwin->w_cursor.lnum, NULL, NULL) | |
8099 #endif | |
8100 ) | |
8101 { | |
8102 oap->motion_type = MLINE; | |
8103 i = cursor_up(cap->count1, oap->op_type == OP_NOP); | |
8104 } | |
8105 else | |
8106 i = nv_screengo(oap, BACKWARD, cap->count1); | |
8107 if (i == FAIL) | |
8108 clearopbeep(oap); | |
8109 break; | |
8110 | |
8111 /* | |
8112 * "gJ": join two lines without inserting a space. | |
8113 */ | |
8114 case 'J': | |
8115 nv_join(cap); | |
8116 break; | |
8117 | |
8118 /* | |
8119 * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines. | |
8120 * "gm": middle of "g0" and "g$". | |
8121 */ | |
8122 case '^': | |
8123 flag = TRUE; | |
8124 /* FALLTHROUGH */ | |
8125 | |
8126 case '0': | |
8127 case 'm': | |
8128 case K_HOME: | |
8129 case K_KHOME: | |
8130 oap->motion_type = MCHAR; | |
8131 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
|
8132 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 8133 { |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8134 int width1 = curwin->w_width - curwin_col_off(); |
7 | 8135 int width2 = width1 + curwin_col_off2(); |
8136 | |
8137 validate_virtcol(); | |
8138 i = 0; | |
8139 if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0) | |
8140 i = (curwin->w_virtcol - width1) / width2 * width2 + width1; | |
8141 } | |
8142 else | |
8143 i = curwin->w_leftcol; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2139
diff
changeset
|
8144 /* 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
|
8145 * '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
|
8146 * to the left. */ |
7 | 8147 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
|
8148 i += (curwin->w_width - curwin_col_off() |
7 | 8149 + ((curwin->w_p_wrap && i > 0) |
8150 ? curwin_col_off2() : 0)) / 2; | |
8151 coladvance((colnr_T)i); | |
8152 if (flag) | |
8153 { | |
8154 do | |
8155 i = gchar_cursor(); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
8156 while (VIM_ISWHITE(i) && oneright() == OK); |
7 | 8157 } |
8158 curwin->w_set_curswant = TRUE; | |
8159 break; | |
8160 | |
8161 case '_': | |
8162 /* "g_": to the last non-blank character in the line or <count> lines | |
8163 * downward. */ | |
8164 cap->oap->motion_type = MCHAR; | |
8165 cap->oap->inclusive = TRUE; | |
8166 curwin->w_curswant = MAXCOL; | |
8167 if (cursor_down((long)(cap->count1 - 1), | |
8168 cap->oap->op_type == OP_NOP) == FAIL) | |
8169 clearopbeep(cap->oap); | |
8170 else | |
8171 { | |
8172 char_u *ptr = ml_get_curline(); | |
8173 | |
8174 /* In Visual mode we may end up after the line. */ | |
8175 if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL) | |
8176 --curwin->w_cursor.col; | |
8177 | |
8178 /* Decrease the cursor column until it's on a non-blank. */ | |
8179 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
|
8180 && VIM_ISWHITE(ptr[curwin->w_cursor.col])) |
7 | 8181 --curwin->w_cursor.col; |
8182 curwin->w_set_curswant = TRUE; | |
2040
70c67b1bb1f1
updated for version 7.2.329
Bram Moolenaar <bram@zimbu.org>
parents:
2024
diff
changeset
|
8183 adjust_for_sel(cap); |
7 | 8184 } |
8185 break; | |
8186 | |
8187 case '$': | |
8188 case K_END: | |
8189 case K_KEND: | |
8190 { | |
8191 int col_off = curwin_col_off(); | |
8192 | |
8193 oap->motion_type = MCHAR; | |
8194 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
|
8195 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 8196 { |
8197 curwin->w_curswant = MAXCOL; /* so we stay at the end */ | |
8198 if (cap->count1 == 1) | |
8199 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8200 int width1 = curwin->w_width - col_off; |
7 | 8201 int width2 = width1 + curwin_col_off2(); |
8202 | |
8203 validate_virtcol(); | |
8204 i = width1 - 1; | |
8205 if (curwin->w_virtcol >= (colnr_T)width1) | |
8206 i += ((curwin->w_virtcol - width1) / width2 + 1) | |
8207 * width2; | |
8208 coladvance((colnr_T)i); | |
5162
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8209 |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8210 /* Make sure we stick in this column. */ |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8211 validate_virtcol(); |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8212 curwin->w_curswant = curwin->w_virtcol; |
c624928fbc49
updated for version 7.4a.007
Bram Moolenaar <bram@vim.org>
parents:
4472
diff
changeset
|
8213 curwin->w_set_curswant = FALSE; |
7 | 8214 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE) |
8215 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap) | |
8216 { | |
8217 /* | |
8218 * Check for landing on a character that got split at | |
8219 * the end of the line. We do not want to advance to | |
8220 * the next screen line. | |
8221 */ | |
8222 if (curwin->w_virtcol > (colnr_T)i) | |
8223 --curwin->w_cursor.col; | |
8224 } | |
8225 #endif | |
8226 } | |
8227 else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == FAIL) | |
8228 clearopbeep(oap); | |
8229 } | |
8230 else | |
8231 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
8232 i = curwin->w_leftcol + curwin->w_width - col_off - 1; |
7 | 8233 coladvance((colnr_T)i); |
40 | 8234 |
8235 /* Make sure we stick in this column. */ | |
8236 validate_virtcol(); | |
8237 curwin->w_curswant = curwin->w_virtcol; | |
8238 curwin->w_set_curswant = FALSE; | |
7 | 8239 } |
8240 } | |
8241 break; | |
8242 | |
8243 /* | |
8244 * "g*" and "g#", like "*" and "#" but without using "\<" and "\>" | |
8245 */ | |
8246 case '*': | |
8247 case '#': | |
8248 #if POUND != '#' | |
8249 case POUND: /* pound sign (sometimes equal to '#') */ | |
8250 #endif | |
8251 case Ctrl_RSB: /* :tag or :tselect for current identifier */ | |
8252 case ']': /* :tselect for current identifier */ | |
8253 nv_ident(cap); | |
8254 break; | |
8255 | |
8256 /* | |
8257 * ge and gE: go back to end of word | |
8258 */ | |
8259 case 'e': | |
8260 case 'E': | |
8261 oap->motion_type = MCHAR; | |
8262 curwin->w_set_curswant = TRUE; | |
8263 oap->inclusive = TRUE; | |
8264 if (bckend_word(cap->count1, cap->nchar == 'E', FALSE) == FAIL) | |
8265 clearopbeep(oap); | |
8266 break; | |
8267 | |
8268 /* | |
8269 * "g CTRL-G": display info about cursor position | |
8270 */ | |
8271 case Ctrl_G: | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7311
diff
changeset
|
8272 cursor_pos_info(NULL); |
7 | 8273 break; |
8274 | |
8275 /* | |
8276 * "gi": start Insert at the last position. | |
8277 */ | |
8278 case 'i': | |
8279 if (curbuf->b_last_insert.lnum != 0) | |
8280 { | |
8281 curwin->w_cursor = curbuf->b_last_insert; | |
8282 check_cursor_lnum(); | |
8283 i = (int)STRLEN(ml_get_curline()); | |
8284 if (curwin->w_cursor.col > (colnr_T)i) | |
8285 { | |
8286 #ifdef FEAT_VIRTUALEDIT | |
8287 if (virtual_active()) | |
8288 curwin->w_cursor.coladd += curwin->w_cursor.col - i; | |
8289 #endif | |
8290 curwin->w_cursor.col = i; | |
8291 } | |
8292 } | |
8293 cap->cmdchar = 'i'; | |
8294 nv_edit(cap); | |
8295 break; | |
8296 | |
8297 /* | |
8298 * "gI": Start insert in column 1. | |
8299 */ | |
8300 case 'I': | |
8301 beginline(0); | |
8302 if (!checkclearopq(oap)) | |
8303 invoke_edit(cap, FALSE, 'g', FALSE); | |
8304 break; | |
8305 | |
8306 #ifdef FEAT_SEARCHPATH | |
8307 /* | |
8308 * "gf": goto file, edit file under cursor | |
8309 * "]f" and "[f": can also be used. | |
8310 */ | |
8311 case 'f': | |
681 | 8312 case 'F': |
7 | 8313 nv_gotofile(cap); |
8314 break; | |
8315 #endif | |
8316 | |
8317 /* "g'm" and "g`m": jump to mark without setting pcmark */ | |
8318 case '\'': | |
8319 cap->arg = TRUE; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
8320 /* FALLTHROUGH */ |
7 | 8321 case '`': |
8322 nv_gomark(cap); | |
8323 break; | |
8324 | |
8325 /* | |
8326 * "gs": Goto sleep. | |
8327 */ | |
8328 case 's': | |
8329 do_sleep(cap->count1 * 1000L); | |
8330 break; | |
8331 | |
8332 /* | |
8333 * "ga": Display the ascii value of the character under the | |
8334 * cursor. It is displayed in decimal, hex, and octal. -- webb | |
8335 */ | |
8336 case 'a': | |
8337 do_ascii(NULL); | |
8338 break; | |
8339 | |
8340 #ifdef FEAT_MBYTE | |
8341 /* | |
8342 * "g8": Display the bytes used for the UTF-8 character under the | |
8343 * cursor. It is displayed in hex. | |
775 | 8344 * "8g8" finds illegal byte sequence. |
7 | 8345 */ |
8346 case '8': | |
775 | 8347 if (cap->count0 == 8) |
8348 utf_find_illegal(); | |
8349 else | |
8350 show_utf8(); | |
7 | 8351 break; |
8352 #endif | |
8353 | |
11366
b16bc115a270
patch 8.0.0568: 1gd may hang
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
8354 /* "g<": show scrollback text */ |
447 | 8355 case '<': |
8356 show_sb_text(); | |
8357 break; | |
8358 | |
7 | 8359 /* |
8360 * "gg": Goto the first line in file. With a count it goes to | |
8361 * that line number like for "G". -- webb | |
8362 */ | |
8363 case 'g': | |
8364 cap->arg = FALSE; | |
8365 nv_goto(cap); | |
8366 break; | |
8367 | |
8368 /* | |
8369 * Two-character operators: | |
8370 * "gq" Format text | |
8371 * "gw" Format text and keep cursor position | |
8372 * "g~" Toggle the case of the text. | |
8373 * "gu" Change text to lower case. | |
8374 * "gU" Change text to upper case. | |
8375 * "g?" rot13 encoding | |
602 | 8376 * "g@" call 'operatorfunc' |
7 | 8377 */ |
8378 case 'q': | |
8379 case 'w': | |
8380 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
|
8381 /* FALLTHROUGH */ |
7 | 8382 case '~': |
8383 case 'u': | |
8384 case 'U': | |
8385 case '?': | |
602 | 8386 case '@': |
7 | 8387 nv_operator(cap); |
8388 break; | |
8389 | |
8390 /* | |
1188 | 8391 * "gd": Find first occurrence of pattern under the cursor in the |
7 | 8392 * current function |
8393 * "gD": idem, but in the current file. | |
8394 */ | |
8395 case 'd': | |
8396 case 'D': | |
523 | 8397 nv_gd(oap, cap->nchar, (int)cap->count0); |
7 | 8398 break; |
8399 | |
8400 #ifdef FEAT_MOUSE | |
8401 /* | |
8402 * g<*Mouse> : <C-*mouse> | |
8403 */ | |
8404 case K_MIDDLEMOUSE: | |
8405 case K_MIDDLEDRAG: | |
8406 case K_MIDDLERELEASE: | |
8407 case K_LEFTMOUSE: | |
8408 case K_LEFTDRAG: | |
8409 case K_LEFTRELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
8410 case K_MOUSEMOVE: |
7 | 8411 case K_RIGHTMOUSE: |
8412 case K_RIGHTDRAG: | |
8413 case K_RIGHTRELEASE: | |
8414 case K_X1MOUSE: | |
8415 case K_X1DRAG: | |
8416 case K_X1RELEASE: | |
8417 case K_X2MOUSE: | |
8418 case K_X2DRAG: | |
8419 case K_X2RELEASE: | |
8420 mod_mask = MOD_MASK_CTRL; | |
8421 (void)do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0); | |
8422 break; | |
8423 #endif | |
8424 | |
8425 case K_IGNORE: | |
8426 break; | |
8427 | |
8428 /* | |
8429 * "gP" and "gp": same as "P" and "p" but leave cursor just after new text | |
8430 */ | |
8431 case 'p': | |
8432 case 'P': | |
8433 nv_put(cap); | |
8434 break; | |
8435 | |
8436 #ifdef FEAT_BYTEOFF | |
8437 /* "go": goto byte count from start of buffer */ | |
8438 case 'o': | |
8439 goto_byte(cap->count0); | |
8440 break; | |
8441 #endif | |
8442 | |
8443 /* "gQ": improved Ex mode */ | |
8444 case 'Q': | |
633 | 8445 if (text_locked()) |
7 | 8446 { |
8447 clearopbeep(cap->oap); | |
633 | 8448 text_locked_msg(); |
7 | 8449 break; |
8450 } | |
631 | 8451 |
7 | 8452 if (!checkclearopq(oap)) |
8453 do_exmode(TRUE); | |
8454 break; | |
8455 | |
8456 #ifdef FEAT_JUMPLIST | |
8457 case ',': | |
8458 nv_pcmark(cap); | |
8459 break; | |
8460 | |
8461 case ';': | |
8462 cap->count1 = -cap->count1; | |
8463 nv_pcmark(cap); | |
8464 break; | |
8465 #endif | |
8466 | |
667 | 8467 case 't': |
3630 | 8468 if (!checkclearop(oap)) |
8469 goto_tabpage((int)cap->count0); | |
667 | 8470 break; |
682 | 8471 case 'T': |
3630 | 8472 if (!checkclearop(oap)) |
8473 goto_tabpage(-(int)cap->count1); | |
682 | 8474 break; |
667 | 8475 |
750 | 8476 case '+': |
8477 case '-': /* "g+" and "g-": undo or redo along the timeline */ | |
8478 if (!checkclearopq(oap)) | |
771 | 8479 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
|
8480 FALSE, FALSE, FALSE); |
750 | 8481 break; |
8482 | |
7 | 8483 default: |
8484 clearopbeep(oap); | |
8485 break; | |
8486 } | |
8487 } | |
8488 | |
8489 /* | |
8490 * Handle "o" and "O" commands. | |
8491 */ | |
8492 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8493 n_opencmd(cmdarg_T *cap) |
7 | 8494 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8495 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8496 linenr_T oldline = curwin->w_cursor.lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8497 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8498 |
7 | 8499 if (!checkclearopq(cap->oap)) |
8500 { | |
8501 #ifdef FEAT_FOLDING | |
8502 if (cap->cmdchar == 'O') | |
8503 /* Open above the first line of a folded sequence of lines */ | |
8504 (void)hasFolding(curwin->w_cursor.lnum, | |
8505 &curwin->w_cursor.lnum, NULL); | |
8506 else | |
8507 /* Open below the last line of a folded sequence of lines */ | |
8508 (void)hasFolding(curwin->w_cursor.lnum, | |
8509 NULL, &curwin->w_cursor.lnum); | |
8510 #endif | |
8511 if (u_save((linenr_T)(curwin->w_cursor.lnum - | |
8512 (cap->cmdchar == 'O' ? 1 : 0)), | |
8513 (linenr_T)(curwin->w_cursor.lnum + | |
8514 (cap->cmdchar == 'o' ? 1 : 0)) | |
8515 ) == OK | |
8516 && open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD, | |
8517 #ifdef FEAT_COMMENTS | |
8518 has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM : | |
8519 #endif | |
8520 0, 0)) | |
8521 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8522 #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
|
8523 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
|
8524 update_single_line(curwin, oldline); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
8525 #endif |
164 | 8526 /* When '#' is in 'cpoptions' ignore the count. */ |
8527 if (vim_strchr(p_cpo, CPO_HASH) != NULL) | |
8528 cap->count1 = 1; | |
6834 | 8529 #ifdef FEAT_SYN_HL |
6821 | 8530 if (curwin->w_p_cul) |
8531 /* force redraw of cursorline */ | |
8532 curwin->w_valid &= ~VALID_CROW; | |
6834 | 8533 #endif |
7 | 8534 invoke_edit(cap, FALSE, cap->cmdchar, TRUE); |
8535 } | |
8536 } | |
8537 } | |
8538 | |
8539 /* | |
8540 * "." command: redo last change. | |
8541 */ | |
8542 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8543 nv_dot(cmdarg_T *cap) |
7 | 8544 { |
8545 if (!checkclearopq(cap->oap)) | |
8546 { | |
8547 /* | |
8548 * If "restart_edit" is TRUE, the last but one command is repeated | |
8549 * instead of the last command (inserting text). This is used for | |
8550 * CTRL-O <.> in insert mode. | |
8551 */ | |
8552 if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == FAIL) | |
8553 clearopbeep(cap->oap); | |
8554 } | |
8555 } | |
8556 | |
8557 /* | |
8558 * CTRL-R: undo undo | |
8559 */ | |
8560 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8561 nv_redo(cmdarg_T *cap) |
7 | 8562 { |
8563 if (!checkclearopq(cap->oap)) | |
8564 { | |
8565 u_redo((int)cap->count1); | |
8566 curwin->w_set_curswant = TRUE; | |
8567 } | |
8568 } | |
8569 | |
8570 /* | |
8571 * Handle "U" command. | |
8572 */ | |
8573 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8574 nv_Undo(cmdarg_T *cap) |
7 | 8575 { |
8576 /* In Visual mode and typing "gUU" triggers an operator */ | |
5735 | 8577 if (cap->oap->op_type == OP_UPPER || VIsual_active) |
7 | 8578 { |
8579 /* translate "gUU" to "gUgU" */ | |
8580 cap->cmdchar = 'g'; | |
8581 cap->nchar = 'U'; | |
8582 nv_operator(cap); | |
8583 } | |
8584 else if (!checkclearopq(cap->oap)) | |
8585 { | |
8586 u_undoline(); | |
8587 curwin->w_set_curswant = TRUE; | |
8588 } | |
8589 } | |
8590 | |
8591 /* | |
8592 * '~' command: If tilde is not an operator and Visual is off: swap case of a | |
8593 * single character. | |
8594 */ | |
8595 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8596 nv_tilde(cmdarg_T *cap) |
7 | 8597 { |
5735 | 8598 if (!p_to && !VIsual_active && cap->oap->op_type != OP_TILDE) |
7 | 8599 n_swapchar(cap); |
8600 else | |
8601 nv_operator(cap); | |
8602 } | |
8603 | |
8604 /* | |
8605 * Handle an operator command. | |
8606 * The actual work is done by do_pending_operator(). | |
8607 */ | |
8608 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8609 nv_operator(cmdarg_T *cap) |
7 | 8610 { |
8611 int op_type; | |
8612 | |
8613 op_type = get_op_type(cap->cmdchar, cap->nchar); | |
8614 | |
8615 if (op_type == cap->oap->op_type) /* double operator works on lines */ | |
8616 nv_lineop(cap); | |
8617 else if (!checkclearop(cap->oap)) | |
8618 { | |
8619 cap->oap->start = curwin->w_cursor; | |
8620 cap->oap->op_type = op_type; | |
1490 | 8621 #ifdef FEAT_EVAL |
8622 set_op_var(op_type); | |
8623 #endif | |
8624 } | |
8625 } | |
8626 | |
8627 #ifdef FEAT_EVAL | |
8628 /* | |
8629 * Set v:operator to the characters for "optype". | |
8630 */ | |
8631 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8632 set_op_var(int optype) |
1490 | 8633 { |
8634 char_u opchars[3]; | |
8635 | |
8636 if (optype == OP_NOP) | |
8637 set_vim_var_string(VV_OP, NULL, 0); | |
8638 else | |
8639 { | |
8640 opchars[0] = get_op_char(optype); | |
8641 opchars[1] = get_extra_op_char(optype); | |
8642 opchars[2] = NUL; | |
8643 set_vim_var_string(VV_OP, opchars, -1); | |
8644 } | |
8645 } | |
8646 #endif | |
7 | 8647 |
8648 /* | |
8649 * Handle linewise operator "dd", "yy", etc. | |
8650 * | |
8651 * "_" is is a strange motion command that helps make operators more logical. | |
8652 * It is actually implemented, but not documented in the real Vi. This motion | |
8653 * command actually refers to "the current line". Commands like "dd" and "yy" | |
8654 * are really an alternate form of "d_" and "y_". It does accept a count, so | |
8655 * "d3_" works to delete 3 lines. | |
8656 */ | |
8657 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8658 nv_lineop(cmdarg_T *cap) |
7 | 8659 { |
8660 cap->oap->motion_type = MLINE; | |
8661 if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL) | |
8662 clearopbeep(cap->oap); | |
4011 | 8663 else if ( (cap->oap->op_type == OP_DELETE /* only with linewise motions */ |
8664 && cap->oap->motion_force != 'v' | |
8665 && cap->oap->motion_force != Ctrl_V) | |
7 | 8666 || cap->oap->op_type == OP_LSHIFT |
8667 || cap->oap->op_type == OP_RSHIFT) | |
8668 beginline(BL_SOL | BL_FIX); | |
8669 else if (cap->oap->op_type != OP_YANK) /* 'Y' does not move cursor */ | |
8670 beginline(BL_WHITE | BL_FIX); | |
8671 } | |
8672 | |
8673 /* | |
8674 * <Home> command. | |
8675 */ | |
8676 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8677 nv_home(cmdarg_T *cap) |
7 | 8678 { |
180 | 8679 /* CTRL-HOME is like "gg" */ |
8680 if (mod_mask & MOD_MASK_CTRL) | |
8681 nv_goto(cap); | |
8682 else | |
8683 { | |
8684 cap->count0 = 1; | |
8685 nv_pipe(cap); | |
8686 } | |
229 | 8687 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8688 one-character line). */ | |
7 | 8689 } |
8690 | |
8691 /* | |
8692 * "|" command. | |
8693 */ | |
8694 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8695 nv_pipe(cmdarg_T *cap) |
7 | 8696 { |
8697 cap->oap->motion_type = MCHAR; | |
8698 cap->oap->inclusive = FALSE; | |
8699 beginline(0); | |
8700 if (cap->count0 > 0) | |
8701 { | |
8702 coladvance((colnr_T)(cap->count0 - 1)); | |
8703 curwin->w_curswant = (colnr_T)(cap->count0 - 1); | |
8704 } | |
8705 else | |
8706 curwin->w_curswant = 0; | |
8707 /* keep curswant at the column where we wanted to go, not where | |
2667 | 8708 * we ended; differs if line is too short */ |
7 | 8709 curwin->w_set_curswant = FALSE; |
8710 } | |
8711 | |
8712 /* | |
8713 * Handle back-word command "b" and "B". | |
8714 * cap->arg is 1 for "B" | |
8715 */ | |
8716 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8717 nv_bck_word(cmdarg_T *cap) |
7 | 8718 { |
8719 cap->oap->motion_type = MCHAR; | |
8720 cap->oap->inclusive = FALSE; | |
8721 curwin->w_set_curswant = TRUE; | |
8722 if (bck_word(cap->count1, cap->arg, FALSE) == FAIL) | |
8723 clearopbeep(cap->oap); | |
8724 #ifdef FEAT_FOLDING | |
8725 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8726 foldOpenCursor(); | |
8727 #endif | |
8728 } | |
8729 | |
8730 /* | |
8731 * Handle word motion commands "e", "E", "w" and "W". | |
8732 * cap->arg is TRUE for "E" and "W". | |
8733 */ | |
8734 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8735 nv_wordcmd(cmdarg_T *cap) |
7 | 8736 { |
8737 int n; | |
8738 int word_end; | |
8739 int flag = FALSE; | |
1573 | 8740 pos_T startpos = curwin->w_cursor; |
7 | 8741 |
8742 /* | |
8743 * Set inclusive for the "E" and "e" command. | |
8744 */ | |
8745 if (cap->cmdchar == 'e' || cap->cmdchar == 'E') | |
8746 word_end = TRUE; | |
8747 else | |
8748 word_end = FALSE; | |
8749 cap->oap->inclusive = word_end; | |
8750 | |
8751 /* | |
8752 * "cw" and "cW" are a special case. | |
8753 */ | |
8754 if (!word_end && cap->oap->op_type == OP_CHANGE) | |
8755 { | |
8756 n = gchar_cursor(); | |
8757 if (n != NUL) /* not an empty line */ | |
8758 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
8759 if (VIM_ISWHITE(n)) |
7 | 8760 { |
8761 /* | |
8762 * Reproduce a funny Vi behaviour: "cw" on a blank only | |
8763 * changes one character, not all blanks until the start of | |
8764 * the next word. Only do this when the 'w' flag is included | |
8765 * in 'cpoptions'. | |
8766 */ | |
8767 if (cap->count1 == 1 && vim_strchr(p_cpo, CPO_CW) != NULL) | |
8768 { | |
8769 cap->oap->inclusive = TRUE; | |
8770 cap->oap->motion_type = MCHAR; | |
8771 return; | |
8772 } | |
8773 } | |
8774 else | |
8775 { | |
8776 /* | |
8777 * This is a little strange. To match what the real Vi does, | |
8778 * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided | |
8779 * that we are not on a space or a TAB. This seems impolite | |
8780 * at first, but it's really more what we mean when we say | |
8781 * 'cw'. | |
8782 * Another strangeness: When standing on the end of a word | |
4352 | 8783 * "ce" will change until the end of the next word, but "cw" |
7 | 8784 * will change only one character! This is done by setting |
8785 * flag. | |
8786 */ | |
8787 cap->oap->inclusive = TRUE; | |
8788 word_end = TRUE; | |
8789 flag = TRUE; | |
8790 } | |
8791 } | |
8792 } | |
8793 | |
8794 cap->oap->motion_type = MCHAR; | |
8795 curwin->w_set_curswant = TRUE; | |
8796 if (word_end) | |
8797 n = end_word(cap->count1, cap->arg, flag, FALSE); | |
8798 else | |
8799 n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP); | |
8800 | |
1573 | 8801 /* Don't leave the cursor on the NUL past the end of line. Unless we |
8802 * 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
|
8803 if (LT_POS(startpos, curwin->w_cursor)) |
1505 | 8804 adjust_cursor(cap->oap); |
7 | 8805 |
8806 if (n == FAIL && cap->oap->op_type == OP_NOP) | |
8807 clearopbeep(cap->oap); | |
8808 else | |
8809 { | |
8810 adjust_for_sel(cap); | |
8811 #ifdef FEAT_FOLDING | |
8812 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8813 foldOpenCursor(); | |
8814 #endif | |
8815 } | |
8816 } | |
8817 | |
8818 /* | |
1505 | 8819 * Used after a movement command: If the cursor ends up on the NUL after the |
8820 * end of the line, may move it back to the last character and make the motion | |
8821 * inclusive. | |
8822 */ | |
8823 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8824 adjust_cursor(oparg_T *oap) |
1505 | 8825 { |
8826 /* The cursor cannot remain on the NUL when: | |
8827 * - the column is > 0 | |
8828 * - not in Visual mode or 'selection' is "o" | |
8829 * - 'virtualedit' is not "all" and not "onemore". | |
8830 */ | |
8831 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL | |
8832 && (!VIsual_active || *p_sel == 'o') | |
8833 #ifdef FEAT_VIRTUALEDIT | |
8834 && !virtual_active() && (ve_flags & VE_ONEMORE) == 0 | |
8835 #endif | |
8836 ) | |
8837 { | |
8838 --curwin->w_cursor.col; | |
8839 #ifdef FEAT_MBYTE | |
8840 /* prevent cursor from moving on the trail byte */ | |
8841 if (has_mbyte) | |
8842 mb_adjust_cursor(); | |
8843 #endif | |
8844 oap->inclusive = TRUE; | |
8845 } | |
8846 } | |
8847 | |
8848 /* | |
7 | 8849 * "0" and "^" commands. |
8850 * cap->arg is the argument for beginline(). | |
8851 */ | |
8852 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8853 nv_beginline(cmdarg_T *cap) |
7 | 8854 { |
8855 cap->oap->motion_type = MCHAR; | |
8856 cap->oap->inclusive = FALSE; | |
8857 beginline(cap->arg); | |
8858 #ifdef FEAT_FOLDING | |
8859 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8860 foldOpenCursor(); | |
8861 #endif | |
557 | 8862 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a |
8863 one-character line). */ | |
7 | 8864 } |
8865 | |
8866 /* | |
8867 * In exclusive Visual mode, may include the last character. | |
8868 */ | |
8869 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8870 adjust_for_sel(cmdarg_T *cap) |
7 | 8871 { |
8872 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
|
8873 && gchar_cursor() != NUL && LT_POS(VIsual, curwin->w_cursor)) |
7 | 8874 { |
5735 | 8875 #ifdef FEAT_MBYTE |
7 | 8876 if (has_mbyte) |
8877 inc_cursor(); | |
8878 else | |
5735 | 8879 #endif |
7 | 8880 ++curwin->w_cursor.col; |
8881 cap->oap->inclusive = FALSE; | |
8882 } | |
8883 } | |
8884 | |
8885 /* | |
8886 * Exclude last character at end of Visual area for 'selection' == "exclusive". | |
8887 * Should check VIsual_mode before calling this. | |
8888 * Returns TRUE when backed up to the previous line. | |
8889 */ | |
8890 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8891 unadjust_for_sel(void) |
7 | 8892 { |
8893 pos_T *pp; | |
8894 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8895 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
|
8896 { |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10980
diff
changeset
|
8897 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 8898 pp = &curwin->w_cursor; |
8899 else | |
8900 pp = &VIsual; | |
8901 #ifdef FEAT_VIRTUALEDIT | |
8902 if (pp->coladd > 0) | |
8903 --pp->coladd; | |
8904 else | |
8905 #endif | |
8906 if (pp->col > 0) | |
8907 { | |
8908 --pp->col; | |
8909 #ifdef FEAT_MBYTE | |
2933 | 8910 mb_adjustpos(curbuf, pp); |
7 | 8911 #endif |
8912 } | |
8913 else if (pp->lnum > 1) | |
8914 { | |
8915 --pp->lnum; | |
8916 pp->col = (colnr_T)STRLEN(ml_get(pp->lnum)); | |
8917 return TRUE; | |
8918 } | |
8919 } | |
8920 return FALSE; | |
8921 } | |
8922 | |
8923 /* | |
8924 * SELECT key in Normal or Visual mode: end of Select mode mapping. | |
8925 */ | |
8926 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8927 nv_select(cmdarg_T *cap) |
7 | 8928 { |
8929 if (VIsual_active) | |
8930 VIsual_select = TRUE; | |
8931 else if (VIsual_reselect) | |
8932 { | |
8933 cap->nchar = 'v'; /* fake "gv" command */ | |
8934 cap->arg = TRUE; | |
8935 nv_g_cmd(cap); | |
8936 } | |
8937 } | |
8938 | |
8939 | |
8940 /* | |
8941 * "G", "gg", CTRL-END, CTRL-HOME. | |
8942 * cap->arg is TRUE for "G". | |
8943 */ | |
8944 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8945 nv_goto(cmdarg_T *cap) |
7 | 8946 { |
8947 linenr_T lnum; | |
8948 | |
8949 if (cap->arg) | |
8950 lnum = curbuf->b_ml.ml_line_count; | |
8951 else | |
8952 lnum = 1L; | |
8953 cap->oap->motion_type = MLINE; | |
8954 setpcmark(); | |
8955 | |
8956 /* When a count is given, use it instead of the default lnum */ | |
8957 if (cap->count0 != 0) | |
8958 lnum = cap->count0; | |
8959 if (lnum < 1L) | |
8960 lnum = 1L; | |
8961 else if (lnum > curbuf->b_ml.ml_line_count) | |
8962 lnum = curbuf->b_ml.ml_line_count; | |
8963 curwin->w_cursor.lnum = lnum; | |
8964 beginline(BL_SOL | BL_FIX); | |
8965 #ifdef FEAT_FOLDING | |
8966 if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP) | |
8967 foldOpenCursor(); | |
8968 #endif | |
8969 } | |
8970 | |
8971 /* | |
8972 * CTRL-\ in Normal mode. | |
8973 */ | |
8974 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
8975 nv_normal(cmdarg_T *cap) |
7 | 8976 { |
8977 if (cap->nchar == Ctrl_N || cap->nchar == Ctrl_G) | |
8978 { | |
8979 clearop(cap->oap); | |
643 | 8980 if (restart_edit != 0 && mode_displayed) |
7 | 8981 clear_cmdline = TRUE; /* unshow mode later */ |
8982 restart_edit = 0; | |
8983 #ifdef FEAT_CMDWIN | |
8984 if (cmdwin_type != 0) | |
8985 cmdwin_result = Ctrl_C; | |
8986 #endif | |
8987 if (VIsual_active) | |
8988 { | |
8989 end_visual_mode(); /* stop Visual */ | |
8990 redraw_curbuf_later(INVERTED); | |
8991 } | |
8992 /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */ | |
8993 if (cap->nchar == Ctrl_G && p_im) | |
8994 restart_edit = 'a'; | |
8995 } | |
8996 else | |
8997 clearopbeep(cap->oap); | |
8998 } | |
8999 | |
9000 /* | |
9001 * ESC in Normal mode: beep, but don't flush buffers. | |
9002 * Don't even beep if we are canceling a command. | |
9003 */ | |
9004 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9005 nv_esc(cmdarg_T *cap) |
7 | 9006 { |
9007 int no_reason; | |
9008 | |
9009 no_reason = (cap->oap->op_type == OP_NOP | |
9010 && cap->opcount == 0 | |
9011 && cap->count0 == 0 | |
9012 && cap->oap->regname == 0 | |
9013 && !p_im); | |
9014 | |
9015 if (cap->arg) /* TRUE for CTRL-C */ | |
9016 { | |
9017 if (restart_edit == 0 | |
9018 #ifdef FEAT_CMDWIN | |
9019 && cmdwin_type == 0 | |
9020 #endif | |
9021 && !VIsual_active | |
9022 && 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
|
9023 MSG(_("Type :qa! and press <Enter> to abandon all changes and exit Vim")); |
7 | 9024 |
9025 /* Don't reset "restart_edit" when 'insertmode' is set, it won't be | |
9026 * set again below when halfway a mapping. */ | |
9027 if (!p_im) | |
9028 restart_edit = 0; | |
9029 #ifdef FEAT_CMDWIN | |
9030 if (cmdwin_type != 0) | |
9031 { | |
9032 cmdwin_result = K_IGNORE; | |
9033 got_int = FALSE; /* don't stop executing autocommands et al. */ | |
9034 return; | |
9035 } | |
9036 #endif | |
9037 } | |
9038 | |
9039 if (VIsual_active) | |
9040 { | |
9041 end_visual_mode(); /* stop Visual */ | |
9042 check_cursor_col(); /* make sure cursor is not beyond EOL */ | |
9043 curwin->w_set_curswant = TRUE; | |
9044 redraw_curbuf_later(INVERTED); | |
9045 } | |
5735 | 9046 else if (no_reason) |
6949 | 9047 vim_beep(BO_ESC); |
7 | 9048 clearop(cap->oap); |
9049 | |
9050 /* A CTRL-C is often used at the start of a menu. When 'insertmode' is | |
9051 * 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
|
9052 if (restart_edit == 0 && goto_im() && ex_normal_busy == 0) |
7 | 9053 restart_edit = 'a'; |
9054 } | |
9055 | |
9056 /* | |
9057 * 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
|
9058 * Also handle K_PS, start bracketed paste. |
7 | 9059 */ |
9060 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9061 nv_edit(cmdarg_T *cap) |
7 | 9062 { |
9063 /* <Insert> is equal to "i" */ | |
9064 if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS) | |
9065 cap->cmdchar = 'i'; | |
9066 | |
9067 /* in Visual mode "A" and "I" are an operator */ | |
9068 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
|
9069 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9070 #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
|
9071 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
|
9072 { |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9073 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
|
9074 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
|
9075 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
|
9076 return; |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9077 } |
66fe20238c1d
patch 8.0.1113: can go to Insert mode from Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
12423
diff
changeset
|
9078 #endif |
7 | 9079 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
|
9080 } |
7 | 9081 |
9082 /* in Visual mode and after an operator "a" and "i" are for text objects */ | |
5735 | 9083 else if ((cap->cmdchar == 'a' || cap->cmdchar == 'i') |
9084 && (cap->oap->op_type != OP_NOP || VIsual_active)) | |
7 | 9085 { |
9086 #ifdef FEAT_TEXTOBJ | |
9087 nv_object(cap); | |
9088 #else | |
9089 clearopbeep(cap->oap); | |
9090 #endif | |
9091 } | |
11892
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9092 #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
|
9093 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
|
9094 { |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9095 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
|
9096 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
|
9097 return; |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9098 } |
50ad151a7482
patch 8.0.0826: cannot use text objects in Terminal mode
Christian Brabandt <cb@256bit.org>
parents:
11866
diff
changeset
|
9099 #endif |
7 | 9100 else if (!curbuf->b_p_ma && !p_im) |
9101 { | |
9102 /* Only give this error when 'insertmode' is off. */ | |
9103 EMSG(_(e_modifiable)); | |
9104 clearop(cap->oap); | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9105 if (cap->cmdchar == K_PS) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9106 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9107 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 9108 } |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9109 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
|
9110 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9111 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
|
9112 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
|
9113 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9114 /* 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
|
9115 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
|
9116 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9117 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
|
9118 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
|
9119 } |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9120 else |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9121 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
|
9122 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
|
9123 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
|
9124 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
|
9125 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
|
9126 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
|
9127 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9128 /* 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
|
9129 * 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
|
9130 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
|
9131 && 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
|
9132 inc_cursor(); |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9133 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9134 /* 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
|
9135 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
|
9136 } |
7 | 9137 else if (!checkclearopq(cap->oap)) |
9138 { | |
9139 switch (cap->cmdchar) | |
9140 { | |
9141 case 'A': /* "A"ppend after the line */ | |
9142 curwin->w_set_curswant = TRUE; | |
9143 #ifdef FEAT_VIRTUALEDIT | |
9144 if (ve_flags == VE_ALL) | |
9145 { | |
9146 int save_State = State; | |
9147 | |
4352 | 9148 /* Pretend Insert mode here to allow the cursor on the |
7 | 9149 * character past the end of the line */ |
9150 State = INSERT; | |
9151 coladvance((colnr_T)MAXCOL); | |
9152 State = save_State; | |
9153 } | |
9154 else | |
9155 #endif | |
9156 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor()); | |
9157 break; | |
9158 | |
9159 case 'I': /* "I"nsert before the first non-blank */ | |
164 | 9160 if (vim_strchr(p_cpo, CPO_INSEND) == NULL) |
9161 beginline(BL_WHITE); | |
9162 else | |
9163 beginline(BL_WHITE|BL_FIX); | |
7 | 9164 break; |
9165 | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10813
diff
changeset
|
9166 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
|
9167 /* 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
|
9168 * 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
|
9169 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
|
9170 break; |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12646
diff
changeset
|
9171 /* FALLTHROUGH */ |
10813
09eb5fd275e0
patch 8.0.0296: bracketed paste can only append, not insert
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
9172 |
7 | 9173 case 'a': /* "a"ppend is like "i"nsert on the next character. */ |
9174 #ifdef FEAT_VIRTUALEDIT | |
9175 /* increment coladd when in virtual space, increment the | |
9176 * column otherwise, also to append after an unprintable char */ | |
9177 if (virtual_active() | |
9178 && (curwin->w_cursor.coladd > 0 | |
9179 || *ml_get_cursor() == NUL | |
9180 || *ml_get_cursor() == TAB)) | |
9181 curwin->w_cursor.coladd++; | |
9182 else | |
9183 #endif | |
9184 if (*ml_get_cursor() != NUL) | |
9185 inc_cursor(); | |
9186 break; | |
9187 } | |
9188 | |
9189 #ifdef FEAT_VIRTUALEDIT | |
9190 if (curwin->w_cursor.coladd && cap->cmdchar != 'A') | |
9191 { | |
9192 int save_State = State; | |
9193 | |
4352 | 9194 /* Pretend Insert mode here to allow the cursor on the |
7 | 9195 * character past the end of the line */ |
9196 State = INSERT; | |
9197 coladvance(getviscol()); | |
9198 State = save_State; | |
9199 } | |
9200 #endif | |
9201 | |
9202 invoke_edit(cap, FALSE, cap->cmdchar, FALSE); | |
9203 } | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9204 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
|
9205 /* drop the pasted text */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
9206 bracketed_paste(PASTE_INSERT, TRUE, NULL); |
7 | 9207 } |
9208 | |
9209 /* | |
9210 * Invoke edit() and take care of "restart_edit" and the return value. | |
9211 */ | |
9212 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9213 invoke_edit( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9214 cmdarg_T *cap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9215 int repl, /* "r" or "gr" command */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9216 int cmd, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9217 int startln) |
7 | 9218 { |
9219 int restart_edit_save = 0; | |
9220 | |
9221 /* Complicated: When the user types "a<C-O>a" we don't want to do Insert | |
9222 * mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow | |
9223 * it. */ | |
9224 if (repl || !stuff_empty()) | |
9225 restart_edit_save = restart_edit; | |
9226 else | |
9227 restart_edit_save = 0; | |
9228 | |
9229 /* Always reset "restart_edit", this is not a restarted edit. */ | |
9230 restart_edit = 0; | |
9231 | |
9232 if (edit(cmd, startln, cap->count1)) | |
9233 cap->retval |= CA_COMMAND_BUSY; | |
9234 | |
9235 if (restart_edit == 0) | |
9236 restart_edit = restart_edit_save; | |
9237 } | |
9238 | |
9239 #ifdef FEAT_TEXTOBJ | |
9240 /* | |
9241 * "a" or "i" while an operator is pending or in Visual mode: object motion. | |
9242 */ | |
9243 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9244 nv_object( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9245 cmdarg_T *cap) |
7 | 9246 { |
9247 int flag; | |
9248 int include; | |
9249 char_u *mps_save; | |
9250 | |
9251 if (cap->cmdchar == 'i') | |
9252 include = FALSE; /* "ix" = inner object: exclude white space */ | |
9253 else | |
9254 include = TRUE; /* "ax" = an object: include white space */ | |
9255 | |
9256 /* Make sure (), [], {} and <> are in 'matchpairs' */ | |
9257 mps_save = curbuf->b_p_mps; | |
9258 curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>"; | |
9259 | |
9260 switch (cap->nchar) | |
9261 { | |
9262 case 'w': /* "aw" = a word */ | |
9263 flag = current_word(cap->oap, cap->count1, include, FALSE); | |
9264 break; | |
9265 case 'W': /* "aW" = a WORD */ | |
9266 flag = current_word(cap->oap, cap->count1, include, TRUE); | |
9267 break; | |
9268 case 'b': /* "ab" = a braces block */ | |
9269 case '(': | |
9270 case ')': | |
9271 flag = current_block(cap->oap, cap->count1, include, '(', ')'); | |
9272 break; | |
9273 case 'B': /* "aB" = a Brackets block */ | |
9274 case '{': | |
9275 case '}': | |
9276 flag = current_block(cap->oap, cap->count1, include, '{', '}'); | |
9277 break; | |
9278 case '[': /* "a[" = a [] block */ | |
9279 case ']': | |
9280 flag = current_block(cap->oap, cap->count1, include, '[', ']'); | |
9281 break; | |
9282 case '<': /* "a<" = a <> block */ | |
9283 case '>': | |
9284 flag = current_block(cap->oap, cap->count1, include, '<', '>'); | |
9285 break; | |
420 | 9286 case 't': /* "at" = a tag block (xml and html) */ |
6661 | 9287 /* Do not adjust oap->end in do_pending_operator() |
9288 * otherwise there are different results for 'dit' | |
9289 * (note leading whitespace in last line): | |
9290 * 1) <b> 2) <b> | |
9291 * foobar foobar | |
9292 * </b> </b> | |
9293 */ | |
9294 cap->retval |= CA_NO_ADJ_OP_END; | |
420 | 9295 flag = current_tagblock(cap->oap, cap->count1, include); |
9296 break; | |
7 | 9297 case 'p': /* "ap" = a paragraph */ |
9298 flag = current_par(cap->oap, cap->count1, include, 'p'); | |
9299 break; | |
9300 case 's': /* "as" = a sentence */ | |
9301 flag = current_sent(cap->oap, cap->count1, include); | |
9302 break; | |
12 | 9303 case '"': /* "a"" = a double quoted string */ |
9304 case '\'': /* "a'" = a single quoted string */ | |
9305 case '`': /* "a`" = a backtick quoted string */ | |
9306 flag = current_quote(cap->oap, cap->count1, include, | |
9307 cap->nchar); | |
9308 break; | |
7 | 9309 #if 0 /* TODO */ |
9310 case 'S': /* "aS" = a section */ | |
9311 case 'f': /* "af" = a filename */ | |
9312 case 'u': /* "au" = a URL */ | |
9313 #endif | |
9314 default: | |
9315 flag = FAIL; | |
9316 break; | |
9317 } | |
9318 | |
9319 curbuf->b_p_mps = mps_save; | |
9320 if (flag == FAIL) | |
9321 clearopbeep(cap->oap); | |
9322 adjust_cursor_col(); | |
9323 curwin->w_set_curswant = TRUE; | |
9324 } | |
9325 #endif | |
9326 | |
9327 /* | |
9328 * "q" command: Start/stop recording. | |
9329 * "q:", "q/", "q?": edit command-line in command-line window. | |
9330 */ | |
9331 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9332 nv_record(cmdarg_T *cap) |
7 | 9333 { |
9334 if (cap->oap->op_type == OP_FORMAT) | |
9335 { | |
9336 /* "gqq" is the same as "gqgq": format line */ | |
9337 cap->cmdchar = 'g'; | |
9338 cap->nchar = 'q'; | |
9339 nv_operator(cap); | |
9340 } | |
9341 else if (!checkclearop(cap->oap)) | |
9342 { | |
9343 #ifdef FEAT_CMDWIN | |
9344 if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?') | |
9345 { | |
9346 stuffcharReadbuff(cap->nchar); | |
9347 stuffcharReadbuff(K_CMDWIN); | |
9348 } | |
9349 else | |
9350 #endif | |
9351 /* (stop) recording into a named register, unless executing a | |
9352 * register */ | |
9353 if (!Exec_reg && do_record(cap->nchar) == FAIL) | |
9354 clearopbeep(cap->oap); | |
9355 } | |
9356 } | |
9357 | |
9358 /* | |
9359 * Handle the "@r" command. | |
9360 */ | |
9361 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9362 nv_at(cmdarg_T *cap) |
7 | 9363 { |
9364 if (checkclearop(cap->oap)) | |
9365 return; | |
9366 #ifdef FEAT_EVAL | |
9367 if (cap->nchar == '=') | |
9368 { | |
9369 if (get_expr_register() == NUL) | |
9370 return; | |
9371 } | |
9372 #endif | |
9373 while (cap->count1-- && !got_int) | |
9374 { | |
1034 | 9375 if (do_execreg(cap->nchar, FALSE, FALSE, FALSE) == FAIL) |
7 | 9376 { |
9377 clearopbeep(cap->oap); | |
9378 break; | |
9379 } | |
9380 line_breakcheck(); | |
9381 } | |
9382 } | |
9383 | |
9384 /* | |
9385 * Handle the CTRL-U and CTRL-D commands. | |
9386 */ | |
9387 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9388 nv_halfpage(cmdarg_T *cap) |
7 | 9389 { |
9390 if ((cap->cmdchar == Ctrl_U && curwin->w_cursor.lnum == 1) | |
9391 || (cap->cmdchar == Ctrl_D | |
9392 && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)) | |
9393 clearopbeep(cap->oap); | |
9394 else if (!checkclearop(cap->oap)) | |
9395 halfpage(cap->cmdchar == Ctrl_D, cap->count0); | |
9396 } | |
9397 | |
9398 /* | |
9399 * Handle "J" or "gJ" command. | |
9400 */ | |
9401 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9402 nv_join(cmdarg_T *cap) |
7 | 9403 { |
9404 if (VIsual_active) /* join the visual lines */ | |
9405 nv_operator(cap); | |
5735 | 9406 else if (!checkclearop(cap->oap)) |
7 | 9407 { |
9408 if (cap->count0 <= 1) | |
9409 cap->count0 = 2; /* default for join is two lines! */ | |
9410 if (curwin->w_cursor.lnum + cap->count0 - 1 > | |
9411 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
|
9412 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9413 /* 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
|
9414 if (cap->count0 <= 2) |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9415 { |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9416 clearopbeep(cap->oap); |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9417 return; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9418 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9419 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
|
9420 - curwin->w_cursor.lnum + 1; |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9421 } |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9422 |
dd2e2bd69d0e
commit https://github.com/vim/vim/commit/41e0f2f48f541eb2c8eb5620d3f1d270eb979154
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
9423 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
|
9424 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
|
9425 (void)do_join(cap->count0, cap->nchar == NUL, TRUE, TRUE, TRUE); |
7 | 9426 } |
9427 } | |
9428 | |
9429 /* | |
9430 * "P", "gP", "p" and "gp" commands. | |
9431 */ | |
9432 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9433 nv_put(cmdarg_T *cap) |
7 | 9434 { |
9435 int regname = 0; | |
9436 void *reg1 = NULL, *reg2 = NULL; | |
84 | 9437 int empty = FALSE; |
236 | 9438 int was_visual = FALSE; |
7 | 9439 int dir; |
9440 int flags = 0; | |
9441 | |
9442 if (cap->oap->op_type != OP_NOP) | |
9443 { | |
9444 #ifdef FEAT_DIFF | |
9445 /* "dp" is ":diffput" */ | |
9446 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p') | |
9447 { | |
9448 clearop(cap->oap); | |
6314 | 9449 nv_diffgetput(TRUE, cap->opcount); |
7 | 9450 } |
9451 else | |
9452 #endif | |
9453 clearopbeep(cap->oap); | |
9454 } | |
9455 else | |
9456 { | |
9457 dir = (cap->cmdchar == 'P' | |
9458 || (cap->cmdchar == 'g' && cap->nchar == 'P')) | |
9459 ? BACKWARD : FORWARD; | |
9460 prep_redo_cmd(cap); | |
9461 if (cap->cmdchar == 'g') | |
9462 flags |= PUT_CURSEND; | |
9463 | |
9464 if (VIsual_active) | |
9465 { | |
9466 /* Putting in Visual mode: The put text replaces the selected | |
9467 * text. First delete the selected text, then put the new text. | |
9468 * Need to save and restore the registers that the delete | |
9469 * overwrites if the old contents is being put. | |
9470 */ | |
236 | 9471 was_visual = TRUE; |
7 | 9472 regname = cap->oap->regname; |
5735 | 9473 #ifdef FEAT_CLIPBOARD |
7 | 9474 adjust_clip_reg(®name); |
5735 | 9475 #endif |
5682 | 9476 if (regname == 0 || regname == '"' |
4013 | 9477 || VIM_ISDIGIT(regname) || regname == '-' |
5735 | 9478 #ifdef FEAT_CLIPBOARD |
7 | 9479 || (clip_unnamed && (regname == '*' || regname == '+')) |
5735 | 9480 #endif |
7 | 9481 |
9482 ) | |
9483 { | |
4013 | 9484 /* The delete is going to overwrite the register we want to |
7 | 9485 * put, save it first. */ |
9486 reg1 = get_register(regname, TRUE); | |
9487 } | |
9488 | |
9489 /* Now delete the selected text. */ | |
9490 cap->cmdchar = 'd'; | |
9491 cap->nchar = NUL; | |
9492 cap->oap->regname = NUL; | |
9493 nv_operator(cap); | |
9494 do_pending_operator(cap, 0, FALSE); | |
84 | 9495 empty = (curbuf->b_ml.ml_flags & ML_EMPTY); |
7 | 9496 |
9497 /* delete PUT_LINE_BACKWARD; */ | |
9498 cap->oap->regname = regname; | |
9499 | |
9500 if (reg1 != NULL) | |
9501 { | |
9502 /* Delete probably changed the register we want to put, save | |
9503 * it first. Then put back what was there before the delete. */ | |
9504 reg2 = get_register(regname, FALSE); | |
9505 put_register(regname, reg1); | |
9506 } | |
9507 | |
9508 /* When deleted a linewise Visual area, put the register as | |
9509 * lines to avoid it joined with the next line. When deletion was | |
9510 * characterwise, split a line when putting lines. */ | |
9511 if (VIsual_mode == 'V') | |
9512 flags |= PUT_LINE; | |
9513 else if (VIsual_mode == 'v') | |
9514 flags |= PUT_LINE_SPLIT; | |
9515 if (VIsual_mode == Ctrl_V && dir == FORWARD) | |
9516 flags |= PUT_LINE_FORWARD; | |
9517 dir = BACKWARD; | |
9518 if ((VIsual_mode != 'V' | |
9519 && curwin->w_cursor.col < curbuf->b_op_start.col) | |
9520 || (VIsual_mode == 'V' | |
9521 && curwin->w_cursor.lnum < curbuf->b_op_start.lnum)) | |
9522 /* cursor is at the end of the line or end of file, put | |
9523 * forward. */ | |
9524 dir = FORWARD; | |
5365 | 9525 /* May have been reset in do_put(). */ |
9526 VIsual_active = TRUE; | |
7 | 9527 } |
9528 do_put(cap->oap->regname, dir, cap->count1, flags); | |
9529 | |
9530 /* If a register was saved, put it back now. */ | |
9531 if (reg2 != NULL) | |
9532 put_register(regname, reg2); | |
236 | 9533 |
9534 /* What to reselect with "gv"? Selecting the just put text seems to | |
9535 * be the most useful, since the original text was removed. */ | |
9536 if (was_visual) | |
9537 { | |
690 | 9538 curbuf->b_visual.vi_start = curbuf->b_op_start; |
9539 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
|
9540 /* need to adjust cursor position */ |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
9541 if (*p_sel == 'e') |
0c1278704b5c
commit https://github.com/vim/vim/commit/d29c6fea94947b3f4b54fbd5a6f832a7d744bf27
Christian Brabandt <cb@256bit.org>
parents:
7143
diff
changeset
|
9542 inc(&curbuf->b_visual.vi_end); |
236 | 9543 } |
9544 | |
84 | 9545 /* When all lines were selected and deleted do_put() leaves an empty |
236 | 9546 * line that needs to be deleted now. */ |
84 | 9547 if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL) |
817 | 9548 { |
84 | 9549 ml_delete(curbuf->b_ml.ml_line_count, TRUE); |
817 | 9550 |
9551 /* If the cursor was in that line, move it to the end of the last | |
9552 * line. */ | |
9553 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
9554 { | |
9555 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
9556 coladvance((colnr_T)MAXCOL); | |
9557 } | |
9558 } | |
7 | 9559 auto_format(FALSE, TRUE); |
9560 } | |
9561 } | |
9562 | |
9563 /* | |
9564 * "o" and "O" commands. | |
9565 */ | |
9566 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9567 nv_open(cmdarg_T *cap) |
7 | 9568 { |
9569 #ifdef FEAT_DIFF | |
9570 /* "do" is ":diffget" */ | |
9571 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o') | |
9572 { | |
9573 clearop(cap->oap); | |
6314 | 9574 nv_diffgetput(FALSE, cap->opcount); |
7 | 9575 } |
9576 else | |
9577 #endif | |
9578 if (VIsual_active) /* switch start and end of visual */ | |
9579 v_swap_corners(cap->cmdchar); | |
9580 else | |
9581 n_opencmd(cap); | |
9582 } | |
9583 | |
9584 #ifdef FEAT_NETBEANS_INTG | |
9585 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9586 nv_nbcmd(cmdarg_T *cap) |
7 | 9587 { |
9588 netbeans_keycommand(cap->nchar); | |
9589 } | |
9590 #endif | |
9591 | |
9592 #ifdef FEAT_DND | |
9593 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9594 nv_drop(cmdarg_T *cap UNUSED) |
7 | 9595 { |
9596 do_put('~', BACKWARD, 1L, PUT_CURSEND); | |
9597 } | |
9598 #endif | |
203 | 9599 |
9600 #ifdef FEAT_AUTOCMD | |
9601 /* | |
9602 * Trigger CursorHold event. | |
9603 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the | |
9604 * input buffer. "did_cursorhold" is set to avoid retriggering. | |
9605 */ | |
9606 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9607 nv_cursorhold(cmdarg_T *cap) |
203 | 9608 { |
9609 apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf); | |
9610 did_cursorhold = TRUE; | |
226 | 9611 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */ |
9612 } | |
9613 #endif | |
6866 | 9614 |
9615 /* | |
7001 | 9616 * Calculate start/end virtual columns for operating in block mode. |
6866 | 9617 */ |
9618 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9619 get_op_vcol( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9620 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9621 colnr_T redo_VIsual_vcol, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
9622 int initial) /* when TRUE adjust position for 'selectmode' */ |
6866 | 9623 { |
9624 colnr_T start, end; | |
9625 | |
7001 | 9626 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
|
9627 || (!initial && oap->end.col < curwin->w_width)) |
6866 | 9628 return; |
9629 | |
7143
fe6d525d12f4
commit https://github.com/vim/vim/commit/10ad1d90da8c464e1bf08bf23d92d4888378a8a1
Christian Brabandt <cb@256bit.org>
parents:
7090
diff
changeset
|
9630 oap->block_mode = TRUE; |
6866 | 9631 |
9632 #ifdef FEAT_MBYTE | |
9633 /* prevent from moving onto a trail byte */ | |
9634 if (has_mbyte) | |
9635 mb_adjustpos(curwin->w_buffer, &oap->end); | |
9636 #endif | |
9637 | |
9638 getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol); | |
6961 | 9639 |
9640 if (!redo_VIsual_busy) | |
9641 { | |
9642 getvvcol(curwin, &(oap->end), &start, NULL, &end); | |
9643 | |
9644 if (start < oap->start_vcol) | |
9645 oap->start_vcol = start; | |
9646 if (end > oap->end_vcol) | |
9647 { | |
9648 if (initial && *p_sel == 'e' && start >= 1 | |
9649 && start - 1 >= oap->end_vcol) | |
9650 oap->end_vcol = start - 1; | |
9651 else | |
9652 oap->end_vcol = end; | |
9653 } | |
9654 } | |
9655 | |
6866 | 9656 /* if '$' was used, get oap->end_vcol from longest line */ |
9657 if (curwin->w_curswant == MAXCOL) | |
9658 { | |
9659 curwin->w_cursor.col = MAXCOL; | |
9660 oap->end_vcol = 0; | |
9661 for (curwin->w_cursor.lnum = oap->start.lnum; | |
9662 curwin->w_cursor.lnum <= oap->end.lnum; | |
9663 ++curwin->w_cursor.lnum) | |
9664 { | |
9665 getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end); | |
9666 if (end > oap->end_vcol) | |
9667 oap->end_vcol = end; | |
9668 } | |
9669 } | |
9670 else if (redo_VIsual_busy) | |
9671 oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1; | |
9672 /* | |
9673 * Correct oap->end.col and oap->start.col to be the | |
9674 * upper-left and lower-right corner of the block area. | |
9675 * | |
9676 * (Actually, this does convert column positions into character | |
9677 * positions) | |
9678 */ | |
9679 curwin->w_cursor.lnum = oap->end.lnum; | |
9680 coladvance(oap->end_vcol); | |
9681 oap->end = curwin->w_cursor; | |
9682 | |
9683 curwin->w_cursor = oap->start; | |
9684 coladvance(oap->start_vcol); | |
9685 oap->start = curwin->w_cursor; | |
9686 } |